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() {

0 commit comments

Comments
 (0)