Skip to content

Commit 03680eb

Browse files
authored
Switch to ES modules and Rollup (mapbox#6196)
* [codemod] convert src/ from commonjs to es6 modules Using 5to6-codemod/transforms/{cjs,exports,named-export-generation}.js * [codemod] convert bench/ to use import instead of require() 5to6-codemod/transforms/cjs.js * [codemod] Convert util.* to use named imports https://gist.github.com/anandthakker/b636ad8cb7782c47998c4de9c0c5419d * Setup rollup * Manual es6 module fixes * Fix(ish) codegen * Apply fixed codegen * Add flow-remove-types require hook using pirates Upstream: facebookarchive/flow-remove-types#62 * Update docs site to use es module import * Upgrade batfish * Update benchmarks build * Update style-spec build * [codemod] Convert test/unit to use import instead of require 5to6 cjs transform * Workaround for standard-things/esm#301 * Add scripts to run node/tap with require hooks * [codemod] test/unit no-strict * Avoid @std/esm 'temporal dead zone' warning * Fixup unit tests * Add comments explaining bundling strategy * Update integration test suite implementation * Update yarn.lock Specifically for zaach/jsonlint#103 (comment) * Polish build - Remove browserify - Update build tests * [lint] Use sourceType: script for test/integration/ * [lint] Add eslint-plugin-import, fix lint in src/ * [lint] Fix lint in test/ * [lint] Fix lint in bench/ * [lint] Fix lint for docs/ * Fix rollup config warning * Move rollup plugins to devDependencies * Use @mapbox-scoped rollup while awaiting upstream merge * Move comment in benchmarks.js * Restore comments stripped by codemods * Fix Style#queryRenderedFeature unit tests
1 parent b98a9f7 commit 03680eb

File tree

418 files changed

+5747
-5433
lines changed

Some content is hidden

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

418 files changed

+5747
-5433
lines changed

.eslintrc

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
{
22
"extends": [
33
"mourner",
4-
"plugin:flowtype/recommended"
4+
"plugin:flowtype/recommended",
5+
"plugin:import/recommended"
56
],
67
"parser": "babel-eslint",
78
"parserOptions": {
89
"sourceType": "script"
910
},
1011
"plugins": [
11-
"flowtype"
12+
"flowtype",
13+
"import"
1214
],
15+
"settings": {
16+
"import/ignore": [
17+
"@mapbox/gl-matrix",
18+
"@mapbox/shelf-pack",
19+
"@mapbox/whoots-js"
20+
]
21+
},
1322
"rules": {
1423
"array-bracket-spacing": "off",
1524
"block-scoped-var": "error",

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/rollup/build/
12
/docs/components/api.json
23
/dist/mapbox-gl-dev.js
34
/dist/mapbox-gl.js

bench/benchmarks.js

+33-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// @flow
22

3-
require('../src').accessToken = require('./lib/access_token');
3+
import mapboxgl from '../src';
4+
import accessToken from './lib/access_token';
5+
mapboxgl.accessToken = accessToken;
46

57
window.mapboxglVersions = window.mapboxglVersions || [];
68
window.mapboxglBenchmarks = window.mapboxglBenchmarks || {};
@@ -13,19 +15,36 @@ function register(Benchmark) {
1315
window.mapboxglBenchmarks[Benchmark.name][version] = new Benchmark();
1416
}
1517

16-
register(require('./benchmarks/layout'));
17-
register(require('./benchmarks/layout_dds'));
18-
register(require('./benchmarks/paint'));
19-
require('./benchmarks/layers').forEach(register);
20-
register(require('./benchmarks/map_load'));
21-
register(require('./benchmarks/style_validate'));
22-
register(require('./benchmarks/style_layer_create'));
23-
register(require('./benchmarks/query_point'));
24-
register(require('./benchmarks/query_box'));
25-
require('./benchmarks/expressions').forEach(register);
26-
register(require('./benchmarks/filter_create'));
27-
register(require('./benchmarks/filter_evaluate'));
18+
import Layout from './benchmarks/layout';
19+
import LayoutDDS from './benchmarks/layout_dds';
20+
import Paint from './benchmarks/paint';
21+
import LayerBenchmarks from './benchmarks/layers';
22+
import Load from './benchmarks/map_load';
23+
import Validate from './benchmarks/style_validate';
24+
import StyleLayerCreate from './benchmarks/style_layer_create';
25+
import QueryPoint from './benchmarks/query_point';
26+
import QueryBox from './benchmarks/query_box';
27+
import ExpressionBenchmarks from './benchmarks/expressions';
28+
import FilterCreate from './benchmarks/filter_create';
29+
import FilterEvaluate from './benchmarks/filter_evaluate';
2830

31+
register(Layout);
32+
register(LayoutDDS);
33+
register(Paint);
34+
LayerBenchmarks.forEach(register);
35+
register(Load);
36+
register(Validate);
37+
register(StyleLayerCreate);
38+
register(QueryPoint);
39+
register(QueryBox);
40+
ExpressionBenchmarks.forEach(register);
41+
register(FilterCreate);
42+
register(FilterEvaluate);
43+
44+
import getWorkerPool from '../src/util/global_worker_pool';
45+
// Set up the worker blob URL--written to window.mapboxGlWorkerUrl before this
46+
// module is executed--before acquiring workers.
47+
mapboxgl.workerUrl = window.mapboxGlWorkerUrl;
2948
// Ensure the global worker pool is never drained. Browsers have resource limits
3049
// on the max number of workers that can be created per page.
31-
require('../src/util/global_worker_pool')().acquire(-1);
50+
getWorkerPool().acquire(-1);

bench/benchmarks/expressions.js

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// @flow
22

3-
const Benchmark = require('../lib/benchmark');
4-
const accessToken = require('../lib/access_token');
5-
const spec = require('../../src/style-spec/reference/latest');
6-
const convertFunction = require('../../src/style-spec/function/convert');
7-
const {isFunction, createFunction} = require('../../src/style-spec/function');
8-
const {createPropertyExpression} = require('../../src/style-spec/expression');
3+
import Benchmark from '../lib/benchmark';
4+
5+
import accessToken from '../lib/access_token';
6+
import spec from '../../src/style-spec/reference/latest';
7+
import convertFunction from '../../src/style-spec/function/convert';
8+
import { isFunction, createFunction } from '../../src/style-spec/function';
9+
import { createPropertyExpression } from '../../src/style-spec/expression';
910

1011
import type {StylePropertySpecification} from '../../src/style-spec/style-spec';
1112
import type {StylePropertyExpression} from '../../src/style-spec/expression';
@@ -102,7 +103,7 @@ class ExpressionEvaluate extends ExpressionBenchmark {
102103
}
103104
}
104105

105-
module.exports = [
106+
export default [
106107
FunctionCreate,
107108
FunctionConvert,
108109
FunctionEvaluate,

bench/benchmarks/filter_create.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// @flow
22

3-
const Benchmark = require('../lib/benchmark');
4-
const createFilter = require('../../src/style-spec/feature_filter');
5-
const filters = require('../data/filters.json');
3+
import Benchmark from '../lib/benchmark';
64

7-
module.exports = class FilterCreate extends Benchmark {
5+
import createFilter from '../../src/style-spec/feature_filter';
6+
import filters from '../data/filters.json';
7+
8+
export default class FilterCreate extends Benchmark {
89
bench() {
910
for (const filter of filters) {
1011
createFilter(filter.filter);
1112
}
1213
}
13-
};
14+
}

bench/benchmarks/filter_evaluate.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
const Benchmark = require('../lib/benchmark');
3-
const VectorTile = require('@mapbox/vector-tile').VectorTile;
4-
const Pbf = require('pbf');
5-
const createFilter = require('../../src/style-spec/feature_filter');
6-
const filters = require('../data/filters.json');
7-
const assert = require('assert');
2+
import Benchmark from '../lib/benchmark';
3+
import { VectorTile } from '@mapbox/vector-tile';
4+
import Pbf from 'pbf';
5+
import createFilter from '../../src/style-spec/feature_filter';
6+
import filters from '../data/filters.json';
7+
import assert from 'assert';
88

9-
module.exports = class FilterEvaluate extends Benchmark {
9+
export default class FilterEvaluate extends Benchmark {
1010
setup() {
1111
return fetch('/bench/data/785.vector.pbf')
1212
.then(response => response.arrayBuffer())
@@ -46,4 +46,4 @@ module.exports = class FilterEvaluate extends Benchmark {
4646
}
4747
}
4848
}
49-
};
49+
}

bench/benchmarks/layers.js

+40-37
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

2-
const Benchmark = require('../lib/benchmark');
3-
const createMap = require('../lib/create_map');
4-
const style = require('../data/empty.json');
2+
import Benchmark from '../lib/benchmark';
3+
import createMap from '../lib/create_map';
4+
import style from '../data/empty.json';
55

66
function generateLayers(layer) {
77
const generated = [];
@@ -100,41 +100,44 @@ class LayerFillExtrusion extends LayerBenchmark {
100100
}
101101

102102
class LayerHeatmap extends LayerBenchmark {
103-
constructor() {
104-
super();
105-
106-
this.layerStyle = Object.assign({}, style, {
107-
sources: {
108-
'heatmap': {
109-
'type': 'geojson',
110-
'data': require('../data/naturalearth-land.json'),
111-
'maxzoom': 23
112-
}
113-
},
114-
layers: generateLayers({
115-
'id': 'layer',
116-
'type': 'heatmap',
117-
'source': 'heatmap',
118-
'paint': {
119-
"heatmap-radius": 50,
120-
"heatmap-weight": {
121-
"stops": [[0, 0.5], [4, 2]]
103+
setup() {
104+
return fetch('/bench/data/naturalearth-land.json')
105+
.then(response => response.json())
106+
.then(data => {
107+
this.layerStyle = Object.assign({}, style, {
108+
sources: {
109+
'heatmap': {
110+
'type': 'geojson',
111+
'data': data,
112+
'maxzoom': 23
113+
}
122114
},
123-
"heatmap-intensity": 0.9,
124-
"heatmap-color": [
125-
"interpolate",
126-
["linear"],
127-
["heatmap-density"],
128-
0, "rgba(0, 0, 255, 0)",
129-
0.1, "royalblue",
130-
0.3, "cyan",
131-
0.5, "lime",
132-
0.7, "yellow",
133-
1, "red"
134-
]
135-
}
115+
layers: generateLayers({
116+
'id': 'layer',
117+
'type': 'heatmap',
118+
'source': 'heatmap',
119+
'paint': {
120+
"heatmap-radius": 50,
121+
"heatmap-weight": {
122+
"stops": [[0, 0.5], [4, 2]]
123+
},
124+
"heatmap-intensity": 0.9,
125+
"heatmap-color": [
126+
"interpolate",
127+
["linear"],
128+
["heatmap-density"],
129+
0, "rgba(0, 0, 255, 0)",
130+
0.1, "royalblue",
131+
0.3, "cyan",
132+
0.5, "lime",
133+
0.7, "yellow",
134+
1, "red"
135+
]
136+
}
137+
})
138+
});
136139
})
137-
});
140+
.then(() => super.setup());
138141
}
139142
}
140143

@@ -214,7 +217,7 @@ class LayerSymbol extends LayerBenchmark {
214217
}
215218

216219

217-
module.exports = [
220+
export default [
218221
LayerBackground,
219222
LayerCircle,
220223
LayerFill,

bench/benchmarks/layout.js

+14-20
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
// @flow
22

3-
const Benchmark = require('../lib/benchmark');
4-
const createStyle = require('../lib/create_style');
5-
6-
const VT = require('@mapbox/vector-tile');
7-
const Protobuf = require('pbf');
8-
const assert = require('assert');
9-
const promisify = require('pify');
10-
11-
const WorkerTile = require('../../src/source/worker_tile');
12-
const StyleLayerIndex = require('../../src/style/style_layer_index');
13-
const deref = require('../../src/style-spec/deref');
14-
const {OverscaledTileID} = require('../../src/source/tile_id');
15-
16-
const {
17-
normalizeStyleURL,
18-
normalizeSourceURL,
19-
normalizeTileURL
20-
} = require('../../src/util/mapbox');
3+
import Benchmark from '../lib/benchmark';
4+
5+
import createStyle from '../lib/create_style';
6+
import VT from '@mapbox/vector-tile';
7+
import Protobuf from 'pbf';
8+
import assert from 'assert';
9+
import promisify from 'pify';
10+
import WorkerTile from '../../src/source/worker_tile';
11+
import StyleLayerIndex from '../../src/style/style_layer_index';
12+
import deref from '../../src/style-spec/deref';
13+
import { OverscaledTileID } from '../../src/source/tile_id';
14+
import { normalizeStyleURL, normalizeSourceURL, normalizeTileURL } from '../../src/util/mapbox';
2115

2216
import type {TileJSON} from '../../src/types/tilejson';
2317

2418
// Note: this class is extended in turn by the LayoutDDS benchmark.
25-
module.exports = class Layout extends Benchmark {
19+
export default class Layout extends Benchmark {
2620
glyphs: Object;
2721
icons: Object;
2822
workerTile: WorkerTile;
@@ -136,4 +130,4 @@ module.exports = class Layout extends Benchmark {
136130

137131
return promise;
138132
}
139-
};
133+
}

bench/benchmarks/layout_dds.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
// @flow
22

3-
const Layout = require('./layout');
4-
const {OverscaledTileID} = require('../../src/source/tile_id');
3+
import Layout from './layout';
4+
5+
import { OverscaledTileID } from '../../src/source/tile_id';
56

67
const LAYER_COUNT = 2;
78

8-
module.exports = class LayoutDDS extends Layout {
9+
export default class LayoutDDS extends Layout {
910
tileIDs(): Array<OverscaledTileID> {
1011
return [
1112
new OverscaledTileID(15, 0, 15, 9373, 12535)
@@ -92,4 +93,4 @@ module.exports = class LayoutDDS extends Layout {
9293

9394
return Promise.resolve(style);
9495
}
95-
};
96+
}

bench/benchmarks/map_load.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
const Benchmark = require('../lib/benchmark');
3-
const createMap = require('../lib/create_map');
2+
import Benchmark from '../lib/benchmark';
3+
import createMap from '../lib/create_map';
44

5-
module.exports = class MapLoad extends Benchmark {
5+
export default class MapLoad extends Benchmark {
66
bench() {
77
return createMap({
88
style: {
@@ -12,4 +12,4 @@ module.exports = class MapLoad extends Benchmark {
1212
}
1313
}).then(map => map.remove());
1414
}
15-
};
15+
}

bench/benchmarks/paint.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
const Benchmark = require('../lib/benchmark');
3-
const createMap = require('../lib/create_map');
2+
import Benchmark from '../lib/benchmark';
3+
import createMap from '../lib/create_map';
44

55
const width = 1024;
66
const height = 768;
77
const zooms = [4, 8, 11, 13, 15, 17];
88

9-
module.exports = class Paint extends Benchmark {
9+
export default class Paint extends Benchmark {
1010
setup() {
1111
return Promise.all(zooms.map(zoom => {
1212
return createMap({
@@ -34,4 +34,4 @@ module.exports = class Paint extends Benchmark {
3434
map.remove();
3535
}
3636
}
37-
};
37+
}

bench/benchmarks/query_box.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

2-
const Benchmark = require('../lib/benchmark');
3-
const createMap = require('../lib/create_map');
2+
import Benchmark from '../lib/benchmark';
3+
import createMap from '../lib/create_map';
44

55
const width = 1024;
66
const height = 768;
77
const zooms = [4, 8, 11, 13, 15, 17];
88

9-
module.exports = class QueryBox extends Benchmark {
9+
export default class QueryBox extends Benchmark {
1010
setup() {
1111
return Promise.all(zooms.map(zoom => {
1212
return createMap({
@@ -30,4 +30,4 @@ module.exports = class QueryBox extends Benchmark {
3030
map.remove();
3131
}
3232
}
33-
};
33+
}

0 commit comments

Comments
 (0)