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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/nice-pillows-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"@react-router/express": major
"@react-router/serve": major
"@react-router/node": major
"@react-router/dev": major
"react-router-dom": major
"react-router": major
---

Add `exports` field to all packages
7 changes: 7 additions & 0 deletions packages/react-router-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"bin": {
"react-router": "bin.js"
},
Expand Down
10 changes: 9 additions & 1 deletion packages/react-router-dom/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
"sideEffects": false,
"main": "./dist/main.js",
"unpkg": "./dist/umd/react-router-dom.production.min.js",
"module": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/main.js"
},
"./package.json": "./package.json"
},
"dependencies": {
"react-router": "workspace:*"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dom/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.

format: "esm",
sourcemap: !PRETTY,
banner: createBanner("React Router DOM", version),
Expand Down
7 changes: 7 additions & 0 deletions packages/react-router-express/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"tsc": "tsc"
},
Expand Down
1 change: 0 additions & 1 deletion packages/react-router-node/install.d.ts

This file was deleted.

8 changes: 0 additions & 8 deletions packages/react-router-node/install.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/react-router-node/install.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { installGlobals } from "./globals";

installGlobals();
16 changes: 15 additions & 1 deletion packages/react-router-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,22 @@
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"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.

"require": "./dist/index.js"
},
"./install": {
"types": "./dist/install.d.ts",
"import": "./dist/install.mjs",
"require": "./dist/install.js"
},
"./package.json": "./package.json"
},
"sideEffects": [
"./install.js"
"./dist/install.js",
"./dist/install.mjs"
],
"scripts": {
"tsc": "tsc"
Expand Down
27 changes: 25 additions & 2 deletions packages/react-router-node/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ module.exports = function rollup() {
"react-router-node"
);

const input = [`${SOURCE_DIR}/index.ts`, `${SOURCE_DIR}/install.ts`];

return [
{
input,
external: (id) => isBareModuleId(id),
input: `${SOURCE_DIR}/index.ts`,
output: {
banner: createBanner(name, version),
dir: OUTPUT_DIR,
format: "cjs",
entryFileNames: "[name].mjs",
format: "esm",
preserveModules: true,
exports: "named",
},
Expand All @@ -50,5 +53,25 @@ module.exports = function rollup() {
}),
],
},
{
input,
external: (id) => isBareModuleId(id),
output: {
banner: createBanner(name, version),
dir: OUTPUT_DIR,
format: "cjs",
preserveModules: true,
exports: "named",
},
plugins: [
babel({
babelHelpers: "bundled",
exclude: /node_modules/,
extensions: [".ts", ".tsx"],
...remixBabelConfig,
}),
nodeResolve({ extensions: [".ts", ".tsx"] }),
],
},
];
};
3 changes: 3 additions & 0 deletions packages/react-router-serve/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"directory": "packages/react-router-serve"
},
"license": "MIT",
"exports": {
"./package.json": "./package.json"
},
"bin": {
"react-router-serve": "bin.js"
},
Expand Down
10 changes: 9 additions & 1 deletion packages/react-router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,16 @@
"sideEffects": false,
"main": "./dist/main.js",
"unpkg": "./dist/umd/react-router.production.min.js",
"module": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/main.js"
},
"./package.json": "./package.json"
},
"dependencies": {
"@types/cookie": "^0.6.0",
"@web3-storage/multipart-parser": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = function rollup() {
{
input: `${SOURCE_DIR}/index.ts`,
output: {
file: `${OUTPUT_DIR}/index.js`,
file: `${OUTPUT_DIR}/index.mjs`,
format: "esm",
sourcemap: !PRETTY,
banner: createBanner("React Router", version),
Expand Down