-
Notifications
You must be signed in to change notification settings - Fork 26
chore: switch to esm #22
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
chore: switch to esm #22
Conversation
This should be ready, just needs a new |
I think all the files need to switch over to using named exports, otherwise this innocuous looking sort of thing: /**
* @typedef {import('foo').Bar} Bar
*/
module.exports = function baz () {} Generates: export type Bar = import('foo').Bar;
export default function baz(): void; and ipjs says to not mix default and named exports. |
Actually maybe not, we can just remove the Still getting some weird |
No, we have to switch to named exports.
const fromString = require('uint8arrays/from-string') to be: const fromString = require('uint8arrays/from-string').default which compiles types but then fails at runtime in node due to "exports": {
"browser": "./esm/src/from-string.js",
"require": "./cjs/src/from-string.js",
"import": "./esm/src/from-string.js"
} Ignoring that for a second, if we run bundled cjs code in the browser, Ingoring that for a second, if we follow my suggestion above:
we're breaking compatibility because we previously exported a We could ditch cjs, which would require all cjs users to change all instances of Instead we can switch to named exports, which will need a major, but then people don't need to use As ever, this springs to mind: |
Thanks for the detailed feedback. I agree that the best solution is to make named exports and I will change it |
BREAKING CHANGE: built content includes ESM and CJS
Co-authored-by: Alex Potsides <[email protected]>
Co-authored-by: Alex Potsides <[email protected]>
fdcc960
to
0d9929c
Compare
types tested on ipfs/js-ipfs#3774 |
19c6e8c
to
61d7b40
Compare
30ed580
to
340eb0e
Compare
340eb0e
to
bb3ed8d
Compare
Codecov Report
@@ Coverage Diff @@
## master #22 +/- ##
==========================================
- Coverage 98.35% 98.15% -0.20%
==========================================
Files 7 7
Lines 243 217 -26
Branches 44 44
==========================================
- Hits 239 213 -26
Misses 4 4
Continue to review full report at Codecov.
|
e2ea96f
to
c5124ff
Compare
.github/workflows/main.yml
Outdated
@@ -17,9 +17,6 @@ jobs: | |||
- uses: gozala/[email protected] | |||
- run: npx aegir build | |||
- run: npx aegir dep-check | |||
- uses: ipfs/aegir/actions/bundle-size@master |
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 needs to be added again once aegir ships it as I could not make it use a branch
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've restored this but now CI is failing on this step with:
Error: Cannot find module '/github/workspace/index.js'
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.
oh damn, I will look into it
This builds up on @achingbrain 's work on #863 with build improvements and full support This adds: - `ipjs` for ESM modules - auto-detected - `types` property transformation, allowing real time ts check in dev and path update for dist folder (TLDR no dist in the path) - `release` for ESM modules will navigate to the dist to publish its content - Dockerfile to bundlesize action per actions/runner#772 (comment) as we need node14+ for ESM One of the problematic modules in skypack using aegir is `uint8arrays`. It is a CJS module that depends on a ESM first module (multiformats), which makes skypack to get bad dependency paths. I tested this out shipping `uint8arrays` achingbrain/uint8arrays#22 PR and everything working smoothly 🎉 Original release: https://codepen.io/vascosantos/pen/KKmXoPV?editors=0011 Scoped release using `aegir`: https://codepen.io/vascosantos/pen/bGWoONq?editors=0011 (see browser built in console for errors) Co-authored-by: achingbrain <[email protected]>
package.json
Outdated
"./index.js": { | ||
"import": "./src/index.js" | ||
}, | ||
"./compare.js": { | ||
"import": "./src/compare.js" | ||
}, | ||
"./concat.js": { | ||
"import": "./src/concat.js" | ||
}, | ||
"./equals.js": { | ||
"import": "./src/equals.js" | ||
}, | ||
"./from-string.js": { | ||
"import": "./src/from-string.js" | ||
}, | ||
"./to-string.js": { | ||
"import": "./src/to-string.js" | ||
}, | ||
"./xor.js": { | ||
"import": "./src/xor.js" | ||
} |
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.
Why do we need to double up these exports? Could be quite error prone over time, maybe we could get ipjs to do this for us?
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.
We talked about this offline a couple of weeks. Anyway, we do not need this anymore. Removed now
BREAKING CHANGE: built content includes ESM and CJS
Needs: