From b9abf822d94da5bfcce995848df85c13e25a949a Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Tue, 8 Feb 2022 20:38:45 +0100 Subject: [PATCH 1/5] Fix web worker in watch mode --- build/rollup_plugins.ts | 3 ++- .../{web_worker_replacement.js => web_worker_replacement.ts} | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) rename build/{web_worker_replacement.js => web_worker_replacement.ts} (57%) diff --git a/build/rollup_plugins.ts b/build/rollup_plugins.ts index fbe1e30986..478314c89c 100644 --- a/build/rollup_plugins.ts +++ b/build/rollup_plugins.ts @@ -40,7 +40,8 @@ export const plugins = (minified: boolean, production: boolean, watch: boolean): }) : false, resolve({ browser: true, - preferBuiltins: false + preferBuiltins: false, + extensions: ['.mjs', '.js', '.json', '.node', '.ts'] }), watch ? typescript() : false, commonjs({ diff --git a/build/web_worker_replacement.js b/build/web_worker_replacement.ts similarity index 57% rename from build/web_worker_replacement.js rename to build/web_worker_replacement.ts index cb58b1814d..c0d007047a 100644 --- a/build/web_worker_replacement.js +++ b/build/web_worker_replacement.ts @@ -1,5 +1,5 @@ -import maplibregl from '../rollup/build/tsc/src/index' +import maplibregl from '../src/index'; export default function () { return new Worker(maplibregl.workerUrl); -} \ No newline at end of file +} diff --git a/package.json b/package.json index 738ec34fc4..8f17c2d5fd 100644 --- a/package.json +++ b/package.json @@ -136,7 +136,7 @@ "typescript": "^4.5.5" }, "browser": { - "./rollup/build/tsc/src/util/web_worker.js": "./build/web_worker_replacement.js" + "./src/util/web_worker.ts": "./build/web_worker_replacement.ts" }, "scripts": { "generate-shaders": "node --loader ts-node/esm --experimental-specifier-resolution=node build/generate-shaders.ts", From c1e49b0819bf0aff12f9f238a133adbb3ee8d382 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Tue, 8 Feb 2022 20:42:07 +0100 Subject: [PATCH 2/5] Add webworker support throughout --- bench/rollup_config_benchmarks.ts | 6 +++++- rollup.config.style-spec.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bench/rollup_config_benchmarks.ts b/bench/rollup_config_benchmarks.ts index 00bab50672..3651f3ca63 100644 --- a/bench/rollup_config_benchmarks.ts +++ b/bench/rollup_config_benchmarks.ts @@ -67,7 +67,11 @@ const viewConfig: RollupOptions = { sourcemap: false }, plugins: [ - resolve({browser: true, preferBuiltins: false}), + resolve({ + browser: true, + preferBuiltins: false, + extensions: ['.mjs', '.js', '.json', '.node', '.ts'] + }), watch ? typescript() : null, commonjs(), replace(replaceConfig) diff --git a/rollup.config.style-spec.ts b/rollup.config.style-spec.ts index 91529bb159..a5bd0f648a 100644 --- a/rollup.config.style-spec.ts +++ b/rollup.config.style-spec.ts @@ -49,7 +49,8 @@ const config: RollupOptions[] = [{ unassert(), resolve({ browser: true, - preferBuiltins: false + preferBuiltins: false, + extensions: ['.mjs', '.js', '.json', '.node', '.ts'] }), commonjs() ] From b694acffd08abc985259af733e4f379f89f563c6 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Tue, 8 Feb 2022 21:02:57 +0100 Subject: [PATCH 3/5] Don't change rollup for style-spec and benchmarks --- bench/rollup_config_benchmarks.ts | 6 +----- rollup.config.style-spec.ts | 3 +-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/bench/rollup_config_benchmarks.ts b/bench/rollup_config_benchmarks.ts index 3651f3ca63..00bab50672 100644 --- a/bench/rollup_config_benchmarks.ts +++ b/bench/rollup_config_benchmarks.ts @@ -67,11 +67,7 @@ const viewConfig: RollupOptions = { sourcemap: false }, plugins: [ - resolve({ - browser: true, - preferBuiltins: false, - extensions: ['.mjs', '.js', '.json', '.node', '.ts'] - }), + resolve({browser: true, preferBuiltins: false}), watch ? typescript() : null, commonjs(), replace(replaceConfig) diff --git a/rollup.config.style-spec.ts b/rollup.config.style-spec.ts index a5bd0f648a..91529bb159 100644 --- a/rollup.config.style-spec.ts +++ b/rollup.config.style-spec.ts @@ -49,8 +49,7 @@ const config: RollupOptions[] = [{ unassert(), resolve({ browser: true, - preferBuiltins: false, - extensions: ['.mjs', '.js', '.json', '.node', '.ts'] + preferBuiltins: false }), commonjs() ] From d2932bfc05ed045f9918ea728750def2c5068099 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Tue, 8 Feb 2022 21:11:38 +0100 Subject: [PATCH 4/5] Revert "Don't change rollup for style-spec and benchmarks" This reverts commit 62a7e143b2670a494ec342b251d84efa7cdde33a. --- bench/rollup_config_benchmarks.ts | 6 +++++- rollup.config.style-spec.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bench/rollup_config_benchmarks.ts b/bench/rollup_config_benchmarks.ts index 00bab50672..3651f3ca63 100644 --- a/bench/rollup_config_benchmarks.ts +++ b/bench/rollup_config_benchmarks.ts @@ -67,7 +67,11 @@ const viewConfig: RollupOptions = { sourcemap: false }, plugins: [ - resolve({browser: true, preferBuiltins: false}), + resolve({ + browser: true, + preferBuiltins: false, + extensions: ['.mjs', '.js', '.json', '.node', '.ts'] + }), watch ? typescript() : null, commonjs(), replace(replaceConfig) diff --git a/rollup.config.style-spec.ts b/rollup.config.style-spec.ts index 91529bb159..a5bd0f648a 100644 --- a/rollup.config.style-spec.ts +++ b/rollup.config.style-spec.ts @@ -49,7 +49,8 @@ const config: RollupOptions[] = [{ unassert(), resolve({ browser: true, - preferBuiltins: false + preferBuiltins: false, + extensions: ['.mjs', '.js', '.json', '.node', '.ts'] }), commonjs() ] From c37f003a4b2bf3cd036d76cfe19b7ca2b87a9bc4 Mon Sep 17 00:00:00 2001 From: Birk Skyum Date: Wed, 9 Feb 2022 13:57:17 +0100 Subject: [PATCH 5/5] Remove duplicate node-resolve configuration --- bench/rollup_config_benchmarks.ts | 9 ++------- build/rollup_plugins.ts | 12 +++++++----- rollup.config.style-spec.ts | 8 ++------ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/bench/rollup_config_benchmarks.ts b/bench/rollup_config_benchmarks.ts index 3651f3ca63..1a08970ec3 100644 --- a/bench/rollup_config_benchmarks.ts +++ b/bench/rollup_config_benchmarks.ts @@ -1,8 +1,7 @@ import fs from 'fs'; import sourcemaps from 'rollup-plugin-sourcemaps'; import replace from '@rollup/plugin-replace'; -import {plugins} from '../build/rollup_plugins'; -import resolve from '@rollup/plugin-node-resolve'; +import {plugins, nodeResolve} from '../build/rollup_plugins'; import commonjs from '@rollup/plugin-commonjs'; import typescript from '@rollup/plugin-typescript'; import {execSync} from 'child_process'; @@ -67,11 +66,7 @@ const viewConfig: RollupOptions = { sourcemap: false }, plugins: [ - resolve({ - browser: true, - preferBuiltins: false, - extensions: ['.mjs', '.js', '.json', '.node', '.ts'] - }), + nodeResolve, watch ? typescript() : null, commonjs(), replace(replaceConfig) diff --git a/build/rollup_plugins.ts b/build/rollup_plugins.ts index 478314c89c..83d31513f0 100644 --- a/build/rollup_plugins.ts +++ b/build/rollup_plugins.ts @@ -12,6 +12,12 @@ import {Plugin} from 'rollup'; // Common set of plugins/transformations shared across different rollup // builds (main maplibre bundle, style-spec package, benchmarks bundle) +export const nodeResolve = resolve({ + browser: true, + preferBuiltins: false, + extensions: ['.mjs', '.js', '.json', '.node', '.ts'] +}); + export const plugins = (minified: boolean, production: boolean, watch: boolean): Plugin[] => [ minifyStyleSpec(), json(), @@ -38,11 +44,7 @@ export const plugins = (minified: boolean, production: boolean, watch: boolean): production ? unassert({ include: ['**/*'], // by default, unassert only includes .js files }) : false, - resolve({ - browser: true, - preferBuiltins: false, - extensions: ['.mjs', '.js', '.json', '.node', '.ts'] - }), + nodeResolve, watch ? typescript() : false, commonjs({ // global keyword handling causes Webpack compatibility issues, so we disabled it: diff --git a/rollup.config.style-spec.ts b/rollup.config.style-spec.ts index a5bd0f648a..5805f9c222 100644 --- a/rollup.config.style-spec.ts +++ b/rollup.config.style-spec.ts @@ -1,11 +1,11 @@ import path, {dirname} from 'path'; import replace from '@rollup/plugin-replace'; -import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import unassert from 'rollup-plugin-unassert'; import json from '@rollup/plugin-json'; import {fileURLToPath, pathToFileURL} from 'url'; import {RollupOptions} from 'rollup'; +import {nodeResolve} from './build/rollup_plugins'; const esm = 'esm' in process.env; @@ -47,11 +47,7 @@ const config: RollupOptions[] = [{ }), json(), unassert(), - resolve({ - browser: true, - preferBuiltins: false, - extensions: ['.mjs', '.js', '.json', '.node', '.ts'] - }), + nodeResolve, commonjs() ] }];