diff --git a/.babelrc b/.babelrc index 812efc5966..4ab657393c 100644 --- a/.babelrc +++ b/.babelrc @@ -4,8 +4,6 @@ ], "plugins": ["@babel/plugin-transform-object-assign"], "ignore": [ - "dist/*.js", - "lib/**/*.js", - "es/**/*.js" + "lib/**/*.js" ] -} \ No newline at end of file +} diff --git a/.gitignore b/.gitignore index 2a4257e2c3..e461c61285 100644 --- a/.gitignore +++ b/.gitignore @@ -2,13 +2,13 @@ .vscode .c9 _site -coverage *swp -node_modules *.log -dist -lib -es -.nyc_output *.bak + +node_modules +.nyc_output +/coverage + +lib *.generated.js diff --git a/.travis.yml b/.travis.yml index d210e781bb..87886bcaf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: node_js node_js: - - 10 - 12 - 14 @@ -12,6 +11,9 @@ jobs: script: npm run lint node_js: lts/* name: Lint + - script: npm run test:src:transpile + node_js: 10 + name: Node 10 - script: 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then npm run test:browserstack; else npm run test:browser; fi' node_js: lts/* name: Browser Test diff --git a/HISTORY.md b/HISTORY.md index 59a8bfded1..e28f5a76cf 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -2,6 +2,16 @@ # not yet published, version 8.0.0 +!!! BE CAREFUL: BREAKING CHANGES !!! + +- You can now use mathjs directly in node.js using ES modules without need for + a transpiler (see #1928, #1941, #1962). + Automatically loading either commonjs code or ES modules code is improved. + All generated code is moved under `/lib`: the browser bundle is moved from + `/dist` to `/lib/browser`, ES module files are moved to `/lib/esm`, + and commonjs files are moved to `/lib/cjs`. Thanks @GreenImp. +- Non-minified bundle `dist/math.js` is no longer provided. Either use the + minified bundle, or create a bundle yourself. - Replaced random library `seed-random` with `seedrandom`, see #1955. Thanks @poppinlp. diff --git a/README.md b/README.md index 05da0f9ea8..b4cdeb0fb3 100644 --- a/README.md +++ b/README.md @@ -102,8 +102,8 @@ Then, the project can be build by executing the build script via npm: npm run build -This will build the library math.js and math.min.js from the source files and -put them in the folder dist. +This will build ESM output, CommonJS output, and the bundle math.js +from the source files and put them in the folder lib. ## Test diff --git a/bin/cli.js b/bin/cli.js index a4bc4ff3c3..449a4d6272 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -58,7 +58,7 @@ const PRECISION = 14 // decimals * @return {*} */ function getMath () { - return require('../lib/bundleAny') + return require('../lib/cjs/defaultInstance.js').default } /** diff --git a/bin/package.json b/bin/package.json new file mode 100644 index 0000000000..5bbefffbab --- /dev/null +++ b/bin/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/bin/repl.js b/bin/repl.js index 0147448bae..21c9b1164a 100755 --- a/bin/repl.js +++ b/bin/repl.js @@ -4,7 +4,7 @@ * This simply preloads mathjs and drops you into a REPL to * help interactive debugging. **/ -global.math = require('../lib/bundleAny') +global.math = require('../lib/cjs/defaultInstance.js').default const repl = require('repl') repl.start({ useGlobal: true }) diff --git a/dist/math.js b/dist/math.js new file mode 100644 index 0000000000..b01e410f9f --- /dev/null +++ b/dist/math.js @@ -0,0 +1,3 @@ +// TODO: deprecated since v8, remove this deprecation warning in v9 +throw new Error('The non-minified file "mathjs/dist/math.js" has removed since mathjs@8.0.0. ' + + 'Please use the minified bundle "mathjs/lib/browser/math.js" instead.') diff --git a/dist/math.min.js b/dist/math.min.js new file mode 100644 index 0000000000..2a2391f07b --- /dev/null +++ b/dist/math.min.js @@ -0,0 +1,3 @@ +// TODO: deprecated since v8, remove this deprecation warning in v9 +throw new Error('The file "mathjs/dist/math.min.js" has been moved to "mathjs/lib/browser/math.js" since mathjs@8.0.0. ' + + 'Please load the bundle via the new path.') diff --git a/dist/package.json b/dist/package.json new file mode 100644 index 0000000000..5bbefffbab --- /dev/null +++ b/dist/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +} diff --git a/examples/browser/angle_configuration.html b/examples/browser/angle_configuration.html index e377893e21..d5f66cde8d 100644 --- a/examples/browser/angle_configuration.html +++ b/examples/browser/angle_configuration.html @@ -15,7 +15,7 @@ } - + diff --git a/examples/browser/basic_usage.html b/examples/browser/basic_usage.html index 90d496e2c8..28ecc06500 100644 --- a/examples/browser/basic_usage.html +++ b/examples/browser/basic_usage.html @@ -3,7 +3,7 @@ math.js | basic usage - + diff --git a/examples/browser/currency_conversion.html b/examples/browser/currency_conversion.html index 293e80baa0..4b826b8121 100644 --- a/examples/browser/currency_conversion.html +++ b/examples/browser/currency_conversion.html @@ -4,7 +4,7 @@ math.js | currency conversion - + - + diff --git a/examples/browser/plot.html b/examples/browser/plot.html index 61c9d2c296..eefc6bb8c2 100644 --- a/examples/browser/plot.html +++ b/examples/browser/plot.html @@ -3,7 +3,7 @@ math.js | plot - + diff --git a/examples/browser/pretty_printing_with_mathjax.html b/examples/browser/pretty_printing_with_mathjax.html index f4427ea004..5d835d2e1a 100644 --- a/examples/browser/pretty_printing_with_mathjax.html +++ b/examples/browser/pretty_printing_with_mathjax.html @@ -4,7 +4,7 @@ math.js | pretty printing with MathJax - +