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

[@mapbox/static-apis] [feature] Provide modules with reference without docs and examples #11628

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/style-spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/style-spec/expression/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,5 @@ function getDefaultValue(spec: StylePropertySpecification): Value {
return spec.default;
}
}

export {isExpressionFilter} from '../feature_filter/index.js';
2 changes: 2 additions & 0 deletions src/style-spec/function/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
40 changes: 39 additions & 1 deletion src/style-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
34 changes: 34 additions & 0 deletions src/style-spec/prepare_modules.js
Original file line number Diff line number Diff line change
@@ -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();