Skip to content

Commit f8bf179

Browse files
authored
Add typescript (#1159)
* Add tsconifg and webpack changes * Change extension.js file to ts * Rename all the things * Quiet some errors * Update package.json * Move amd-public-path * Change require to import for controls * Change require to import for layers part 1 * Change require to import for layers part 2 * Change rest of files to import * Stragglers * Add CSS folder * technically builds * Change register stuff * Temp comment out tilelayer stuff * Add files to package.json * Fix imports * Update gitignore * Update package.json and lockfile * Prettier things * eslint things * Remove commented code
1 parent 57b78a5 commit f8bf179

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+992
-800
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ ui-tests/.yarn/
1212
ipyleaflet/nbextension/
1313
ipyleaflet/labextension/
1414
js/dist/
15+
js/lib/
1516

1617
# OS X
1718
.DS_Store

js/.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
dist
3+
lib

js/.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
22
dist
3+
lib
File renamed without changes.

js/package.json

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,36 @@
88
"jupyterlab-extension",
99
"widgets"
1010
],
11+
"files": [
12+
"css/",
13+
"lib/"
14+
],
1115
"repository": {
1216
"type": "git",
1317
"url": "https://github.com/jupyter-widgets/ipyleaflet.git"
1418
},
1519
"license": "MIT",
1620
"author": "Project Jupyter",
17-
"main": "src/index.js",
21+
"main": "lib/index.js",
22+
"types": "./lib/index.d.ts",
1823
"scripts": {
19-
"build": "webpack && jupyter labextension build .",
20-
"clean": "rimraf dist/ && rimraf ../ipyleaflet/labextension/ && rimraf ../ipyleaflet/nbextension",
21-
"prepublish": "npm run clean && npm run build",
22-
"test": "echo \"Error: no test specified\" && exit 1",
23-
"watch": "run-p watch:src watch:labextension",
24-
"watch:src": "webpack --watch",
25-
"watch:labextension": "jupyter labextension watch .",
26-
"lint": "eslint . --fix && prettier --write .",
27-
"lint:check": "eslint . && prettier ."
24+
"build": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension",
25+
"build:lib": "tsc",
26+
"build:nbextension": "webpack --no-devtool",
27+
"build:labextension": "jupyter labextension build .",
28+
"build:extensions": "yarn run build && yarn run build:labextension",
29+
"clean": "yarn run clean:lib && yarn run clean:nbextension && yarn run clean:labextension",
30+
"clean:lib": "rimraf lib",
31+
"clean:nbextension": "rimraf ../ipyleaflet/nbextension/index.js",
32+
"clean:labextension": "rimraf ../ipyleaflet/labextension",
33+
"lint": "yarn prettier && yarn eslint",
34+
"lint:check": "yarn prettier:check && yarn eslint",
35+
"prettier": "yarn prettier:base --write --list-different",
36+
"prettier:base": "prettier \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}\"",
37+
"prettier:check": "yarn prettier:base --check",
38+
"prepack": "yarn run build",
39+
"watch:lib": "tsc -w",
40+
"watch:nbextension": "webpack --watch"
2841
},
2942
"dependencies": {
3043
"@jupyter-widgets/base": "^2 || ^3 || ^4 || ^5 || ^6",
@@ -52,6 +65,9 @@
5265
},
5366
"devDependencies": {
5467
"@jupyterlab/builder": "^4.0.8",
68+
"@types/leaflet": "^1.9.8",
69+
"@types/node": "^20.10.5",
70+
"@types/webpack-env": "^1.18.4",
5571
"css-loader": "^3.4.2",
5672
"eslint": "^8.23.1",
5773
"eslint-config-prettier": "^8.5.0",
@@ -64,12 +80,15 @@
6480
"npm-run-all": "^4.1.5",
6581
"prettier": "^2.7.1",
6682
"rimraf": "^2.6.1",
83+
"source-map-loader": "^4.0.1",
6784
"style-loader": "^1.1.2",
85+
"ts-loader": "^9.5.1",
86+
"typescript": "^5.3.3",
6887
"webpack": "^5",
6988
"webpack-cli": "^5.1.4"
7089
},
7190
"jupyterlab": {
72-
"extension": "src/jupyterlab-plugin",
91+
"extension": "lib/jupyterlab-plugin",
7392
"outputDir": "../ipyleaflet/labextension",
7493
"webpackConfig": "webpack.lab.config.js",
7594
"sharedPackages": {

js/src/Map.js renamed to js/src/Map.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
3+
// @ts-nocheck
34

4-
const widgets = require('@jupyter-widgets/base');
5-
const L = require('./leaflet.js');
6-
const utils = require('./utils.js');
7-
const proj = require('./projections.js');
5+
import * as widgets from '@jupyter-widgets/base';
6+
import L from './leaflet';
7+
import * as utils from './utils';
8+
import * as proj from './projections';
89

910
const DEFAULT_LOCATION = [0.0, 0.0];
1011

@@ -448,7 +449,7 @@ export class LeafletMapView extends utils.LeafletDOMWidgetView {
448449

449450
_processLuminoMessage(msg, _super) {
450451
_super.call(this, msg);
451-
if(!this.obj) return;
452+
if (!this.obj) return;
452453
switch (msg.type) {
453454
case 'resize':
454455
// We set the dirty flag to true to prevent the sub-pixel error

js/amd-public-path.js renamed to js/src/amd-public-path.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// In an AMD module, we set the public path using the magic requirejs 'module' dependency
22
// See https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#module
33
// Since 'module' is a requirejs magic module, we must include 'module' in the webpack externals configuration.
4-
var module = require('module');
4+
// @ts-nocheck
5+
6+
import * as module from 'module';
57
var url = new URL(module.uri, document.location);
68
// Using lastIndexOf('/')+1 gives us the empty string if there is no '/', so pathname becomes '/'
79
url.pathname = url.pathname.slice(0, url.pathname.lastIndexOf('/') + 1);

js/src/controls/AttributionControl.js renamed to js/src/controls/AttributionControl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
3+
//@ts-nocheck
34

4-
const L = require('../leaflet.js');
5-
const control = require('./Control.js');
5+
import L from '../leaflet';
6+
import * as control from './Control';
67

78
export class LeafletAttributionControlModel extends control.LeafletControlModel {
89
defaults() {

js/src/controls/Control.js renamed to js/src/controls/Control.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const widgets = require('@jupyter-widgets/base');
5-
const L = require('../leaflet.js');
6-
const utils = require('../utils.js');
4+
//@ts-nocheck
75

6+
import * as widgets from '@jupyter-widgets/base';
7+
import L from '../leaflet';
8+
import * as utils from '../utils';
89
export class LeafletControlModel extends widgets.WidgetModel {
910
defaults() {
1011
return {

js/src/controls/DrawControl.js renamed to js/src/controls/DrawControl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const widgets = require('@jupyter-widgets/base');
5-
const L = require('../leaflet.js');
6-
const control = require('./Control.js');
4+
//@ts-nocheck
5+
6+
import * as widgets from '@jupyter-widgets/base';
7+
import L from '../leaflet';
8+
import * as control from './Control';
79

810
export class LeafletDrawControlModel extends control.LeafletControlModel {
911
defaults() {

js/src/controls/FullScreenControl.js renamed to js/src/controls/FullScreenControl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const L = require('../leaflet.js');
5-
const control = require('./Control.js');
6-
4+
//@ts-nocheck
5+
import L from '../leaflet';
6+
import * as control from './Control';
77
export class LeafletFullScreenControlModel extends control.LeafletControlModel {
88
defaults() {
99
return {
@@ -21,6 +21,8 @@ export class LeafletFullScreenControlView extends control.LeafletControlView {
2121
}
2222

2323
create_obj() {
24+
//@ts-ignore
25+
2426
this.obj = L.control.fullscreen(this.get_options());
2527
}
2628
}

js/src/controls/LayersControl.js renamed to js/src/controls/LayersControl.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const L = require('../leaflet.js');
5-
const control = require('./Control.js');
4+
//@ts-nocheck
5+
import L from '../leaflet';
6+
import * as control from './Control';
67

78
export class LeafletLayersControlModel extends control.LeafletControlModel {
89
defaults() {
@@ -56,6 +57,7 @@ export class LeafletLayersControlView extends control.LeafletControlView {
5657
}
5758
return ov;
5859
}, {});
60+
//@ts-ignore
5961
this.obj = L.control.layers(baselayers, overlays, this.get_options());
6062
return this;
6163
})

js/src/controls/LegendControl.js renamed to js/src/controls/LegendControl.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
const L = require('../leaflet.js');
2-
const control = require('./Control.js');
1+
// @ts-nocheck
32

3+
import L from '../leaflet';
4+
import * as control from './Control';
45
export class LeafletLegendControlModel extends control.LeafletControlModel {
56
defaults() {
67
return {

js/src/controls/MeasureControl.js renamed to js/src/controls/MeasureControl.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
3-
4-
const L = require('../leaflet.js');
5-
const control = require('./Control.js');
3+
//@ts-nocheck
4+
import L from '../leaflet';
5+
import * as control from './Control';
66

77
export class LeafletMeasureControlModel extends control.LeafletControlModel {
88
defaults() {

js/src/controls/ScaleControl.js renamed to js/src/controls/ScaleControl.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const L = require('../leaflet.js');
5-
const control = require('./Control.js');
6-
4+
//@ts-nocheck
5+
import L from '../leaflet';
6+
import * as control from './Control';
77
export class LeafletScaleControlModel extends control.LeafletControlModel {
88
defaults() {
99
return {
@@ -21,6 +21,7 @@ export class LeafletScaleControlView extends control.LeafletControlView {
2121
}
2222

2323
create_obj() {
24+
//@ts-ignore
2425
this.obj = L.control.scale(this.get_options());
2526
}
2627
}

js/src/controls/SearchControl.js renamed to js/src/controls/SearchControl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const widgets = require('@jupyter-widgets/base');
5-
const L = require('../leaflet.js');
6-
const control = require('./Control.js');
4+
//@ts-nocheck
5+
import * as widgets from '@jupyter-widgets/base';
6+
import L from '../leaflet';
7+
import * as control from './Control';
78

89
export class LeafletSearchControlModel extends control.LeafletControlModel {
910
defaults() {
@@ -47,6 +48,7 @@ export class LeafletSearchControlView extends control.LeafletControlView {
4748
const options = this.get_options();
4849
options.layer = layer_view !== null ? layer_view.obj : null;
4950
options.marker = marker_view !== null ? marker_view.obj : false;
51+
//@ts-ignore
5052
this.obj = L.control.search(options);
5153
});
5254
}

js/src/controls/SplitMapControl.js renamed to js/src/controls/SplitMapControl.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const widgets = require('@jupyter-widgets/base');
5-
const L = require('../leaflet.js');
6-
const control = require('./Control.js');
4+
//@ts-nocheck
5+
import * as widgets from '@jupyter-widgets/base';
6+
import L from '../leaflet';
7+
import * as control from './Control';
78

89
export class LeafletSplitMapControlModel extends control.LeafletControlModel {
910
default() {
@@ -50,6 +51,7 @@ export class LeafletSplitMapControlView extends control.LeafletControlView {
5051
right_views.push(view.obj);
5152
}
5253
});
54+
//@ts-ignore
5355
this.obj = L.control.splitMap(left_views, right_views);
5456
});
5557
}

js/src/controls/WidgetControl.js renamed to js/src/controls/WidgetControl.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
3-
4-
const widgets = require('@jupyter-widgets/base');
5-
const L = require('../leaflet.js');
6-
const control = require('./Control.js');
7-
const PMessaging = require('@lumino/messaging');
8-
const PWidgets = require('@lumino/widgets');
3+
//@ts-nocheck
4+
import * as widgets from '@jupyter-widgets/base';
5+
import * as PMessaging from '@lumino/messaging';
6+
import * as PWidgets from '@lumino/widgets';
7+
import L from '../leaflet';
8+
import * as control from './Control';
99

1010
class WidgetControl extends L.Control {
1111
updateLayout(options) {

js/src/controls/ZoomControl.js renamed to js/src/controls/ZoomControl.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
const L = require('../leaflet.js');
5-
const control = require('./Control.js');
4+
//@ts-nocheck
5+
import L from '../leaflet';
6+
import * as control from './Control';
67

78
export class LeafletZoomControlModel extends control.LeafletControlModel {
89
defaults() {
@@ -25,6 +26,7 @@ export class LeafletZoomControlView extends control.LeafletControlView {
2526
}
2627

2728
create_obj() {
29+
//@ts-ignore
2830
this.obj = L.control.zoom(this.get_options());
2931
}
3032
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
33

4-
module.exports = require('./index.js');
4+
export * from './index';

js/src/extension.js renamed to js/src/extension.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
3+
// @ts-nocheck
34

45
// Configure requirejs
56
if (window.require) {
@@ -12,7 +13,4 @@ if (window.require) {
1213
});
1314
}
1415

15-
// Export the required load_ipython_extention
16-
module.exports = {
17-
load_ipython_extension: function () {},
18-
};
16+
export const load_ipython_extension = function () {};
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
3+
// @ts-nocheck
4+
5+
import packageJson from '../package.json';
36

47
// Export everything from jupyter-leaflet and the npm package version number.
58
var _oldL = window.L;
6-
module.exports = require('./jupyter-leaflet.js');
7-
module.exports['version'] = require('../package.json').version;
89

910
// if previous L existed and it got changed while loading this module
1011
if (_oldL !== undefined && _oldL !== window.L) {
@@ -13,3 +14,8 @@ if (_oldL !== undefined && _oldL !== window.L) {
1314
);
1415
ipyL = L.noConflict(); // eslint-disable-line no-undef
1516
}
17+
18+
const { version } = packageJson;
19+
20+
export * from './jupyter-leaflet';
21+
export { version };

0 commit comments

Comments
 (0)