-
-
Notifications
You must be signed in to change notification settings - Fork 236
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
feat: Add CommonJS export for parse5 module #418
Changes from all commits
1a29456
8962f1e
21b4bc0
496ea08
88f997a
a314888
07bf12f
40ce151
033c591
57a36c4
6fa3d07
eda5873
de39a2b
5a65dfa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,15 @@ | |
"serialize" | ||
], | ||
"license": "MIT", | ||
"main": "dist/index.js", | ||
"main": "dist/cjs/index.js", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wouldn't we still want the default to be ESM? so the only way to reach any commonjs entrypoints is by reading the package exports There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Node versions with ESM support will not read the |
||
"module": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "dist/index.js", | ||
"require": "dist/cjs/index.js" | ||
} | ||
}, | ||
Comment on lines
+33
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this breaks rehype/test/parse-error.js in rehypejs/rehype#113 import p5errors from 'parse5/lib/common/error-codes.js'
wontfix in rehype, as ERR is not exported by parse5 → export as ErrorCodes? https://nodejs.org/api/esm.html
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the package exports are right IMO. if we have consumers of the error codes enum, we should probably just export it top-level along with i.e. in |
||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/inikulin/parse5.git" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"module": "CommonJS", | ||
"target": "ES6", | ||
"outDir": "dist/cjs" | ||
} | ||
} |
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.
does this make node think
dist/cjs/
is its own package?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.
This will make
require('parse5')
work in Node versions with ESM support.Because the files are plain
.js
files, Node will look at the closestpackage.json
file to determine if the code is ESM or not. We create apackage.json
for the CJS code, to make sure requiring it works as expected.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.
i get that part, was just wondering what other effects it might have. since you're telling node the
cjs
path is its own standalone package by giving it its own package manifest. curiosity more than anything, just wondering what other behaviour it might change in tooling.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.
I can't think of any side-effects, but definitely something worth keeping in mind for future bug-reports. I adopted the pattern from this article from SenseDeep, which is used in several published (but not very popular) modules.