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

Simplify build pipeline #961

Merged
merged 5 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions bench/rollup_config_benchmarks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ const replaceConfig = {
'process.env.NODE_ENV': JSON.stringify('production')
};

const watch = process.env.ROLLUP_WATCH === 'true';
const srcDir = watch ? '' : 'rollup/build/tsc/';
const inputExt = watch ? 'ts' : 'js';

const allPlugins = plugins(true, true, watch).concat(replace(replaceConfig));
const allPlugins = plugins(true, true).concat(replace(replaceConfig));
const intro = fs.readFileSync('rollup/bundle_prelude.js', 'utf8');

const splitConfig = (name: string): RollupOptions[] => [{
input: [`${srcDir}bench/${name}/benchmarks.${inputExt}`, `${srcDir}src/source/worker.${inputExt}`],
input: [`bench/${name}/benchmarks.ts`, 'src/source/worker.ts'],
output: {
dir: `rollup/build/benchmarks/${name}`,
format: 'amd',
Expand All @@ -57,7 +53,7 @@ const splitConfig = (name: string): RollupOptions[] => [{
}];

const viewConfig: RollupOptions = {
input: `${srcDir}bench/benchmarks_view.${inputExt}${watch ? 'x' : ''}`,
input: 'bench/benchmarks_view.tsx',
output: {
name: 'Benchmarks',
file: 'bench/benchmarks_view_generated.js',
Expand All @@ -67,7 +63,7 @@ const viewConfig: RollupOptions = {
},
plugins: [
nodeResolve,
watch ? typescript() : null,
typescript(),
commonjs(),
replace(replaceConfig)
].filter(Boolean)
Expand Down
4 changes: 2 additions & 2 deletions build/rollup_plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const nodeResolve = resolve({
extensions: ['.mjs', '.js', '.json', '.node', '.ts']
});

export const plugins = (minified: boolean, production: boolean, watch: boolean): Plugin[] => [
export const plugins = (minified: boolean, production: boolean): Plugin[] => [
minifyStyleSpec(),
json(),
// https://github.com/zaach/jison/issues/351
Expand All @@ -45,7 +45,7 @@ export const plugins = (minified: boolean, production: boolean, watch: boolean):
include: ['**/*'], // by default, unassert only includes .js files
}) : false,
nodeResolve,
watch ? typescript() : false,
typescript(),
commonjs({
// global keyword handling causes Webpack compatibility issues, so we disabled it:
// https://github.com/mapbox/mapbox-gl-js/pull/6956
Expand Down
12 changes: 4 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,17 +145,13 @@
"generate-style-spec": "node --loader ts-node/esm --experimental-specifier-resolution=node build/generate-style-spec.ts",
"generate-typings": "node --loader ts-node/esm --experimental-specifier-resolution=node build/generate-typings.ts",
"generate-query-test-fixtures": "node --loader ts-node/esm --experimental-specifier-resolution=node build/generate-query-test-fixtures.ts",
"build-swc-src": "swc src -d rollup/build/tsc/src -D -s",
"build-swc-bench": "swc bench -d rollup/build/tsc/bench -D -s",
"build-tsc": "npm run build-swc-src && npm run build-swc-bench",
"build-tsc-old": "tsc --outDir rollup/build/tsc",
"build-dev": "npm run build-tsc && rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev",
"build-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev",
HarelM marked this conversation as resolved.
Show resolved Hide resolved
"watch-dev": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:dev --watch",
"build-prod": "npm run build-tsc && rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production",
"build-prod-min": "npm run build-tsc && rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production,MINIFY:true",
"build-prod": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production",
"build-prod-min": "rollup --configPlugin @rollup/plugin-typescript -c --environment BUILD:production,MINIFY:true",
"build-csp": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.csp.ts",
"build-css": "postcss -o dist/maplibre-gl.css src/css/maplibre-gl.css",
"build-style-spec": "npm run build-tsc && rollup --configPlugin @rollup/plugin-typescript -c rollup.config.style-spec.ts && rollup --configPlugin @rollup/plugin-typescript -c rollup.config.style-spec.ts --environment esm",
"build-style-spec": "rollup --configPlugin @rollup/plugin-typescript -c rollup.config.style-spec.ts && rollup --configPlugin @rollup/plugin-typescript -c rollup.config.style-spec.ts --environment esm",
"build-diagrams": "cd docs/diagrams; ls *.plantuml | xargs -I {} puml generate --svg {} -o {}.svg",
"watch-css": "postcss --watch -o dist/maplibre-gl.css src/css/maplibre-gl.css",
"build-benchmarks": "npm run build-dev && rollup --configPlugin @rollup/plugin-typescript -c bench/rollup_config_benchmarks.ts",
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.csp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const config = (input: InputOption, file: string, format: ModuleFormat): RollupO
banner
},
treeshake: true,
plugins: plugins(true, true, false)
plugins: plugins(true, true)
});

export default [
config('rollup/build/tsc/src/index.js', 'dist/maplibre-gl-csp.js', 'umd'),
config('rollup/build/tsc/src/source/worker.js', 'dist/maplibre-gl-csp-worker.js', 'iife')
config('src/index.ts', 'dist/maplibre-gl-csp.js', 'umd'),
config('src/source/worker.ts', 'dist/maplibre-gl-csp-worker.js', 'iife')
];
4 changes: 3 additions & 1 deletion rollup.config.style-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import json from '@rollup/plugin-json';
import {fileURLToPath, pathToFileURL} from 'url';
import {RollupOptions} from 'rollup';
import {nodeResolve} from './build/rollup_plugins';
import typescript from '@rollup/plugin-typescript';

const esm = 'esm' in process.env;

const config: RollupOptions[] = [{
input: 'rollup/build/tsc/src/style-spec/style-spec.js',
input: 'src/style-spec/style-spec.ts',
output: {
name: 'maplibreGlStyleSpecification',
file: `dist/style-spec/${esm ? 'index.mjs' : 'index.js'}`,
Expand Down Expand Up @@ -48,6 +49,7 @@ const config: RollupOptions[] = [{
json(),
unassert(),
nodeResolve,
typescript(),
commonjs()
]
}];
Expand Down
9 changes: 3 additions & 6 deletions rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@ import {plugins} from './build/rollup_plugins';
import banner from './build/banner';
import {RollupOptions} from 'rollup';

const {BUILD, MINIFY, ROLLUP_WATCH} = process.env;
const {BUILD, MINIFY} = process.env;
const minified = MINIFY === 'true';
const watch = ROLLUP_WATCH === 'true';
const srcDir = watch ? 'src' : 'rollup/build/tsc/src';
const inputExt = watch ? 'ts' : 'js';
const production = BUILD === 'production';
const outputFile =
!production ? 'dist/maplibre-gl-dev.js' :
Expand All @@ -22,7 +19,7 @@ const config: RollupOptions[] = [{
// - rollup/build/maplibregl/shared.js: the set of modules that are dependencies of both the main module and the worker module
//
// This is also where we do all of our source transformations using the plugins.
input: [`${srcDir}/index.${inputExt}`, `${srcDir}/source/worker.${inputExt}`],
input: ['src/index.ts', 'src/source/worker.ts'],
birkskyum marked this conversation as resolved.
Show resolved Hide resolved
output: {
dir: 'rollup/build/maplibregl',
format: 'amd',
Expand All @@ -31,7 +28,7 @@ const config: RollupOptions[] = [{
chunkFileNames: 'shared.js'
},
treeshake: production,
plugins: plugins(minified, production, watch)
plugins: plugins(minified, production)
}, {
// Next, bundle together the three "chunks" produced in the previous pass
// into a single, final bundle. See rollup/bundle_prelude.js and
Expand Down
1 change: 0 additions & 1 deletion src/source/tile_id.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ describe('CanonicalTileID', () => {
expect(new CanonicalTileID(17, 22914, 52870).url(['quadkey={quadkey}'], 1)).toBe('quadkey=02301322130000230');

// Test case confirmed by quadkeytools package
// https://bitbucket.org/steele/quadkeytools/rollup/build/tsc/src/master/test/quadkey.js?fileviewer=file-view-default#quadkey.js-57
expect(new CanonicalTileID(6, 29, 3).url(['quadkey={quadkey}'], 1)).toBe('quadkey=011123');

});
Expand Down
6 changes: 3 additions & 3 deletions test/build/style-spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ describe('@maplibre/maplibre-gl-style-spec npm package', () => {
test('build plain ES5 bundle in prepublish', async () => {
jest.spyOn(console, 'warn').mockImplementation(() => {});
await rollup.rollup({
input: './rollup/build/tsc/src/style-spec/style-spec.js',
input: './src/style-spec/style-spec.ts',
plugins: [{
name: 'tset-checker',
name: 'test-checker',
resolveId: (id, importer) => {
if (
/^[\/\.]/.test(id) ||
Expand All @@ -31,7 +31,7 @@ describe('@maplibre/maplibre-gl-style-spec npm package', () => {
}).catch(e => {
expect(e).toBeFalsy();
});
});
}, 40000);

test('exports components directly, not behind `default` - https://github.com/mapbox/mapbox-gl-js/issues/6601', () => {
// @ts-ignore
Expand Down