Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specify import require paths (continuation of #1941) #1962

Merged
merged 19 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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 mathjs@8.0.0. ' +
'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 mathjs@8.0.0. ' +
'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