@react-router/dev 0.0.0-experimental-9c1812606 → 0.0.0-experimental-3278f3ca6
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/bin.js +1 -1
- package/dist/cli/commands.js +1 -1
- package/dist/cli/detectPackageManager.js +1 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +7 -6
- package/dist/cli/run.js +1 -1
- package/dist/cli/useJavascript.js +1 -1
- package/dist/colors.js +1 -1
- package/dist/config/defaults/entry.client.tsx +1 -1
- package/dist/config/format.js +1 -1
- package/dist/config/routes.d.ts +77 -50
- package/dist/config/routes.js +175 -43
- package/dist/invariant.js +1 -1
- package/dist/routes.d.ts +2 -0
- package/dist/routes.js +23 -0
- package/dist/vite/babel.d.ts +10 -10
- package/dist/vite/babel.js +1 -1
- package/dist/vite/build.js +2 -2
- package/dist/vite/cloudflare-dev-proxy.d.ts +7 -1
- package/dist/vite/cloudflare-dev-proxy.js +14 -7
- package/dist/vite/cloudflare.d.ts +1 -0
- package/dist/vite/cloudflare.js +19 -0
- package/dist/vite/combine-urls.js +1 -1
- package/dist/{config.d.ts → vite/config.d.ts} +15 -24
- package/dist/{config.js → vite/config.js} +61 -39
- package/dist/vite/dev.js +1 -1
- package/dist/vite/import-vite-esm-sync.js +1 -1
- package/dist/vite/node-adapter.d.ts +1 -1
- package/dist/vite/node-adapter.js +7 -3
- package/dist/vite/plugin.d.ts +6 -3
- package/dist/vite/plugin.js +152 -103
- package/dist/vite/profiler.js +1 -1
- package/dist/vite/remove-exports.d.ts +2 -2
- package/dist/vite/remove-exports.js +113 -243
- package/dist/vite/resolve-file-url.js +1 -1
- package/dist/vite/static/refresh-utils.cjs +7 -26
- package/dist/vite/styles.d.ts +3 -2
- package/dist/vite/styles.js +23 -2
- package/dist/vite/vmod.js +1 -1
- package/dist/vite/with-props.d.ts +4 -0
- package/dist/vite/with-props.js +151 -0
- package/dist/vite.d.ts +2 -0
- package/dist/{cli.js → vite.js} +7 -8
- package/package.json +21 -12
- package/dist/cli.d.ts +0 -1
- package/dist/config/findConfig.d.ts +0 -1
- package/dist/config/findConfig.js +0 -32
- package/dist/config/flatRoutes.d.ts +0 -14
- package/dist/config/flatRoutes.js +0 -418
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -23
- package/dist/vite/define-route.d.ts +0 -5
- package/dist/vite/define-route.js +0 -207
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-3278f3ca6
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -12,267 +12,137 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
+
var babelDeadCodeElimination = require('babel-dead-code-elimination');
|
|
15
16
|
var babel = require('./babel.js');
|
|
16
|
-
var parser = require('@babel/parser');
|
|
17
|
-
var t = require('@babel/types');
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
const removeExports = (ast, exportsToRemove) => {
|
|
19
|
+
let previouslyReferencedIdentifiers = babelDeadCodeElimination.findReferencedIdentifiers(ast);
|
|
20
|
+
let exportsFiltered = false;
|
|
21
|
+
let markedForRemoval = new Set();
|
|
22
|
+
babel.traverse(ast, {
|
|
23
|
+
ExportDeclaration(path) {
|
|
24
|
+
// export { foo };
|
|
25
|
+
// export { bar } from "./module";
|
|
26
|
+
if (path.node.type === "ExportNamedDeclaration") {
|
|
27
|
+
var _path$node$declaratio, _path$node$declaratio2, _path$node$declaratio3;
|
|
28
|
+
if (path.node.specifiers.length) {
|
|
29
|
+
path.node.specifiers = path.node.specifiers.filter(specifier => {
|
|
30
|
+
// Filter out individual specifiers
|
|
31
|
+
if (specifier.type === "ExportSpecifier" && specifier.exported.type === "Identifier") {
|
|
32
|
+
if (exportsToRemove.includes(specifier.exported.name)) {
|
|
33
|
+
exportsFiltered = true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
37
|
+
return true;
|
|
38
|
+
});
|
|
39
|
+
// Remove the entire export statement if all specifiers were removed
|
|
40
|
+
if (path.node.specifiers.length === 0) {
|
|
41
|
+
markedForRemoval.add(path);
|
|
145
42
|
}
|
|
146
43
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
declaration.declarations = declaration.declarations.filter(declarator => {
|
|
158
|
-
for (let name of exportsToRemove) {
|
|
159
|
-
if (declarator.id.name === name) {
|
|
160
|
-
removedExports.add(name);
|
|
44
|
+
// export const foo = ...;
|
|
45
|
+
// export const [ foo ] = ...;
|
|
46
|
+
if (((_path$node$declaratio = path.node.declaration) === null || _path$node$declaratio === void 0 ? void 0 : _path$node$declaratio.type) === "VariableDeclaration") {
|
|
47
|
+
let declaration = path.node.declaration;
|
|
48
|
+
declaration.declarations = declaration.declarations.filter(declaration => {
|
|
49
|
+
// export const foo = ...;
|
|
50
|
+
// export const foo = ..., bar = ...;
|
|
51
|
+
if (declaration.id.type === "Identifier" && exportsToRemove.includes(declaration.id.name)) {
|
|
52
|
+
// Filter out individual variables
|
|
53
|
+
exportsFiltered = true;
|
|
161
54
|
return false;
|
|
162
55
|
}
|
|
56
|
+
// export const [ foo ] = ...;
|
|
57
|
+
// export const { foo } = ...;
|
|
58
|
+
if (declaration.id.type === "ArrayPattern" || declaration.id.type === "ObjectPattern") {
|
|
59
|
+
// NOTE: These exports cannot be safely removed, so instead we
|
|
60
|
+
// validate them to ensure that any exports that are intended to
|
|
61
|
+
// be removed are not present
|
|
62
|
+
validateDestructuredExports(declaration.id, exportsToRemove);
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
// Remove the entire export statement if all variables were removed
|
|
67
|
+
if (declaration.declarations.length === 0) {
|
|
68
|
+
markedForRemoval.add(path);
|
|
163
69
|
}
|
|
164
|
-
return true;
|
|
165
|
-
});
|
|
166
|
-
if (declaration.declarations.length === 0) {
|
|
167
|
-
shouldRemove = true;
|
|
168
70
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
71
|
+
// export function foo() {}
|
|
72
|
+
if (((_path$node$declaratio2 = path.node.declaration) === null || _path$node$declaratio2 === void 0 ? void 0 : _path$node$declaratio2.type) === "FunctionDeclaration") {
|
|
73
|
+
let id = path.node.declaration.id;
|
|
74
|
+
if (id && exportsToRemove.includes(id.name)) {
|
|
75
|
+
markedForRemoval.add(path);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// export class Foo() {}
|
|
79
|
+
if (((_path$node$declaratio3 = path.node.declaration) === null || _path$node$declaratio3 === void 0 ? void 0 : _path$node$declaratio3.type) === "ClassDeclaration") {
|
|
80
|
+
let id = path.node.declaration.id;
|
|
81
|
+
if (id && exportsToRemove.includes(id.name)) {
|
|
82
|
+
markedForRemoval.add(path);
|
|
176
83
|
}
|
|
177
84
|
}
|
|
178
85
|
}
|
|
179
|
-
|
|
180
|
-
|
|
86
|
+
// export default ...;
|
|
87
|
+
if (path.node.type === "ExportDefaultDeclaration" && exportsToRemove.includes("default")) {
|
|
88
|
+
markedForRemoval.add(path);
|
|
181
89
|
}
|
|
182
90
|
}
|
|
183
91
|
});
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
92
|
+
if (markedForRemoval.size > 0 || exportsFiltered) {
|
|
93
|
+
for (let path of markedForRemoval) {
|
|
94
|
+
path.remove();
|
|
95
|
+
}
|
|
96
|
+
// Run dead code elimination on any newly unreferenced identifiers
|
|
97
|
+
babelDeadCodeElimination.deadCodeElimination(ast, previouslyReferencedIdentifiers);
|
|
188
98
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
path.parentPath.remove();
|
|
196
|
-
} else {
|
|
197
|
-
path.remove();
|
|
99
|
+
};
|
|
100
|
+
function validateDestructuredExports(id, exportsToRemove) {
|
|
101
|
+
if (id.type === "ArrayPattern") {
|
|
102
|
+
for (let element of id.elements) {
|
|
103
|
+
if (!element) {
|
|
104
|
+
continue;
|
|
198
105
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
106
|
+
// [ foo ]
|
|
107
|
+
if (element.type === "Identifier" && exportsToRemove.includes(element.name)) {
|
|
108
|
+
throw invalidDestructureError(element.name);
|
|
109
|
+
}
|
|
110
|
+
// [ ...foo ]
|
|
111
|
+
if (element.type === "RestElement" && element.argument.type === "Identifier" && exportsToRemove.includes(element.argument.name)) {
|
|
112
|
+
throw invalidDestructureError(element.argument.name);
|
|
113
|
+
}
|
|
114
|
+
// [ [...] ]
|
|
115
|
+
// [ {...} ]
|
|
116
|
+
if (element.type === "ArrayPattern" || element.type === "ObjectPattern") {
|
|
117
|
+
validateDestructuredExports(element, exportsToRemove);
|
|
208
118
|
}
|
|
209
119
|
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
}
|
|
120
|
+
}
|
|
121
|
+
if (id.type === "ObjectPattern") {
|
|
122
|
+
for (let property of id.properties) {
|
|
123
|
+
if (!property) {
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (property.type === "ObjectProperty" && property.key.type === "Identifier") {
|
|
127
|
+
// { foo }
|
|
128
|
+
if (property.value.type === "Identifier" && exportsToRemove.includes(property.value.name)) {
|
|
129
|
+
throw invalidDestructureError(property.value.name);
|
|
265
130
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
}
|
|
131
|
+
// { foo: [...] }
|
|
132
|
+
// { foo: {...} }
|
|
133
|
+
if (property.value.type === "ArrayPattern" || property.value.type === "ObjectPattern") {
|
|
134
|
+
validateDestructuredExports(property.value, exportsToRemove);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
// { ...foo }
|
|
138
|
+
if (property.type === "RestElement" && property.argument.type === "Identifier" && exportsToRemove.includes(property.argument.name)) {
|
|
139
|
+
throw invalidDestructureError(property.argument.name);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function invalidDestructureError(name) {
|
|
145
|
+
return new Error(`Cannot remove destructured export "${name}"`);
|
|
146
|
+
}
|
|
277
147
|
|
|
278
148
|
exports.removeExports = removeExports;
|
|
@@ -60,7 +60,13 @@ const enqueueUpdate = debounce(async () => {
|
|
|
60
60
|
window.__reactRouterRouteModuleUpdates.clear();
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
try {
|
|
64
|
+
window.__remixHdrActive = true;
|
|
65
|
+
await __remixRouter.revalidate();
|
|
66
|
+
} finally {
|
|
67
|
+
window.__remixHdrActive = false;
|
|
68
|
+
}
|
|
69
|
+
|
|
64
70
|
if (manifest) {
|
|
65
71
|
Object.assign(window.__remixManifest, manifest);
|
|
66
72
|
}
|
|
@@ -145,31 +151,6 @@ function __hmr_import(module) {
|
|
|
145
151
|
const routeUpdates = new Map();
|
|
146
152
|
window.__reactRouterRouteModuleUpdates = new Map();
|
|
147
153
|
|
|
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
154
|
import.meta.hot.on("react-router:hmr", async ({ route }) => {
|
|
174
155
|
window.__remixClearCriticalCss();
|
|
175
156
|
|
package/dist/vite/styles.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import type { ServerBuild } from "react-router";
|
|
2
2
|
import type { ViteDevServer } from "vite";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ResolvedReactRouterConfig } from "./config";
|
|
4
4
|
export declare const isCssModulesFile: (file: string) => boolean;
|
|
5
|
+
export declare const isCssUrlWithoutSideEffects: (url: string) => boolean;
|
|
5
6
|
export declare const getStylesForUrl: ({ viteDevServer, rootDirectory, reactRouterConfig, entryClientFilePath, cssModulesManifest, build, url, }: {
|
|
6
7
|
viteDevServer: ViteDevServer;
|
|
7
8
|
rootDirectory: string;
|
|
8
|
-
reactRouterConfig: Pick<
|
|
9
|
+
reactRouterConfig: Pick<ResolvedReactRouterConfig, "appDirectory" | "routes">;
|
|
9
10
|
entryClientFilePath: string;
|
|
10
11
|
cssModulesManifest: Record<string, string>;
|
|
11
12
|
build: ServerBuild;
|
package/dist/vite/styles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @react-router/dev v0.0.0-experimental-
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-3278f3ca6
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Remix Software Inc.
|
|
5
5
|
*
|
|
@@ -44,6 +44,26 @@ const cssFileRegExp = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\
|
|
|
44
44
|
const cssModulesRegExp = new RegExp(`\\.module${cssFileRegExp.source}`);
|
|
45
45
|
const isCssFile = file => cssFileRegExp.test(file);
|
|
46
46
|
const isCssModulesFile = file => cssModulesRegExp.test(file);
|
|
47
|
+
// https://vitejs.dev/guide/features#disabling-css-injection-into-the-page
|
|
48
|
+
// https://github.com/vitejs/vite/blob/561b940f6f963fbb78058a6e23b4adad53a2edb9/packages/vite/src/node/plugins/css.ts#L194
|
|
49
|
+
// https://vitejs.dev/guide/features#static-assets
|
|
50
|
+
// https://github.com/vitejs/vite/blob/561b940f6f963fbb78058a6e23b4adad53a2edb9/packages/vite/src/node/utils.ts#L309-L310
|
|
51
|
+
const cssUrlParamsWithoutSideEffects = ["url", "inline", "raw", "inline-css"];
|
|
52
|
+
const isCssUrlWithoutSideEffects = url => {
|
|
53
|
+
let queryString = url.split("?")[1];
|
|
54
|
+
if (!queryString) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
let params = new URLSearchParams(queryString);
|
|
58
|
+
for (let paramWithoutSideEffects of cssUrlParamsWithoutSideEffects) {
|
|
59
|
+
if (
|
|
60
|
+
// Parameter is blank and not explicitly set, i.e. "?url", not "?url="
|
|
61
|
+
params.get(paramWithoutSideEffects) === "" && !url.includes(`?${paramWithoutSideEffects}=`) && !url.includes(`&${paramWithoutSideEffects}=`)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return false;
|
|
66
|
+
};
|
|
47
67
|
const getStylesForFiles = async ({
|
|
48
68
|
viteDevServer,
|
|
49
69
|
rootDirectory,
|
|
@@ -79,7 +99,7 @@ const getStylesForFiles = async ({
|
|
|
79
99
|
console.error(err);
|
|
80
100
|
}
|
|
81
101
|
for (let dep of deps) {
|
|
82
|
-
if (dep.file && isCssFile(dep.file) && !dep.url
|
|
102
|
+
if (dep.file && isCssFile(dep.file) && !isCssUrlWithoutSideEffects(dep.url) // Ignore styles that resolved as URLs, inline or raw. These shouldn't get injected.
|
|
83
103
|
) {
|
|
84
104
|
try {
|
|
85
105
|
let css = isCssModulesFile(dep.file) ? cssModulesManifest[dep.file] : (await viteDevServer.ssrLoadModule(dep.url)).default;
|
|
@@ -174,3 +194,4 @@ const getStylesForUrl = async ({
|
|
|
174
194
|
|
|
175
195
|
exports.getStylesForUrl = getStylesForUrl;
|
|
176
196
|
exports.isCssModulesFile = isCssModulesFile;
|
|
197
|
+
exports.isCssUrlWithoutSideEffects = isCssUrlWithoutSideEffects;
|
package/dist/vite/vmod.js
CHANGED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @react-router/dev v0.0.0-experimental-3278f3ca6
|
|
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 dedent = require('dedent');
|
|
16
|
+
var babel = require('./babel.js');
|
|
17
|
+
var vmod = require('./vmod.js');
|
|
18
|
+
var t = require('@babel/types');
|
|
19
|
+
|
|
20
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
21
|
+
|
|
22
|
+
function _interopNamespace(e) {
|
|
23
|
+
if (e && e.__esModule) return e;
|
|
24
|
+
var n = Object.create(null);
|
|
25
|
+
if (e) {
|
|
26
|
+
Object.keys(e).forEach(function (k) {
|
|
27
|
+
if (k !== 'default') {
|
|
28
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
29
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function () { return e[k]; }
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
n["default"] = e;
|
|
37
|
+
return Object.freeze(n);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
var dedent__default = /*#__PURE__*/_interopDefaultLegacy(dedent);
|
|
41
|
+
var t__namespace = /*#__PURE__*/_interopNamespace(t);
|
|
42
|
+
|
|
43
|
+
const vmodId = vmod.id("with-props");
|
|
44
|
+
const NAMED_COMPONENT_EXPORTS = ["HydrateFallback", "ErrorBoundary"];
|
|
45
|
+
const plugin = {
|
|
46
|
+
name: "react-router-with-props",
|
|
47
|
+
enforce: "pre",
|
|
48
|
+
resolveId(id) {
|
|
49
|
+
if (id === vmodId) return vmod.resolve(vmodId);
|
|
50
|
+
},
|
|
51
|
+
async load(id) {
|
|
52
|
+
if (id !== vmod.resolve(vmodId)) return;
|
|
53
|
+
return dedent__default["default"]`
|
|
54
|
+
import { createElement as h } from "react";
|
|
55
|
+
import { useActionData, useLoaderData, useParams } from "react-router";
|
|
56
|
+
|
|
57
|
+
export function withComponentProps(Component) {
|
|
58
|
+
return function Wrapped() {
|
|
59
|
+
const props = {
|
|
60
|
+
params: useParams(),
|
|
61
|
+
loaderData: useLoaderData(),
|
|
62
|
+
actionData: useActionData(),
|
|
63
|
+
};
|
|
64
|
+
return h(Component, props);
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function withHydrateFallbackProps(HydrateFallback) {
|
|
69
|
+
return function Wrapped() {
|
|
70
|
+
const props = {
|
|
71
|
+
params: useParams(),
|
|
72
|
+
};
|
|
73
|
+
return h(HydrateFallback, props);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function withErrorBoundaryProps(ErrorBoundary) {
|
|
78
|
+
return function Wrapped() {
|
|
79
|
+
const props = {
|
|
80
|
+
params: useParams(),
|
|
81
|
+
loaderData: useLoaderData(),
|
|
82
|
+
actionData: useActionData(),
|
|
83
|
+
};
|
|
84
|
+
return h(ErrorBoundary, props);
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
const transform = ast => {
|
|
91
|
+
const hocs = [];
|
|
92
|
+
function getHocUid(path, hocName) {
|
|
93
|
+
const uid = path.scope.generateUidIdentifier(hocName);
|
|
94
|
+
hocs.push([hocName, uid]);
|
|
95
|
+
return uid;
|
|
96
|
+
}
|
|
97
|
+
babel.traverse(ast, {
|
|
98
|
+
ExportDeclaration(path) {
|
|
99
|
+
if (path.isExportDefaultDeclaration()) {
|
|
100
|
+
const declaration = path.get("declaration");
|
|
101
|
+
// prettier-ignore
|
|
102
|
+
const expr = declaration.isExpression() ? declaration.node : declaration.isFunctionDeclaration() ? toFunctionExpression(declaration.node) : undefined;
|
|
103
|
+
if (expr) {
|
|
104
|
+
const uid = getHocUid(path, "withComponentProps");
|
|
105
|
+
declaration.replaceWith(t__namespace.callExpression(uid, [expr]));
|
|
106
|
+
}
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (path.isExportNamedDeclaration()) {
|
|
110
|
+
const decl = path.get("declaration");
|
|
111
|
+
if (decl.isVariableDeclaration()) {
|
|
112
|
+
decl.get("declarations").forEach(varDeclarator => {
|
|
113
|
+
const id = varDeclarator.get("id");
|
|
114
|
+
const init = varDeclarator.get("init");
|
|
115
|
+
const expr = init.node;
|
|
116
|
+
if (!expr) return;
|
|
117
|
+
if (!id.isIdentifier()) return;
|
|
118
|
+
const {
|
|
119
|
+
name
|
|
120
|
+
} = id.node;
|
|
121
|
+
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
122
|
+
const uid = getHocUid(path, `with${name}Props`);
|
|
123
|
+
init.replaceWith(t__namespace.callExpression(uid, [expr]));
|
|
124
|
+
});
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
if (decl.isFunctionDeclaration()) {
|
|
128
|
+
const {
|
|
129
|
+
id
|
|
130
|
+
} = decl.node;
|
|
131
|
+
if (!id) return;
|
|
132
|
+
const {
|
|
133
|
+
name
|
|
134
|
+
} = id;
|
|
135
|
+
if (!NAMED_COMPONENT_EXPORTS.includes(name)) return;
|
|
136
|
+
const uid = getHocUid(path, `with${name}Props`);
|
|
137
|
+
decl.replaceWith(t__namespace.variableDeclaration("const", [t__namespace.variableDeclarator(t__namespace.identifier(name), t__namespace.callExpression(uid, [toFunctionExpression(decl.node)]))]));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
if (hocs.length > 0) {
|
|
143
|
+
ast.program.body.unshift(t__namespace.importDeclaration(hocs.map(([name, identifier]) => t__namespace.importSpecifier(identifier, t__namespace.identifier(name))), t__namespace.stringLiteral(vmodId)));
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
function toFunctionExpression(decl) {
|
|
147
|
+
return t__namespace.functionExpression(decl.id, decl.params, decl.body, decl.generator, decl.async);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
exports.plugin = plugin;
|
|
151
|
+
exports.transform = transform;
|