From 6f007157547c02ab6bfda06842bb1e118adbb9e8 Mon Sep 17 00:00:00 2001 From: Jos de Jong Date: Sun, 20 Sep 2020 18:01:29 +0200 Subject: [PATCH] Specify import require paths (continuation of #1941) (#1962) * Add `.js` extension to source file imports * Specify package `exports` in `package.json` Specify package type as `commonjs` (It's good to be specific) * Move all compiled scripts into `lib` directory Remove ./number.js (You can use the compiled ones in `./lib/*`) Tell node that the `esm` directory is type `module` and enable tree shaking. Remove unused files from packages `files` property * Allow importing of package.json * Make library ESM first * - Fix merge conflicts - Refactor `bundleAny` into `defaultInstance.js` and `browserBundle.cjs` - Refactor unit tests to be able to run with plain nodejs (no transpiling) - Fix browser examples * Fix browser and browserstack tests * Fix running unit tests on Node 10 (which has no support for modules) * Fix node.js examples (those are still commonjs) * Remove the need for `browserBundle.cjs` * Generate minified bundle only * [Security] Bump node-fetch from 2.6.0 to 2.6.1 (#1963) Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1. **This update includes a security fix.** - [Release notes](https://github.com/bitinn/node-fetch/releases) - [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md) - [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> * Cleanup console.log * Add integration tests to test the entry points (commonjs/esm, full/number only) * Create backward compatibility error messages in the files moved/removed since v8 * Describe breaking changes in HISTORY.md * Bump karma from 5.2.1 to 5.2.2 (#1965) Bumps [karma](https://github.com/karma-runner/karma) from 5.2.1 to 5.2.2. - [Release notes](https://github.com/karma-runner/karma/releases) - [Changelog](https://github.com/karma-runner/karma/blob/master/CHANGELOG.md) - [Commits](https://github.com/karma-runner/karma/compare/v5.2.1...v5.2.2) Signed-off-by: dependabot-preview[bot] Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Lee Langley-Rees Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> --- .babelrc | 6 +- .gitignore | 12 +- .travis.yml | 4 +- HISTORY.md | 10 + README.md | 4 +- bin/cli.js | 2 +- bin/package.json | 3 + bin/repl.js | 2 +- dist/math.js | 3 + dist/math.min.js | 3 + dist/package.json | 3 + examples/browser/angle_configuration.html | 2 +- examples/browser/basic_usage.html | 2 +- examples/browser/currency_conversion.html | 2 +- examples/browser/custom_separators.html | 2 +- examples/browser/plot.html | 2 +- .../browser/pretty_printing_with_mathjax.html | 2 +- examples/browser/printing_html.html | 2 +- examples/browser/requirejs_loading.html | 2 +- .../rocket_trajectory_optimization.html | 2 +- examples/browser/webworkers/worker.js | 2 +- examples/package.json | 3 + gulpfile.js => gulpfile.cjs | 145 +++-- main/es5/index.js | 4 +- main/es5/number.js | 4 +- main/es5/package.json | 3 + main/esm/index.js | 4 +- main/esm/number.js | 4 +- main/esm/package.json | 3 + number.cjs | 3 + number.js | 1 - package-lock.json | 44 +- package.json | 57 +- src/bundleAny.js | 7 - src/constants.js | 8 +- src/core/create.js | 22 +- src/core/function/config.js | 4 +- src/core/function/import.js | 10 +- src/core/function/typed.js | 6 +- src/defaultInstance.js | 4 + src/entry/allFactoriesAny.js | 2 +- src/entry/allFactoriesNumber.js | 2 +- src/entry/configReadonly.js | 4 +- src/entry/mainAny.js | 22 +- src/entry/mainNumber.js | 22 +- src/entry/typeChecks.js | 2 +- src/expression/Help.js | 8 +- src/expression/Parser.js | 6 +- src/expression/embeddedDocs/embeddedDocs.js | 426 +++++++-------- src/expression/function/compile.js | 4 +- src/expression/function/evaluate.js | 4 +- src/expression/function/help.js | 8 +- src/expression/function/parser.js | 2 +- src/expression/node/AccessorNode.js | 8 +- src/expression/node/ArrayNode.js | 6 +- src/expression/node/AssignmentNode.js | 12 +- src/expression/node/BlockNode.js | 6 +- src/expression/node/ConditionalNode.js | 6 +- src/expression/node/ConstantNode.js | 8 +- src/expression/node/FunctionAssignmentNode.js | 18 +- src/expression/node/FunctionNode.js | 16 +- src/expression/node/IndexNode.js | 10 +- src/expression/node/Node.js | 8 +- src/expression/node/ObjectNode.js | 10 +- src/expression/node/OperatorNode.js | 14 +- src/expression/node/ParenthesisNode.js | 4 +- src/expression/node/RangeNode.js | 6 +- src/expression/node/RelationalNode.js | 10 +- src/expression/node/SymbolNode.js | 8 +- src/expression/node/utils/access.js | 4 +- src/expression/node/utils/assign.js | 4 +- src/expression/operators.js | 4 +- src/expression/parse.js | 8 +- src/expression/transform/apply.transform.js | 8 +- src/expression/transform/column.transform.js | 8 +- src/expression/transform/concat.transform.js | 8 +- src/expression/transform/diff.transform.js | 8 +- src/expression/transform/filter.transform.js | 10 +- src/expression/transform/forEach.transform.js | 10 +- src/expression/transform/index.transform.js | 4 +- src/expression/transform/map.transform.js | 10 +- src/expression/transform/max.transform.js | 8 +- src/expression/transform/mean.transform.js | 8 +- src/expression/transform/min.transform.js | 8 +- src/expression/transform/range.transform.js | 4 +- src/expression/transform/row.transform.js | 8 +- src/expression/transform/std.transform.js | 8 +- src/expression/transform/subset.transform.js | 6 +- src/expression/transform/sum.transform.js | 8 +- .../utils/compileInlineExpression.js | 2 +- .../transform/utils/errorTransform.js | 2 +- .../transform/variance.transform.js | 8 +- src/factoriesAny.js | 514 +++++++++--------- src/factoriesNumber.js | 210 +++---- src/function/algebra/decomposition/lup.js | 4 +- src/function/algebra/decomposition/qr.js | 2 +- src/function/algebra/decomposition/slu.js | 8 +- src/function/algebra/derivative.js | 4 +- src/function/algebra/rationalize.js | 8 +- src/function/algebra/simplify.js | 14 +- src/function/algebra/simplify/resolve.js | 4 +- .../algebra/simplify/simplifyConstant.js | 8 +- src/function/algebra/simplify/simplifyCore.js | 4 +- src/function/algebra/simplify/util.js | 6 +- src/function/algebra/solver/lsolve.js | 4 +- src/function/algebra/solver/lsolveAll.js | 4 +- src/function/algebra/solver/lusolve.js | 8 +- src/function/algebra/solver/usolve.js | 4 +- src/function/algebra/solver/usolveAll.js | 4 +- .../algebra/solver/utils/solveValidation.js | 6 +- src/function/algebra/sparse/csAmd.js | 8 +- src/function/algebra/sparse/csChol.js | 6 +- src/function/algebra/sparse/csCounts.js | 4 +- src/function/algebra/sparse/csDfs.js | 6 +- src/function/algebra/sparse/csEreach.js | 4 +- src/function/algebra/sparse/csLu.js | 4 +- src/function/algebra/sparse/csMark.js | 2 +- src/function/algebra/sparse/csPost.js | 2 +- src/function/algebra/sparse/csReach.js | 6 +- src/function/algebra/sparse/csSpsolve.js | 4 +- src/function/algebra/sparse/csSqr.js | 12 +- src/function/algebra/sparse/csSymperm.js | 4 +- src/function/algebra/sparse/csUnflip.js | 2 +- src/function/arithmetic/abs.js | 6 +- src/function/arithmetic/add.js | 14 +- src/function/arithmetic/addScalar.js | 4 +- src/function/arithmetic/cbrt.js | 8 +- src/function/arithmetic/ceil.js | 10 +- src/function/arithmetic/cube.js | 6 +- src/function/arithmetic/divide.js | 8 +- src/function/arithmetic/divideScalar.js | 4 +- src/function/arithmetic/dotDivide.js | 16 +- src/function/arithmetic/dotMultiply.js | 12 +- src/function/arithmetic/dotPow.js | 14 +- src/function/arithmetic/exp.js | 6 +- src/function/arithmetic/expm1.js | 6 +- src/function/arithmetic/fix.js | 4 +- src/function/arithmetic/floor.js | 8 +- src/function/arithmetic/gcd.js | 14 +- src/function/arithmetic/hypot.js | 4 +- src/function/arithmetic/lcm.js | 14 +- src/function/arithmetic/log.js | 6 +- src/function/arithmetic/log10.js | 6 +- src/function/arithmetic/log1p.js | 6 +- src/function/arithmetic/log2.js | 6 +- src/function/arithmetic/mod.js | 18 +- src/function/arithmetic/multiply.js | 12 +- src/function/arithmetic/multiplyScalar.js | 4 +- src/function/arithmetic/norm.js | 2 +- src/function/arithmetic/nthRoot.js | 16 +- src/function/arithmetic/nthRoots.js | 2 +- src/function/arithmetic/pow.js | 8 +- src/function/arithmetic/round.js | 14 +- src/function/arithmetic/sign.js | 6 +- src/function/arithmetic/sqrt.js | 4 +- src/function/arithmetic/square.js | 6 +- src/function/arithmetic/subtract.js | 16 +- src/function/arithmetic/unaryMinus.js | 6 +- src/function/arithmetic/unaryPlus.js | 6 +- src/function/arithmetic/xgcd.js | 4 +- src/function/bitwise/bitAnd.js | 16 +- src/function/bitwise/bitNot.js | 8 +- src/function/bitwise/bitOr.js | 16 +- src/function/bitwise/bitXor.js | 16 +- src/function/bitwise/leftShift.js | 20 +- src/function/bitwise/rightArithShift.js | 20 +- src/function/bitwise/rightLogShift.js | 18 +- src/function/combinatorics/bellNumbers.js | 2 +- src/function/combinatorics/catalan.js | 2 +- src/function/combinatorics/composition.js | 2 +- src/function/combinatorics/stirlingS2.js | 2 +- src/function/complex/arg.js | 4 +- src/function/complex/conj.js | 4 +- src/function/complex/im.js | 4 +- src/function/complex/re.js | 4 +- src/function/geometry/distance.js | 4 +- src/function/geometry/intersect.js | 4 +- src/function/logical/and.js | 14 +- src/function/logical/not.js | 6 +- src/function/logical/or.js | 14 +- src/function/logical/xor.js | 14 +- src/function/matrix/apply.js | 8 +- src/function/matrix/column.js | 6 +- src/function/matrix/concat.js | 12 +- src/function/matrix/cross.js | 4 +- src/function/matrix/ctranspose.js | 2 +- src/function/matrix/det.js | 8 +- src/function/matrix/diag.js | 8 +- src/function/matrix/diff.js | 6 +- src/function/matrix/dot.js | 4 +- src/function/matrix/eigs.js | 6 +- src/function/matrix/expm.js | 6 +- src/function/matrix/filter.js | 6 +- src/function/matrix/flatten.js | 6 +- src/function/matrix/forEach.js | 6 +- src/function/matrix/getMatrixDataType.js | 6 +- src/function/matrix/identity.js | 8 +- src/function/matrix/inv.js | 8 +- src/function/matrix/kron.js | 4 +- src/function/matrix/map.js | 4 +- src/function/matrix/ones.js | 8 +- src/function/matrix/partitionSelect.js | 6 +- src/function/matrix/range.js | 4 +- src/function/matrix/reshape.js | 4 +- src/function/matrix/resize.js | 16 +- src/function/matrix/row.js | 6 +- src/function/matrix/size.js | 6 +- src/function/matrix/sort.js | 4 +- src/function/matrix/sqrtm.js | 8 +- src/function/matrix/squeeze.js | 6 +- src/function/matrix/subset.js | 12 +- src/function/matrix/trace.js | 6 +- src/function/matrix/transpose.js | 6 +- src/function/matrix/zeros.js | 8 +- src/function/probability/combinations.js | 4 +- .../probability/combinationsWithRep.js | 6 +- src/function/probability/factorial.js | 4 +- src/function/probability/gamma.js | 6 +- src/function/probability/kldivergence.js | 2 +- src/function/probability/multinomial.js | 4 +- src/function/probability/permutations.js | 6 +- src/function/probability/pickRandom.js | 8 +- src/function/probability/random.js | 8 +- src/function/probability/randomInt.js | 8 +- src/function/relational/compare.js | 16 +- src/function/relational/compareNatural.js | 4 +- src/function/relational/compareText.js | 8 +- src/function/relational/deepEqual.js | 2 +- src/function/relational/equal.js | 12 +- src/function/relational/equalScalar.js | 8 +- src/function/relational/equalText.js | 2 +- src/function/relational/larger.js | 16 +- src/function/relational/largerEq.js | 16 +- src/function/relational/smaller.js | 16 +- src/function/relational/smallerEq.js | 16 +- src/function/relational/unequal.js | 12 +- src/function/set/setCartesian.js | 4 +- src/function/set/setDifference.js | 4 +- src/function/set/setDistinct.js | 4 +- src/function/set/setIntersect.js | 4 +- src/function/set/setIsSubset.js | 4 +- src/function/set/setMultiplicity.js | 4 +- src/function/set/setPowerset.js | 4 +- src/function/set/setSize.js | 4 +- src/function/set/setSymDifference.js | 4 +- src/function/set/setUnion.js | 4 +- src/function/special/erf.js | 6 +- src/function/statistics/mad.js | 6 +- src/function/statistics/max.js | 6 +- src/function/statistics/mean.js | 8 +- src/function/statistics/median.js | 8 +- src/function/statistics/min.js | 6 +- src/function/statistics/mode.js | 4 +- src/function/statistics/prod.js | 6 +- src/function/statistics/quantileSeq.js | 8 +- src/function/statistics/std.js | 2 +- src/function/statistics/sum.js | 6 +- .../statistics/utils/improveErrorMessage.js | 2 +- src/function/statistics/variance.js | 8 +- src/function/string/format.js | 4 +- src/function/string/print.js | 6 +- src/function/trigonometry/acos.js | 4 +- src/function/trigonometry/acosh.js | 6 +- src/function/trigonometry/acot.js | 6 +- src/function/trigonometry/acoth.js | 6 +- src/function/trigonometry/acsc.js | 6 +- src/function/trigonometry/acsch.js | 6 +- src/function/trigonometry/asec.js | 6 +- src/function/trigonometry/asech.js | 6 +- src/function/trigonometry/asin.js | 4 +- src/function/trigonometry/asinh.js | 6 +- src/function/trigonometry/atan.js | 4 +- src/function/trigonometry/atan2.js | 16 +- src/function/trigonometry/atanh.js | 6 +- src/function/trigonometry/cos.js | 4 +- src/function/trigonometry/cosh.js | 6 +- src/function/trigonometry/cot.js | 6 +- src/function/trigonometry/coth.js | 6 +- src/function/trigonometry/csc.js | 6 +- src/function/trigonometry/csch.js | 6 +- src/function/trigonometry/sec.js | 6 +- src/function/trigonometry/sech.js | 6 +- src/function/trigonometry/sin.js | 4 +- src/function/trigonometry/sinh.js | 6 +- src/function/trigonometry/tan.js | 4 +- src/function/trigonometry/tanh.js | 6 +- src/function/unit/to.js | 6 +- src/function/utils/clone.js | 4 +- src/function/utils/hasNumericValue.js | 2 +- src/function/utils/isInteger.js | 6 +- src/function/utils/isNaN.js | 6 +- src/function/utils/isNegative.js | 6 +- src/function/utils/isNumeric.js | 4 +- src/function/utils/isPositive.js | 6 +- src/function/utils/isPrime.js | 4 +- src/function/utils/isZero.js | 6 +- src/function/utils/numeric.js | 6 +- src/function/utils/typeOf.js | 4 +- src/index.js | 1 + src/json/replacer.js | 2 +- src/json/reviver.js | 2 +- src/number.js | 1 + src/plain/bignumber/index.js | 2 +- src/plain/number/arithmetic.js | 2 +- src/plain/number/bitwise.js | 2 +- src/plain/number/combinations.js | 4 +- src/plain/number/index.js | 18 +- src/plain/number/probability.js | 4 +- src/plain/number/trigonometry.js | 2 +- src/plain/number/utils.js | 2 +- src/type/bignumber/BigNumber.js | 2 +- src/type/bignumber/function/bignumber.js | 4 +- src/type/boolean.js | 4 +- src/type/chain/Chain.js | 8 +- src/type/chain/function/chain.js | 2 +- src/type/complex/Complex.js | 6 +- src/type/complex/function/complex.js | 4 +- src/type/fraction/Fraction.js | 2 +- src/type/fraction/function/fraction.js | 4 +- src/type/matrix/DenseMatrix.js | 14 +- src/type/matrix/FibonacciHeap.js | 2 +- src/type/matrix/ImmutableDenseMatrix.js | 6 +- src/type/matrix/Matrix.js | 2 +- src/type/matrix/MatrixIndex.js | 8 +- src/type/matrix/Range.js | 6 +- src/type/matrix/Spa.js | 2 +- src/type/matrix/SparseMatrix.js | 14 +- src/type/matrix/function/index.js | 4 +- src/type/matrix/function/matrix.js | 2 +- src/type/matrix/function/sparse.js | 2 +- src/type/matrix/utils/algorithm01.js | 4 +- src/type/matrix/utils/algorithm02.js | 4 +- src/type/matrix/utils/algorithm03.js | 4 +- src/type/matrix/utils/algorithm04.js | 4 +- src/type/matrix/utils/algorithm05.js | 4 +- src/type/matrix/utils/algorithm06.js | 6 +- src/type/matrix/utils/algorithm07.js | 4 +- src/type/matrix/utils/algorithm08.js | 4 +- src/type/matrix/utils/algorithm09.js | 4 +- src/type/matrix/utils/algorithm10.js | 2 +- src/type/matrix/utils/algorithm11.js | 2 +- src/type/matrix/utils/algorithm12.js | 2 +- src/type/matrix/utils/algorithm13.js | 4 +- src/type/matrix/utils/algorithm14.js | 4 +- src/type/number.js | 4 +- src/type/resultset/ResultSet.js | 2 +- src/type/string.js | 6 +- src/type/unit/Unit.js | 10 +- src/type/unit/function/createUnit.js | 2 +- src/type/unit/function/splitUnit.js | 2 +- src/type/unit/function/unit.js | 4 +- src/type/unit/physicalConstants.js | 2 +- src/utils/array.js | 10 +- src/utils/bignumber/constants.js | 2 +- src/utils/collection.js | 6 +- src/utils/complex.js | 2 +- src/utils/customs.js | 2 +- src/utils/factory.js | 4 +- src/utils/latex.js | 2 +- src/utils/number.js | 2 +- src/utils/object.js | 2 +- src/utils/snapshot.js | 6 +- src/utils/string.js | 6 +- test/benchmark/expression_parser.js | 2 +- test/browser-test-config/package.json | 3 + .../generated-code-tests/dependencies.test.js | 4 +- .../entry/mainAny.test.js | 6 +- .../entry/mainNumber.test.js | 6 +- .../{dist.test.js => browser.test.js} | 42 +- test/node-tests/commonjs.test.js | 23 + test/node-tests/commonjsApp.cjs | 4 + test/node-tests/commonjsAppNumberOnly.cjs | 4 + .../defaultInstance.test.js} | 24 +- test/node-tests/esm.test.js | 24 + test/node-tests/esmApp.mjs | 5 + test/node-tests/esmAppNumberOnly.mjs | 5 + .../alegbra/decomposition/slu.test.js | 2 +- .../function/alegbra/sparse/csAmd.test.js | 4 +- .../function/alegbra/sparse/csLu.test.js | 8 +- .../function/arithmetic/multiply.test.js | 2 +- test/node-tests/lib.test.js | 34 -- test/node-tests/package.json | 3 + ...rototype.js => pollutedObjectPrototype.js} | 2 +- test/unit-tests/approx.test.js | 2 +- test/unit-tests/constants.test.js | 8 +- test/unit-tests/core/config.test.js | 2 +- test/unit-tests/core/import.test.js | 10 +- test/unit-tests/core/typed.test.js | 2 +- test/unit-tests/error/ArgumentsError.test.js | 2 +- test/unit-tests/error/DimensionError.test.js | 2 +- test/unit-tests/error/IndexError.test.js | 2 +- test/unit-tests/expression/Help.test.js | 4 +- test/unit-tests/expression/Parser.test.js | 4 +- .../expression/function/compile.test.js | 2 +- .../expression/function/evaluate.test.js | 4 +- .../expression/function/help.test.js | 4 +- .../expression/function/parse.test.js | 2 +- .../expression/function/parser.test.js | 2 +- test/unit-tests/expression/keywords.test.js | 2 +- .../expression/node/AccessorNode.test.js | 2 +- .../expression/node/ArrayNode.test.js | 2 +- .../expression/node/AssignmentNode.test.js | 2 +- .../expression/node/BlockNode.test.js | 2 +- .../expression/node/ConditionalNode.test.js | 2 +- .../expression/node/ConstantNode.test.js | 2 +- .../node/FunctionAssignmentNode.test.js | 2 +- .../expression/node/FunctionNode.test.js | 2 +- .../expression/node/IndexNode.test.js | 2 +- test/unit-tests/expression/node/Node.test.js | 2 +- .../expression/node/ObjectNode.test.js | 2 +- .../expression/node/OperatorNode.test.js | 2 +- .../expression/node/ParenthesisNode.test.js | 2 +- .../expression/node/RangeNode.test.js | 2 +- .../expression/node/RelationalNode.test.js | 2 +- .../expression/node/SymbolNode.test.js | 2 +- test/unit-tests/expression/operators.test.js | 4 +- test/unit-tests/expression/parse.test.js | 4 +- test/unit-tests/expression/security.test.js | 2 +- .../transform/apply.transform.test.js | 2 +- .../transform/diff.transform.test.js | 2 +- .../transform/std.transform.test.js | 4 +- .../transform/variance.transform.test.js | 4 +- test/unit-tests/expression/transforms.test.js | 2 +- .../algebra/decomposition/lup.test.js | 4 +- .../function/algebra/decomposition/qr.test.js | 4 +- .../algebra/decomposition/slu.test.js | 4 +- .../function/algebra/derivative.test.js | 2 +- .../function/algebra/rationalize.test.js | 2 +- .../function/algebra/simplify.test.js | 2 +- .../function/algebra/solver/lsolve.test.js | 4 +- .../function/algebra/solver/lsolveAll.test.js | 4 +- .../function/algebra/solver/lusolve.test.js | 4 +- .../function/algebra/solver/usolve.test.js | 4 +- .../function/algebra/solver/usolveAll.test.js | 4 +- .../function/algebra/sparse/csLu.test.js | 10 +- .../function/arithmetic/abs.test.js | 2 +- .../function/arithmetic/add.test.js | 2 +- .../function/arithmetic/addScalar.test.js | 4 +- .../function/arithmetic/cbrt.test.js | 4 +- .../function/arithmetic/ceil.test.js | 4 +- .../function/arithmetic/createHypot.test.js | 4 +- .../function/arithmetic/cube.test.js | 2 +- .../function/arithmetic/divide.test.js | 4 +- .../function/arithmetic/dotDivide.test.js | 4 +- .../function/arithmetic/dotMultiply.test.js | 4 +- .../function/arithmetic/dotPow.test.js | 4 +- .../function/arithmetic/exp.test.js | 4 +- .../function/arithmetic/expm1.test.js | 4 +- .../function/arithmetic/fix.test.js | 4 +- .../function/arithmetic/floor.test.js | 4 +- .../function/arithmetic/gcd.test.js | 2 +- .../function/arithmetic/lcm.test.js | 2 +- .../function/arithmetic/log.test.js | 4 +- .../function/arithmetic/log10.test.js | 4 +- .../function/arithmetic/log1p.test.js | 4 +- .../function/arithmetic/log2.test.js | 4 +- .../function/arithmetic/mod.test.js | 4 +- .../function/arithmetic/multiply.test.js | 4 +- .../function/arithmetic/norm.test.js | 2 +- .../function/arithmetic/nthRoot.test.js | 4 +- .../function/arithmetic/nthRoots.test.js | 2 +- .../function/arithmetic/pow.test.js | 4 +- .../function/arithmetic/round.test.js | 4 +- .../function/arithmetic/sign.test.js | 4 +- .../function/arithmetic/sqrt.test.js | 2 +- .../function/arithmetic/square.test.js | 2 +- .../function/arithmetic/subtract.test.js | 4 +- .../function/arithmetic/unaryMinus.test.js | 2 +- .../function/arithmetic/unaryPlus.test.js | 2 +- .../function/arithmetic/xgcd.test.js | 2 +- .../function/bitwise/bitAnd.test.js | 2 +- .../function/bitwise/bitNot.test.js | 2 +- .../unit-tests/function/bitwise/bitOr.test.js | 2 +- .../function/bitwise/bitXor.test.js | 2 +- .../function/bitwise/leftShift.test.js | 2 +- .../function/bitwise/rightArithShift.test.js | 2 +- .../function/bitwise/rightLogShift.test.js | 2 +- .../combinatorics/bellNumbers.test.js | 2 +- .../function/combinatorics/catalan.test.js | 2 +- .../combinatorics/composition.test.js | 2 +- .../function/combinatorics/stirlingS2.test.js | 2 +- test/unit-tests/function/complex/arg.test.js | 4 +- test/unit-tests/function/complex/conj.test.js | 2 +- test/unit-tests/function/complex/im.test.js | 2 +- test/unit-tests/function/complex/re.test.js | 2 +- .../function/geometry/distance.test.js | 2 +- .../function/geometry/intersect.test.js | 2 +- test/unit-tests/function/logical/and.test.js | 2 +- test/unit-tests/function/logical/not.test.js | 2 +- test/unit-tests/function/logical/or.test.js | 2 +- test/unit-tests/function/logical/xor.test.js | 2 +- test/unit-tests/function/matrix/apply.test.js | 2 +- .../unit-tests/function/matrix/column.test.js | 2 +- .../unit-tests/function/matrix/concat.test.js | 2 +- test/unit-tests/function/matrix/cross.test.js | 2 +- .../function/matrix/ctranspose.test.js | 2 +- test/unit-tests/function/matrix/det.test.js | 4 +- test/unit-tests/function/matrix/diag.test.js | 2 +- test/unit-tests/function/matrix/diff.test.js | 4 +- test/unit-tests/function/matrix/dot.test.js | 2 +- test/unit-tests/function/matrix/eigs.test.js | 4 +- test/unit-tests/function/matrix/expm.test.js | 4 +- .../unit-tests/function/matrix/filter.test.js | 2 +- .../function/matrix/flatten.test.js | 2 +- .../function/matrix/forEach.test.js | 2 +- .../function/matrix/identity.test.js | 2 +- test/unit-tests/function/matrix/inv.test.js | 4 +- test/unit-tests/function/matrix/kron.test.js | 2 +- test/unit-tests/function/matrix/map.test.js | 2 +- test/unit-tests/function/matrix/ones.test.js | 2 +- .../function/matrix/partitionSelect.test.js | 2 +- test/unit-tests/function/matrix/range.test.js | 2 +- .../function/matrix/reshape.test.js | 4 +- .../unit-tests/function/matrix/resize.test.js | 2 +- test/unit-tests/function/matrix/row.test.js | 2 +- test/unit-tests/function/matrix/size.test.js | 2 +- test/unit-tests/function/matrix/sort.test.js | 2 +- test/unit-tests/function/matrix/sqrtm.test.js | 4 +- .../function/matrix/squeeze.test.js | 2 +- .../unit-tests/function/matrix/subset.test.js | 2 +- test/unit-tests/function/matrix/trace.test.js | 4 +- .../function/matrix/transpose.test.js | 2 +- test/unit-tests/function/matrix/zeros.test.js | 2 +- .../function/probability/combinations.test.js | 2 +- .../probability/combinationsWithRep.test.js | 2 +- .../function/probability/factorial.test.js | 4 +- .../function/probability/gamma.test.js | 4 +- .../function/probability/kldivergence.test.js | 2 +- .../function/probability/multinomial.test.js | 5 +- .../function/probability/permutations.test.js | 2 +- .../function/probability/pickRandom.test.js | 109 ++-- .../function/probability/random.test.js | 15 +- .../function/probability/randomInt.test.js | 23 +- .../function/probability/seededrandom.test.js | 2 +- .../function/relational/compare.test.js | 2 +- .../relational/compareNatural.test.js | 2 +- .../function/relational/compareText.test.js | 2 +- .../function/relational/deepEqual.test.js | 2 +- .../function/relational/equal.test.js | 2 +- .../function/relational/equalText.test.js | 2 +- .../function/relational/larger.test.js | 2 +- .../function/relational/largerEq.test.js | 2 +- .../function/relational/smaller.test.js | 2 +- .../function/relational/smallerEq.test.js | 2 +- .../function/relational/unequal.test.js | 2 +- .../function/set/setCartesian.test.js | 2 +- .../function/set/setDifference.test.js | 2 +- .../function/set/setDistinct.test.js | 2 +- .../function/set/setIntersect.test.js | 2 +- .../function/set/setIsSubset.test.js | 2 +- .../function/set/setMultiplicity.test.js | 2 +- .../function/set/setPowerset.test.js | 2 +- test/unit-tests/function/set/setSize.test.js | 2 +- .../function/set/setSymDifference.test.js | 2 +- test/unit-tests/function/set/setUnion.test.js | 2 +- test/unit-tests/function/special/erf.test.js | 147 ++++- .../function/special/erf.values.json | 46 -- .../function/statistics/mad.test.js | 2 +- .../function/statistics/max.test.js | 2 +- .../function/statistics/mean.test.js | 4 +- .../function/statistics/median.test.js | 4 +- .../function/statistics/min.test.js | 2 +- .../function/statistics/mode.test.js | 2 +- .../function/statistics/prod.test.js | 2 +- .../function/statistics/quantileSeq.test.js | 4 +- .../function/statistics/std.test.js | 4 +- .../function/statistics/sum.test.js | 3 +- .../function/statistics/variance.test.js | 4 +- .../unit-tests/function/string/format.test.js | 2 +- test/unit-tests/function/string/print.test.js | 2 +- .../function/trigonometry/acos.test.js | 4 +- .../function/trigonometry/acosh.test.js | 4 +- .../function/trigonometry/acot.test.js | 4 +- .../function/trigonometry/acoth.test.js | 4 +- .../function/trigonometry/acsc.test.js | 4 +- .../function/trigonometry/acsch.test.js | 4 +- .../function/trigonometry/asec.test.js | 4 +- .../function/trigonometry/asech.test.js | 4 +- .../function/trigonometry/asin.test.js | 4 +- .../function/trigonometry/asinh.test.js | 4 +- .../function/trigonometry/atan.test.js | 4 +- .../function/trigonometry/atan2.test.js | 4 +- .../function/trigonometry/atanh.test.js | 4 +- .../function/trigonometry/cos.test.js | 4 +- .../function/trigonometry/cosh.test.js | 4 +- .../function/trigonometry/cot.test.js | 4 +- .../function/trigonometry/coth.test.js | 4 +- .../function/trigonometry/csc.test.js | 4 +- .../function/trigonometry/csch.test.js | 4 +- .../function/trigonometry/sec.test.js | 4 +- .../function/trigonometry/sech.test.js | 4 +- .../function/trigonometry/sin.test.js | 4 +- .../function/trigonometry/sinh.test.js | 4 +- .../function/trigonometry/tan.test.js | 4 +- .../function/trigonometry/tanh.test.js | 4 +- test/unit-tests/function/unit/to.test.js | 4 +- test/unit-tests/function/utils/clone.test.js | 2 +- .../function/utils/hasNumericValue.test.js | 2 +- .../function/utils/isInteger.test.js | 2 +- test/unit-tests/function/utils/isNaN.test.js | 2 +- .../function/utils/isNegative.test.js | 2 +- .../function/utils/isNumeric.test.js | 2 +- .../function/utils/isPositive.test.js | 2 +- .../unit-tests/function/utils/isPrime.test.js | 2 +- test/unit-tests/function/utils/isZero.test.js | 2 +- test/unit-tests/function/utils/typeof.test.js | 2 +- test/unit-tests/json/replacer.test.js | 2 +- test/unit-tests/json/reviver.test.js | 2 +- test/unit-tests/test.html | 5 +- test/unit-tests/test.min.html | 31 -- .../type/bignumber/BigNumber.test.js | 2 +- .../type/bignumber/function/bignumber.test.js | 2 +- test/unit-tests/type/boolean.test.js | 2 +- test/unit-tests/type/chain/Chain.test.js | 4 +- .../type/chain/function/chain.test.js | 2 +- test/unit-tests/type/complex/Complex.test.js | 2 +- .../type/complex/function/complex.test.js | 2 +- .../unit-tests/type/fraction/Fraction.test.js | 2 +- .../type/fraction/function/fraction.test.js | 2 +- .../type/matrix/DenseMatrix.test.js | 2 +- .../type/matrix/FibonacciHeap.test.js | 2 +- .../type/matrix/ImmutableDenseMatrix.test.js | 2 +- test/unit-tests/type/matrix/Index.test.js | 2 +- test/unit-tests/type/matrix/Matrix.test.js | 2 +- test/unit-tests/type/matrix/Range.test.js | 2 +- test/unit-tests/type/matrix/Spa.test.js | 2 +- .../type/matrix/SparseMatrix.test.js | 2 +- .../unit-tests/type/matrix/collection.test.js | 4 +- .../type/matrix/function/index.test.js | 2 +- .../type/matrix/function/matrix.test.js | 2 +- .../type/matrix/function/sparse.test.js | 2 +- .../matrix/utils/getMatrixDataType.test.js | 2 +- test/unit-tests/type/number.test.js | 4 +- test/unit-tests/type/numeric.test.js | 2 +- .../type/resultset/ResultSet.test.js | 2 +- test/unit-tests/type/string.test.js | 2 +- test/unit-tests/type/unit/Unit.test.js | 8 +- .../type/unit/function/createUnit.test.js | 2 +- .../type/unit/function/splitUnit.test.js | 2 +- .../type/unit/function/unit.test.js | 2 +- .../type/unit/physicalConstants.test.js | 8 +- test/unit-tests/utils/array.test.js | 2 +- .../utils/bignumber/constants.test.js | 2 +- .../utils/bignumber/formatter.test.js | 2 +- .../utils/bignumber/nearlyEqual.test.js | 2 +- test/unit-tests/utils/customs.test.js | 4 +- test/unit-tests/utils/factory.test.js | 2 +- test/unit-tests/utils/function.test.js | 4 +- test/unit-tests/utils/is.test.js | 4 +- test/unit-tests/utils/latex.test.js | 2 +- test/unit-tests/utils/number.test.js | 2 +- test/unit-tests/utils/object.test.js | 2 +- test/unit-tests/utils/string.test.js | 4 +- tools/docgenerator.js | 4 +- tools/entryGenerator.js | 20 +- tools/matrixmarket.js | 3 +- tools/package.json | 3 + 657 files changed, 2573 insertions(+), 2390 deletions(-) create mode 100644 bin/package.json create mode 100644 dist/math.js create mode 100644 dist/math.min.js create mode 100644 dist/package.json create mode 100644 examples/package.json rename gulpfile.js => gulpfile.cjs (67%) create mode 100644 main/es5/package.json create mode 100644 main/esm/package.json create mode 100644 number.cjs delete mode 100644 number.js delete mode 100644 src/bundleAny.js create mode 100644 src/defaultInstance.js create mode 100644 src/index.js create mode 100644 src/number.js create mode 100644 test/browser-test-config/package.json rename test/node-tests/{dist.test.js => browser.test.js} (69%) create mode 100644 test/node-tests/commonjs.test.js create mode 100644 test/node-tests/commonjsApp.cjs create mode 100644 test/node-tests/commonjsAppNumberOnly.cjs rename test/{unit-tests/bundleAny.test.js => node-tests/defaultInstance.test.js} (84%) create mode 100644 test/node-tests/esm.test.js create mode 100644 test/node-tests/esmApp.mjs create mode 100644 test/node-tests/esmAppNumberOnly.mjs delete mode 100644 test/node-tests/lib.test.js create mode 100644 test/node-tests/package.json rename test/node-tests/{polluted_object_prototype.js => pollutedObjectPrototype.js} (82%) delete mode 100644 test/unit-tests/function/special/erf.values.json delete mode 100644 test/unit-tests/test.min.html create mode 100644 tools/package.json 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 - +