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

Add exports field to all packages #11675

Merged
merged 7 commits into from
Jul 11, 2024
Merged

Conversation

markdalgleish
Copy link
Member

The exports field was added to react-router and react-router-dom as part of #11669, but this PR standardises this across all packages. I've split this out into a separate PR as a standalone decision.

Copy link

changeset-bot bot commented Jun 18, 2024

🦋 Changeset detected

Latest commit: 3bf46a7

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

This PR includes changesets to release 6 packages
Name Type
@react-router/express Major
@react-router/serve Major
@react-router/node Major
@react-router/dev Major
react-router-dom Major
react-router Major

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

@@ -24,7 +24,7 @@ module.exports = function rollup() {
return [
{
external: (id) => isBareModuleId(id),
input: `${SOURCE_DIR}/index.ts`,
input: [`${SOURCE_DIR}/index.ts`, `${SOURCE_DIR}/install.ts`],
Copy link
Member Author

Choose a reason for hiding this comment

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

Now that we have the exports field, we can point to the dist folder and remove the hard-coded install.js and install.d.ts files.

@@ -23,7 +23,7 @@ module.exports = function rollup() {
{
input: `${SOURCE_DIR}/index.ts`,
output: {
file: `${OUTPUT_DIR}/index.js`,
file: `${OUTPUT_DIR}/index.mjs`,
Copy link
Member Author

Choose a reason for hiding this comment

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

We have to use the mjs extension now to prevent this file being resolved as CJS via the import field within exports.

Comment on lines 1 to 8
/* eslint-disable */
"use strict";

var globals = require("./dist/globals.js");

Object.defineProperty(exports, "__esModule", { value: true });

globals.installGlobals();
Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned, this file and its types are now built into the dist folder.

@markdalgleish markdalgleish changed the title Add exports field to packages Add exports field to all packages Jun 18, 2024
Comment on lines 14 to 16
"exports": {
"./package.json": "./package.json"
},
Copy link
Member Author

Choose a reason for hiding this comment

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

This is only being added to prevent reaching into package internals.

Copy link
Contributor

@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.

LGTM but I would probably get a 👍 from @jacob-ebey as well since he knows the nuances of this stuff really well

@brophdawg11
Copy link
Contributor

@mjackson @jacob-ebey and I chatted yesterday about the ESM/CJS stuff and came up with a gameplan that we think should work for v7 - filed that as a separate task in https://github.com/orgs/remix-run/projects/21/views/1 so I think this can probably get merged and then w'ell tackle that task and we can start experimenting with deployed builds on the nightlies?

@brophdawg11
Copy link
Contributor

I might add a major changeset too just so we have something to catch our eye and elaborate on it a bit in the release notes too as something for folks to be aware of if they hit any bundler issues.

"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
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 had to add an ESM build to fix a dual-package-hazard issue. In the upload-test integration test we have an instanceof MaxPartSizeExceededError check that started failing because the app and @react-router/node imported different builds of React Router. It seems the move to using exports triggered Playwright to load the ESM build rather than the CJS build.

@markdalgleish markdalgleish merged commit 4901f05 into v7 Jul 11, 2024
8 checks passed
@markdalgleish markdalgleish deleted the markdalgleish/exports-field branch July 11, 2024 00:46
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.

None yet

2 participants