From e3afc15a34e459699b2f61929d7b42bd7d64c89d Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Fri, 1 Apr 2022 17:37:34 +0200 Subject: [PATCH 1/2] Provide minified style spec and use it where applicable --- src/style-spec/feature_filter/index.js | 2 +- src/style-spec/reference/latest.js | 7 +++--- src/style-spec/rollup.config.js | 30 ++++++++++++++++++++++++-- src/style-spec/style-spec.js | 3 ++- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/style-spec/feature_filter/index.js b/src/style-spec/feature_filter/index.js index 4ef02631c05..f527e7ace22 100644 --- a/src/style-spec/feature_filter/index.js +++ b/src/style-spec/feature_filter/index.js @@ -3,7 +3,7 @@ import {createExpression} from '../expression/index.js'; import {isFeatureConstant} from '../expression/is_constant.js'; import {deepUnbundle} from '../util/unbundle_jsonlint.js'; -import latest from '../reference/latest.js'; +import {min as latest} from '../reference/latest.js'; import type {GlobalProperties, Feature} from '../expression/index.js'; import type {CanonicalTileID} from '../../source/tile_id.js'; import type Point from '@mapbox/point-geometry'; diff --git a/src/style-spec/reference/latest.js b/src/style-spec/reference/latest.js index 9448f6be777..c40e444afde 100644 --- a/src/style-spec/reference/latest.js +++ b/src/style-spec/reference/latest.js @@ -1,7 +1,8 @@ // @flow -import spec from './v8.json'; +import * as spec from './v8.json'; -export type StyleReference = typeof spec; +export type StyleReference = typeof spec.default; -export default spec; +export default spec.default; +export const min = spec.default; diff --git a/src/style-spec/rollup.config.js b/src/style-spec/rollup.config.js index a93738776af..8c7e4d0babb 100644 --- a/src/style-spec/rollup.config.js +++ b/src/style-spec/rollup.config.js @@ -3,7 +3,6 @@ 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 {flow} from '../../build/rollup_plugins.js'; // Build es modules? @@ -12,6 +11,8 @@ const esm = 'esm' in process.env; import {fileURLToPath} from 'url'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); +const reviver = (key, value) => ['doc', 'example'].includes(key) ? undefined : value; + const config = [{ input: `${__dirname}/style-spec.js`, output: { @@ -46,8 +47,33 @@ const config = [{ '_token_stack:': '' } }), + replace({ + include: /\/reference\/latest\.js$/, + delimiters: ['', ''], + values: { + 'export const min = spec.default': 'export const min = spec.min' + } + }), flow(), - json(), + { + name: 'json-min', + transform(code, id) { + if (id.endsWith('.json')) { + const json = JSON.parse(code); + const min = JSON.stringify(json, reviver); + const full = JSON.stringify(json); + code = `export default ${full}`; + if (min !== full) { + code += `\nexport const min = ${min}`; + } + return { + code, + map: null + }; + } + return null; + } + }, unassert(), resolve({ browser: true, diff --git a/src/style-spec/style-spec.js b/src/style-spec/style-spec.js index c1c4986b915..11781ca6d13 100644 --- a/src/style-spec/style-spec.js +++ b/src/style-spec/style-spec.js @@ -66,7 +66,7 @@ export type StylePropertySpecification = { }; import v8 from './reference/v8.json'; -import latest from './reference/latest.js'; +import latest, {min as latestWithoutDocsAndExamples} from './reference/latest.js'; import format from './format.js'; import migrate from './migrate.js'; import composite from './composite.js'; @@ -109,6 +109,7 @@ const visit = {eachSource, eachLayer, eachProperty}; export { v8, latest, + latestWithoutDocsAndExamples, format, migrate, composite, From 8657b84c33cf69b20d7deb9bb32fbd75a77fb246 Mon Sep 17 00:00:00 2001 From: Andreas Hocevar Date: Mon, 11 Apr 2022 22:58:34 +0200 Subject: [PATCH 2/2] Also exclude sdk-support; find better name --- src/style-spec/rollup.config.js | 2 +- src/style-spec/style-spec.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/style-spec/rollup.config.js b/src/style-spec/rollup.config.js index 8c7e4d0babb..c9e05607a20 100644 --- a/src/style-spec/rollup.config.js +++ b/src/style-spec/rollup.config.js @@ -11,7 +11,7 @@ const esm = 'esm' in process.env; import {fileURLToPath} from 'url'; const __dirname = fileURLToPath(new URL('.', import.meta.url)); -const reviver = (key, value) => ['doc', 'example'].includes(key) ? undefined : value; +const reviver = (key, value) => ['doc', 'example', 'sdk-support'].includes(key) ? undefined : value; const config = [{ input: `${__dirname}/style-spec.js`, diff --git a/src/style-spec/style-spec.js b/src/style-spec/style-spec.js index 11781ca6d13..0b9e32a28f0 100644 --- a/src/style-spec/style-spec.js +++ b/src/style-spec/style-spec.js @@ -66,7 +66,7 @@ export type StylePropertySpecification = { }; import v8 from './reference/v8.json'; -import latest, {min as latestWithoutDocsAndExamples} from './reference/latest.js'; +import latest, {min as specMin} from './reference/latest.js'; import format from './format.js'; import migrate from './migrate.js'; import composite from './composite.js'; @@ -109,7 +109,7 @@ const visit = {eachSource, eachLayer, eachProperty}; export { v8, latest, - latestWithoutDocsAndExamples, + specMin, format, migrate, composite,