Skip to content

Commit b7fadce

Browse files
authored
ci: Simplify router rollup build and dist directory (#9017)
* ci: Simplify router rollup build and dist directory * Update bundle check for new router non-minified build * Include TS source in package for deno
1 parent 4247a3a commit b7fadce

File tree

9 files changed

+61
-210
lines changed

9 files changed

+61
-210
lines changed

.changeset/strong-bees-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@remix-run/router": patch
3+
---
4+
5+
ci: simplify dist/ directory for CJS/ESM only

package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,8 @@
9999
"typescript": "^4.7.3"
100100
},
101101
"filesize": {
102-
"packages/router/dist/router.production.min.js": {
103-
"none": "21 kB"
104-
},
105-
"packages/router/dist//umd/router.production.min.js": {
106-
"none": "23 kB"
102+
"packages/router/dist/router.js": {
103+
"none": "77 kB"
107104
},
108105
"packages/react-router/dist/react-router.production.min.js": {
109106
"none": "10 kB"

packages/router/.eslintrc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
"browser": true,
44
"commonjs": true
55
},
6-
"globals": {
7-
"__DEV__": true
8-
},
96
"rules": {
107
"strict": 0
118
}

packages/router/history.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,6 @@ export function createHashHistory(
426426
//#region UTILS
427427
////////////////////////////////////////////////////////////////////////////////
428428

429-
const readOnly: <T>(obj: T) => Readonly<T> = __DEV__
430-
? (obj) => Object.freeze(obj)
431-
: (obj) => obj;
432-
433429
function warning(cond: any, message: string) {
434430
if (!cond) {
435431
// eslint-disable-next-line no-console
@@ -469,8 +465,8 @@ export function createLocation(
469465
to: To,
470466
state: any = null,
471467
key?: string
472-
): Location {
473-
return readOnly<Location>({
468+
): Readonly<Location> {
469+
let location: Readonly<Location> = {
474470
pathname: typeof current === "string" ? current : current.pathname,
475471
search: "",
476472
hash: "",
@@ -481,7 +477,8 @@ export function createLocation(
481477
// But that's a pretty big refactor to the current test suite so going to
482478
// keep as is for the time being and just let any incoming keys take precedence
483479
key: (to as Location)?.key || key || createKey(),
484-
});
480+
};
481+
return location;
485482
}
486483

487484
/**

packages/router/jest.config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ module.exports = {
33
transform: {
44
"\\.[jt]sx?$": "./jest-transformer.js",
55
},
6-
globals: {
7-
__DEV__: true,
8-
},
96
setupFiles: ["./__tests__/setup.ts"],
107
moduleNameMapper: {
118
"^@remix-run/router$": "<rootDir>/index.ts",

packages/router/node-main.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

packages/router/package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
"license": "MIT",
1616
"author": "Remix Software <hello@remix.run>",
1717
"sideEffects": false,
18-
"main": "./dist/main.js",
19-
"unpkg": "./dist/umd/router.production.min.js",
20-
"module": "./dist/index.js",
18+
"main": "./dist/router.cjs.js",
19+
"module": "./dist/router.js",
2120
"types": "./dist/index.d.ts",
2221
"files": [
2322
"dist/",
24-
"CHANGELOG.md",
25-
"LICENSE.md",
26-
"README.md"
23+
"*.ts",
24+
"CHANGELOG.md"
2725
],
2826
"publishConfig": {
2927
"access": "public"

packages/router/rollup.config.js

Lines changed: 41 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ const babel = require("@rollup/plugin-babel").default;
33
const copy = require("rollup-plugin-copy");
44
const extensions = require("rollup-plugin-extensions");
55
const prettier = require("rollup-plugin-prettier");
6-
const replace = require("@rollup/plugin-replace");
7-
const { terser } = require("rollup-plugin-terser");
86
const typescript = require("@rollup/plugin-typescript");
97
const {
108
createBanner,
@@ -13,185 +11,56 @@ const {
1311
} = require("../../rollup.utils");
1412
const { name, version } = require("./package.json");
1513

16-
module.exports = function rollup() {
14+
function getRollupConfig(format, filename, includeTypesAndCopy = false) {
1715
const { ROOT_DIR, SOURCE_DIR, OUTPUT_DIR } = getBuildDirectories(
1816
name,
1917
// We don't live in a folder matching our package name
2018
"router"
2119
);
2220

23-
// JS modules for bundlers
24-
const modules = [
25-
{
26-
input: `${SOURCE_DIR}/index.ts`,
27-
output: {
28-
file: `${OUTPUT_DIR}/index.js`,
29-
format: "esm",
30-
sourcemap: !PRETTY,
31-
banner: createBanner("@remix-run/router", version),
32-
},
33-
plugins: [
34-
extensions({ extensions: [".ts"] }),
35-
babel({
36-
babelHelpers: "bundled",
37-
exclude: /node_modules/,
38-
presets: [
39-
["@babel/preset-env", { loose: true }],
40-
"@babel/preset-typescript",
41-
],
42-
plugins: ["babel-plugin-dev-expression"],
43-
extensions: [".ts"],
44-
}),
45-
typescript({
46-
tsconfig: path.join(__dirname, "tsconfig.json"),
47-
exclude: ["__tests__"],
48-
noEmitOnError: true,
49-
}),
50-
copy({
51-
targets: [
52-
{ src: path.join(ROOT_DIR, "LICENSE.md"), dest: SOURCE_DIR },
53-
],
54-
verbose: true,
55-
}),
56-
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
21+
return {
22+
input: `${SOURCE_DIR}/index.ts`,
23+
output: {
24+
file: `${OUTPUT_DIR}/${filename}`,
25+
format,
26+
sourcemap: !PRETTY,
27+
banner: createBanner("@remix-run/router", version),
5728
},
58-
];
29+
plugins: [
30+
extensions({ extensions: [".ts"] }),
31+
babel({
32+
babelHelpers: "bundled",
33+
exclude: /node_modules/,
34+
presets: [
35+
["@babel/preset-env", { loose: true }],
36+
"@babel/preset-typescript",
37+
],
38+
extensions: [".ts"],
39+
}),
40+
...(includeTypesAndCopy
41+
? [
42+
typescript({
43+
tsconfig: path.join(__dirname, "tsconfig.json"),
44+
exclude: ["__tests__"],
45+
noEmitOnError: true,
46+
}),
47+
copy({
48+
targets: [
49+
{ src: path.join(ROOT_DIR, "LICENSE.md"), dest: SOURCE_DIR },
50+
],
51+
verbose: true,
52+
}),
53+
]
54+
: []),
55+
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
56+
};
57+
}
5958

60-
// JS modules for <script type=module>
61-
const webModules = [
62-
{
63-
input: `${SOURCE_DIR}/index.ts`,
64-
output: {
65-
file: `${OUTPUT_DIR}/router.development.js`,
66-
format: "esm",
67-
sourcemap: !PRETTY,
68-
banner: createBanner("@remix-run/router", version),
69-
},
70-
plugins: [
71-
extensions({ extensions: [".ts"] }),
72-
babel({
73-
babelHelpers: "bundled",
74-
exclude: /node_modules/,
75-
presets: ["@babel/preset-modules", "@babel/preset-typescript"],
76-
plugins: ["babel-plugin-dev-expression"],
77-
extensions: [".ts"],
78-
}),
79-
replace({
80-
preventAssignment: true,
81-
values: { "process.env.NODE_ENV": JSON.stringify("development") },
82-
}),
83-
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
84-
},
85-
{
86-
input: `${SOURCE_DIR}/index.ts`,
87-
output: {
88-
file: `${OUTPUT_DIR}/router.production.min.js`,
89-
format: "esm",
90-
sourcemap: !PRETTY,
91-
banner: createBanner("@remix-run/router", version),
92-
},
93-
plugins: [
94-
extensions({ extensions: [".ts"] }),
95-
babel({
96-
babelHelpers: "bundled",
97-
exclude: /node_modules/,
98-
presets: [
99-
[
100-
"@babel/preset-modules",
101-
{
102-
// Don't spoof `.name` for Arrow Functions, which breaks when minified anyway.
103-
loose: true,
104-
},
105-
],
106-
"@babel/preset-typescript",
107-
],
108-
plugins: ["babel-plugin-dev-expression"],
109-
extensions: [".ts"],
110-
}),
111-
replace({
112-
preventAssignment: true,
113-
values: { "process.env.NODE_ENV": JSON.stringify("production") },
114-
}),
115-
// compiler(),
116-
terser({ ecma: 8, safari10: true }),
117-
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
118-
},
119-
];
120-
121-
// UMD modules for <script> tags and CommonJS (node)
122-
const globals = [
123-
{
124-
input: `${SOURCE_DIR}/index.ts`,
125-
output: {
126-
file: `${OUTPUT_DIR}/umd/router.development.js`,
127-
format: "umd",
128-
sourcemap: !PRETTY,
129-
banner: createBanner("@remix-run/router", version),
130-
name: "Router",
131-
},
132-
plugins: [
133-
extensions({ extensions: [".ts"] }),
134-
babel({
135-
babelHelpers: "bundled",
136-
exclude: /node_modules/,
137-
presets: [
138-
["@babel/preset-env", { loose: true }],
139-
"@babel/preset-typescript",
140-
],
141-
plugins: ["babel-plugin-dev-expression"],
142-
extensions: [".ts"],
143-
}),
144-
replace({
145-
preventAssignment: true,
146-
values: { "process.env.NODE_ENV": JSON.stringify("development") },
147-
}),
148-
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
149-
},
150-
{
151-
input: `${SOURCE_DIR}/index.ts`,
152-
output: {
153-
file: `${OUTPUT_DIR}/umd/router.production.min.js`,
154-
format: "umd",
155-
sourcemap: !PRETTY,
156-
banner: createBanner("@remix-run/router", version),
157-
name: "Router",
158-
},
159-
plugins: [
160-
extensions({ extensions: [".ts"] }),
161-
babel({
162-
babelHelpers: "bundled",
163-
exclude: /node_modules/,
164-
presets: [
165-
["@babel/preset-env", { loose: true }],
166-
"@babel/preset-typescript",
167-
],
168-
plugins: ["babel-plugin-dev-expression"],
169-
extensions: [".ts"],
170-
}),
171-
replace({
172-
preventAssignment: true,
173-
values: { "process.env.NODE_ENV": JSON.stringify("production") },
174-
}),
175-
// compiler(),
176-
terser(),
177-
].concat(PRETTY ? prettier({ parser: "babel" }) : []),
178-
},
179-
];
180-
181-
// Node entry points
182-
const node = [
183-
{
184-
input: `${SOURCE_DIR}/node-main.js`,
185-
output: {
186-
file: `${OUTPUT_DIR}/main.js`,
187-
format: "cjs",
188-
banner: createBanner("@remix-run/router", version),
189-
},
190-
plugins: [].concat(PRETTY ? prettier({ parser: "babel" }) : []),
191-
},
59+
module.exports = function rollup() {
60+
return [
61+
getRollupConfig("esm", "router.js", true),
62+
getRollupConfig("cjs", "router.cjs.js", false),
19263
];
193-
194-
return [...modules, ...webModules, ...globals, ...node];
19564
};
19665

19766
/**

packages/router/router.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,11 @@ export function createRouter(init: RouterInit): Router {
872872

873873
let actionMatch = matches.slice(-1)[0];
874874
if (!actionMatch.route.action) {
875-
if (__DEV__) {
876-
console.warn(
877-
"You're trying to submit to a route that does not have an action. To " +
878-
"fix this, please add an `action` function to the route for " +
879-
`[${createHref(location)}]`
880-
);
881-
}
875+
console.warn(
876+
"You're trying to submit to a route that does not have an action. To " +
877+
"fix this, please add an `action` function to the route for " +
878+
`[${createHref(location)}]`
879+
);
882880
result = {
883881
type: ResultType.error,
884882
error: new ErrorResponse(

0 commit comments

Comments
 (0)