-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
♻️ Add module / CJS and types to purifier npm package #26297
Conversation
/to @choumx |
src/purifier/package.json
Outdated
"description": "AMP-specific sanitization library", | ||
"author": "The AMP HTML Authors", | ||
"license": "Apache-2.0", | ||
"main": "dist/purifier.js", | ||
"files": ["dist/*"], | ||
"main": "dist/purifier.mjs", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is only having an "mjs" output typical?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My impression was that main:
should be CJS and module:
is normally mjs.
From Rollup's documentation:
To make sure your ES modules are immediately usable by tools that work with CommonJS such as Node.js and webpack, you can use Rollup to compile to UMD or CommonJS format, and then point to that compiled version with the main property in your package.json file. If your package.json file also has a module field, ESM-aware tools like Rollup and webpack 2+ will import the ES module version directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, didn't know this. Added CJS output now and used main
and module
in package.json.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this was a bridge until Node.js supported ES6 modules: https://nodejs.org/api/esm.html#esm_dual_commonjs_es_module_packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reading a bit into this, it seems the module
+ main
approach @samouri suggested is still best, since Node.js will just ignore module
and use main
. The solution from nodejs.org to have a wrapper instead seems only useful to allow ESM support in Node (which is still experimental in LTS) and I fear it will cause complications when used in a browser.
TLDR: I see no real advantages in having an ESM version in Node (for now).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, just sharing for anyone who was also curious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it, sorry I misunderstood your previous comment.
ef85108
to
b67d9e2
Compare
Update: it seems passing |
No description provided.