@react-router/dev 0.0.0-experimental-c0856287f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1773 -0
- package/LICENSE.md +23 -0
- package/README.md +13 -0
- package/dist/cli/commands.d.ts +12 -0
- package/dist/cli/commands.js +174 -0
- package/dist/cli/detectPackageManager.d.ts +10 -0
- package/dist/cli/detectPackageManager.js +39 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +19 -0
- package/dist/cli/run.d.ts +5 -0
- package/dist/cli/run.js +180 -0
- package/dist/cli/useJavascript.d.ts +4 -0
- package/dist/cli/useJavascript.js +66 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +21 -0
- package/dist/colors.d.ts +17 -0
- package/dist/colors.js +49 -0
- package/dist/config/defaults/entry.client.tsx +12 -0
- package/dist/config/defaults/entry.dev.d.ts +2 -0
- package/dist/config/defaults/entry.dev.ts +13 -0
- package/dist/config/defaults/entry.server.cloudflare.tsx +55 -0
- package/dist/config/defaults/entry.server.deno.tsx +55 -0
- package/dist/config/defaults/entry.server.node.tsx +155 -0
- package/dist/config/defaults/entry.server.spa.tsx +20 -0
- package/dist/config/flat-routes.d.ts +14 -0
- package/dist/config/flat-routes.js +418 -0
- package/dist/config/format.d.ts +5 -0
- package/dist/config/format.js +68 -0
- package/dist/config/routes.d.ts +98 -0
- package/dist/config/routes.js +93 -0
- package/dist/config/serverModes.d.ts +9 -0
- package/dist/config/serverModes.js +28 -0
- package/dist/config.d.ts +75 -0
- package/dist/config.js +152 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +23 -0
- package/dist/invariant.d.ts +2 -0
- package/dist/invariant.js +22 -0
- package/dist/manifest.d.ts +28 -0
- package/dist/vite/babel.d.ts +20 -0
- package/dist/vite/babel.js +49 -0
- package/dist/vite/build.d.ts +15 -0
- package/dist/vite/build.js +271 -0
- package/dist/vite/cloudflare-proxy-plugin.d.ts +15 -0
- package/dist/vite/cloudflare-proxy-plugin.js +82 -0
- package/dist/vite/dev.d.ts +15 -0
- package/dist/vite/dev.js +81 -0
- package/dist/vite/import-vite-esm-sync.d.ts +4 -0
- package/dist/vite/import-vite-esm-sync.js +28 -0
- package/dist/vite/index.d.ts +4 -0
- package/dist/vite/index.js +30 -0
- package/dist/vite/node-adapter.d.ts +6 -0
- package/dist/vite/node-adapter.js +78 -0
- package/dist/vite/plugin.d.ts +165 -0
- package/dist/vite/plugin.js +1178 -0
- package/dist/vite/profiler.d.ts +5 -0
- package/dist/vite/profiler.js +55 -0
- package/dist/vite/remove-exports-test.d.ts +1 -0
- package/dist/vite/remove-exports.d.ts +2 -0
- package/dist/vite/remove-exports.js +278 -0
- package/dist/vite/resolve-file-url.d.ts +3 -0
- package/dist/vite/resolve-file-url.js +53 -0
- package/dist/vite/static/refresh-utils.cjs +185 -0
- package/dist/vite/styles.d.ts +13 -0
- package/dist/vite/styles.js +176 -0
- package/dist/vite/vmod.d.ts +3 -0
- package/dist/vite/vmod.js +21 -0
- package/package.json +107 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { Session } from "node:inspector";
|
|
3
|
+
export declare const getSession: () => Session | undefined;
|
|
4
|
+
export declare const start: (callback?: () => void | Promise<void>) => Promise<void>;
|
|
5
|
+
export declare const stop: (log: (message: string) => void) => void | Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-c0856287f
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
var fs = require('node:fs');
|
|
16
|
+
var path = require('node:path');
|
|
17
|
+
var colors = require('picocolors');
|
|
18
|
+
|
|
19
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
20
|
+
|
|
21
|
+
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
22
|
+
var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
|
|
23
|
+
var colors__default = /*#__PURE__*/_interopDefaultLegacy(colors);
|
|
24
|
+
|
|
25
|
+
// Adapted from:
|
|
26
|
+
const getSession = () => global.__reactRouter_profile_session;
|
|
27
|
+
const start = async callback => {
|
|
28
|
+
let inspector = await import('node:inspector').then(r => r.default);
|
|
29
|
+
let session = global.__reactRouter_profile_session = new inspector.Session();
|
|
30
|
+
session.connect();
|
|
31
|
+
session.post("Profiler.enable", () => {
|
|
32
|
+
session.post("Profiler.start", callback);
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
let profileCount = 0;
|
|
36
|
+
const stop = log => {
|
|
37
|
+
let session = getSession();
|
|
38
|
+
if (!session) return;
|
|
39
|
+
return new Promise((res, rej) => {
|
|
40
|
+
session.post("Profiler.stop", (err, {
|
|
41
|
+
profile
|
|
42
|
+
}) => {
|
|
43
|
+
if (err) return rej(err);
|
|
44
|
+
let outPath = path__default["default"].resolve(`./react-router-${profileCount++}.cpuprofile`);
|
|
45
|
+
fs__default["default"].writeFileSync(outPath, JSON.stringify(profile));
|
|
46
|
+
log(colors__default["default"].yellow(`CPU profile written to ${colors__default["default"].white(colors__default["default"].dim(outPath))}`));
|
|
47
|
+
global.__reactRouter_profile_session = undefined;
|
|
48
|
+
res();
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.getSession = getSession;
|
|
54
|
+
exports.start = start;
|
|
55
|
+
exports.stop = stop;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-c0856287f
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
var babel = require('./babel.js');
|
|
16
|
+
var parser = require('@babel/parser');
|
|
17
|
+
var t = require('@babel/types');
|
|
18
|
+
|
|
19
|
+
function _interopNamespace(e) {
|
|
20
|
+
if (e && e.__esModule) return e;
|
|
21
|
+
var n = Object.create(null);
|
|
22
|
+
if (e) {
|
|
23
|
+
Object.keys(e).forEach(function (k) {
|
|
24
|
+
if (k !== 'default') {
|
|
25
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
26
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function () { return e[k]; }
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
n["default"] = e;
|
|
34
|
+
return Object.freeze(n);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var t__namespace = /*#__PURE__*/_interopNamespace(t);
|
|
38
|
+
|
|
39
|
+
function getIdentifier(path) {
|
|
40
|
+
let parentPath = path.parentPath;
|
|
41
|
+
if (parentPath.type === "VariableDeclarator") {
|
|
42
|
+
let variablePath = parentPath;
|
|
43
|
+
let name = variablePath.get("id");
|
|
44
|
+
return name.node.type === "Identifier" ? name : null;
|
|
45
|
+
}
|
|
46
|
+
if (parentPath.type === "AssignmentExpression") {
|
|
47
|
+
let variablePath = parentPath;
|
|
48
|
+
let name = variablePath.get("left");
|
|
49
|
+
return name.node.type === "Identifier" ? name : null;
|
|
50
|
+
}
|
|
51
|
+
if (path.node.type === "ArrowFunctionExpression") {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
return path.node.id && path.node.id.type === "Identifier" ? path.get("id") : null;
|
|
55
|
+
}
|
|
56
|
+
function isIdentifierReferenced(ident) {
|
|
57
|
+
let binding = ident.scope.getBinding(ident.node.name);
|
|
58
|
+
if (binding !== null && binding !== void 0 && binding.referenced) {
|
|
59
|
+
// Functions can reference themselves, so we need to check if there's a
|
|
60
|
+
// binding outside the function scope or not.
|
|
61
|
+
if (binding.path.type === "FunctionDeclaration") {
|
|
62
|
+
return !binding.constantViolations.concat(binding.referencePaths)
|
|
63
|
+
// Check that every reference is contained within the function:
|
|
64
|
+
.every(ref => ref.findParent(parent => parent === (binding === null || binding === void 0 ? void 0 : binding.path)));
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const removeExports = (source, exportsToRemove, generateOptions = {}) => {
|
|
71
|
+
let document = parser.parse(source, {
|
|
72
|
+
sourceType: "module"
|
|
73
|
+
});
|
|
74
|
+
let referencedIdentifiers = new Set();
|
|
75
|
+
let removedExports = new Set();
|
|
76
|
+
let markImport = path => {
|
|
77
|
+
let local = path.get("local");
|
|
78
|
+
if (isIdentifierReferenced(local)) {
|
|
79
|
+
referencedIdentifiers.add(local);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
let markFunction = path => {
|
|
83
|
+
let identifier = getIdentifier(path);
|
|
84
|
+
if (identifier !== null && identifier !== void 0 && identifier.node && isIdentifierReferenced(identifier)) {
|
|
85
|
+
referencedIdentifiers.add(identifier);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
babel.traverse(document, {
|
|
89
|
+
VariableDeclarator(variablePath) {
|
|
90
|
+
if (variablePath.node.id.type === "Identifier") {
|
|
91
|
+
let local = variablePath.get("id");
|
|
92
|
+
if (isIdentifierReferenced(local)) {
|
|
93
|
+
referencedIdentifiers.add(local);
|
|
94
|
+
}
|
|
95
|
+
} else if (variablePath.node.id.type === "ObjectPattern") {
|
|
96
|
+
let pattern = variablePath.get("id");
|
|
97
|
+
let properties = pattern.get("properties");
|
|
98
|
+
properties.forEach(p => {
|
|
99
|
+
let local = p.get(p.node.type === "ObjectProperty" ? "value" : p.node.type === "RestElement" ? "argument" : function () {
|
|
100
|
+
throw new Error("invariant");
|
|
101
|
+
}());
|
|
102
|
+
if (isIdentifierReferenced(local)) {
|
|
103
|
+
referencedIdentifiers.add(local);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
} else if (variablePath.node.id.type === "ArrayPattern") {
|
|
107
|
+
let pattern = variablePath.get("id");
|
|
108
|
+
let elements = pattern.get("elements");
|
|
109
|
+
elements.forEach(element => {
|
|
110
|
+
var _element$node, _element$node2;
|
|
111
|
+
let local;
|
|
112
|
+
if (((_element$node = element.node) === null || _element$node === void 0 ? void 0 : _element$node.type) === "Identifier") {
|
|
113
|
+
local = element;
|
|
114
|
+
} else if (((_element$node2 = element.node) === null || _element$node2 === void 0 ? void 0 : _element$node2.type) === "RestElement") {
|
|
115
|
+
local = element.get("argument");
|
|
116
|
+
} else {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (isIdentifierReferenced(local)) {
|
|
120
|
+
referencedIdentifiers.add(local);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
FunctionDeclaration: markFunction,
|
|
126
|
+
FunctionExpression: markFunction,
|
|
127
|
+
ArrowFunctionExpression: markFunction,
|
|
128
|
+
ImportSpecifier: markImport,
|
|
129
|
+
ImportDefaultSpecifier: markImport,
|
|
130
|
+
ImportNamespaceSpecifier: markImport,
|
|
131
|
+
ExportNamedDeclaration(path) {
|
|
132
|
+
let shouldRemove = false;
|
|
133
|
+
// Handle re-exports: export { preload } from './foo'
|
|
134
|
+
path.node.specifiers = path.node.specifiers.filter(spec => {
|
|
135
|
+
if (spec.exported.type !== "Identifier") {
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
let {
|
|
139
|
+
name
|
|
140
|
+
} = spec.exported;
|
|
141
|
+
for (let namedExport of exportsToRemove) {
|
|
142
|
+
if (name === namedExport) {
|
|
143
|
+
removedExports.add(namedExport);
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return true;
|
|
148
|
+
});
|
|
149
|
+
let {
|
|
150
|
+
declaration
|
|
151
|
+
} = path.node;
|
|
152
|
+
// When no re-exports are left, remove the path
|
|
153
|
+
if (!declaration && path.node.specifiers.length === 0) {
|
|
154
|
+
shouldRemove = true;
|
|
155
|
+
}
|
|
156
|
+
if (declaration && declaration.type === "VariableDeclaration") {
|
|
157
|
+
declaration.declarations = declaration.declarations.filter(declarator => {
|
|
158
|
+
for (let name of exportsToRemove) {
|
|
159
|
+
if (declarator.id.name === name) {
|
|
160
|
+
removedExports.add(name);
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return true;
|
|
165
|
+
});
|
|
166
|
+
if (declaration.declarations.length === 0) {
|
|
167
|
+
shouldRemove = true;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (declaration && declaration.type === "FunctionDeclaration") {
|
|
171
|
+
for (let name of exportsToRemove) {
|
|
172
|
+
var _declaration$id;
|
|
173
|
+
if (((_declaration$id = declaration.id) === null || _declaration$id === void 0 ? void 0 : _declaration$id.name) === name) {
|
|
174
|
+
shouldRemove = true;
|
|
175
|
+
removedExports.add(name);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if (shouldRemove) {
|
|
180
|
+
path.remove();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
if (removedExports.size === 0) {
|
|
185
|
+
// No server-specific exports found so there's
|
|
186
|
+
// no need to remove unused references
|
|
187
|
+
return babel.generate(document, generateOptions);
|
|
188
|
+
}
|
|
189
|
+
let referencesRemovedInThisPass;
|
|
190
|
+
let sweepFunction = path => {
|
|
191
|
+
let identifier = getIdentifier(path);
|
|
192
|
+
if (identifier !== null && identifier !== void 0 && identifier.node && referencedIdentifiers.has(identifier) && !isIdentifierReferenced(identifier)) {
|
|
193
|
+
++referencesRemovedInThisPass;
|
|
194
|
+
if (t__namespace.isAssignmentExpression(path.parentPath.node) || t__namespace.isVariableDeclarator(path.parentPath.node)) {
|
|
195
|
+
path.parentPath.remove();
|
|
196
|
+
} else {
|
|
197
|
+
path.remove();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
let sweepImport = path => {
|
|
202
|
+
let local = path.get("local");
|
|
203
|
+
if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
|
|
204
|
+
++referencesRemovedInThisPass;
|
|
205
|
+
path.remove();
|
|
206
|
+
if (path.parent.specifiers.length === 0) {
|
|
207
|
+
path.parentPath.remove();
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
// Traverse again to remove unused references. This happens at least once,
|
|
212
|
+
// then repeats until no more references are removed.
|
|
213
|
+
do {
|
|
214
|
+
referencesRemovedInThisPass = 0;
|
|
215
|
+
babel.traverse(document, {
|
|
216
|
+
Program(path) {
|
|
217
|
+
path.scope.crawl();
|
|
218
|
+
},
|
|
219
|
+
// eslint-disable-next-line no-loop-func
|
|
220
|
+
VariableDeclarator(variablePath) {
|
|
221
|
+
if (variablePath.node.id.type === "Identifier") {
|
|
222
|
+
let local = variablePath.get("id");
|
|
223
|
+
if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
|
|
224
|
+
++referencesRemovedInThisPass;
|
|
225
|
+
variablePath.remove();
|
|
226
|
+
}
|
|
227
|
+
} else if (variablePath.node.id.type === "ObjectPattern") {
|
|
228
|
+
let pattern = variablePath.get("id");
|
|
229
|
+
let beforeCount = referencesRemovedInThisPass;
|
|
230
|
+
let properties = pattern.get("properties");
|
|
231
|
+
properties.forEach(property => {
|
|
232
|
+
let local = property.get(property.node.type === "ObjectProperty" ? "value" : property.node.type === "RestElement" ? "argument" : function () {
|
|
233
|
+
throw new Error("invariant");
|
|
234
|
+
}());
|
|
235
|
+
if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
|
|
236
|
+
++referencesRemovedInThisPass;
|
|
237
|
+
property.remove();
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
if (beforeCount !== referencesRemovedInThisPass && pattern.get("properties").length < 1) {
|
|
241
|
+
variablePath.remove();
|
|
242
|
+
}
|
|
243
|
+
} else if (variablePath.node.id.type === "ArrayPattern") {
|
|
244
|
+
let pattern = variablePath.get("id");
|
|
245
|
+
let beforeCount = referencesRemovedInThisPass;
|
|
246
|
+
let elements = pattern.get("elements");
|
|
247
|
+
elements.forEach(e => {
|
|
248
|
+
var _e$node, _e$node2;
|
|
249
|
+
let local;
|
|
250
|
+
if (((_e$node = e.node) === null || _e$node === void 0 ? void 0 : _e$node.type) === "Identifier") {
|
|
251
|
+
local = e;
|
|
252
|
+
} else if (((_e$node2 = e.node) === null || _e$node2 === void 0 ? void 0 : _e$node2.type) === "RestElement") {
|
|
253
|
+
local = e.get("argument");
|
|
254
|
+
} else {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (referencedIdentifiers.has(local) && !isIdentifierReferenced(local)) {
|
|
258
|
+
++referencesRemovedInThisPass;
|
|
259
|
+
e.remove();
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
if (beforeCount !== referencesRemovedInThisPass && pattern.get("elements").length < 1) {
|
|
263
|
+
variablePath.remove();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
FunctionDeclaration: sweepFunction,
|
|
268
|
+
FunctionExpression: sweepFunction,
|
|
269
|
+
ArrowFunctionExpression: sweepFunction,
|
|
270
|
+
ImportSpecifier: sweepImport,
|
|
271
|
+
ImportDefaultSpecifier: sweepImport,
|
|
272
|
+
ImportNamespaceSpecifier: sweepImport
|
|
273
|
+
});
|
|
274
|
+
} while (referencesRemovedInThisPass);
|
|
275
|
+
return babel.generate(document, generateOptions);
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
exports.removeExports = removeExports;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-c0856287f
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) Remix Software Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
+
*
|
|
9
|
+
* @license MIT
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
+
|
|
15
|
+
var path = require('node:path');
|
|
16
|
+
var importViteEsmSync = require('./import-vite-esm-sync.js');
|
|
17
|
+
|
|
18
|
+
function _interopNamespace(e) {
|
|
19
|
+
if (e && e.__esModule) return e;
|
|
20
|
+
var n = Object.create(null);
|
|
21
|
+
if (e) {
|
|
22
|
+
Object.keys(e).forEach(function (k) {
|
|
23
|
+
if (k !== 'default') {
|
|
24
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
25
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function () { return e[k]; }
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
n["default"] = e;
|
|
33
|
+
return Object.freeze(n);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
37
|
+
|
|
38
|
+
const resolveFileUrl = ({
|
|
39
|
+
rootDirectory
|
|
40
|
+
}, filePath) => {
|
|
41
|
+
let vite = importViteEsmSync.importViteEsmSync();
|
|
42
|
+
let relativePath = path__namespace.relative(rootDirectory, filePath);
|
|
43
|
+
let isWithinRoot = !relativePath.startsWith("..") && !path__namespace.isAbsolute(relativePath);
|
|
44
|
+
if (!isWithinRoot) {
|
|
45
|
+
// Vite will prevent serving files outside of the workspace
|
|
46
|
+
// unless user explictly opts in with `server.fs.allow`
|
|
47
|
+
// https://vitejs.dev/config/server-options.html#server-fs-allow
|
|
48
|
+
return path__namespace.posix.join("/@fs", vite.normalizePath(filePath));
|
|
49
|
+
}
|
|
50
|
+
return "/" + vite.normalizePath(relativePath);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
exports.resolveFileUrl = resolveFileUrl;
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
// adapted from https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/src/refreshUtils.js
|
|
2
|
+
// This file gets injected into the browser as a part of the HMR runtime
|
|
3
|
+
|
|
4
|
+
function debounce(fn, delay) {
|
|
5
|
+
let handle;
|
|
6
|
+
return () => {
|
|
7
|
+
clearTimeout(handle);
|
|
8
|
+
handle = setTimeout(fn, delay);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-undef */
|
|
13
|
+
const enqueueUpdate = debounce(async () => {
|
|
14
|
+
let manifest;
|
|
15
|
+
if (routeUpdates.size > 0) {
|
|
16
|
+
manifest = JSON.parse(JSON.stringify(__remixManifest));
|
|
17
|
+
|
|
18
|
+
for (let route of routeUpdates.values()) {
|
|
19
|
+
manifest.routes[route.id] = route;
|
|
20
|
+
let imported = window.__reactRouterRouteModuleUpdates.get(route.id);
|
|
21
|
+
if (!imported) {
|
|
22
|
+
throw Error(
|
|
23
|
+
`[react-router:hmr] No module update found for route ${route.id}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
let routeModule = {
|
|
27
|
+
...imported,
|
|
28
|
+
// react-refresh takes care of updating these in-place,
|
|
29
|
+
// if we don't preserve existing values we'll loose state.
|
|
30
|
+
default: imported.default
|
|
31
|
+
? window.__remixRouteModules[route.id]?.default ?? imported.default
|
|
32
|
+
: imported.default,
|
|
33
|
+
ErrorBoundary: imported.ErrorBoundary
|
|
34
|
+
? window.__remixRouteModules[route.id]?.ErrorBoundary ??
|
|
35
|
+
imported.ErrorBoundary
|
|
36
|
+
: imported.ErrorBoundary,
|
|
37
|
+
HydrateFallback: imported.HydrateFallback
|
|
38
|
+
? window.__remixRouteModules[route.id]?.HydrateFallback ??
|
|
39
|
+
imported.HydrateFallback
|
|
40
|
+
: imported.HydrateFallback,
|
|
41
|
+
};
|
|
42
|
+
window.__remixRouteModules[route.id] = routeModule;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let needsRevalidation = new Set(
|
|
46
|
+
Array.from(routeUpdates.values())
|
|
47
|
+
.filter((route) => route.hasLoader || route.hasClientLoader)
|
|
48
|
+
.map((route) => route.id)
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
let routes = __remixRouter.createRoutesForHMR(
|
|
52
|
+
needsRevalidation,
|
|
53
|
+
manifest.routes,
|
|
54
|
+
window.__remixRouteModules,
|
|
55
|
+
window.__remixContext.future,
|
|
56
|
+
window.__remixContext.isSpaMode
|
|
57
|
+
);
|
|
58
|
+
__remixRouter._internalSetRoutes(routes);
|
|
59
|
+
routeUpdates.clear();
|
|
60
|
+
window.__reactRouterRouteModuleUpdates.clear();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
await revalidate();
|
|
64
|
+
if (manifest) {
|
|
65
|
+
Object.assign(window.__remixManifest, manifest);
|
|
66
|
+
}
|
|
67
|
+
exports.performReactRefresh();
|
|
68
|
+
}, 16);
|
|
69
|
+
|
|
70
|
+
// Taken from https://github.com/pmmmwh/react-refresh-webpack-plugin/blob/main/lib/runtime/RefreshUtils.js#L141
|
|
71
|
+
// This allows to resister components not detected by SWC like styled component
|
|
72
|
+
function registerExportsForReactRefresh(filename, moduleExports) {
|
|
73
|
+
for (let key in moduleExports) {
|
|
74
|
+
if (key === "__esModule") continue;
|
|
75
|
+
let exportValue = moduleExports[key];
|
|
76
|
+
if (exports.isLikelyComponentType(exportValue)) {
|
|
77
|
+
// 'export' is required to avoid key collision when renamed exports that
|
|
78
|
+
// shadow a local component name: https://github.com/vitejs/vite-plugin-react/issues/116
|
|
79
|
+
// The register function has an identity check to not register twice the same component,
|
|
80
|
+
// so this is safe to not used the same key here.
|
|
81
|
+
exports.register(exportValue, filename + " export " + key);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function validateRefreshBoundaryAndEnqueueUpdate(
|
|
87
|
+
prevExports,
|
|
88
|
+
nextExports,
|
|
89
|
+
// non-component exports that are handled by the framework (e.g. `meta` and `links` for route modules)
|
|
90
|
+
acceptExports = []
|
|
91
|
+
) {
|
|
92
|
+
if (
|
|
93
|
+
!predicateOnExport(
|
|
94
|
+
prevExports,
|
|
95
|
+
(key) => key in nextExports || acceptExports.includes(key)
|
|
96
|
+
)
|
|
97
|
+
) {
|
|
98
|
+
return "Could not Fast Refresh (export removed)";
|
|
99
|
+
}
|
|
100
|
+
if (
|
|
101
|
+
!predicateOnExport(
|
|
102
|
+
nextExports,
|
|
103
|
+
(key) => key in prevExports || acceptExports.includes(key)
|
|
104
|
+
)
|
|
105
|
+
) {
|
|
106
|
+
return "Could not Fast Refresh (new export)";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let hasExports = false;
|
|
110
|
+
let allExportsAreHandledOrUnchanged = predicateOnExport(
|
|
111
|
+
nextExports,
|
|
112
|
+
(key, value) => {
|
|
113
|
+
hasExports = true;
|
|
114
|
+
// Remix can handle Remix-specific exports (e.g. `meta` and `links`)
|
|
115
|
+
if (acceptExports.includes(key)) return true;
|
|
116
|
+
// React Fast Refresh can handle component exports
|
|
117
|
+
if (exports.isLikelyComponentType(value)) return true;
|
|
118
|
+
// Unchanged exports are implicitly handled
|
|
119
|
+
return prevExports[key] === nextExports[key];
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
if (hasExports && allExportsAreHandledOrUnchanged) {
|
|
123
|
+
enqueueUpdate();
|
|
124
|
+
} else {
|
|
125
|
+
return "Could not Fast Refresh. Learn more at https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#consistent-components-exports";
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function predicateOnExport(moduleExports, predicate) {
|
|
130
|
+
for (let key in moduleExports) {
|
|
131
|
+
if (key === "__esModule") continue;
|
|
132
|
+
let desc = Object.getOwnPropertyDescriptor(moduleExports, key);
|
|
133
|
+
if (desc && desc.get) return false;
|
|
134
|
+
if (!predicate(key, moduleExports[key])) return false;
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Hides vite-ignored dynamic import so that Vite can skip analysis if no other
|
|
140
|
+
// dynamic import is present (https://github.com/vitejs/vite/pull/12732)
|
|
141
|
+
function __hmr_import(module) {
|
|
142
|
+
return import(/* @vite-ignore */ module);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const routeUpdates = new Map();
|
|
146
|
+
window.__reactRouterRouteModuleUpdates = new Map();
|
|
147
|
+
|
|
148
|
+
async function revalidate() {
|
|
149
|
+
let { promise, resolve } = channel();
|
|
150
|
+
let unsub = __remixRouter.subscribe((state) => {
|
|
151
|
+
if (state.revalidation === "idle") {
|
|
152
|
+
unsub();
|
|
153
|
+
// Ensure RouterProvider setState has flushed before re-rendering
|
|
154
|
+
resolve();
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
window.__remixRevalidation = (window.__remixRevalidation || 0) + 1;
|
|
158
|
+
__remixRouter.revalidate();
|
|
159
|
+
return promise;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function channel() {
|
|
163
|
+
let resolve;
|
|
164
|
+
let reject;
|
|
165
|
+
|
|
166
|
+
let promise = new Promise((_resolve, _reject) => {
|
|
167
|
+
resolve = _resolve;
|
|
168
|
+
reject = _reject;
|
|
169
|
+
});
|
|
170
|
+
return { promise, resolve, reject };
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
import.meta.hot.on("react-router:hmr", async ({ route }) => {
|
|
174
|
+
window.__remixClearCriticalCss();
|
|
175
|
+
|
|
176
|
+
if (route) {
|
|
177
|
+
routeUpdates.set(route.id, route);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
exports.__hmr_import = __hmr_import;
|
|
182
|
+
exports.registerExportsForReactRefresh = registerExportsForReactRefresh;
|
|
183
|
+
exports.validateRefreshBoundaryAndEnqueueUpdate =
|
|
184
|
+
validateRefreshBoundaryAndEnqueueUpdate;
|
|
185
|
+
exports.enqueueUpdate = enqueueUpdate;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ServerBuild } from "@react-router/server-runtime";
|
|
2
|
+
import type { ViteDevServer } from "vite";
|
|
3
|
+
import type { RemixConfig as ResolvedRemixConfig } from "../config";
|
|
4
|
+
export declare const isCssModulesFile: (file: string) => boolean;
|
|
5
|
+
export declare const getStylesForUrl: ({ viteDevServer, rootDirectory, reactRouterConfig, entryClientFilePath, cssModulesManifest, build, url, }: {
|
|
6
|
+
viteDevServer: ViteDevServer;
|
|
7
|
+
rootDirectory: string;
|
|
8
|
+
reactRouterConfig: Pick<ResolvedRemixConfig, "appDirectory" | "routes">;
|
|
9
|
+
entryClientFilePath: string;
|
|
10
|
+
cssModulesManifest: Record<string, string>;
|
|
11
|
+
build: ServerBuild;
|
|
12
|
+
url: string | undefined;
|
|
13
|
+
}) => Promise<string | undefined>;
|