Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ES modules and Rollup #6196

Merged
merged 33 commits into from
Mar 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
74f4cf4
[codemod] convert src/ from commonjs to es6 modules
Feb 26, 2018
a80507a
[codemod] convert bench/ to use import instead of require()
Feb 26, 2018
1737c18
[codemod] Convert util.* to use named imports
Feb 26, 2018
2b5d971
Manual es6 module fixes
Feb 12, 2018
4fd0df3
Fix(ish) codegen
Feb 21, 2018
686a550
Apply fixed codegen
Feb 21, 2018
1fe378f
Setup rollup
Feb 3, 2018
10533cc
Add flow-remove-types require hook using pirates
Feb 27, 2018
9a4f07b
Upgrade batfish
Feb 27, 2018
c4cf6c2
Update docs site to use es module import
Feb 27, 2018
369c829
Update benchmarks build
Feb 27, 2018
b3bc4a4
Update style-spec build
Feb 28, 2018
09b4639
[codemod] Convert test/unit to use import instead of require
Feb 27, 2018
3193569
[codemod] test/unit no-strict
Feb 28, 2018
d3f101f
Workaround for https://github.com/standard-things/esm/issues/301
Feb 27, 2018
8ef8ac7
Add scripts to run node/tap with require hooks
Feb 27, 2018
6d6fc82
Avoid @std/esm 'temporal dead zone' warning
Feb 28, 2018
f2ab770
Fixup unit tests
Feb 28, 2018
835a9a9
Add comments explaining bundling strategy
Mar 2, 2018
97b2496
Update integration test suite implementation
Mar 2, 2018
71297a1
Update yarn.lock
Mar 2, 2018
eeaf6ec
Polish build
Mar 6, 2018
d9ae1f7
[lint] Use sourceType: script for test/integration/
Mar 7, 2018
e8f4603
[lint] Add eslint-plugin-import, fix lint in src/
Mar 7, 2018
87791a1
[lint] Fix lint in test/
Mar 7, 2018
88e2f8f
[lint] Fix lint in bench/
Mar 7, 2018
9b24e5f
[lint] Fix lint for docs/
Mar 7, 2018
cb36e57
Fix rollup config warning
Mar 9, 2018
3d287da
Move rollup plugins to devDependencies
Mar 9, 2018
f057de1
Use @mapbox-scoped rollup while awaiting upstream merge
Mar 10, 2018
998e92f
Move comment in benchmarks.js
Mar 10, 2018
32163ff
Restore comments stripped by codemods
Mar 11, 2018
98833b9
Fix Style#queryRenderedFeature unit tests
Mar 12, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 11 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
{
"extends": [
"mourner",
"plugin:flowtype/recommended"
"plugin:flowtype/recommended",
"plugin:import/recommended"
],
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "script"
},
"plugins": [
"flowtype"
"flowtype",
"import"
],
"settings": {
"import/ignore": [
"@mapbox/gl-matrix",
"@mapbox/shelf-pack",
"@mapbox/whoots-js"
]
},
"rules": {
"array-bracket-spacing": "off",
"block-scoped-var": "error",
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/rollup/build/
/docs/components/api.json
/dist/mapbox-gl-dev.js
/dist/mapbox-gl.js
Expand Down
47 changes: 33 additions & 14 deletions bench/benchmarks.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow

require('../src').accessToken = require('./lib/access_token');
import mapboxgl from '../src';
import accessToken from './lib/access_token';
mapboxgl.accessToken = accessToken;

window.mapboxglVersions = window.mapboxglVersions || [];
window.mapboxglBenchmarks = window.mapboxglBenchmarks || {};
Expand All @@ -13,19 +15,36 @@ function register(Benchmark) {
window.mapboxglBenchmarks[Benchmark.name][version] = new Benchmark();
}

register(require('./benchmarks/layout'));
register(require('./benchmarks/layout_dds'));
register(require('./benchmarks/paint'));
require('./benchmarks/layers').forEach(register);
register(require('./benchmarks/map_load'));
register(require('./benchmarks/style_validate'));
register(require('./benchmarks/style_layer_create'));
register(require('./benchmarks/query_point'));
register(require('./benchmarks/query_box'));
require('./benchmarks/expressions').forEach(register);
register(require('./benchmarks/filter_create'));
register(require('./benchmarks/filter_evaluate'));
import Layout from './benchmarks/layout';
import LayoutDDS from './benchmarks/layout_dds';
import Paint from './benchmarks/paint';
import LayerBenchmarks from './benchmarks/layers';
import Load from './benchmarks/map_load';
import Validate from './benchmarks/style_validate';
import StyleLayerCreate from './benchmarks/style_layer_create';
import QueryPoint from './benchmarks/query_point';
import QueryBox from './benchmarks/query_box';
import ExpressionBenchmarks from './benchmarks/expressions';
import FilterCreate from './benchmarks/filter_create';
import FilterEvaluate from './benchmarks/filter_evaluate';

register(Layout);
register(LayoutDDS);
register(Paint);
LayerBenchmarks.forEach(register);
register(Load);
register(Validate);
register(StyleLayerCreate);
register(QueryPoint);
register(QueryBox);
ExpressionBenchmarks.forEach(register);
register(FilterCreate);
register(FilterEvaluate);

import getWorkerPool from '../src/util/global_worker_pool';
// Set up the worker blob URL--written to window.mapboxGlWorkerUrl before this
// module is executed--before acquiring workers.
mapboxgl.workerUrl = window.mapboxGlWorkerUrl;
// Ensure the global worker pool is never drained. Browsers have resource limits
// on the max number of workers that can be created per page.
require('../src/util/global_worker_pool')().acquire(-1);
getWorkerPool().acquire(-1);
15 changes: 8 additions & 7 deletions bench/benchmarks/expressions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @flow

const Benchmark = require('../lib/benchmark');
const accessToken = require('../lib/access_token');
const spec = require('../../src/style-spec/reference/latest');
const convertFunction = require('../../src/style-spec/function/convert');
const {isFunction, createFunction} = require('../../src/style-spec/function');
const {createPropertyExpression} = require('../../src/style-spec/expression');
import Benchmark from '../lib/benchmark';

import accessToken from '../lib/access_token';
import spec from '../../src/style-spec/reference/latest';
import convertFunction from '../../src/style-spec/function/convert';
import { isFunction, createFunction } from '../../src/style-spec/function';
import { createPropertyExpression } from '../../src/style-spec/expression';

import type {StylePropertySpecification} from '../../src/style-spec/style-spec';
import type {StylePropertyExpression} from '../../src/style-spec/expression';
Expand Down Expand Up @@ -102,7 +103,7 @@ class ExpressionEvaluate extends ExpressionBenchmark {
}
}

module.exports = [
export default [
FunctionCreate,
FunctionConvert,
FunctionEvaluate,
Expand Down
11 changes: 6 additions & 5 deletions bench/benchmarks/filter_create.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// @flow

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

module.exports = class FilterCreate extends Benchmark {
import createFilter from '../../src/style-spec/feature_filter';
import filters from '../data/filters.json';

export default class FilterCreate extends Benchmark {
bench() {
for (const filter of filters) {
createFilter(filter.filter);
}
}
};
}
16 changes: 8 additions & 8 deletions bench/benchmarks/filter_evaluate.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

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

module.exports = class FilterEvaluate extends Benchmark {
export default class FilterEvaluate extends Benchmark {
setup() {
return fetch('/bench/data/785.vector.pbf')
.then(response => response.arrayBuffer())
Expand Down Expand Up @@ -46,4 +46,4 @@ module.exports = class FilterEvaluate extends Benchmark {
}
}
}
};
}
77 changes: 40 additions & 37 deletions bench/benchmarks/layers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

const Benchmark = require('../lib/benchmark');
const createMap = require('../lib/create_map');
const style = require('../data/empty.json');
import Benchmark from '../lib/benchmark';
import createMap from '../lib/create_map';
import style from '../data/empty.json';

function generateLayers(layer) {
const generated = [];
Expand Down Expand Up @@ -100,41 +100,44 @@ class LayerFillExtrusion extends LayerBenchmark {
}

class LayerHeatmap extends LayerBenchmark {
constructor() {
super();

this.layerStyle = Object.assign({}, style, {
sources: {
'heatmap': {
'type': 'geojson',
'data': require('../data/naturalearth-land.json'),
'maxzoom': 23
}
},
layers: generateLayers({
'id': 'layer',
'type': 'heatmap',
'source': 'heatmap',
'paint': {
"heatmap-radius": 50,
"heatmap-weight": {
"stops": [[0, 0.5], [4, 2]]
setup() {
return fetch('/bench/data/naturalearth-land.json')
.then(response => response.json())
.then(data => {
this.layerStyle = Object.assign({}, style, {
sources: {
'heatmap': {
'type': 'geojson',
'data': data,
'maxzoom': 23
}
},
"heatmap-intensity": 0.9,
"heatmap-color": [
"interpolate",
["linear"],
["heatmap-density"],
0, "rgba(0, 0, 255, 0)",
0.1, "royalblue",
0.3, "cyan",
0.5, "lime",
0.7, "yellow",
1, "red"
]
}
layers: generateLayers({
'id': 'layer',
'type': 'heatmap',
'source': 'heatmap',
'paint': {
"heatmap-radius": 50,
"heatmap-weight": {
"stops": [[0, 0.5], [4, 2]]
},
"heatmap-intensity": 0.9,
"heatmap-color": [
"interpolate",
["linear"],
["heatmap-density"],
0, "rgba(0, 0, 255, 0)",
0.1, "royalblue",
0.3, "cyan",
0.5, "lime",
0.7, "yellow",
1, "red"
]
}
})
});
})
});
.then(() => super.setup());
}
}

Expand Down Expand Up @@ -214,7 +217,7 @@ class LayerSymbol extends LayerBenchmark {
}


module.exports = [
export default [
LayerBackground,
LayerCircle,
LayerFill,
Expand Down
34 changes: 14 additions & 20 deletions bench/benchmarks/layout.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
// @flow

const Benchmark = require('../lib/benchmark');
const createStyle = require('../lib/create_style');

const VT = require('@mapbox/vector-tile');
const Protobuf = require('pbf');
const assert = require('assert');
const promisify = require('pify');

const WorkerTile = require('../../src/source/worker_tile');
const StyleLayerIndex = require('../../src/style/style_layer_index');
const deref = require('../../src/style-spec/deref');
const {OverscaledTileID} = require('../../src/source/tile_id');

const {
normalizeStyleURL,
normalizeSourceURL,
normalizeTileURL
} = require('../../src/util/mapbox');
import Benchmark from '../lib/benchmark';

import createStyle from '../lib/create_style';
import VT from '@mapbox/vector-tile';
import Protobuf from 'pbf';
import assert from 'assert';
import promisify from 'pify';
import WorkerTile from '../../src/source/worker_tile';
import StyleLayerIndex from '../../src/style/style_layer_index';
import deref from '../../src/style-spec/deref';
import { OverscaledTileID } from '../../src/source/tile_id';
import { normalizeStyleURL, normalizeSourceURL, normalizeTileURL } from '../../src/util/mapbox';

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

// Note: this class is extended in turn by the LayoutDDS benchmark.
module.exports = class Layout extends Benchmark {
export default class Layout extends Benchmark {
glyphs: Object;
icons: Object;
workerTile: WorkerTile;
Expand Down Expand Up @@ -136,4 +130,4 @@ module.exports = class Layout extends Benchmark {

return promise;
}
};
}
9 changes: 5 additions & 4 deletions bench/benchmarks/layout_dds.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// @flow

const Layout = require('./layout');
const {OverscaledTileID} = require('../../src/source/tile_id');
import Layout from './layout';

import { OverscaledTileID } from '../../src/source/tile_id';

const LAYER_COUNT = 2;

module.exports = class LayoutDDS extends Layout {
export default class LayoutDDS extends Layout {
tileIDs(): Array<OverscaledTileID> {
return [
new OverscaledTileID(15, 0, 15, 9373, 12535)
Expand Down Expand Up @@ -92,4 +93,4 @@ module.exports = class LayoutDDS extends Layout {

return Promise.resolve(style);
}
};
}
8 changes: 4 additions & 4 deletions bench/benchmarks/map_load.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

const Benchmark = require('../lib/benchmark');
const createMap = require('../lib/create_map');
import Benchmark from '../lib/benchmark';
import createMap from '../lib/create_map';

module.exports = class MapLoad extends Benchmark {
export default class MapLoad extends Benchmark {
bench() {
return createMap({
style: {
Expand All @@ -12,4 +12,4 @@ module.exports = class MapLoad extends Benchmark {
}
}).then(map => map.remove());
}
};
}
8 changes: 4 additions & 4 deletions bench/benchmarks/paint.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

const Benchmark = require('../lib/benchmark');
const createMap = require('../lib/create_map');
import Benchmark from '../lib/benchmark';
import createMap from '../lib/create_map';

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

module.exports = class Paint extends Benchmark {
export default class Paint extends Benchmark {
setup() {
return Promise.all(zooms.map(zoom => {
return createMap({
Expand Down Expand Up @@ -34,4 +34,4 @@ module.exports = class Paint extends Benchmark {
map.remove();
}
}
};
}
8 changes: 4 additions & 4 deletions bench/benchmarks/query_box.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

const Benchmark = require('../lib/benchmark');
const createMap = require('../lib/create_map');
import Benchmark from '../lib/benchmark';
import createMap from '../lib/create_map';

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

module.exports = class QueryBox extends Benchmark {
export default class QueryBox extends Benchmark {
setup() {
return Promise.all(zooms.map(zoom => {
return createMap({
Expand All @@ -30,4 +30,4 @@ module.exports = class QueryBox extends Benchmark {
map.remove();
}
}
};
}
Loading