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

Conversation

josdejong
Copy link
Owner

@josdejong josdejong commented Sep 9, 2020

@GreenImp I continued your PR and got everything working I think.

  • I resolved a few merge conflicts
  • All unit tests can now run using plain node.js, no transpilation needed anymore when running mocha
  • I created a script which generates /lib/cjs/package.json and /lib/browser/package.json during the build
  • I updated the urls in the browser examples

Still to do:

  • Only generate a single, minified bundle math.js
  • Write some unit tests to validate running loading the library via ESM and CJS
  • Create backward compatible warnings for all old index files and the removed bundle files from the dist folder
  • Describe breaking changes in HISTORY.md
  • A few more cleanup actions in the build scripts and tests
  • Update download description on the website, remove the part about the non-minified bundle
  • BONUS: try to rewrite the gulpfile and some of the left over commonjs files in the build/testing part to ESM.

Reference #1941

GreenImp and others added 9 commits August 6, 2020 23:55
Specify package type as `commonjs` (It's good to be specific)
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
….com/GreenImp/mathjs into GreenImp-feature/specify-import-require-paths

# Conflicts:
#	package-lock.json
#	package.json
#	src/expression/embeddedDocs/embeddedDocs.js
#	src/factoriesAny.js
#	src/function/algebra/solver/utils/solveValidation.js
- Refactor `bundleAny` into `defaultInstance.js` and `browserBundle.cjs`
- Refactor unit tests to be able to run with plain nodejs (no transpiling)
- Fix browser examples
'browser',
'docs'
bundle,
generateDocs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thought it worth mentioning, I set these to the string names of the tasks that I created above, so Gulp will run those tasks. That way, if one of the tasks changes (Like with the browser compiling changing from bundle, minify to just bundle) you only need to change the individual task, and not the one here as well.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, true. Formerly the 'browser' task did two things: bundle and minify. There is only one left now: bundle, so I thought like let's remove this indirection. I think we can maybe remove gulp.task('browser', bundle) because it's not used anywhere externally from the package.json scripts. The task 'docs' only does one thing (generateDocs) but is actually used in the package.json scripts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I initially created those tasks because I found that I kept needing to clean out things and only rebuild certain things when I was testing, so it made it a bit easier.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Makes sense. If you like it better to call the gulp tasks instead of the function it's totally fine with me, for me both is ok.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really mind. It's a minor thing anyway, so might as well leave it as is for now.

dependabot-preview bot and others added 5 commits September 12, 2020 16:51
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] <support@dependabot.com>

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

I think this PR is now ready to be merged. I hope to publish a release candidate for v8 somewhere coming week.

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] <support@dependabot.com>

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

Thanks for sorting the deprecation messages on the old files! I just didn't seem to have the time to get around to it.

@josdejong josdejong changed the base branch from develop to v8 September 20, 2020 15:57
@josdejong josdejong merged commit 6f00715 into v8 Sep 20, 2020
@josdejong josdejong deleted the specify-import-require-paths branch September 20, 2020 16:01
@josdejong
Copy link
Owner Author

I merged this PR now in the v8 branch. I hope to do a beta release of v8 somewhere coming week.

@GreenImp
Copy link
Contributor

I've npm installed the V8 branch in one of my projects, and it seems to be working okay.

I'm able to compile my library, without including mathjs in the bundle, but have it as a dependency of my project. So when installing my library it brings down mathjs and everything still works as if it was bundled
That's using both ESM and CommonJS.

And my Jest tests still seem to work as well!

That's exactly what I needed from these changes, so I'm really happy. It's looking really good! Thanks.

@josdejong
Copy link
Owner Author

That's great news, thanks for testing it out Lee 👍

@josdejong josdejong mentioned this pull request Oct 18, 2020
4 tasks
@josdejong
Copy link
Owner Author

I've finally published the first beta version on npm: 8.0.0-beta.0.

I'm still thinking about how we can make it easier or more obvious that all imports now require to have the *.js extension in the file name. This gives a bit vague errors as long as your IDE thinks all is ok. IDE's are normally configured to not add file extensions in case of automatically adding an import, so that can be quite annoying.

Maybe it's possible to create a lint rule to check for that (not possible with standardjs, so we may have to switch to eslint-config-standard for example).

@GreenImp
Copy link
Contributor

That's fab! I'm really looking forward to being able to use v8.

I'm not sure I understand the problem with file extensions?
When a developer requires the library, they can include it by name (If using npm). If they want to include a particular script, that's listed in the exports, then they will all work.
So you can still import:

'math-js'         // points to ./lib/{esm|cjs}/index.js
'math-js/number'  // points to ./lib/{esm|cjs}/number.js

But you can also import various other files with the full path (Including extension).

Or am I misunderstanding the issue?

@josdejong
Copy link
Owner Author

@GreenImp I mean not when consuming mathjs as a library, but when you're developing mathjs itself (like add a new function). When creating a new file in the mathjs repo, you have to be careful to add the file extensions.

@josdejong
Copy link
Owner Author

For now, I've added a section "Develop" in the README.md explaining this. I think it's a generic issue that we'll see with more libraries when more and libraries start being written in plain ESM.

@josdejong
Copy link
Owner Author

I've just published v8.0.0

@GreenImp
Copy link
Contributor

Thanks @josdejong that's brilliant! Really appreciate your time in getting this all sorted and merged in.
I've started implementing v8 in my project and it's working well so far!

@josdejong
Copy link
Owner Author

Thanks! Good to hear it's working smoothly in your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants