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

fix: export CJS version for browser #43

Merged
merged 2 commits into from Sep 1, 2023

Conversation

MichaelDeBoey
Copy link
Member

@MichaelDeBoey MichaelDeBoey commented Aug 22, 2023

Just like @SimonB did with uuidjs/uuid#616

This will remove the necessity of having all the packages in transformIgnorePatterns in remix-run/remix#7220 or having them in moduleNameMapper in remix-run/react-router#9895


Closes #11
Closes remix-run/remix#3402

@changeset-bot
Copy link

changeset-bot bot commented Aug 22, 2023

🦋 Changeset detected

Latest commit: 1d4135d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@remix-run/web-blob Minor
@remix-run/web-fetch Minor
@remix-run/web-file Minor
@remix-run/web-form-data Minor
@remix-run/web-stream Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@jacob-ebey
Copy link
Member

@MichaelDeBoey explained to me that the ultimate issue here is when node is running in a jsdom env it attempts to load the browser export and therefore needs a CJS version as it doesn't fully support ESM yet.

@MichaelDeBoey
Copy link
Member Author

For a more in depth explanation on what Jest is doing: have a look at microsoft/accessibility-insights-web#5421 (comment)

Copy link

@brophdawg11 brophdawg11 left a comment

Choose a reason for hiding this comment

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

👍 Looks like all the exports entries match up to npm pack --dry-run now. We may eventually want to align the fetch distributed package with the others, but that's a separate undertaking I think.

I think it's confusing how the others are currently building into dist/src while also including unbuilt src files in the package - so my vote would be to align everything to something like this in the published package:

dist/blob.cjs  // built CJS version
dist/lib.cjs   // built CJS version
src/blob.js    // raw ESM source file
src/lib.js     // raw ESM source file

Plus all .map files and .d.ts etc go in dist/

@brophdawg11
Copy link

@jacob-ebey Do you think this deserves a prerelease we can test against before we do the stable? Or are we comfortable publishing the stable? Remix uses caret dependencies for these so folks may pick them up as soon as they're published.

@MichaelDeBoey
Copy link
Member Author

but that's a separate undertaking I think

Yeah I would do that in a follow-up PR if wanted

so my vote would be to align everything to something like this in the published package:

dist/blob.cjs  // built CJS version
dist/lib.cjs   // built CJS version
src/blob.js    // raw ESM source file
src/lib.js     // raw ESM source file

Plus all .map files and .d.ts etc go in dist/

Here blob is for browser & lib for node?

@brophdawg11
Copy link

@MichaelDeBoey Sorry I trimmed that for brevity. There would also be dist/blob.node.cjs/src/blob.node.js/etc file if it has node versions. The key is just that src/ is unbuilt files, and dist/ is build files and there is no longer a confusing dist/src/ folder.

Comment on lines 2 to 7
"@remix-run/web-blob": patch
"@remix-run/web-fetch": patch
"@remix-run/web-file": patch
"@remix-run/web-form-data": patch
"@remix-run/web-stream": patch
---

Choose a reason for hiding this comment

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

Should this be a minor since it's sort of adding a new feature in CJS files?

Copy link
Member Author

Choose a reason for hiding this comment

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

I went with patch as it not a real feature, but I can go with minor if you want

Choose a reason for hiding this comment

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

ok - yeah I think it could go either way since there's no userland code API changes. Going to update to minor just to be safe since we're providing a new surface area for the bundler

@brophdawg11 brophdawg11 merged commit 807fc63 into remix-run:main Sep 1, 2023
65 checks passed
@MichaelDeBoey MichaelDeBoey deleted the export-CJS-for-browser branch September 2, 2023 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants