Skip to content

Make loader ESM by default, with UMD fallback #1513

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

Merged
merged 7 commits into from
Oct 22, 2020
Merged

Make loader ESM by default, with UMD fallback #1513

merged 7 commits into from
Oct 22, 2020

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Oct 22, 2020

The loader cannot be easily used on the web currently without either bundling or exports-shimming it, so this PR refactors it to an ES module by default with an UMD fallback. The package is set up in a way that either requireing (from CommonJS) or importing (from ESM) the loader should work in recent node.js, and where that's not applicable for some reason one may require("@assemblyscript/loader/umd") as a fallback.

Should not break backwards compatibility under recent node.js, but will break usage under older node.js and on the web (to the better, esp. on the web), e.g. will require updating the editor on our website by removing the exports-shim.

Unlike #1313 this does not do any silly .mjs or .cjs stuff (turned out to break CDNs, i.e. not understanding what a .cjs's content type is) and does not refactor anything else but the loader, which is the most important for now.

  • I've read the contributing guidelines

@dcodeIO
Copy link
Member Author

dcodeIO commented Oct 22, 2020

Erm, when I put the exports key into package.json, a require("assemblyscript") inside of the package finds the package, otherwise it doesn't. That's unexpected.

Edit, docs: https://nodejs.org/api/packages.html#packages_self_referencing_a_package_using_its_name

@dcodeIO
Copy link
Member Author

dcodeIO commented Oct 22, 2020

Seems that'll break on node 12 LTS. Ouch.

@dcodeIO
Copy link
Member Author

dcodeIO commented Oct 22, 2020

Ok, turns out we can't know for sure anymore what require("assemblyscript") requires in newer node versions. A little unfortunate, but given that this is all set up and will probably change anyway once there's a new LTS, it should be fine to remove the respective checks for the time being so we can move on.

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

Successfully merging this pull request may close these issues.

2 participants