vite-plugin-react-server 1.1.13 → 1.1.15
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/dist/package.json +3 -1
- package/dist/plugin/config/defaults.d.ts +2 -2
- package/dist/plugin/config/defaults.d.ts.map +1 -1
- package/dist/plugin/config/defaults.js +2 -2
- package/dist/plugin/config/defaults.js.map +1 -1
- package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
- package/dist/plugin/config/resolveOptions.js +101 -75
- package/dist/plugin/config/resolveOptions.js.map +1 -1
- package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
- package/dist/plugin/config/resolveUserConfig.js +27 -5
- package/dist/plugin/config/resolveUserConfig.js.map +1 -1
- package/dist/plugin/error/toError.d.ts.map +1 -1
- package/dist/plugin/error/toError.js +0 -1
- package/dist/plugin/error/toError.js.map +1 -1
- package/dist/plugin/helpers/collectManifestCss.d.ts +1 -2
- package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -1
- package/dist/plugin/helpers/collectManifestCss.js +3 -5
- package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
- package/dist/plugin/helpers/collectViteModuleGraphCss.js +6 -2
- package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts +1 -1
- package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
- package/dist/plugin/helpers/createCssProps.js +11 -32
- package/dist/plugin/helpers/createCssProps.js.map +1 -1
- package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
- package/dist/plugin/helpers/createRscStream.js +1 -0
- package/dist/plugin/helpers/createRscStream.js.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.d.ts +1 -8
- package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
- package/dist/plugin/helpers/inputNormalizer.js +2 -5
- package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
- package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -1
- package/dist/plugin/loader/createDefaultLoader.js +68 -4
- package/dist/plugin/loader/css-loader.development.d.ts +2 -15
- package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.development.js +16 -15
- package/dist/plugin/loader/css-loader.development.js.map +1 -1
- package/dist/plugin/loader/css-loader.production.d.ts +1 -1
- package/dist/plugin/loader/css-loader.production.d.ts.map +1 -1
- package/dist/plugin/loader/css-loader.production.js +1 -1
- package/dist/plugin/loader/css-loader.production.js.map +1 -1
- package/dist/plugin/loader/env-loader.development.d.ts +1 -0
- package/dist/plugin/loader/env-loader.development.d.ts.map +1 -1
- package/dist/plugin/loader/env-loader.development.js +17 -9
- package/dist/plugin/loader/handleExports.d.ts +1 -0
- package/dist/plugin/loader/handleExports.d.ts.map +1 -1
- package/dist/plugin/loader/handleExports.js +27 -8
- package/dist/plugin/loader/handleExports.js.map +1 -1
- package/dist/plugin/loader/react-loader.server.d.ts +2 -2
- package/dist/plugin/loader/react-loader.server.d.ts.map +1 -1
- package/dist/plugin/loader/react-loader.server.js +88 -26
- package/dist/plugin/loader/sourceMap.d.ts.map +1 -1
- package/dist/plugin/loader/sourceMap.js +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.js +1 -1
- package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -1
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -1
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +86 -13
- package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -1
- package/dist/plugin/plugin.client.d.ts.map +1 -1
- package/dist/plugin/plugin.client.js +0 -1
- package/dist/plugin/plugin.client.js.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
- package/dist/plugin/react-client/configureWorkerRequestHandler.js +81 -5
- package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
- package/dist/plugin/react-client/createMessageHandlers.js +3 -0
- package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.d.ts +2 -2
- package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
- package/dist/plugin/react-client/createWorkerStream.js +13 -2
- package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
- package/dist/plugin/react-client/handleWorkerRscStream.js +10 -3
- package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -1
- package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
- package/dist/plugin/react-client/restartWorker.js +2 -1
- package/dist/plugin/react-client/restartWorker.js.map +1 -1
- package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
- package/dist/plugin/react-server/configureReactServer.js +1 -2
- package/dist/plugin/react-server/configureReactServer.js.map +1 -1
- package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -1
- package/dist/plugin/react-server/handleServerAction.js +0 -16
- package/dist/plugin/react-server/handleServerAction.js.map +1 -1
- package/dist/plugin/react-static/createBuildLoader.d.ts.map +1 -0
- package/dist/plugin/react-static/createBuildLoader.js.map +1 -0
- package/dist/plugin/react-static/plugin.d.ts.map +1 -1
- package/dist/plugin/react-static/plugin.js +9 -12
- package/dist/plugin/react-static/plugin.js.map +1 -1
- package/dist/plugin/react-static/temporaryReferences.d.ts.map +1 -0
- package/dist/plugin/react-static/temporaryReferences.js.map +1 -0
- package/dist/plugin/transformer/plugin.server.js +2 -2
- package/dist/plugin/transformer/plugin.server.js.map +1 -1
- package/dist/plugin/types.d.ts +20 -3
- package/dist/plugin/types.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/handleRender.js +1 -0
- package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
- package/dist/plugin/worker/rsc/handlers.d.ts +3 -0
- package/dist/plugin/worker/rsc/handlers.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/handlers.js +225 -0
- package/dist/plugin/worker/rsc/handlers.js.map +1 -0
- package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/messageHandler.js +4 -110
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +14 -16
- package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
- package/dist/plugin/worker/rsc/state.d.ts +1 -2
- package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
- package/dist/plugin/worker/rsc/state.js +1 -2
- package/dist/plugin/worker/rsc/state.js.map +1 -1
- package/dist/plugin/worker/rsc/userOptions.d.ts +2 -0
- package/dist/plugin/worker/rsc/userOptions.d.ts.map +1 -0
- package/dist/plugin/worker/rsc/userOptions.js +17 -0
- package/dist/plugin/worker/rsc/userOptions.js.map +1 -0
- package/dist/plugin/worker/types.d.ts +2 -1
- package/dist/plugin/worker/types.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -1
- package/plugin/config/defaults.tsx +5 -2
- package/plugin/config/resolveOptions.ts +106 -91
- package/plugin/config/resolveUserConfig.ts +29 -5
- package/plugin/error/toError.ts +0 -2
- package/plugin/helpers/collectManifestCss.ts +2 -6
- package/plugin/helpers/collectViteModuleGraphCss.ts +6 -0
- package/plugin/helpers/createCssProps.tsx +17 -46
- package/plugin/helpers/createRscStream.tsx +1 -0
- package/plugin/helpers/inputNormalizer.ts +4 -13
- package/plugin/loader/createDefaultLoader.ts +80 -4
- package/plugin/loader/css-loader.development.ts +17 -34
- package/plugin/loader/css-loader.production.ts +2 -4
- package/plugin/loader/env-loader.development.ts +38 -15
- package/plugin/loader/handleExports.ts +36 -13
- package/plugin/loader/react-loader.server.ts +110 -32
- package/plugin/loader/sourceMap.ts +1 -1
- package/plugin/loader/transformModuleIfNeeded.ts +2 -2
- package/plugin/loader/transformModuleWithPreservedFunctions.ts +128 -21
- package/plugin/plugin.client.ts +0 -2
- package/plugin/react-client/configureWorkerRequestHandler.ts +104 -4
- package/plugin/react-client/createMessageHandlers.ts +3 -0
- package/plugin/react-client/createWorkerStream.ts +15 -1
- package/plugin/react-client/handleWorkerRscStream.ts +12 -3
- package/plugin/react-client/restartWorker.ts +1 -0
- package/plugin/react-server/configureReactServer.ts +1 -2
- package/plugin/react-server/handleServerAction.ts +1 -19
- package/plugin/react-static/plugin.ts +9 -12
- package/plugin/transformer/plugin.server.ts +2 -2
- package/plugin/types.ts +31 -2
- package/plugin/worker/rsc/handleRender.ts +1 -0
- package/plugin/worker/rsc/handlers.ts +246 -0
- package/plugin/worker/rsc/messageHandler.tsx +3 -118
- package/plugin/worker/rsc/rsc-worker.development.ts +18 -20
- package/plugin/worker/rsc/state.ts +2 -6
- package/plugin/worker/rsc/userOptions.ts +8 -0
- package/plugin/worker/types.ts +2 -0
- package/dist/plugin/loader/createBuildLoader.d.ts.map +0 -1
- package/dist/plugin/loader/createBuildLoader.js.map +0 -1
- package/dist/plugin/loader/plugin.d.ts +0 -22
- package/dist/plugin/loader/plugin.d.ts.map +0 -1
- package/dist/plugin/loader/plugin.js +0 -27
- package/dist/plugin/loader/temporaryReferences.d.ts.map +0 -1
- package/dist/plugin/loader/temporaryReferences.js.map +0 -1
- package/plugin/loader/plugin.ts +0 -33
- /package/dist/plugin/{loader → react-static}/createBuildLoader.d.ts +0 -0
- /package/dist/plugin/{loader → react-static}/createBuildLoader.js +0 -0
- /package/dist/plugin/{loader → react-static}/temporaryReferences.d.ts +0 -0
- /package/dist/plugin/{loader → react-static}/temporaryReferences.js +0 -0
- /package/plugin/{loader → react-static}/createBuildLoader.ts +0 -0
- /package/plugin/{loader → react-static}/temporaryReferences.ts +0 -0
|
@@ -40,8 +40,11 @@ const handleSearchQuery = (path: string) => {
|
|
|
40
40
|
const registerPath = (
|
|
41
41
|
path: string,
|
|
42
42
|
_pattern?: string | RegExp | ((path: string) => boolean) | undefined,
|
|
43
|
-
|
|
43
|
+
ext?: string | undefined
|
|
44
44
|
) => {
|
|
45
|
+
if (ext && !path.endsWith(ext)) {
|
|
46
|
+
return path + ext;
|
|
47
|
+
}
|
|
45
48
|
return path;
|
|
46
49
|
};
|
|
47
50
|
|
|
@@ -145,24 +148,24 @@ export const resolveOptions = <
|
|
|
145
148
|
moduleBasePath,
|
|
146
149
|
});
|
|
147
150
|
|
|
148
|
-
const
|
|
151
|
+
const moduleExtension = resolveAutoDiscoverMatcher(
|
|
149
152
|
options.autoDiscover?.moduleExtension,
|
|
150
153
|
DEFAULT_CONFIG.AUTO_DISCOVER.moduleExtension
|
|
151
154
|
);
|
|
152
155
|
// Auto-discovery pattern matchers
|
|
153
|
-
const
|
|
156
|
+
const modulePattern = resolveAutoDiscoverMatcher(
|
|
154
157
|
options.autoDiscover?.modulePattern,
|
|
155
158
|
options.autoDiscover?.moduleExtension
|
|
156
|
-
? (id: string) =>
|
|
159
|
+
? (id: string) => moduleExtension(id.toLowerCase())
|
|
157
160
|
: DEFAULT_CONFIG.AUTO_DISCOVER.modulePattern
|
|
158
161
|
);
|
|
159
162
|
|
|
160
|
-
const
|
|
163
|
+
const jsonPattern = resolveAutoDiscoverMatcher(
|
|
161
164
|
options.autoDiscover?.jsonPattern,
|
|
162
165
|
DEFAULT_CONFIG.AUTO_DISCOVER.jsonPattern
|
|
163
166
|
);
|
|
164
167
|
|
|
165
|
-
const
|
|
168
|
+
const cssPattern = resolveAutoDiscoverMatcher(
|
|
166
169
|
options.autoDiscover?.cssPattern,
|
|
167
170
|
DEFAULT_CONFIG.AUTO_DISCOVER.cssPattern
|
|
168
171
|
);
|
|
@@ -177,80 +180,85 @@ export const resolveOptions = <
|
|
|
177
180
|
DEFAULT_CONFIG.AUTO_DISCOVER.rscPattern
|
|
178
181
|
);
|
|
179
182
|
|
|
180
|
-
const
|
|
183
|
+
const clientComponents = resolveAutoDiscoverMatcher(
|
|
181
184
|
options.autoDiscover?.clientComponents,
|
|
182
185
|
options.autoDiscover?.moduleExtension
|
|
183
186
|
? (id: string) =>
|
|
184
|
-
|
|
187
|
+
moduleExtension(id.toLowerCase()) &&
|
|
185
188
|
/(\.|\/)?client(\.|\/)/.test(id.toLowerCase())
|
|
186
189
|
: DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents
|
|
187
190
|
);
|
|
188
191
|
|
|
189
|
-
const
|
|
192
|
+
const serverFunctions = resolveAutoDiscoverMatcher(
|
|
190
193
|
options.autoDiscover?.serverFunctions,
|
|
191
194
|
options.autoDiscover?.moduleExtension
|
|
192
195
|
? (id: string) =>
|
|
193
|
-
|
|
196
|
+
moduleExtension(id.toLowerCase()) &&
|
|
194
197
|
/(\.|\/)?server(\.|\/)/.test(id.toLowerCase())
|
|
195
198
|
: DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions
|
|
196
199
|
);
|
|
197
200
|
|
|
198
|
-
const
|
|
201
|
+
const nodeOnly = resolveAutoDiscoverMatcher(
|
|
199
202
|
options.autoDiscover?.nodeOnly,
|
|
200
203
|
DEFAULT_CONFIG.AUTO_DISCOVER.nodeOnly
|
|
201
204
|
);
|
|
202
205
|
|
|
203
|
-
const
|
|
206
|
+
const propsPattern = resolveAutoDiscoverMatcher(
|
|
204
207
|
options.autoDiscover?.propsPattern,
|
|
205
208
|
options.autoDiscover?.moduleExtension
|
|
206
209
|
? (id: string) =>
|
|
207
|
-
|
|
210
|
+
moduleExtension(id.toLowerCase()) &&
|
|
208
211
|
/(\.|\/)?props(\.|\/)/.test(id.toLowerCase())
|
|
209
212
|
: DEFAULT_CONFIG.AUTO_DISCOVER.propsPattern
|
|
210
213
|
);
|
|
211
214
|
|
|
212
|
-
const
|
|
215
|
+
const pagePattern = resolveAutoDiscoverMatcher(
|
|
213
216
|
options.autoDiscover?.pagePattern,
|
|
214
217
|
options.autoDiscover?.moduleExtension
|
|
215
218
|
? (id: string) =>
|
|
216
|
-
|
|
219
|
+
moduleExtension(id.toLowerCase()) &&
|
|
217
220
|
/(\.|\/)?page(\.|\/)/.test(id.toLowerCase())
|
|
218
221
|
: DEFAULT_CONFIG.AUTO_DISCOVER.pagePattern
|
|
219
222
|
);
|
|
220
223
|
|
|
221
|
-
const
|
|
224
|
+
const cssModulePattern = resolveAutoDiscoverMatcher(
|
|
222
225
|
options.autoDiscover?.cssModulePattern,
|
|
223
226
|
DEFAULT_CONFIG.AUTO_DISCOVER.cssModulePattern
|
|
224
227
|
);
|
|
225
228
|
|
|
226
|
-
const
|
|
229
|
+
const vendorPattern = resolveAutoDiscoverMatcher(
|
|
227
230
|
options.autoDiscover?.vendorPattern,
|
|
228
231
|
DEFAULT_CONFIG.AUTO_DISCOVER.vendorPattern
|
|
229
232
|
);
|
|
230
233
|
|
|
231
|
-
const
|
|
234
|
+
const virtualPattern = resolveAutoDiscoverMatcher(
|
|
232
235
|
options.autoDiscover?.virtualPattern,
|
|
233
236
|
DEFAULT_CONFIG.AUTO_DISCOVER.virtualPattern
|
|
234
237
|
);
|
|
235
238
|
|
|
236
|
-
const
|
|
239
|
+
const dotFiles = resolveAutoDiscoverMatcher(
|
|
237
240
|
options.autoDiscover?.dotFiles,
|
|
238
241
|
DEFAULT_CONFIG.AUTO_DISCOVER.dotFiles
|
|
239
242
|
);
|
|
240
243
|
|
|
241
|
-
const
|
|
244
|
+
const isServerFunctionCode = resolveAutoDiscoverMatcher(
|
|
242
245
|
options.autoDiscover?.isServerFunction,
|
|
243
246
|
options.autoDiscover?.serverDirective
|
|
244
|
-
? (code: string) =>
|
|
245
|
-
code.match(options.autoDiscover?.serverDirective!)
|
|
246
|
-
|
|
247
|
+
? (code: string, moduleId?: string) =>
|
|
248
|
+
code.match(options.autoDiscover?.serverDirective!) != null ||
|
|
249
|
+
(moduleId && serverFunctions(moduleId)) ||
|
|
250
|
+
false
|
|
251
|
+
: (code: string, moduleId?: string) =>
|
|
252
|
+
code.match(DEFAULT_CONFIG.AUTO_DISCOVER.serverDirective) != null ||
|
|
253
|
+
(moduleId && serverFunctions(moduleId)) ||
|
|
254
|
+
false
|
|
247
255
|
);
|
|
248
256
|
|
|
249
|
-
const
|
|
257
|
+
const isClientComponentCode = resolveAutoDiscoverMatcher(
|
|
250
258
|
options.autoDiscover?.isClientComponent,
|
|
251
259
|
options.autoDiscover?.clientDirective
|
|
252
260
|
? (code: string) =>
|
|
253
|
-
code.match(options.autoDiscover?.clientDirective!)
|
|
261
|
+
code.match(options.autoDiscover?.clientDirective!) != null
|
|
254
262
|
: DEFAULT_CONFIG.AUTO_DISCOVER.clientDirective
|
|
255
263
|
);
|
|
256
264
|
|
|
@@ -287,67 +295,83 @@ export const resolveOptions = <
|
|
|
287
295
|
return n + hashString;
|
|
288
296
|
}
|
|
289
297
|
};
|
|
298
|
+
const jsExtension = options.autoDiscover?.jsExtension ?? ".js";
|
|
299
|
+
const cssExtension = options.autoDiscover?.cssExtension ?? ".css";
|
|
300
|
+
const htmlExtension = options.autoDiscover?.htmlExtension ?? ".html";
|
|
301
|
+
const jsonExtension = options.autoDiscover?.jsonExtension ?? ".json";
|
|
302
|
+
const rscExtension = options.autoDiscover?.rscExtension ?? ".rsc";
|
|
290
303
|
|
|
291
304
|
// Output path resolution
|
|
292
305
|
const getOutputPath = (n: string | null) => {
|
|
293
306
|
if (!n) return "";
|
|
294
307
|
let path = handleSearchQuery(n);
|
|
295
|
-
path = path.startsWith(moduleBase +
|
|
296
|
-
? path.slice(moduleBase.length +
|
|
308
|
+
path = path.startsWith(moduleBase + moduleBasePath)
|
|
309
|
+
? path.slice(moduleBase.length + moduleBasePath.length)
|
|
297
310
|
: path;
|
|
298
311
|
|
|
299
|
-
if (
|
|
300
|
-
return registerPath(
|
|
301
|
-
|
|
312
|
+
if (vendorPattern(path))
|
|
313
|
+
return registerPath(
|
|
314
|
+
path,
|
|
315
|
+
options.autoDiscover?.vendorPattern,
|
|
316
|
+
jsExtension
|
|
317
|
+
);
|
|
318
|
+
if (cssModulePattern(path))
|
|
302
319
|
return registerPath(
|
|
303
320
|
path,
|
|
304
321
|
options.autoDiscover?.cssModulePattern,
|
|
305
|
-
|
|
322
|
+
cssExtension + jsExtension
|
|
306
323
|
);
|
|
307
|
-
if (
|
|
308
|
-
return registerPath(path, options.autoDiscover?.cssPattern,
|
|
309
|
-
if (
|
|
324
|
+
if (cssPattern(path))
|
|
325
|
+
return registerPath(path, options.autoDiscover?.cssPattern, cssExtension);
|
|
326
|
+
if (clientComponents(path))
|
|
310
327
|
return registerPath(
|
|
311
328
|
path,
|
|
312
329
|
options.autoDiscover?.clientComponents,
|
|
313
|
-
|
|
330
|
+
jsExtension
|
|
314
331
|
);
|
|
315
332
|
if (testHtml(path))
|
|
316
|
-
return registerPath(path, options.autoDiscover?.htmlPattern, ".html");
|
|
317
|
-
if (testJson(path))
|
|
318
|
-
return registerPath(path, options.autoDiscover?.jsonPattern, ".json");
|
|
319
|
-
if (testPropsPattern(path))
|
|
320
333
|
return registerPath(
|
|
321
334
|
path,
|
|
322
|
-
options.autoDiscover?.
|
|
323
|
-
|
|
324
|
-
DEFAULT_CONFIG.PROPS_EXPORT_NAME.toLowerCase()
|
|
335
|
+
options.autoDiscover?.htmlPattern,
|
|
336
|
+
htmlExtension
|
|
325
337
|
);
|
|
326
|
-
if (
|
|
338
|
+
if (jsonPattern(path))
|
|
327
339
|
return registerPath(
|
|
328
340
|
path,
|
|
329
|
-
options.autoDiscover?.
|
|
330
|
-
|
|
331
|
-
DEFAULT_CONFIG.PAGE_EXPORT_NAME.toLowerCase()
|
|
341
|
+
options.autoDiscover?.jsonPattern,
|
|
342
|
+
jsonExtension
|
|
332
343
|
);
|
|
333
|
-
if (
|
|
344
|
+
if (propsPattern(path))
|
|
345
|
+
return registerPath(
|
|
346
|
+
path,
|
|
347
|
+
options.autoDiscover?.propsPattern,
|
|
348
|
+
jsExtension
|
|
349
|
+
);
|
|
350
|
+
if (pagePattern(path))
|
|
351
|
+
return registerPath(path, options.autoDiscover?.pagePattern, jsExtension);
|
|
352
|
+
if (serverFunctions(path))
|
|
334
353
|
return registerPath(
|
|
335
354
|
path,
|
|
336
355
|
options.autoDiscover?.serverFunctions,
|
|
337
|
-
|
|
356
|
+
jsExtension
|
|
357
|
+
);
|
|
358
|
+
if (modulePattern(path))
|
|
359
|
+
return registerPath(
|
|
360
|
+
path,
|
|
361
|
+
options.autoDiscover?.modulePattern,
|
|
362
|
+
jsExtension
|
|
338
363
|
);
|
|
339
|
-
if (testModulePattern(path)) return path;
|
|
340
364
|
return path;
|
|
341
365
|
};
|
|
342
366
|
|
|
343
367
|
// File naming functions
|
|
344
368
|
const entryFile = (n: PreRenderedChunk, ssr: boolean) => {
|
|
345
|
-
if (
|
|
369
|
+
if (vendorPattern(n.name)) {
|
|
346
370
|
const search = n.facadeModuleId?.split("?")[1];
|
|
347
371
|
if (search) {
|
|
348
|
-
return hash(`${n.name}.${search}
|
|
372
|
+
return hash(`${n.name}.${search}${jsExtension}`, ssr);
|
|
349
373
|
} else {
|
|
350
|
-
return hash(`${n.name}
|
|
374
|
+
return hash(`${n.name}${jsExtension}`, ssr);
|
|
351
375
|
}
|
|
352
376
|
}
|
|
353
377
|
return hash(addModuleExtension(getOutputPath(normalizer(n.name)[0])), ssr);
|
|
@@ -358,39 +382,25 @@ export const resolveOptions = <
|
|
|
358
382
|
};
|
|
359
383
|
|
|
360
384
|
const assetFile = (n: PreRenderedAsset, ssr: boolean) => {
|
|
361
|
-
|
|
385
|
+
const firstName = n.names[0];
|
|
386
|
+
const extIndex = firstName.lastIndexOf(".");
|
|
387
|
+
const nameWithoutExtension = firstName.slice(0, extIndex);
|
|
388
|
+
const extension = firstName.slice(extIndex);
|
|
389
|
+
const assetName = normalizer(nameWithoutExtension)[0] + extension;
|
|
390
|
+
return hash(getOutputPath(assetName), ssr);
|
|
362
391
|
};
|
|
363
392
|
|
|
364
393
|
const moduleID =
|
|
365
394
|
typeof options.moduleID === "function"
|
|
366
395
|
? options.moduleID
|
|
367
396
|
: (id: string) => {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (
|
|
373
|
-
moduleBasePath !== "" &&
|
|
374
|
-
!normalizedId.startsWith(moduleBasePath)
|
|
375
|
-
) {
|
|
376
|
-
normalizedId = join(moduleBasePath, normalizedId);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// Handle moduleBase in production
|
|
380
|
-
if (process.env["NODE_ENV"] === "production") {
|
|
381
|
-
if (normalizedId.startsWith(moduleBase)) {
|
|
382
|
-
normalizedId = normalizedId.slice(moduleBase.length);
|
|
383
|
-
} else if (normalizedId.startsWith("/" + moduleBase)) {
|
|
384
|
-
normalizedId = normalizedId.slice(moduleBase.length + 1);
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
// Ensure the path starts with a slash
|
|
389
|
-
if (!normalizedId.startsWith("/")) {
|
|
390
|
-
normalizedId = "/" + normalizedId;
|
|
397
|
+
|
|
398
|
+
// Ensure the path starts with moduleBasePath
|
|
399
|
+
if (!id.startsWith(moduleBasePath)) {
|
|
400
|
+
id = join(moduleBasePath, id);
|
|
391
401
|
}
|
|
392
402
|
|
|
393
|
-
return
|
|
403
|
+
return id;
|
|
394
404
|
};
|
|
395
405
|
|
|
396
406
|
const rscOutputPath =
|
|
@@ -427,6 +437,11 @@ export const resolveOptions = <
|
|
|
427
437
|
|
|
428
438
|
// Auto-discovery configuration
|
|
429
439
|
const autoDiscover = {
|
|
440
|
+
jsExtension: jsExtension,
|
|
441
|
+
cssExtension: cssExtension,
|
|
442
|
+
htmlExtension: htmlExtension,
|
|
443
|
+
jsonExtension: jsonExtension,
|
|
444
|
+
rscExtension: rscExtension,
|
|
430
445
|
moduleExtension:
|
|
431
446
|
options.autoDiscover?.moduleExtension ??
|
|
432
447
|
DEFAULT_CONFIG.AUTO_DISCOVER.moduleExtension,
|
|
@@ -436,22 +451,22 @@ export const resolveOptions = <
|
|
|
436
451
|
clientDirective:
|
|
437
452
|
options.autoDiscover?.clientDirective ??
|
|
438
453
|
DEFAULT_CONFIG.AUTO_DISCOVER.clientDirective,
|
|
439
|
-
modulePattern:
|
|
440
|
-
cssPattern:
|
|
441
|
-
jsonPattern:
|
|
442
|
-
clientComponents:
|
|
443
|
-
serverFunctions:
|
|
444
|
-
nodeOnly:
|
|
445
|
-
propsPattern:
|
|
446
|
-
pagePattern:
|
|
447
|
-
cssModulePattern:
|
|
448
|
-
vendorPattern:
|
|
449
|
-
dotFiles:
|
|
450
|
-
virtualPattern:
|
|
454
|
+
modulePattern: modulePattern,
|
|
455
|
+
cssPattern: cssPattern,
|
|
456
|
+
jsonPattern: jsonPattern,
|
|
457
|
+
clientComponents: clientComponents,
|
|
458
|
+
serverFunctions: serverFunctions,
|
|
459
|
+
nodeOnly: nodeOnly,
|
|
460
|
+
propsPattern: propsPattern,
|
|
461
|
+
pagePattern: pagePattern,
|
|
462
|
+
cssModulePattern: cssModulePattern,
|
|
463
|
+
vendorPattern: vendorPattern,
|
|
464
|
+
dotFiles: dotFiles,
|
|
465
|
+
virtualPattern: virtualPattern,
|
|
451
466
|
htmlPattern: testHtml,
|
|
452
467
|
rscPattern: testRsc,
|
|
453
|
-
|
|
454
|
-
|
|
468
|
+
isServerFunctionCode: isServerFunctionCode,
|
|
469
|
+
isClientComponentCode: isClientComponentCode,
|
|
455
470
|
};
|
|
456
471
|
const pipeableStreamOptions = options.pipeableStreamOptions
|
|
457
472
|
? options.pipeableStreamOptions
|
|
@@ -136,8 +136,20 @@ export function resolveUserConfig<
|
|
|
136
136
|
entryFileNames:
|
|
137
137
|
userDefinedEntryFileNames ??
|
|
138
138
|
((info) => {
|
|
139
|
-
const input = info.facadeModuleId;
|
|
140
|
-
|
|
139
|
+
const input = info.facadeModuleId ?? (info.name + userOptions.autoDiscover.moduleExtension);
|
|
140
|
+
if (!stashedReturns[input]) {
|
|
141
|
+
const r = handleSsrName(
|
|
142
|
+
info,
|
|
143
|
+
input,
|
|
144
|
+
userOptions.build.entryFile,
|
|
145
|
+
ssr
|
|
146
|
+
);
|
|
147
|
+
if (userOptions.verbose) {
|
|
148
|
+
console.log("entryFileNames", input, r);
|
|
149
|
+
}
|
|
150
|
+
stashedReturns[input] = r;
|
|
151
|
+
}
|
|
152
|
+
return stashedReturns[input];
|
|
141
153
|
}),
|
|
142
154
|
assetFileNames: process.env["VITEST"]
|
|
143
155
|
? undefined
|
|
@@ -146,15 +158,27 @@ export function resolveUserConfig<
|
|
|
146
158
|
const input = i.originalFileNames[0];
|
|
147
159
|
if (!stashedReturns[input]) {
|
|
148
160
|
const r = handleSsrName(i, input, userOptions.build.assetFile, ssr);
|
|
161
|
+
|
|
162
|
+
if (userOptions.verbose) {
|
|
163
|
+
console.log("assetFileNames", input, stashedReturns[input]);
|
|
164
|
+
}
|
|
149
165
|
stashedReturns[input] = r;
|
|
150
166
|
}
|
|
151
167
|
return stashedReturns[input];
|
|
152
168
|
}),
|
|
153
169
|
chunkFileNames:
|
|
154
170
|
userDefinedChunkFileNames ??
|
|
155
|
-
((
|
|
156
|
-
const input =
|
|
157
|
-
|
|
171
|
+
((info) => {
|
|
172
|
+
const input = info.facadeModuleId ?? (info.name + userOptions.autoDiscover.moduleExtension);
|
|
173
|
+
if (!stashedReturns[input]) {
|
|
174
|
+
const r = handleSsrName(info, input, userOptions.build.chunkFile, ssr);
|
|
175
|
+
|
|
176
|
+
if (userOptions.verbose) {
|
|
177
|
+
console.log("chunkFileNames", input, stashedReturns[input]);
|
|
178
|
+
}
|
|
179
|
+
stashedReturns[input] = r;
|
|
180
|
+
}
|
|
181
|
+
return stashedReturns[input];
|
|
158
182
|
}),
|
|
159
183
|
format: "esm",
|
|
160
184
|
exports: "named",
|
package/plugin/error/toError.ts
CHANGED
|
@@ -34,8 +34,6 @@ export function toError(error: unknown): {
|
|
|
34
34
|
export function logError(error: unknown, logger: Logger | Console = console) {
|
|
35
35
|
const err = toError(error);
|
|
36
36
|
if (process.env["NODE_ENV"] !== "production") {
|
|
37
|
-
console.trace(err)
|
|
38
|
-
|
|
39
37
|
if (err.stack && err.stack.includes(err.message)) {
|
|
40
38
|
logger.error(err.stack);
|
|
41
39
|
} else if (err.stack) {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Manifest } from "vite";
|
|
2
|
-
import type { ResolvedUserOptions } from "../types.js";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Collects CSS file paths from a manifest by walking through imports starting from a given file
|
|
@@ -7,7 +6,6 @@ import type { ResolvedUserOptions } from "../types.js";
|
|
|
7
6
|
export function collectManifestCss(
|
|
8
7
|
manifest: Manifest,
|
|
9
8
|
startFile: string | string[],
|
|
10
|
-
userOptions: Pick<ResolvedUserOptions, "normalizer">
|
|
11
9
|
): Record<string, string> {
|
|
12
10
|
const cssInputs: Record<string, string> = {};
|
|
13
11
|
const visited = new Set<string>();
|
|
@@ -29,8 +27,7 @@ export function collectManifestCss(
|
|
|
29
27
|
// Add CSS files from the css property
|
|
30
28
|
if (fileInfo.css) {
|
|
31
29
|
for (const cssFile of fileInfo.css) {
|
|
32
|
-
|
|
33
|
-
cssInputs[keyNormalized] = valueNormalized;
|
|
30
|
+
cssInputs[cssFile] = cssFile + '.css';
|
|
34
31
|
}
|
|
35
32
|
}
|
|
36
33
|
|
|
@@ -49,8 +46,7 @@ export function collectManifestCss(
|
|
|
49
46
|
const importedFile = manifest[importPath];
|
|
50
47
|
if (importedFile?.css) {
|
|
51
48
|
for (const cssFile of importedFile.css) {
|
|
52
|
-
|
|
53
|
-
cssInputs[keyNormalized] = valueNormalized;
|
|
49
|
+
cssInputs[cssFile] = cssFile + '.css';
|
|
54
50
|
}
|
|
55
51
|
}
|
|
56
52
|
}
|
|
@@ -49,6 +49,8 @@ export async function collectViteModuleGraphCss<
|
|
|
49
49
|
| "projectRoot"
|
|
50
50
|
| "css"
|
|
51
51
|
| "loader"
|
|
52
|
+
| "normalizer"
|
|
53
|
+
| "moduleID"
|
|
52
54
|
>;
|
|
53
55
|
}): Promise<CollectViteModuleGraphCssResult> {
|
|
54
56
|
const {
|
|
@@ -59,6 +61,8 @@ export async function collectViteModuleGraphCss<
|
|
|
59
61
|
projectRoot,
|
|
60
62
|
css,
|
|
61
63
|
loader,
|
|
64
|
+
normalizer,
|
|
65
|
+
moduleID,
|
|
62
66
|
} = handlerOptions;
|
|
63
67
|
if (!pagePath) return { type: "skip" };
|
|
64
68
|
|
|
@@ -107,6 +111,8 @@ export async function collectViteModuleGraphCss<
|
|
|
107
111
|
moduleRootPath: moduleRootPath,
|
|
108
112
|
projectRoot: projectRoot,
|
|
109
113
|
css: css,
|
|
114
|
+
normalizer: normalizer,
|
|
115
|
+
moduleID: moduleID,
|
|
110
116
|
},
|
|
111
117
|
});
|
|
112
118
|
cssFiles.set(mod?.url, cssContent);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResolvedUserOptions, CssContent } from "../types.js";
|
|
2
2
|
import type { InlineCssOpt, PagePropOpt } from "../../server.js";
|
|
3
|
-
import { join
|
|
3
|
+
import { join } from "node:path";
|
|
4
4
|
import { deserializeRegExp } from "./serializeUserOptions.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -39,23 +39,20 @@ export const createCssProps = <
|
|
|
39
39
|
| "moduleBasePath"
|
|
40
40
|
| "moduleRootPath"
|
|
41
41
|
| "projectRoot"
|
|
42
|
+
| "normalizer"
|
|
43
|
+
| "moduleID"
|
|
42
44
|
>;
|
|
43
45
|
}): CssContent<InlineCSS> => {
|
|
44
|
-
const { css,
|
|
45
|
-
userOptions;
|
|
46
|
+
const { css, moduleRootPath } = userOptions;
|
|
46
47
|
// If we don't have a bundle entry, create a linked CSS file
|
|
47
48
|
let inline = typeof code === "string" && code.length > css.inlineThreshold;
|
|
48
49
|
// Normalize the ID to be relative to src/
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
: id;
|
|
52
|
-
|
|
50
|
+
const [, value] = userOptions.normalizer(id);
|
|
51
|
+
const moduleID = userOptions.moduleID(value);
|
|
53
52
|
if (css.inlinePatterns?.length) {
|
|
54
53
|
// Deserialize RegExp patterns if they exist
|
|
55
|
-
const inlinePatterns = css.inlinePatterns
|
|
56
|
-
|
|
57
|
-
);
|
|
58
|
-
if (inlinePatterns.some((pattern) => pattern.test?.(normalizedId))) {
|
|
54
|
+
const inlinePatterns = css.inlinePatterns;
|
|
55
|
+
if (inlinePatterns.some((pattern) => pattern.test?.(id))) {
|
|
59
56
|
inline = true;
|
|
60
57
|
}
|
|
61
58
|
}
|
|
@@ -63,59 +60,33 @@ export const createCssProps = <
|
|
|
63
60
|
const linkPatterns = css.linkPatterns?.map((pattern) =>
|
|
64
61
|
typeof pattern === "string" ? deserializeRegExp(pattern) : pattern
|
|
65
62
|
);
|
|
66
|
-
if (linkPatterns.some((pattern) => pattern.test?.(
|
|
63
|
+
if (linkPatterns.some((pattern) => pattern.test?.(id))) {
|
|
67
64
|
inline = false;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
70
67
|
if (inline) {
|
|
71
68
|
return {
|
|
72
69
|
type: "text/css",
|
|
73
|
-
id:
|
|
70
|
+
id: moduleID,
|
|
74
71
|
as: "style",
|
|
75
72
|
children: code.trim(),
|
|
76
73
|
...(process.env["NODE_ENV"] !== "production"
|
|
77
74
|
? {
|
|
78
|
-
"data-vite-dev-id": join(
|
|
75
|
+
"data-vite-dev-id": join(moduleRootPath, moduleID),
|
|
79
76
|
}
|
|
80
77
|
: {}),
|
|
81
78
|
} as CssContent<InlineCSS>;
|
|
82
79
|
}
|
|
83
|
-
const joined = normalizedId.startsWith(moduleBasePath)
|
|
84
|
-
? normalizedId
|
|
85
|
-
: join(moduleBasePath, normalizedId);
|
|
86
|
-
const moduleBaseHasTrailingSlash = moduleBaseURL.endsWith("/");
|
|
87
|
-
const joinedHasLeadingSlash = joined.startsWith("/");
|
|
88
|
-
const safeParseURL = (() => {
|
|
89
|
-
if (
|
|
90
|
-
joined.startsWith(
|
|
91
|
-
moduleBaseHasTrailingSlash ? moduleBaseURL.slice(0, -1) : moduleBaseURL
|
|
92
|
-
)
|
|
93
|
-
) {
|
|
94
|
-
return joined;
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
if (moduleBaseURL.includes("//")) {
|
|
98
|
-
// relative to moduleBaseURL
|
|
99
|
-
return new URL(
|
|
100
|
-
joinedHasLeadingSlash ? joined.slice(1) : joined,
|
|
101
|
-
moduleBaseURL
|
|
102
|
-
).href;
|
|
103
|
-
}
|
|
104
|
-
} catch (error) {}
|
|
105
|
-
// if the url is not valid, we return the moduleBaseURL + the normalizedId
|
|
106
|
-
// dont make it a argument of join or it will mangle something like http:// into http:/
|
|
107
|
-
return (
|
|
108
|
-
moduleBaseURL +
|
|
109
|
-
(!moduleBaseHasTrailingSlash && !joinedHasLeadingSlash ? "/" : "") +
|
|
110
|
-
(moduleBaseHasTrailingSlash ? joined.slice(1) : joined)
|
|
111
|
-
);
|
|
112
|
-
})();
|
|
113
80
|
// Default case
|
|
114
81
|
return {
|
|
115
|
-
id:
|
|
82
|
+
id: moduleID,
|
|
116
83
|
as: "link",
|
|
117
84
|
rel: "stylesheet",
|
|
118
|
-
href:
|
|
85
|
+
href:
|
|
86
|
+
typeof process.env.VITE_PUBLIC_ORIGIN === "string" &&
|
|
87
|
+
process.env.VITE_PUBLIC_ORIGIN !== ""
|
|
88
|
+
? new URL(moduleID, process.env.VITE_PUBLIC_ORIGIN).href
|
|
89
|
+
: moduleID,
|
|
119
90
|
precedence: "high",
|
|
120
91
|
} as CssContent<InlineCSS>;
|
|
121
92
|
};
|
|
@@ -97,6 +97,7 @@ export function createRscStream<T extends PagePropOpt = PagePropOpt>({
|
|
|
97
97
|
moduleBasePath,
|
|
98
98
|
{
|
|
99
99
|
...pipeableStreamOptions,
|
|
100
|
+
moduleBaseURL: moduleBaseURL,
|
|
100
101
|
onError(error: Error, errorInfo: any) {
|
|
101
102
|
const err = error instanceof Error ? error : new Error(String(error));
|
|
102
103
|
streamError = err;
|
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { normalizePath } from "vite";
|
|
2
|
-
import type { InputNormalizer, NormalizerInput } from "../types.js";
|
|
2
|
+
import type { CreateInputNormalizerProps, InputNormalizer, NormalizerInput } from "../types.js";
|
|
3
3
|
import path, { join, sep } from "path";
|
|
4
4
|
import { DEFAULT_CONFIG } from "../config/defaults.js";
|
|
5
5
|
|
|
6
6
|
let stashedNormalizer: InputNormalizer | null = null;
|
|
7
7
|
|
|
8
|
-
type CreateInputNormalizerProps = {
|
|
9
|
-
root: string;
|
|
10
|
-
preserveModulesRoot?: string | undefined;
|
|
11
|
-
removeExtension?: boolean | RegExp | string | ((path: string) => boolean);
|
|
12
|
-
moduleBasePath?: string | undefined;
|
|
13
|
-
};
|
|
14
8
|
|
|
15
9
|
const resolveExtensionOptions = (
|
|
16
10
|
removeExtension: CreateInputNormalizerProps["removeExtension"]
|
|
@@ -64,6 +58,7 @@ const resolveRootOption = (
|
|
|
64
58
|
}
|
|
65
59
|
return "";
|
|
66
60
|
};
|
|
61
|
+
|
|
67
62
|
const createKeyNormalizer =
|
|
68
63
|
({
|
|
69
64
|
root: normalizedRoot,
|
|
@@ -178,7 +173,7 @@ const createPathNormalizer =
|
|
|
178
173
|
*/
|
|
179
174
|
export function createInputNormalizer({
|
|
180
175
|
root,
|
|
181
|
-
moduleBasePath,
|
|
176
|
+
moduleBasePath = DEFAULT_CONFIG.MODULE_BASE_PATH,
|
|
182
177
|
preserveModulesRoot = undefined,
|
|
183
178
|
removeExtension = DEFAULT_CONFIG.AUTO_DISCOVER.moduleExtension,
|
|
184
179
|
}: CreateInputNormalizerProps): InputNormalizer {
|
|
@@ -235,8 +230,7 @@ export function createInputNormalizer({
|
|
|
235
230
|
|
|
236
231
|
stashedNormalizer = (input: NormalizerInput): [string, string] => {
|
|
237
232
|
const [key, path] = normalizeInput(input);
|
|
238
|
-
|
|
239
|
-
const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
|
|
233
|
+
const normalizedPath = path.startsWith(moduleBasePath) ? path.slice(moduleBasePath.length) : path;
|
|
240
234
|
const virtualPrefix = key.match(/^\0+/) ?? "";
|
|
241
235
|
// If key has virtual prefix, ensure path has it too
|
|
242
236
|
const finalPath = virtualPrefix
|
|
@@ -246,9 +240,6 @@ export function createInputNormalizer({
|
|
|
246
240
|
? virtualPrefix[0] + normalizedPath
|
|
247
241
|
: normalizedPath
|
|
248
242
|
: normalizedPath;
|
|
249
|
-
if(virtualPrefix){
|
|
250
|
-
return ['', ''];
|
|
251
|
-
}
|
|
252
243
|
return [key, finalPath];
|
|
253
244
|
};
|
|
254
245
|
return stashedNormalizer;
|