Skip to content

Commit

Permalink
Specify import require paths (continuation of #1941) (#1962)
Browse files Browse the repository at this point in the history
* 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](node-fetch/node-fetch@v2.6.0...v2.6.1)

Signed-off-by: dependabot-preview[bot] <[email protected]>

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](karma-runner/karma@v5.2.1...v5.2.2)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>

Co-authored-by: Lee Langley-Rees <[email protected]>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 20, 2020
1 parent b17b6eb commit 6f00715
Show file tree
Hide file tree
Showing 657 changed files with 2,573 additions and 2,390 deletions.
6 changes: 2 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
],
"plugins": ["@babel/plugin-transform-object-assign"],
"ignore": [
"dist/*.js",
"lib/**/*.js",
"es/**/*.js"
"lib/**/*.js"
]
}
}
12 changes: 6 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- 10
- 12
- 14

Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const PRECISION = 14 // decimals
* @return {*}
*/
function getMath () {
return require('../lib/bundleAny')
return require('../lib/cjs/defaultInstance.js').default
}

/**
Expand Down
3 changes: 3 additions & 0 deletions bin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
2 changes: 1 addition & 1 deletion bin/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
3 changes: 3 additions & 0 deletions dist/math.js
Original file line number Diff line number Diff line change
@@ -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 [email protected]. ' +
'Please use the minified bundle "mathjs/lib/browser/math.js" instead.')
3 changes: 3 additions & 0 deletions dist/math.min.js
Original file line number Diff line number Diff line change
@@ -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 [email protected]. ' +
'Please load the bundle via the new path.')
3 changes: 3 additions & 0 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
2 changes: 1 addition & 1 deletion examples/browser/angle_configuration.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
</style>

<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/basic_usage.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>math.js | basic usage</title>
<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/currency_conversion.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | currency conversion</title>

<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>

<style>
body,
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/custom_separators.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
}
</style>

<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>
</head>
<body>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/plot.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<title>math.js | plot</title>
<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>

<script src="https://cdn.plot.ly/plotly-1.35.2.min.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion examples/browser/pretty_printing_with_mathjax.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | pretty printing with MathJax</title>

<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.3/MathJax.js?config=TeX-AMS-MML_HTMLorMML.js"></script>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/printing_html.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | printing HTML</title>

<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>

<style>
body {
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/requirejs_loading.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<script>
// load math.js using require.js
require(['../../dist/math.js'], function (math) {
require(['../../lib/browser/math.js'], function (math) {
// evaluate some expression
const result = math.evaluate('1.2 * (2 + 4.5)')
document.write(result)
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/rocket_trajectory_optimization.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<title>math.js | rocket trajectory optimization</title>

<script src="../../dist/math.js"></script>
<script src="../../lib/browser/math.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>

<style>
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/webworkers/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
importScripts('../../../dist/math.js')
importScripts('../../../lib/browser/math.js')

// create a parser
const parser = self.math.parser()
Expand Down
3 changes: 3 additions & 0 deletions examples/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
Loading

0 comments on commit 6f00715

Please sign in to comment.