diff --git a/.gitignore b/.gitignore index d15163d8ed9..02e28f90279 100644 --- a/.gitignore +++ b/.gitignore @@ -22,7 +22,7 @@ test/integration/**/test-results.xml test/integration/dist/**/*.js test/integration/dist/**/*.json .eslintcache -src/style-spec/dist/index.cjs +src/style-spec/dist/ _batfish_site _batfish_tmp _site diff --git a/package.json b/package.json index 2aa01bd2c8a..34d963cfcc5 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "build-test-suite": "rollup -c test/integration/rollup.config.test.js", "build-flow-types": "mkdir -p dist && cp build/mapbox-gl.js.flow dist/mapbox-gl.js.flow && cp build/mapbox-gl.js.flow dist/mapbox-gl-dev.js.flow", "build-css": "postcss -o dist/mapbox-gl.css src/css/mapbox-gl.css", - "build-style-spec": "cd src/style-spec && npm run build && cd ../.. && mkdir -p dist/style-spec && cp src/style-spec/dist/* dist/style-spec", + "build-style-spec": "cd src/style-spec && npm run build && cd ../.. && mkdir -p dist/style-spec && cp src/style-spec/dist/index.* dist/style-spec", "watch-css": "postcss --watch -o dist/mapbox-gl.css src/css/mapbox-gl.css", "build-token": "node build/generate-access-token-script.js", "build-benchmarks": "BENCHMARK_VERSION=${BENCHMARK_VERSION:-\"$(git rev-parse --abbrev-ref HEAD) $(git rev-parse --short=7 HEAD)\"} rollup -c bench/versions/rollup_config_benchmarks.js", diff --git a/src/style-spec/README.md b/src/style-spec/README.md index 412e6848513..05e66a16d31 100644 --- a/src/style-spec/README.md +++ b/src/style-spec/README.md @@ -9,6 +9,8 @@ package so that they can be installed without the bulk of GL JS. npm install @mapbox/mapbox-gl-style-spec +In addition to ESM and CJS bundles, the package also provides separate modules. The difference between the bundles and the modules is that the modules use a minified version of the `latest` style refererence, which does not contain any `doc` and `example` fields. See the `exports` section of `package.json` for available modules. + ## CLI Tools If you install this package globally, you will have access to several CLI tools. diff --git a/src/style-spec/expression/index.js b/src/style-spec/expression/index.js index 5753a385c9f..d7d0f917d32 100644 --- a/src/style-spec/expression/index.js +++ b/src/style-spec/expression/index.js @@ -397,3 +397,5 @@ function getDefaultValue(spec: StylePropertySpecification): Value { return spec.default; } } + +export {isExpressionFilter} from '../feature_filter/index.js'; diff --git a/src/style-spec/function/index.js b/src/style-spec/function/index.js index 6400f6d2f5a..40dbb4aaff0 100644 --- a/src/style-spec/function/index.js +++ b/src/style-spec/function/index.js @@ -260,3 +260,5 @@ function interpolationFactor(input, base, lowerValue, upperValue) { return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1); } } + +export {default as convertFunction} from './convert.js'; diff --git a/src/style-spec/package.json b/src/style-spec/package.json index ca0e73b8eb0..cbe64f4aa24 100644 --- a/src/style-spec/package.json +++ b/src/style-spec/package.json @@ -17,15 +17,53 @@ "require": "./dist/index.cjs", "import": "./dist/index.es.js" }, + "./v8": "./src/reference/v8.json", + "./v8.min": "./dist/reference/v8.json", + "./latest": "./dist/reference/latest.js", + "./format": "./dist/format.js", + "./migrate": "./dist/migrate.js", + "./composite": "./dist/composite.js", + "./derefLayers": "./dist/deref.js", + "./diff": "./dist/diff.js", + "./ValidationError": "./dist/error/validation_error.js", + "./ParsingError": "./dist/error/parsing_error.js", + "./expression": "./dist/expression/index.js", + "./featureFilter": "./dist/feature_filter/index.js", + "./convertFilter": "./dist/feature_filter/convert.js", + "./Color": "./dist/util/color.js", + "./function": "./dist/function/index.js", + "./validate": "./dist/validate_style.js", + "./validateMapboxApiSupported": "./dist/validate_mapbox_api_supported.js", + "./visit": "./dist/visit.js", "./": { "import": "./" } }, + "typesVersions": { + "*": { + "latest": ["dist/reference/latest.js"], + "format": ["dist/format.js"], + "migrate": ["dist/migrate.js"], + "composite": ["dist/composite.js"], + "derefLayers": ["dist/deref.js"], + "diff": ["dist/diff.js"], + "ValidationError": ["dist/error/validation_error.js"], + "ParsingError": ["dist/error/parsing_error.js"], + "expression": ["dist/expression/index.js"], + "featureFilter": ["dist/feature_filter/index.js"], + "convertFilter": ["dist/feature_filter/convert.js"], + "Color": ["dist/util/color.js"], + "function": ["dist/function/index.js"], + "validate": ["dist/validate_style.js"], + "validateMapboxApiSupported": ["dist/validate_mapbox_api_supported.js"], + "visit": ["dist/visit.js"] + } + }, "scripts": { "pretest": "npm run build", "test": "node ./test.js", "copy-flow-typed": "cp -R ../../flow-typed .", - "build": "../../node_modules/.bin/rollup -c && ../../node_modules/.bin/rollup -c --environment esm", + "build": "../../node_modules/.bin/rollup -c && ../../node_modules/.bin/rollup -c --environment esm && node prepare_modules.js", "prepublishOnly": "npm run copy-flow-typed && npm run build", "postpublish": "rm -r flow-typed dist/index.cjs" }, diff --git a/src/style-spec/prepare_modules.js b/src/style-spec/prepare_modules.js new file mode 100755 index 00000000000..7b447e95877 --- /dev/null +++ b/src/style-spec/prepare_modules.js @@ -0,0 +1,34 @@ +#!/usr/bin/env node +import {existsSync, mkdirSync, readFileSync, writeFileSync} from 'fs'; +import glob from 'glob'; +import unassert from 'rollup-plugin-unassert'; +import flow from '@mapbox/flow-remove-types'; +import {dirname, join} from 'path'; + +const removeAssert = unassert({include: [/\.js$/]}); + +async function main() { + const files = glob.sync('**/*.js', { + ignore: ['+(bin|build|node_modules|dist)/**/*', 'rollup.config.js', 'test.js', 'prepare_modules.js'] + }); + for (let i = 0, ii = files.length; i < ii; i++) { + const path = files[i]; + console.log(path); + let file = readFileSync(path, 'utf8'); + file = flow(file, path).toString(); + const {code} = await removeAssert.transform(file, path); + const dir = join('dist', dirname(path)); + if (!existsSync(dir)) { + mkdirSync(dir); + } + writeFileSync(join('dist', path), code, 'utf8'); + } + + if (!existsSync(join('dist', 'reference'))) { + mkdirSync('dist/reference'); + } + const fullSpecJson = readFileSync('./reference/v8.json', 'utf8'); + const minifiedSpec = JSON.parse(fullSpecJson, (key, value) => ['doc', 'example'].includes(key) ? undefined : value); + writeFileSync('./dist/reference/v8.json', JSON.stringify(minifiedSpec), 'utf8'); +} +main();