From 535ba4a03ff0a23d41a565dd45059f489c9edd7e Mon Sep 17 00:00:00 2001 From: Anand Thakker Date: Thu, 3 May 2018 11:28:04 -0400 Subject: [PATCH] Use named exports in style-spec.js (#6602) Fixes #6601 --- package.json | 2 +- src/style-spec/style-spec.js | 41 ++++++++++++++-------------- test/build/style-spec.test.js | 7 +++++ test/unit/style-spec/migrate.test.js | 4 ++- test/unit/style-spec/spec.test.js | 4 ++- 5 files changed, 35 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index e9d9d3eefc4..296b2868c81 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "watch-dev": "rollup -c --environment BUILD:dev --watch", "build-min": "rollup -c --environment BUILD:production", "build-css": "postcss -o dist/mapbox-gl.css src/css/mapbox-gl.css", - "build-style-spec": "cd src/style-spec && npm run build && cd ../.. && cp -R 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/* 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/rollup_config_benchmarks.js", diff --git a/src/style-spec/style-spec.js b/src/style-spec/style-spec.js index 1d48171fc9c..379f1e8bf85 100644 --- a/src/style-spec/style-spec.js +++ b/src/style-spec/style-spec.js @@ -58,8 +58,6 @@ export type StylePropertySpecification = { }; import v8 from './reference/v8.json'; -export {v8}; - import latest from './reference/latest'; import format from './format'; import migrate from './migrate'; @@ -75,7 +73,25 @@ import convertFunction from './function/convert'; import validate from './validate_style'; -const exported = { +const expression = { + StyleExpression, + isExpression, + createExpression, + createPropertyExpression, + normalizePropertyExpression, + ZoomConstantExpression, + ZoomDependentExpression, + StylePropertyFunction +}; + +const styleFunction = { + convertFunction, + createFunction, + isFunction +}; + +export { + v8, latest, format, migrate, @@ -83,27 +99,12 @@ const exported = { diff, ValidationError, ParsingError, - expression: { - StyleExpression, - isExpression, - createExpression, - createPropertyExpression, - normalizePropertyExpression, - ZoomConstantExpression, - ZoomDependentExpression, - StylePropertyFunction - }, + expression, featureFilter, Color, - function: { - convertFunction, - createFunction, - isFunction - }, + styleFunction as function, validate }; -export default exported; - validate.parsed = validate; validate.latest = validate; diff --git a/test/build/style-spec.test.js b/test/build/style-spec.test.js index c4352d393c2..94793509d6a 100644 --- a/test/build/style-spec.test.js +++ b/test/build/style-spec.test.js @@ -54,5 +54,12 @@ test('@mapbox/mapbox-gl-style-spec npm package', (t) => { }); }); + t.test('exports components directly, not behind `default` - https://github.com/mapbox/mapbox-gl-js/issues/6601', (t) => { + const spec = require('../../dist/style-spec/index.js'); + t.ok(spec.validate); + t.notOk(spec.default && spec.default.validate); + t.end(); + }); + t.end(); }); diff --git a/test/unit/style-spec/migrate.test.js b/test/unit/style-spec/migrate.test.js index 1b93747cfbc..24eab4aa237 100644 --- a/test/unit/style-spec/migrate.test.js +++ b/test/unit/style-spec/migrate.test.js @@ -1,12 +1,14 @@ import { test as t } from 'mapbox-gl-js-test'; import fs from 'fs'; import glob from 'glob'; -import spec from '../../../src/style-spec/style-spec'; import path from 'path'; import validate from '../../../src/style-spec/validate_style'; import v8 from '../../../src/style-spec/reference/v8'; import migrate from '../../../src/style-spec/migrate'; +/* eslint-disable import/namespace */ +import * as spec from '../../../src/style-spec/style-spec'; + const UPDATE = !!process.env.UPDATE; t('does not migrate from version 5', (t) => { diff --git a/test/unit/style-spec/spec.test.js b/test/unit/style-spec/spec.test.js index 80751ba13de..ad58f701d28 100644 --- a/test/unit/style-spec/spec.test.js +++ b/test/unit/style-spec/spec.test.js @@ -1,5 +1,7 @@ import { test } from 'mapbox-gl-js-test'; -import spec from '../../../src/style-spec/style-spec'; + +/* eslint-disable import/namespace */ +import * as spec from '../../../src/style-spec/style-spec'; ['v8', 'latest'].forEach((version) => { ['', 'min'].forEach((kind) => {