vite-plugin-react-server 1.1.13 → 1.1.14
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 +98 -61
- package/dist/plugin/config/resolveOptions.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/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/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 +85 -6
- 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 +14 -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 +223 -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 +5 -110
- package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
- package/dist/plugin/worker/rsc/rsc-worker.development.js +13 -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 +101 -67
- 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/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/transformModuleIfNeeded.ts +2 -2
- package/plugin/loader/transformModuleWithPreservedFunctions.ts +128 -21
- package/plugin/plugin.client.ts +0 -2
- package/plugin/react-client/configureWorkerRequestHandler.ts +107 -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 +25 -2
- package/plugin/worker/rsc/handleRender.ts +1 -0
- package/plugin/worker/rsc/handlers.ts +243 -0
- package/plugin/worker/rsc/messageHandler.tsx +4 -118
- package/plugin/worker/rsc/rsc-worker.development.ts +17 -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,7 +382,12 @@ 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 =
|
|
@@ -427,6 +456,11 @@ export const resolveOptions = <
|
|
|
427
456
|
|
|
428
457
|
// Auto-discovery configuration
|
|
429
458
|
const autoDiscover = {
|
|
459
|
+
jsExtension: jsExtension,
|
|
460
|
+
cssExtension: cssExtension,
|
|
461
|
+
htmlExtension: htmlExtension,
|
|
462
|
+
jsonExtension: jsonExtension,
|
|
463
|
+
rscExtension: rscExtension,
|
|
430
464
|
moduleExtension:
|
|
431
465
|
options.autoDiscover?.moduleExtension ??
|
|
432
466
|
DEFAULT_CONFIG.AUTO_DISCOVER.moduleExtension,
|
|
@@ -436,22 +470,22 @@ export const resolveOptions = <
|
|
|
436
470
|
clientDirective:
|
|
437
471
|
options.autoDiscover?.clientDirective ??
|
|
438
472
|
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:
|
|
473
|
+
modulePattern: modulePattern,
|
|
474
|
+
cssPattern: cssPattern,
|
|
475
|
+
jsonPattern: jsonPattern,
|
|
476
|
+
clientComponents: clientComponents,
|
|
477
|
+
serverFunctions: serverFunctions,
|
|
478
|
+
nodeOnly: nodeOnly,
|
|
479
|
+
propsPattern: propsPattern,
|
|
480
|
+
pagePattern: pagePattern,
|
|
481
|
+
cssModulePattern: cssModulePattern,
|
|
482
|
+
vendorPattern: vendorPattern,
|
|
483
|
+
dotFiles: dotFiles,
|
|
484
|
+
virtualPattern: virtualPattern,
|
|
451
485
|
htmlPattern: testHtml,
|
|
452
486
|
rscPattern: testRsc,
|
|
453
|
-
|
|
454
|
-
|
|
487
|
+
isServerFunctionCode: isServerFunctionCode,
|
|
488
|
+
isClientComponentCode: isClientComponentCode,
|
|
455
489
|
};
|
|
456
490
|
const pipeableStreamOptions = options.pipeableStreamOptions
|
|
457
491
|
? options.pipeableStreamOptions
|
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,6 +1,8 @@
|
|
|
1
1
|
import { readFileSync } from "fs";
|
|
2
2
|
import * as esbuild from "esbuild";
|
|
3
3
|
import type { LoaderContext } from "../types.js";
|
|
4
|
+
import { transformModuleIfNeeded } from "./transformModuleIfNeeded.js";
|
|
5
|
+
import { createMappingsSerializer } from "../source-map/createMappingsSerializer.js";
|
|
4
6
|
|
|
5
7
|
export interface LoaderResult {
|
|
6
8
|
source: string;
|
|
@@ -25,9 +27,46 @@ export function createDefaultLoader(source?: string): Loader {
|
|
|
25
27
|
sourcemap: true,
|
|
26
28
|
sourcefile: id,
|
|
27
29
|
});
|
|
30
|
+
|
|
31
|
+
// Transform the code for RSC boundaries
|
|
32
|
+
const transformed = transformModuleIfNeeded(
|
|
33
|
+
result.code,
|
|
34
|
+
id,
|
|
35
|
+
null, // isServerFunction
|
|
36
|
+
null, // isClientComponent
|
|
37
|
+
true // isServerEnvironment
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// Create a new source map with proper mappings
|
|
41
|
+
const map = result.map ? {
|
|
42
|
+
version: 3,
|
|
43
|
+
sources: [id],
|
|
44
|
+
sourcesContent: [transformed],
|
|
45
|
+
mappings: (() => {
|
|
46
|
+
const serializer = createMappingsSerializer();
|
|
47
|
+
let mappings = '';
|
|
48
|
+
|
|
49
|
+
// Map each line of the transformed code to its corresponding line in the original source
|
|
50
|
+
const transformedLines = transformed.split('\n');
|
|
51
|
+
for (let i = 0; i < transformedLines.length; i++) {
|
|
52
|
+
if (i > 0) mappings += ';';
|
|
53
|
+
// For the import and registration lines, map to the first line of the original source
|
|
54
|
+
if (transformedLines[i].includes('import {') || transformedLines[i].includes('registerServerReference')) {
|
|
55
|
+
mappings += serializer(i + 1, 0, 0, 1, 0, 0);
|
|
56
|
+
} else {
|
|
57
|
+
// For the actual code, map to the corresponding line in the original source
|
|
58
|
+
const originalLine = Math.max(1, i - 1); // Adjust for the import line
|
|
59
|
+
mappings += serializer(i + 1, 0, 0, originalLine, 0, 0);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return mappings;
|
|
64
|
+
})()
|
|
65
|
+
} : null;
|
|
66
|
+
|
|
28
67
|
return {
|
|
29
|
-
source:
|
|
30
|
-
map
|
|
68
|
+
source: transformed,
|
|
69
|
+
map
|
|
31
70
|
};
|
|
32
71
|
};
|
|
33
72
|
}
|
|
@@ -47,9 +86,46 @@ export function createDefaultLoader(source?: string): Loader {
|
|
|
47
86
|
sourcemap: true,
|
|
48
87
|
sourcefile: id,
|
|
49
88
|
});
|
|
89
|
+
|
|
90
|
+
// Transform the code for RSC boundaries
|
|
91
|
+
const transformed = transformModuleIfNeeded(
|
|
92
|
+
result.code,
|
|
93
|
+
id,
|
|
94
|
+
null, // isServerFunction
|
|
95
|
+
null, // isClientComponent
|
|
96
|
+
true // isServerEnvironment
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
// Create a new source map with proper mappings
|
|
100
|
+
const map = result.map ? {
|
|
101
|
+
version: 3,
|
|
102
|
+
sources: [id],
|
|
103
|
+
sourcesContent: [transformed],
|
|
104
|
+
mappings: (() => {
|
|
105
|
+
const serializer = createMappingsSerializer();
|
|
106
|
+
let mappings = '';
|
|
107
|
+
|
|
108
|
+
// Map each line of the transformed code to its corresponding line in the original source
|
|
109
|
+
const transformedLines = transformed.split('\n');
|
|
110
|
+
for (let i = 0; i < transformedLines.length; i++) {
|
|
111
|
+
if (i > 0) mappings += ';';
|
|
112
|
+
// For the import and registration lines, map to the first line of the original source
|
|
113
|
+
if (transformedLines[i].includes('import {') || transformedLines[i].includes('registerServerReference')) {
|
|
114
|
+
mappings += serializer(i + 1, 0, 0, 1, 0, 0);
|
|
115
|
+
} else {
|
|
116
|
+
// For the actual code, map to the corresponding line in the original source
|
|
117
|
+
const originalLine = Math.max(1, i - 1); // Adjust for the import line
|
|
118
|
+
mappings += serializer(i + 1, 0, 0, originalLine, 0, 0);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return mappings;
|
|
123
|
+
})()
|
|
124
|
+
} : null;
|
|
125
|
+
|
|
50
126
|
return {
|
|
51
|
-
source:
|
|
52
|
-
map
|
|
127
|
+
source: transformed,
|
|
128
|
+
map
|
|
53
129
|
};
|
|
54
130
|
};
|
|
55
131
|
}
|