Skip to content

Commit 49af8da

Browse files
authored
ci: Update rollup setup (#8953)
* ci: update rollup to latest version * ci: split rollup configs to individual packages * soften yarn rollup versions * Update to build to packages/[pkg]/dist * remove duped files * update package.json main/module/types references * fix jest module scope issues * fix static router tests * update bundlesize paths in package.json * Revert "fix static router tests" This reverts commit 5d97844. * Revert "fix jest module scope issues" This reverts commit 65e5b34. * Add jest moduleNameMapper to point unit tests to source code * clean up regexes * Remove unnused node-resolve plugin * Move typescript definition generation into rollup * move rollup copy earlier for v5-compat * Use relative import for private API * fix LICENSE copy and add server build to root
1 parent be77a06 commit 49af8da

37 files changed

+1474
-1181
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
npm-debug.log
22

3-
/build/
43
/docs/api/
54
/website/build/
65
node_modules/
@@ -14,6 +13,11 @@ node_modules/
1413
/packages/*/esm/
1514
/packages/*/umd/
1615

16+
# v6 build files
17+
/build/
18+
/packages/*/dist/
19+
/packages/*/LICENSE.md
20+
1721
# compat module copies
1822
/packages/react-router-dom-v5-compat/react-router-dom
1923

package.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
]
1414
},
1515
"scripts": {
16-
"build": "rollup -c && tsc -b",
16+
"build": "rollup -c",
1717
"clean": "git clean -fdX .",
1818
"format": "prettier --ignore-path .eslintignore --write .",
1919
"format:check": "prettier --ignore-path .eslintignore --check .",
@@ -31,14 +31,15 @@
3131
},
3232
"dependencies": {
3333
"@ampproject/filesize": "^4.3.0",
34-
"@ampproject/rollup-plugin-closure-compiler": "^0.26.0",
3534
"@babel/core": "^7.7.4",
3635
"@babel/preset-env": "^7.15.8",
3736
"@babel/preset-modules": "^0.1.4",
3837
"@babel/preset-react": "^7.14.5",
3938
"@babel/preset-typescript": "^7.15.0",
4039
"@remix-run/web-fetch": "4.1.3",
41-
"@rollup/plugin-replace": "^2.2.1",
40+
"@rollup/plugin-babel": "^5.3.1",
41+
"@rollup/plugin-replace": "^4.0.0",
42+
"@rollup/plugin-typescript": "^8.3.2",
4243
"@testing-library/jest-dom": "5.16.3",
4344
"@testing-library/react": "12.1.4",
4445
"@types/jest": "26.x",
@@ -71,33 +72,32 @@
7172
"react": "^17.0.2",
7273
"react-dom": "^17.0.2",
7374
"react-test-renderer": "^17.0.2",
74-
"rollup": "^1.27.9",
75-
"rollup-plugin-babel": "^4.3.3",
76-
"rollup-plugin-copy": "^3.1.0",
75+
"rollup": "^2.75.5",
76+
"rollup-plugin-copy": "^3.4.0",
7777
"rollup-plugin-extensions": "^0.1.0",
78-
"rollup-plugin-prettier": "^0.6.0",
78+
"rollup-plugin-prettier": "^2.2.2",
7979
"rollup-plugin-terser": "^7.0.2",
8080
"semver": "^7.3.5",
8181
"ts-jest": "^26.5.6",
8282
"typescript": "^4.3.5"
8383
},
8484
"filesize": {
85-
"build/node_modules/@remix-run/router/router.production.min.js": {
85+
"packages/router/dist/router.production.min.js": {
8686
"none": "21 kB"
8787
},
88-
"build/node_modules/@remix-run/router/umd/router.production.min.js": {
88+
"packages/router/dist//umd/router.production.min.js": {
8989
"none": "23 kB"
9090
},
91-
"build/node_modules/react-router/react-router.production.min.js": {
91+
"packages/react-router/dist/react-router.production.min.js": {
9292
"none": "10 kB"
9393
},
94-
"build/node_modules/react-router/umd/react-router.production.min.js": {
94+
"packages/react-router/dist/umd/react-router.production.min.js": {
9595
"none": "12 kB"
9696
},
97-
"build/node_modules/react-router-dom/react-router-dom.production.min.js": {
97+
"packages/react-router-dom/dist/react-router-dom.production.min.js": {
9898
"none": "10 kB"
9999
},
100-
"build/node_modules/react-router-dom/umd/react-router-dom.production.min.js": {
100+
"packages/react-router-dom/dist/umd/react-router-dom.production.min.js": {
101101
"none": "14 kB"
102102
}
103103
}

packages/react-router-dom-v5-compat/jest.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@ module.exports = {
66
globals: {
77
__DEV__: true,
88
},
9+
moduleNameMapper: {
10+
"^@remix-run/router$": "<rootDir>/../router/index.ts",
11+
"^react-router$": "<rootDir>/../react-router/index.ts",
12+
"^react-router-dom-v5-compat$": "<rootDir>/index.ts",
13+
},
914
};

packages/react-router-dom-v5-compat/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
"license": "MIT",
1919
"author": "Remix Software <[email protected]>",
2020
"sideEffects": false,
21-
"main": "./main.js",
22-
"unpkg": "./umd/react-router.production.min.js",
23-
"module": "./index.js",
24-
"types": "./index.d.ts",
21+
"main": "./dist/main.js",
22+
"unpkg": "./dist/umd/react-router.production.min.js",
23+
"module": "./dist/index.js",
24+
"types": "./dist/index.d.ts",
2525
"dependencies": {
2626
"history": "^5.3.0",
2727
"react-router": "6.4.0-pre.2"
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
const path = require("path");
2+
const babel = require("@rollup/plugin-babel").default;
3+
const copy = require("rollup-plugin-copy");
4+
const extensions = require("rollup-plugin-extensions");
5+
const prettier = require("rollup-plugin-prettier");
6+
const replace = require("@rollup/plugin-replace");
7+
const { terser } = require("rollup-plugin-terser");
8+
const typescript = require("@rollup/plugin-typescript");
9+
const {
10+
createBanner,
11+
getBuildDirectories,
12+
PRETTY,
13+
} = require("../../rollup.utils");
14+
const { name, version } = require("./package.json");
15+
16+
module.exports = function rollup() {
17+
const { ROOT_DIR, SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories(name);
18+
const ROUTER_DOM_SOURCE = path.join(
19+
ROOT_DIR,
20+
"packages",
21+
"react-router-dom",
22+
"(index|dom).ts*"
23+
);
24+
const ROUTER_DOM_COPY_DEST = path.join(SOURCE_DIR, "react-router-dom");
25+
26+
// JS modules for bundlers
27+
let modules = [
28+
{
29+
input: `${SOURCE_DIR}/index.ts`,
30+
output: {
31+
file: `${OUTPUT_DIR}/index.js`,
32+
format: "esm",
33+
sourcemap: !PRETTY,
34+
banner: createBanner("React Router DOM v5 Compat", version),
35+
},
36+
external: [
37+
"history",
38+
"@remix-run/router",
39+
"react",
40+
"react-dom",
41+
"react-router",
42+
"react-router-dom",
43+
],
44+
plugins: [
45+
copy({
46+
targets: [{ src: ROUTER_DOM_SOURCE, dest: ROUTER_DOM_COPY_DEST }],
47+
// buildStart is not soon enough to run before the typescript plugin :/
48+
hook: "options",
49+
verbose: true,
50+
}),
51+
extensions({ extensions: [".tsx", ".ts"] }),
52+
babel({
53+
babelHelpers: "bundled",
54+
exclude: /node_modules/,
55+
presets: [
56+
["@babel/preset-env", { loose: true }],
57+
"@babel/preset-react",
58+
"@babel/preset-typescript",
59+
],
60+
plugins: ["babel-plugin-dev-expression"],
61+
extensions: [".ts", ".tsx"],
62+
}),
63+
typescript({
64+
tsconfig: path.join(__dirname, "tsconfig.json"),
65+
exclude: ["__tests__"],
66+
noEmitOnError: true,
67+
}),
68+
copy({
69+
targets: [
70+
{ src: path.join(ROOT_DIR, "LICENSE.md"), dest: SOURCE_DIR },
71+
],
72+
verbose: true,
73+
}),
74+
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
75+
},
76+
];
77+
78+
// UMD modules for <script> tags and CommonJS (node)
79+
let globals = [
80+
{
81+
input: `${SOURCE_DIR}/index.ts`,
82+
output: {
83+
file: `${OUTPUT_DIR}/umd/react-router-dom-v5-compat.development.js`,
84+
format: "umd",
85+
sourcemap: !PRETTY,
86+
banner: createBanner("React Router DOM v5 Compat", version),
87+
globals: {
88+
history: "HistoryLibrary",
89+
"@remix-run/router": "Router",
90+
react: "React",
91+
"react-router": "ReactRouter",
92+
"react-router-dom": "ReactRouterDOM",
93+
},
94+
name: "ReactRouterDOMv5Compat",
95+
},
96+
external: [
97+
"history",
98+
"@remix-run/router",
99+
"react",
100+
"react-router",
101+
"react-router-dom",
102+
],
103+
plugins: [
104+
extensions({ extensions: [".tsx", ".ts"] }),
105+
babel({
106+
babelHelpers: "bundled",
107+
exclude: /node_modules/,
108+
presets: [
109+
["@babel/preset-env", { loose: true }],
110+
"@babel/preset-react",
111+
"@babel/preset-typescript",
112+
],
113+
plugins: ["babel-plugin-dev-expression"],
114+
extensions: [".ts", ".tsx"],
115+
}),
116+
replace({
117+
preventAssignment: true,
118+
values: { "process.env.NODE_ENV": JSON.stringify("development") },
119+
}),
120+
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
121+
},
122+
{
123+
input: `${SOURCE_DIR}/index.ts`,
124+
output: {
125+
file: `${OUTPUT_DIR}/umd/react-router-dom-v5-compat.production.min.js`,
126+
format: "umd",
127+
sourcemap: !PRETTY,
128+
banner: createBanner("React Router DOM v5 Compat", version),
129+
globals: {
130+
history: "HistoryLibrary",
131+
"@remix-run/router": "Router",
132+
react: "React",
133+
"react-router": "ReactRouter",
134+
"react-router-dom": "ReactRouterDOM",
135+
},
136+
name: "ReactRouterDOMv5Compat",
137+
},
138+
external: [
139+
"history",
140+
"@remix-run/router",
141+
"react",
142+
"react-router",
143+
"react-router-dom",
144+
],
145+
plugins: [
146+
extensions({ extensions: [".tsx", ".ts"] }),
147+
babel({
148+
babelHelpers: "bundled",
149+
exclude: /node_modules/,
150+
presets: [
151+
["@babel/preset-env", { loose: true }],
152+
"@babel/preset-react",
153+
"@babel/preset-typescript",
154+
],
155+
plugins: ["babel-plugin-dev-expression"],
156+
extensions: [".ts", ".tsx"],
157+
}),
158+
replace({
159+
preventAssignment: true,
160+
values: { "process.env.NODE_ENV": JSON.stringify("production") },
161+
}),
162+
terser(),
163+
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
164+
},
165+
];
166+
167+
// Node entry points
168+
let node = [
169+
{
170+
input: `${SOURCE_DIR}/node-main.js`,
171+
output: {
172+
file: `${OUTPUT_DIR}/main.js`,
173+
format: "cjs",
174+
banner: createBanner("React Router DOM v5 Compat", version),
175+
},
176+
plugins: [].concat(PRETTY ? prettier({ parser: "babel" }) : []),
177+
},
178+
];
179+
180+
return [...modules, ...globals, ...node];
181+
};

packages/react-router-dom-v5-compat/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"files": ["index.ts"],
3+
"exclude": ["dist/**/*"],
34
"compilerOptions": {
45
"lib": ["ES2020", "DOM", "DOM.Iterable"],
56
"target": "ES2020",
@@ -14,7 +15,7 @@
1415

1516
"skipLibCheck": true,
1617

17-
"outDir": "../../build/node_modules/react-router-dom-v5-compat",
18+
"outDir": ".",
1819
"rootDirs": ["."]
1920
}
2021
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# TODO: Delete in v7
2+
server.js
3+
server.mjs
4+
server.d.ts

packages/react-router-dom/__tests__/DataBrowserRouter-test.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,18 @@ import {
2121
useLoaderData,
2222
useActionData,
2323
useRouteError,
24+
useNavigate,
2425
useNavigation,
2526
Form,
2627
Link,
2728
useSubmit,
2829
useFetcher,
2930
useFetchers,
30-
} from "../index";
31-
import { _resetModuleScope } from "react-router/lib/components";
32-
import { useNavigate } from "react-router/lib/hooks";
33-
import { UNSAFE_DataRouterStateContext } from "react-router";
31+
UNSAFE_DataRouterStateContext,
32+
} from "react-router-dom";
33+
34+
// Private API
35+
import { _resetModuleScope } from "../../react-router/lib/components";
3436

3537
testDomRouter("<DataBrowserRouter>", DataBrowserRouter, (url) =>
3638
getWindowImpl(url, false)

packages/react-router-dom/__tests__/data-static-router-test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import * as React from "react";
22
import * as ReactDOMServer from "react-dom/server";
3-
import { Route, useLocation } from "react-router-dom";
3+
import {
4+
Outlet,
5+
Route,
6+
useLoaderData,
7+
useLocation,
8+
useMatches,
9+
} from "react-router-dom";
410
import { DataStaticRouter } from "react-router-dom/server";
5-
import { Outlet } from "react-router/lib/components";
6-
import { useLoaderData, useMatches } from "react-router/lib/hooks";
711

812
beforeEach(() => {
913
jest.spyOn(console, "warn").mockImplementation(() => {});

packages/react-router-dom/__tests__/nav-link-active-test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import {
1515
Outlet,
1616
DataBrowserRouter,
1717
} from "react-router-dom";
18-
import { _resetModuleScope } from "react-router/lib/components";
18+
19+
// Private API
20+
import { _resetModuleScope } from "../../react-router/lib/components";
1921

2022
describe("NavLink", () => {
2123
describe("when it does not match", () => {

0 commit comments

Comments
 (0)