From 882e07c1ba9283ec2ba884eae959cd75f7a1d4d5 Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 16 Jan 2021 23:10:27 +0000 Subject: [PATCH] fix poly-decomp external require --- package-lock.json | 74 ++++++++++++++++++++++++------------------- package.json | 2 ++ src/factory/Bodies.js | 9 +----- webpack.config.js | 18 ++++++----- 4 files changed, 54 insertions(+), 49 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1d7c9893..477172b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1731,12 +1731,6 @@ } } }, - "dat.gui": { - "version": "0.7.7", - "resolved": "https://registry.npmjs.org/dat.gui/-/dat.gui-0.7.7.tgz", - "integrity": "sha512-sRl/28gF/XRC5ywC9I4zriATTsQcpSsRG7seXCPnTkK8/EQMIbCu5NPMpICLGxX9ZEUvcXR3ArLYCtgreFoMDw==", - "dev": true - }, "eslint": { "version": "6.8.0", "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.8.0.tgz", @@ -7564,39 +7558,12 @@ } } }, - "jquery": { - "version": "3.5.1", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz", - "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==", - "dev": true - }, "json-stringify-pretty-compact": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/json-stringify-pretty-compact/-/json-stringify-pretty-compact-2.0.0.tgz", "integrity": "sha512-WRitRfs6BGq4q8gTgOy4ek7iPFXjbra0H3PmDLKm2xnZ+Gh1HUhiKGgCZkSPNULlP7mvfu6FV/mOLhCarspADQ==", "dev": true }, - "jstree": { - "version": "3.3.11", - "resolved": "https://registry.npmjs.org/jstree/-/jstree-3.3.11.tgz", - "integrity": "sha512-9ZJKroPjCyjb6JLPuAbBrLJKT6pS1f4m5gkwoEagG5oQWtvzm0IiDsntXTxeFtz7AmqrKfij+gLfF9MgWriNxg==", - "dev": true, - "requires": { - "jquery": ">=1.9.1" - } - }, - "keymaster": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/keymaster/-/keymaster-1.6.2.tgz", - "integrity": "sha1-4a5U0OqUiPn2C2a2aPAumhlGxus=", - "dev": true - }, - "matter-js": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/matter-js/-/matter-js-0.15.0.tgz", - "integrity": "sha512-+SXrgSz0IbbXo5pifWnw/IlWVrkrZXPI+2gMdvI6BCHpXrgRsmlj2wGKVBmjZC6qzBNM2ImqHCRuYhmEmwTOlA==", - "dev": true - }, "matter-tools": { "version": "0.12.3", "resolved": "https://registry.npmjs.org/matter-tools/-/matter-tools-0.12.3.tgz", @@ -7608,6 +7575,41 @@ "jstree": "^3.3.11", "keymaster": "^1.6.2", "matter-js": "^0.15.0" + }, + "dependencies": { + "dat.gui": { + "version": "0.7.7", + "resolved": "https://registry.npmjs.org/dat.gui/-/dat.gui-0.7.7.tgz", + "integrity": "sha512-sRl/28gF/XRC5ywC9I4zriATTsQcpSsRG7seXCPnTkK8/EQMIbCu5NPMpICLGxX9ZEUvcXR3ArLYCtgreFoMDw==", + "dev": true + }, + "jquery": { + "version": "3.5.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.5.1.tgz", + "integrity": "sha512-XwIBPqcMn57FxfT+Go5pzySnm4KWkT1Tv7gjrpT1srtf8Weynl6R273VJ5GjkRb51IzMp5nbaPjJXMWeju2MKg==", + "dev": true + }, + "jstree": { + "version": "3.3.11", + "resolved": "https://registry.npmjs.org/jstree/-/jstree-3.3.11.tgz", + "integrity": "sha512-9ZJKroPjCyjb6JLPuAbBrLJKT6pS1f4m5gkwoEagG5oQWtvzm0IiDsntXTxeFtz7AmqrKfij+gLfF9MgWriNxg==", + "dev": true, + "requires": { + "jquery": ">=1.9.1" + } + }, + "keymaster": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/keymaster/-/keymaster-1.6.2.tgz", + "integrity": "sha1-4a5U0OqUiPn2C2a2aPAumhlGxus=", + "dev": true + }, + "matter-js": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/matter-js/-/matter-js-0.15.0.tgz", + "integrity": "sha512-+SXrgSz0IbbXo5pifWnw/IlWVrkrZXPI+2gMdvI6BCHpXrgRsmlj2wGKVBmjZC6qzBNM2ImqHCRuYhmEmwTOlA==", + "dev": true + } } }, "pathseg": { @@ -7616,6 +7618,12 @@ "integrity": "sha512-+pQS7lTaoVIXhaCW7R3Wd/165APzZHWzYVqe7dxzdupxQwebgpBaCmf0/XZwmoA/rkDq3qvzO0qv4d5oFVrBRw==", "dev": true }, + "poly-decomp": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/poly-decomp/-/poly-decomp-0.3.0.tgz", + "integrity": "sha512-hWeBxGzPYiybmI4548Fca7Up/0k1qS5+79cVHI9+H33dKya5YNb9hxl0ZnDaDgvrZSuYFBhkCK/HOnqN7gefkQ==", + "dev": true + }, "puppeteer-core": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/puppeteer-core/-/puppeteer-core-5.5.0.tgz", diff --git a/package.json b/package.json index d9225feb..2d3e7432 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "json-stringify-pretty-compact": "^2.0.0", "matter-tools": "^0.12.3", "pathseg": "^1.2.0", + "poly-decomp": "^0.3.0", "puppeteer-core": "^5.5.0", "webpack": "^4.46.0", "webpack-cli": "^3.3.11", @@ -38,6 +39,7 @@ "build-alpha": "webpack --mode=production --env.ALPHA & webpack --mode=production --env.MINIMIZE --env.ALPHA", "build-examples": "webpack --config webpack.examples.config.js --mode=production & webpack --config webpack.examples.config.js --mode=production --env.MINIMIZE", "build-examples-alpha": "webpack --config webpack.examples.config.js --mode=production --env.ALPHA & webpack --config webpack.examples.config.js --mode=production --env.MINIMIZE --env.ALPHA", + "build-demo": "mkdir -p demo/lib && cp node_modules/matter-tools/build/matter-tools.demo.js demo/lib & cp node_modules/matter-tools/build/matter-tools.gui.js demo/lib & cp node_modules/matter-tools/build/matter-tools.inspector.js demo/lib & cp node_modules/pathseg/pathseg.js demo/lib & cp node_modules/poly-decomp/build/decomp.js demo/lib", "lint": "eslint 'src/**/*.js' 'demo/js/Demo.js' 'demo/js/Compare.js' 'examples/*.js' 'webpack.*.js'", "doc": "yuidoc --config yuidoc.json --project-version $npm_package_version", "test": "npm run test-node", diff --git a/src/factory/Bodies.js b/src/factory/Bodies.js index e4ffe667..6de5a4fc 100644 --- a/src/factory/Bodies.js +++ b/src/factory/Bodies.js @@ -197,8 +197,7 @@ var Vector = require('../geometry/Vector'); * @return {body} */ Bodies.fromVertices = function(x, y, vertexSets, options, flagInternal, removeCollinear, minimumArea, removeDuplicatePoints) { - var globals = typeof global !== 'undefined' ? global : window, - decomp, + var decomp = require('poly-decomp'), body, parts, isConvex, @@ -209,12 +208,6 @@ var Vector = require('../geometry/Vector'); v, z; - try { - decomp = globals.decomp || require('poly-decomp'); - } catch (e) { - // decomp is undefined - } - options = options || {}; parts = []; diff --git a/webpack.config.js b/webpack.config.js index b833432d..5362dd92 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -26,6 +26,15 @@ License ${pkg.license}${!minimize ? '\n\n' + license : ''}`; const entry = isDevServer ? './demo/js/Server.js' : './src/module/main.js'; + const externals = isDevServer ? undefined : { + 'poly-decomp': { + commonjs: 'poly-decomp', + commonjs2: 'poly-decomp', + amd: 'poly-decomp', + root: 'decomp' + } + }; + return { entry: { [name]: entry }, output: { @@ -48,14 +57,7 @@ License ${pkg.license}${!minimize ? '\n\n' + license : ''}`; __MATTER_VERSION__: JSON.stringify(!isDevServer ? version : '*'), }) ], - externals: { - 'poly-decomp': { - commonjs: 'poly-decomp', - commonjs2: 'poly-decomp', - amd: 'poly-decomp', - root: 'decomp' - } - }, + externals, devServer: { contentBase: [ path.resolve(__dirname, './demo'),