Skip to content

Commit

Permalink
Fix build, bundling and distribution issues (#1032)
Browse files Browse the repository at this point in the history
- Fix `package.json` main not pointing to dist
- Fix node builtins not being shimmed and treeshaken out out
  • Loading branch information
Arindam Bose authored Feb 3, 2021
1 parent 2412b28 commit ff4f8d1
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 24 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"homepage": "https://github.com/mapbox/mapbox-gl-draw",
"author": "mapbox",
"license": "ISC",
"main": "index.js",
"main": "dist/mapbox-gl-draw.js",
"browser": "dist/mapbox-gl-draw.js",
"style": "dist/mapbox-gl-draw.css",
"browserify": {
Expand Down Expand Up @@ -77,6 +77,7 @@
"opener": "^1.4.1",
"rollup": "^1.27.13",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-terser": "^5.1.3",
"sinon": "^7.5.0",
"st": "^2.0.0",
Expand All @@ -86,7 +87,7 @@
"unassertify": "^2.0.3"
},
"peerDependencies": {
"mapbox-gl": ">=0.27.0 <2.0.0"
"mapbox-gl": ">=0.27.0"
},
"dependencies": {
"@mapbox/geojson-area": "^0.2.1",
Expand Down
10 changes: 3 additions & 7 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import buble from '@rollup/plugin-buble';
import {terser} from 'rollup-plugin-terser';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import builtins from 'rollup-plugin-node-builtins';

export default {
input: ['index.js'],
Expand All @@ -18,12 +19,6 @@ export default {
indent: false
},
treeshake: true,
external: [
// geojsonlint-lines has a main function that requires the path and fs module.
// We never call it.
'fs',
'path'
],
plugins: [
replace({
'process.env.NODE_ENV': "'browser'"
Expand All @@ -32,8 +27,9 @@ export default {
minified ? terser() : false,
resolve({
browser: true,
preferBuiltins: false
preferBuiltins: true
}),
builtins(),
commonjs({
// global keyword handling causes Webpack compatibility issues, so we disabled it:
// https://github.com/mapbox/mapbox-gl-js/pull/6956
Expand Down
2 changes: 1 addition & 1 deletion test/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import test from 'tape';
import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy
import * as Constants from '../src/constants';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import createMap from './utils/create_map';
import getGeoJSON from './utils/get_geojson';
import setupAfterNextRender from './utils/after_next_render';
Expand Down
2 changes: 1 addition & 1 deletion test/direct_select.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint no-shadow:[0] */
import turfCentroid from '@turf/centroid';
import test from 'tape';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import click from './utils/mouse_click';
import tap from './utils/touch_tap';
import getGeoJSON from './utils/get_geojson';
Expand Down
2 changes: 1 addition & 1 deletion test/draw_line_string.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'tape';
import xtend from 'xtend';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import mouseClick from './utils/mouse_click';
import touchTap from './utils/touch_tap';
import createMap from './utils/create_map';
Expand Down
2 changes: 1 addition & 1 deletion test/draw_point.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'tape';
import xtend from 'xtend';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import mouseClick from './utils/mouse_click';
import touchTap from './utils/touch_tap';
import createMap from './utils/create_map';
Expand Down
2 changes: 1 addition & 1 deletion test/draw_polygon.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'tape';
import xtend from 'xtend';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import createMap from './utils/create_map';
import mouseClick from './utils/mouse_click';
import touchTap from './utils/touch_tap';
Expand Down
2 changes: 1 addition & 1 deletion test/interaction_events.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import test from 'tape';
import xtend from 'xtend';
import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy
import MapboxDraw from '../';
import MapboxDraw from '../index';
import click from './utils/mouse_click';
import createMap from './utils/create_map';
import createAfterNextRender from './utils/after_next_render';
Expand Down
2 changes: 1 addition & 1 deletion test/line_string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'tape';
import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy
import Feature from '../src/feature_types/feature';
import LineString from '../src/feature_types/line_string';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import createFeature from './utils/create_feature';
import getPublicMemberKeys from './utils/get_public_member_keys';
import createMockCtx from './utils/create_mock_feature_context';
Expand Down
2 changes: 1 addition & 1 deletion test/options.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-shadow:[0] */
import test from 'tape';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import modes from '../src/modes/index';
import styleWithSourcesFixture from './fixtures/style_with_sources.json';

Expand Down
2 changes: 1 addition & 1 deletion test/point.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'tape';
import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy
import Feature from '../src/feature_types/feature';
import Point from '../src/feature_types/point';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import createFeature from './utils/create_feature';
import getPublicMemberKeys from './utils/get_public_member_keys';
import createMockCtx from './utils/create_mock_feature_context';
Expand Down
2 changes: 1 addition & 1 deletion test/polygon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import test from 'tape';
import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy
import Feature from '../src/feature_types/feature';
import Polygon from '../src/feature_types/polygon';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import createFeature from './utils/create_feature';
import getPublicMemberKeys from './utils/get_public_member_keys';
import createMockCtx from './utils/create_mock_feature_context';
Expand Down
2 changes: 1 addition & 1 deletion test/simple_select.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-shadow:[0] */
import test from 'tape';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy
import setupAfterNextRender from './utils/after_next_render';
import makeMouseEvent from './utils/make_mouse_event';
Expand Down
2 changes: 1 addition & 1 deletion test/static.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint no-shadow:[0] */
import test from 'tape';
import MapboxDraw from '../';
import MapboxDraw from '../index';
import spy from 'sinon/lib/sinon/spy'; // avoid babel-register-related error by importing only spy
import setupAfterNextRender from './utils/after_next_render';
import makeMouseEvent from './utils/make_mouse_event';
Expand Down
Loading

0 comments on commit ff4f8d1

Please sign in to comment.