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.
Files changed (171) hide show
  1. package/dist/package.json +3 -1
  2. package/dist/plugin/config/defaults.d.ts +2 -2
  3. package/dist/plugin/config/defaults.d.ts.map +1 -1
  4. package/dist/plugin/config/defaults.js +2 -2
  5. package/dist/plugin/config/defaults.js.map +1 -1
  6. package/dist/plugin/config/resolveOptions.d.ts.map +1 -1
  7. package/dist/plugin/config/resolveOptions.js +101 -75
  8. package/dist/plugin/config/resolveOptions.js.map +1 -1
  9. package/dist/plugin/config/resolveUserConfig.d.ts.map +1 -1
  10. package/dist/plugin/config/resolveUserConfig.js +27 -5
  11. package/dist/plugin/config/resolveUserConfig.js.map +1 -1
  12. package/dist/plugin/error/toError.d.ts.map +1 -1
  13. package/dist/plugin/error/toError.js +0 -1
  14. package/dist/plugin/error/toError.js.map +1 -1
  15. package/dist/plugin/helpers/collectManifestCss.d.ts +1 -2
  16. package/dist/plugin/helpers/collectManifestCss.d.ts.map +1 -1
  17. package/dist/plugin/helpers/collectManifestCss.js +3 -5
  18. package/dist/plugin/helpers/collectManifestCss.js.map +1 -1
  19. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts +1 -1
  20. package/dist/plugin/helpers/collectViteModuleGraphCss.d.ts.map +1 -1
  21. package/dist/plugin/helpers/collectViteModuleGraphCss.js +6 -2
  22. package/dist/plugin/helpers/collectViteModuleGraphCss.js.map +1 -1
  23. package/dist/plugin/helpers/createCssProps.d.ts +1 -1
  24. package/dist/plugin/helpers/createCssProps.d.ts.map +1 -1
  25. package/dist/plugin/helpers/createCssProps.js +11 -32
  26. package/dist/plugin/helpers/createCssProps.js.map +1 -1
  27. package/dist/plugin/helpers/createRscStream.d.ts.map +1 -1
  28. package/dist/plugin/helpers/createRscStream.js +1 -0
  29. package/dist/plugin/helpers/createRscStream.js.map +1 -1
  30. package/dist/plugin/helpers/inputNormalizer.d.ts +1 -8
  31. package/dist/plugin/helpers/inputNormalizer.d.ts.map +1 -1
  32. package/dist/plugin/helpers/inputNormalizer.js +2 -5
  33. package/dist/plugin/helpers/inputNormalizer.js.map +1 -1
  34. package/dist/plugin/loader/createDefaultLoader.d.ts.map +1 -1
  35. package/dist/plugin/loader/createDefaultLoader.js +68 -4
  36. package/dist/plugin/loader/css-loader.development.d.ts +2 -15
  37. package/dist/plugin/loader/css-loader.development.d.ts.map +1 -1
  38. package/dist/plugin/loader/css-loader.development.js +16 -15
  39. package/dist/plugin/loader/css-loader.development.js.map +1 -1
  40. package/dist/plugin/loader/css-loader.production.d.ts +1 -1
  41. package/dist/plugin/loader/css-loader.production.d.ts.map +1 -1
  42. package/dist/plugin/loader/css-loader.production.js +1 -1
  43. package/dist/plugin/loader/css-loader.production.js.map +1 -1
  44. package/dist/plugin/loader/env-loader.development.d.ts +1 -0
  45. package/dist/plugin/loader/env-loader.development.d.ts.map +1 -1
  46. package/dist/plugin/loader/env-loader.development.js +17 -9
  47. package/dist/plugin/loader/handleExports.d.ts +1 -0
  48. package/dist/plugin/loader/handleExports.d.ts.map +1 -1
  49. package/dist/plugin/loader/handleExports.js +27 -8
  50. package/dist/plugin/loader/handleExports.js.map +1 -1
  51. package/dist/plugin/loader/react-loader.server.d.ts +2 -2
  52. package/dist/plugin/loader/react-loader.server.d.ts.map +1 -1
  53. package/dist/plugin/loader/react-loader.server.js +88 -26
  54. package/dist/plugin/loader/sourceMap.d.ts.map +1 -1
  55. package/dist/plugin/loader/sourceMap.js +1 -1
  56. package/dist/plugin/loader/transformModuleIfNeeded.d.ts.map +1 -1
  57. package/dist/plugin/loader/transformModuleIfNeeded.js +1 -1
  58. package/dist/plugin/loader/transformModuleIfNeeded.js.map +1 -1
  59. package/dist/plugin/loader/transformModuleWithPreservedFunctions.d.ts.map +1 -1
  60. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js +86 -13
  61. package/dist/plugin/loader/transformModuleWithPreservedFunctions.js.map +1 -1
  62. package/dist/plugin/plugin.client.d.ts.map +1 -1
  63. package/dist/plugin/plugin.client.js +0 -1
  64. package/dist/plugin/plugin.client.js.map +1 -1
  65. package/dist/plugin/react-client/configureWorkerRequestHandler.d.ts.map +1 -1
  66. package/dist/plugin/react-client/configureWorkerRequestHandler.js +81 -5
  67. package/dist/plugin/react-client/configureWorkerRequestHandler.js.map +1 -1
  68. package/dist/plugin/react-client/createMessageHandlers.d.ts.map +1 -1
  69. package/dist/plugin/react-client/createMessageHandlers.js +3 -0
  70. package/dist/plugin/react-client/createMessageHandlers.js.map +1 -1
  71. package/dist/plugin/react-client/createWorkerStream.d.ts +2 -2
  72. package/dist/plugin/react-client/createWorkerStream.d.ts.map +1 -1
  73. package/dist/plugin/react-client/createWorkerStream.js +13 -2
  74. package/dist/plugin/react-client/createWorkerStream.js.map +1 -1
  75. package/dist/plugin/react-client/handleWorkerRscStream.d.ts.map +1 -1
  76. package/dist/plugin/react-client/handleWorkerRscStream.js +10 -3
  77. package/dist/plugin/react-client/handleWorkerRscStream.js.map +1 -1
  78. package/dist/plugin/react-client/restartWorker.d.ts.map +1 -1
  79. package/dist/plugin/react-client/restartWorker.js +2 -1
  80. package/dist/plugin/react-client/restartWorker.js.map +1 -1
  81. package/dist/plugin/react-server/configureReactServer.d.ts.map +1 -1
  82. package/dist/plugin/react-server/configureReactServer.js +1 -2
  83. package/dist/plugin/react-server/configureReactServer.js.map +1 -1
  84. package/dist/plugin/react-server/handleServerAction.d.ts.map +1 -1
  85. package/dist/plugin/react-server/handleServerAction.js +0 -16
  86. package/dist/plugin/react-server/handleServerAction.js.map +1 -1
  87. package/dist/plugin/react-static/createBuildLoader.d.ts.map +1 -0
  88. package/dist/plugin/react-static/createBuildLoader.js.map +1 -0
  89. package/dist/plugin/react-static/plugin.d.ts.map +1 -1
  90. package/dist/plugin/react-static/plugin.js +9 -12
  91. package/dist/plugin/react-static/plugin.js.map +1 -1
  92. package/dist/plugin/react-static/temporaryReferences.d.ts.map +1 -0
  93. package/dist/plugin/react-static/temporaryReferences.js.map +1 -0
  94. package/dist/plugin/transformer/plugin.server.js +2 -2
  95. package/dist/plugin/transformer/plugin.server.js.map +1 -1
  96. package/dist/plugin/types.d.ts +20 -3
  97. package/dist/plugin/types.d.ts.map +1 -1
  98. package/dist/plugin/worker/rsc/handleRender.d.ts.map +1 -1
  99. package/dist/plugin/worker/rsc/handleRender.js +1 -0
  100. package/dist/plugin/worker/rsc/handleRender.js.map +1 -1
  101. package/dist/plugin/worker/rsc/handlers.d.ts +3 -0
  102. package/dist/plugin/worker/rsc/handlers.d.ts.map +1 -0
  103. package/dist/plugin/worker/rsc/handlers.js +225 -0
  104. package/dist/plugin/worker/rsc/handlers.js.map +1 -0
  105. package/dist/plugin/worker/rsc/messageHandler.d.ts.map +1 -1
  106. package/dist/plugin/worker/rsc/messageHandler.js +4 -110
  107. package/dist/plugin/worker/rsc/messageHandler.js.map +1 -1
  108. package/dist/plugin/worker/rsc/rsc-worker.development.js +14 -16
  109. package/dist/plugin/worker/rsc/rsc-worker.development.js.map +1 -1
  110. package/dist/plugin/worker/rsc/state.d.ts +1 -2
  111. package/dist/plugin/worker/rsc/state.d.ts.map +1 -1
  112. package/dist/plugin/worker/rsc/state.js +1 -2
  113. package/dist/plugin/worker/rsc/state.js.map +1 -1
  114. package/dist/plugin/worker/rsc/userOptions.d.ts +2 -0
  115. package/dist/plugin/worker/rsc/userOptions.d.ts.map +1 -0
  116. package/dist/plugin/worker/rsc/userOptions.js +17 -0
  117. package/dist/plugin/worker/rsc/userOptions.js.map +1 -0
  118. package/dist/plugin/worker/types.d.ts +2 -1
  119. package/dist/plugin/worker/types.d.ts.map +1 -1
  120. package/dist/tsconfig.tsbuildinfo +1 -1
  121. package/package.json +5 -1
  122. package/plugin/config/defaults.tsx +5 -2
  123. package/plugin/config/resolveOptions.ts +106 -91
  124. package/plugin/config/resolveUserConfig.ts +29 -5
  125. package/plugin/error/toError.ts +0 -2
  126. package/plugin/helpers/collectManifestCss.ts +2 -6
  127. package/plugin/helpers/collectViteModuleGraphCss.ts +6 -0
  128. package/plugin/helpers/createCssProps.tsx +17 -46
  129. package/plugin/helpers/createRscStream.tsx +1 -0
  130. package/plugin/helpers/inputNormalizer.ts +4 -13
  131. package/plugin/loader/createDefaultLoader.ts +80 -4
  132. package/plugin/loader/css-loader.development.ts +17 -34
  133. package/plugin/loader/css-loader.production.ts +2 -4
  134. package/plugin/loader/env-loader.development.ts +38 -15
  135. package/plugin/loader/handleExports.ts +36 -13
  136. package/plugin/loader/react-loader.server.ts +110 -32
  137. package/plugin/loader/sourceMap.ts +1 -1
  138. package/plugin/loader/transformModuleIfNeeded.ts +2 -2
  139. package/plugin/loader/transformModuleWithPreservedFunctions.ts +128 -21
  140. package/plugin/plugin.client.ts +0 -2
  141. package/plugin/react-client/configureWorkerRequestHandler.ts +104 -4
  142. package/plugin/react-client/createMessageHandlers.ts +3 -0
  143. package/plugin/react-client/createWorkerStream.ts +15 -1
  144. package/plugin/react-client/handleWorkerRscStream.ts +12 -3
  145. package/plugin/react-client/restartWorker.ts +1 -0
  146. package/plugin/react-server/configureReactServer.ts +1 -2
  147. package/plugin/react-server/handleServerAction.ts +1 -19
  148. package/plugin/react-static/plugin.ts +9 -12
  149. package/plugin/transformer/plugin.server.ts +2 -2
  150. package/plugin/types.ts +31 -2
  151. package/plugin/worker/rsc/handleRender.ts +1 -0
  152. package/plugin/worker/rsc/handlers.ts +246 -0
  153. package/plugin/worker/rsc/messageHandler.tsx +3 -118
  154. package/plugin/worker/rsc/rsc-worker.development.ts +18 -20
  155. package/plugin/worker/rsc/state.ts +2 -6
  156. package/plugin/worker/rsc/userOptions.ts +8 -0
  157. package/plugin/worker/types.ts +2 -0
  158. package/dist/plugin/loader/createBuildLoader.d.ts.map +0 -1
  159. package/dist/plugin/loader/createBuildLoader.js.map +0 -1
  160. package/dist/plugin/loader/plugin.d.ts +0 -22
  161. package/dist/plugin/loader/plugin.d.ts.map +0 -1
  162. package/dist/plugin/loader/plugin.js +0 -27
  163. package/dist/plugin/loader/temporaryReferences.d.ts.map +0 -1
  164. package/dist/plugin/loader/temporaryReferences.js.map +0 -1
  165. package/plugin/loader/plugin.ts +0 -33
  166. /package/dist/plugin/{loader → react-static}/createBuildLoader.d.ts +0 -0
  167. /package/dist/plugin/{loader → react-static}/createBuildLoader.js +0 -0
  168. /package/dist/plugin/{loader → react-static}/temporaryReferences.d.ts +0 -0
  169. /package/dist/plugin/{loader → react-static}/temporaryReferences.js +0 -0
  170. /package/plugin/{loader → react-static}/createBuildLoader.ts +0 -0
  171. /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
- _fallback?: string | undefined
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 testModuleExtension = resolveAutoDiscoverMatcher(
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 testModulePattern = resolveAutoDiscoverMatcher(
156
+ const modulePattern = resolveAutoDiscoverMatcher(
154
157
  options.autoDiscover?.modulePattern,
155
158
  options.autoDiscover?.moduleExtension
156
- ? (id: string) => testModuleExtension(id.toLowerCase())
159
+ ? (id: string) => moduleExtension(id.toLowerCase())
157
160
  : DEFAULT_CONFIG.AUTO_DISCOVER.modulePattern
158
161
  );
159
162
 
160
- const testJson = resolveAutoDiscoverMatcher(
163
+ const jsonPattern = resolveAutoDiscoverMatcher(
161
164
  options.autoDiscover?.jsonPattern,
162
165
  DEFAULT_CONFIG.AUTO_DISCOVER.jsonPattern
163
166
  );
164
167
 
165
- const testCss = resolveAutoDiscoverMatcher(
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 testClientComponents = resolveAutoDiscoverMatcher(
183
+ const clientComponents = resolveAutoDiscoverMatcher(
181
184
  options.autoDiscover?.clientComponents,
182
185
  options.autoDiscover?.moduleExtension
183
186
  ? (id: string) =>
184
- testModuleExtension(id.toLowerCase()) &&
187
+ moduleExtension(id.toLowerCase()) &&
185
188
  /(\.|\/)?client(\.|\/)/.test(id.toLowerCase())
186
189
  : DEFAULT_CONFIG.AUTO_DISCOVER.clientComponents
187
190
  );
188
191
 
189
- const testServerFunctions = resolveAutoDiscoverMatcher(
192
+ const serverFunctions = resolveAutoDiscoverMatcher(
190
193
  options.autoDiscover?.serverFunctions,
191
194
  options.autoDiscover?.moduleExtension
192
195
  ? (id: string) =>
193
- testModuleExtension(id.toLowerCase()) &&
196
+ moduleExtension(id.toLowerCase()) &&
194
197
  /(\.|\/)?server(\.|\/)/.test(id.toLowerCase())
195
198
  : DEFAULT_CONFIG.AUTO_DISCOVER.serverFunctions
196
199
  );
197
200
 
198
- const testNodeOnly = resolveAutoDiscoverMatcher(
201
+ const nodeOnly = resolveAutoDiscoverMatcher(
199
202
  options.autoDiscover?.nodeOnly,
200
203
  DEFAULT_CONFIG.AUTO_DISCOVER.nodeOnly
201
204
  );
202
205
 
203
- const testPropsPattern = resolveAutoDiscoverMatcher(
206
+ const propsPattern = resolveAutoDiscoverMatcher(
204
207
  options.autoDiscover?.propsPattern,
205
208
  options.autoDiscover?.moduleExtension
206
209
  ? (id: string) =>
207
- testModuleExtension(id.toLowerCase()) &&
210
+ moduleExtension(id.toLowerCase()) &&
208
211
  /(\.|\/)?props(\.|\/)/.test(id.toLowerCase())
209
212
  : DEFAULT_CONFIG.AUTO_DISCOVER.propsPattern
210
213
  );
211
214
 
212
- const testPagePattern = resolveAutoDiscoverMatcher(
215
+ const pagePattern = resolveAutoDiscoverMatcher(
213
216
  options.autoDiscover?.pagePattern,
214
217
  options.autoDiscover?.moduleExtension
215
218
  ? (id: string) =>
216
- testModuleExtension(id.toLowerCase()) &&
219
+ moduleExtension(id.toLowerCase()) &&
217
220
  /(\.|\/)?page(\.|\/)/.test(id.toLowerCase())
218
221
  : DEFAULT_CONFIG.AUTO_DISCOVER.pagePattern
219
222
  );
220
223
 
221
- const testCssModule = resolveAutoDiscoverMatcher(
224
+ const cssModulePattern = resolveAutoDiscoverMatcher(
222
225
  options.autoDiscover?.cssModulePattern,
223
226
  DEFAULT_CONFIG.AUTO_DISCOVER.cssModulePattern
224
227
  );
225
228
 
226
- const testVendor = resolveAutoDiscoverMatcher(
229
+ const vendorPattern = resolveAutoDiscoverMatcher(
227
230
  options.autoDiscover?.vendorPattern,
228
231
  DEFAULT_CONFIG.AUTO_DISCOVER.vendorPattern
229
232
  );
230
233
 
231
- const testVirtual = resolveAutoDiscoverMatcher(
234
+ const virtualPattern = resolveAutoDiscoverMatcher(
232
235
  options.autoDiscover?.virtualPattern,
233
236
  DEFAULT_CONFIG.AUTO_DISCOVER.virtualPattern
234
237
  );
235
238
 
236
- const testDotFiles = resolveAutoDiscoverMatcher(
239
+ const dotFiles = resolveAutoDiscoverMatcher(
237
240
  options.autoDiscover?.dotFiles,
238
241
  DEFAULT_CONFIG.AUTO_DISCOVER.dotFiles
239
242
  );
240
243
 
241
- const isServerFunction = resolveAutoDiscoverMatcher(
244
+ const isServerFunctionCode = resolveAutoDiscoverMatcher(
242
245
  options.autoDiscover?.isServerFunction,
243
246
  options.autoDiscover?.serverDirective
244
- ? (code: string) =>
245
- code.match(options.autoDiscover?.serverDirective!) !== null
246
- : DEFAULT_CONFIG.AUTO_DISCOVER.serverDirective
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 isClientComponent = resolveAutoDiscoverMatcher(
257
+ const isClientComponentCode = resolveAutoDiscoverMatcher(
250
258
  options.autoDiscover?.isClientComponent,
251
259
  options.autoDiscover?.clientDirective
252
260
  ? (code: string) =>
253
- code.match(options.autoDiscover?.clientDirective!) !== null
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 + 1)
308
+ path = path.startsWith(moduleBase + moduleBasePath)
309
+ ? path.slice(moduleBase.length + moduleBasePath.length)
297
310
  : path;
298
311
 
299
- if (testVendor(path))
300
- return registerPath(path, options.autoDiscover?.vendorPattern, "vendor");
301
- if (testCssModule(path))
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
- ".css.js"
322
+ cssExtension + jsExtension
306
323
  );
307
- if (testCss(path))
308
- return registerPath(path, options.autoDiscover?.cssPattern, ".css");
309
- if (testClientComponents(path))
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
- "client"
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?.propsPattern,
323
- options.propsExportName?.toLowerCase() ??
324
- DEFAULT_CONFIG.PROPS_EXPORT_NAME.toLowerCase()
335
+ options.autoDiscover?.htmlPattern,
336
+ htmlExtension
325
337
  );
326
- if (testPagePattern(path))
338
+ if (jsonPattern(path))
327
339
  return registerPath(
328
340
  path,
329
- options.autoDiscover?.pagePattern,
330
- options.pageExportName?.toLowerCase() ??
331
- DEFAULT_CONFIG.PAGE_EXPORT_NAME.toLowerCase()
341
+ options.autoDiscover?.jsonPattern,
342
+ jsonExtension
332
343
  );
333
- if (testServerFunctions(path))
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
- "server"
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 (testVendor(n.name)) {
369
+ if (vendorPattern(n.name)) {
346
370
  const search = n.facadeModuleId?.split("?")[1];
347
371
  if (search) {
348
- return hash(`${n.name}.${search}.js`, ssr);
372
+ return hash(`${n.name}.${search}${jsExtension}`, ssr);
349
373
  } else {
350
- return hash(`${n.name}.js`, ssr);
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
- return hash(getOutputPath(normalizer(n.names[0])[0]), ssr);
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
- // First normalize the path to handle any leading/trailing slashes
369
- let normalizedId = id.replace(/^\/+|\/+$/g, "");
370
-
371
- // If moduleBasePath is set and id doesn't start with it, add it
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 normalizedId;
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: testModulePattern,
440
- cssPattern: testCss,
441
- jsonPattern: testJson,
442
- clientComponents: testClientComponents,
443
- serverFunctions: testServerFunctions,
444
- nodeOnly: testNodeOnly,
445
- propsPattern: testPropsPattern,
446
- pagePattern: testPagePattern,
447
- cssModulePattern: testCssModule,
448
- vendorPattern: testVendor,
449
- dotFiles: testDotFiles,
450
- virtualPattern: testVirtual,
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
- isServerFunction: isServerFunction,
454
- isClientComponent: isClientComponent,
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
- return handleSsrName(info, input, userOptions.build.entryFile, ssr);
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
- ((i) => {
156
- const input = i.facadeModuleId;
157
- return handleSsrName(i, input, userOptions.build.chunkFile, ssr);
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",
@@ -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
- const [keyNormalized, valueNormalized] = userOptions.normalizer(cssFile);
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
- const [keyNormalized, valueNormalized] = userOptions.normalizer(cssFile);
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, relative } from "node:path";
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, moduleBaseURL, moduleBasePath, moduleRootPath, projectRoot } =
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 normalizedId = id.startsWith(projectRoot)
50
- ? relative(projectRoot, id)
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?.map((pattern) =>
56
- typeof pattern === "string" ? deserializeRegExp(pattern) : pattern
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?.(normalizedId))) {
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: normalizedId,
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(projectRoot, moduleRootPath, normalizedId),
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: normalizedId,
82
+ id: moduleID,
116
83
  as: "link",
117
84
  rel: "stylesheet",
118
- href: safeParseURL,
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
- // Apply the same normalization to both key and path
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;