dinou 9.3.0 → 10.0.1

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 (166) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/README.md +157 -132
  3. package/dinou/adapters/bun.js +34 -5
  4. package/dinou/adapters/cloudflare.js +110 -17
  5. package/dinou/adapters/deno.js +46 -8
  6. package/dinou/adapters/netlify.js +86 -50
  7. package/dinou/adapters/node.js +8 -0
  8. package/dinou/assets.d.ts +32 -5
  9. package/dinou/bun/build.js +190 -106
  10. package/dinou/cli.js +992 -532
  11. package/dinou/cloudflare/build.js +187 -106
  12. package/dinou/compiled/autoprefixer/index.js +509 -517
  13. package/dinou/compiled/babel-core/index.js +738 -716
  14. package/dinou/compiled/babel-generator/index.js +341 -299
  15. package/dinou/compiled/babel-loader/index.js +766 -744
  16. package/dinou/compiled/babel-parser/index.js +2 -2
  17. package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
  18. package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
  19. package/dinou/compiled/babel-preset-react/index.js +752 -730
  20. package/dinou/compiled/babel-preset-typescript/index.js +738 -716
  21. package/dinou/compiled/babel-traverse/index.js +463 -433
  22. package/dinou/compiled/babel-types/index.js +176 -176
  23. package/dinou/compiled/chokidar/index.js +4 -4
  24. package/dinou/compiled/commander/index.js +15 -15
  25. package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
  26. package/dinou/compiled/css-loader/index.js +289 -289
  27. package/dinou/compiled/css-loader/runtime/api.js +85 -0
  28. package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
  29. package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
  30. package/dinou/compiled/css-loader/runtime/package.json +3 -0
  31. package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
  32. package/dinou/compiled/fast-glob/index.js +5810 -0
  33. package/dinou/compiled/generic-names/index.js +16 -16
  34. package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
  35. package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
  36. package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
  37. package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
  38. package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
  39. package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
  40. package/dinou/compiled/postcss/index.js +83 -83
  41. package/dinou/compiled/postcss-import/index.js +147 -117
  42. package/dinou/compiled/postcss-modules/index.js +216 -216
  43. package/dinou/compiled/resolve/index.js +1224 -0
  44. package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
  45. package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
  46. package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
  47. package/dinou/compiled/rollup-plugin-json/index.js +22 -18
  48. package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
  49. package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
  50. package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
  51. package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
  52. package/dinou/compiled/vendors-manifest.json +59 -83
  53. package/dinou/core/asset-extensions.js +482 -33
  54. package/dinou/core/bailout-proxy.js +21 -2
  55. package/dinou/core/build-static-pages.js +523 -371
  56. package/dinou/core/builtin-asset-extensions.js +63 -0
  57. package/dinou/core/cache-revalidate.js +449 -256
  58. package/dinou/core/cache-slot.js +289 -79
  59. package/dinou/core/client-webpack.jsx +470 -39
  60. package/dinou/core/client.jsx +402 -39
  61. package/dinou/core/config.js +3 -0
  62. package/dinou/core/copy-static-dirs.js +98 -0
  63. package/dinou/core/createScopedName.js +22 -4
  64. package/dinou/core/dinou-paths.js +1 -1
  65. package/dinou/core/discover-layouts.js +200 -0
  66. package/dinou/core/edge-ssr.js +1 -1
  67. package/dinou/core/ensure-vendor-mode.js +78 -19
  68. package/dinou/core/env.js +544 -0
  69. package/dinou/core/export-static.js +41 -9
  70. package/dinou/core/generate-route-types.js +989 -95
  71. package/dinou/core/generate-static-rsc.js +5 -6
  72. package/dinou/core/generate-static.js +45 -6
  73. package/dinou/core/get-abs-path-with-ext.js +217 -75
  74. package/dinou/core/get-asset-from-manifest.js +19 -8
  75. package/dinou/core/get-error-jsx.js +4 -5
  76. package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
  77. package/dinou/core/get-jsx.js +220 -53
  78. package/dinou/core/handler.js +1647 -466
  79. package/dinou/core/import-module.js +7 -0
  80. package/dinou/core/layout-functions.js +72 -13
  81. package/dinou/core/link.jsx +34 -6
  82. package/dinou/core/load-dinou-config.js +520 -89
  83. package/dinou/core/manifest-provider.js +4 -14
  84. package/dinou/core/navigation-utils.js +141 -3
  85. package/dinou/core/navigation.js +134 -50
  86. package/dinou/core/node-middleware-runner.js +165 -0
  87. package/dinou/core/postcss-pipeline.js +236 -0
  88. package/dinou/core/ppr-context.js +114 -22
  89. package/dinou/core/ppr-runtime.js +391 -127
  90. package/dinou/core/redirect.jsx +1 -1
  91. package/dinou/core/render-jsx-to-client-jsx.js +216 -48
  92. package/dinou/core/request-context.js +59 -3
  93. package/dinou/core/resolve-contextual-dinou.js +523 -0
  94. package/dinou/core/resolve-setup-files.js +85 -27
  95. package/dinou/core/revalidating.js +10 -2
  96. package/dinou/core/route-generator.js +6 -2
  97. package/dinou/core/rsc-renderer.js +4 -1
  98. package/dinou/core/run-ssg.js +6 -0
  99. package/dinou/core/runtime-env.js +265 -0
  100. package/dinou/core/server-css-modules-plugin.js +155 -0
  101. package/dinou/core/server-function-proxy-webpack.js +27 -2
  102. package/dinou/core/server-function-proxy.js +27 -2
  103. package/dinou/core/slot.js +47 -2
  104. package/dinou/core/static-assets.js +503 -0
  105. package/dinou/core/storage-adapter.js +452 -24
  106. package/dinou/core/transform-server-functions.js +272 -24
  107. package/dinou/core/tsconfig-aliases.js +964 -0
  108. package/dinou/core/uneject.js +640 -0
  109. package/dinou/core/url-resolver.js +1 -1
  110. package/dinou/core/vfs.js +11 -2
  111. package/dinou/css.d.ts +4 -1
  112. package/dinou/deno/build.js +205 -153
  113. package/dinou/deno/seed-kv.js +4 -0
  114. package/dinou/env.d.ts +22 -2
  115. package/dinou/esbuild/build.js +40 -50
  116. package/dinou/esbuild/dev.js +33 -7
  117. package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
  118. package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
  119. package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
  120. package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
  121. package/dinou/esbuild/helpers-esbuild/write.js +13 -3
  122. package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
  123. package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
  124. package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
  125. package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
  126. package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
  127. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
  128. package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
  129. package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
  130. package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
  131. package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
  132. package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
  133. package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
  134. package/dinou/index.d.ts +1028 -88
  135. package/dinou/node/build.js +138 -74
  136. package/dinou/node/bundle-dual-engine.js +393 -131
  137. package/dinou/node/dev.js +1005 -275
  138. package/dinou/package.json +11 -34
  139. package/dinou/rollup/postcss.config.js +3 -4
  140. package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
  141. package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
  142. package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
  143. package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
  144. package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
  145. package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
  146. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
  147. package/dinou/rollup/rollup.config.js +174 -101
  148. package/dinou/scripts/build-vendors.js +123 -33
  149. package/dinou/server.d.ts +126 -15
  150. package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
  151. package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
  152. package/dinou/webpack/loaders/server-functions-loader.js +1 -1
  153. package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
  154. package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
  155. package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
  156. package/dinou/webpack/postcss.config.js +3 -4
  157. package/dinou/webpack/webpack.config.js +408 -132
  158. package/eject.js +6 -224
  159. package/package.json +7 -9
  160. package/dinou/compiled/cross-env/index.js +0 -661
  161. package/dinou/compiled/dotenv/index.js +0 -375
  162. package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
  163. package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
  164. package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
  165. package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
  166. package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
@@ -11,25 +11,49 @@ import { fileURLToPath, pathToFileURL } from "node:url";
11
11
  import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
12
12
  import parseExports from "../core/parse-exports.js";
13
13
  import { useClientRegex, useServerRegex } from "../constants.js";
14
- import { transformServerFunctions, hasServerFunctions } from "../core/transform-server-functions.js";
15
- import createScopedName from "../core/createScopedName.js";
16
- import { regex as assetRegex } from "../core/asset-extensions.js";
14
+ import {
15
+ transformServerFunctions,
16
+ hasServerFunctions,
17
+ buildSsrServerReferenceModule,
18
+ generateSsrServerManifestStubs,
19
+ } from "../core/transform-server-functions.js";
20
+ import {
21
+ createServerAssetPlugin,
22
+ getAssetExtensionsInfo,
23
+ } from "../core/asset-extensions.js";
24
+ import { createServerCssModulesPlugin } from "../core/server-css-modules-plugin.js";
25
+ import { esbuildTsconfigAliasesPlugin } from "../core/tsconfig-aliases.js";
17
26
  import {
18
27
  isSupportedClientModule,
19
28
  scanProjectDependenciesForClientComponents,
20
29
  } from "../core/scan-dependency-components.js";
21
- import { getDinouConfig } from "../core/load-dinou-config.js";
30
+ import {
31
+ getDinouConfig,
32
+ findDinouConfigFile,
33
+ prepareDist1ServerEntries,
34
+ } from "../core/load-dinou-config.js";
22
35
  import { resolveSetupFiles } from "../core/resolve-setup-files.js";
36
+ import {
37
+ loadEnvFiles,
38
+ getEsbuildPublicEnvDefines,
39
+ } from "../core/env.js";
40
+ import {
41
+ esbuildContextualDinouPlugin,
42
+ filterEscapedClientManifest,
43
+ } from "../core/resolve-contextual-dinou.js";
44
+ import { discoverLayoutsFromFs, sortEntriesByName } from "../core/discover-layouts.js";
23
45
 
24
46
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
25
47
 
26
48
  export async function bundleDualEngine(options = {}) {
27
49
  const isDev = Boolean(options.isDev);
28
50
  const projectRoot = path.resolve(options.projectRoot || process.cwd());
51
+ loadEnvFiles(projectRoot, { mode: isDev ? "development" : "production" });
29
52
  const nodeDir = path.resolve(projectRoot, options.outDir || ".dinou/node");
30
53
  fs.mkdirSync(nodeDir, { recursive: true });
31
54
 
32
- const dinouConfig = await getDinouConfig();
55
+ const dinouConfig = await getDinouConfig(projectRoot);
56
+ const configFile = findDinouConfigFile(projectRoot);
33
57
  const setupFiles = resolveSetupFiles(projectRoot, dinouConfig);
34
58
  if (setupFiles.length > 0) {
35
59
  console.log(` 🔌 [Dinou Setup] Active setup files (${setupFiles.length}):`, setupFiles.map((f) => path.relative(projectRoot, f)).join(", "));
@@ -70,31 +94,22 @@ export async function bundleDualEngine(options = {}) {
70
94
  // 2. Discover manifests
71
95
  const isWebpackBuild = process.env.DINOU_BUILD_TOOL === "webpack";
72
96
 
73
- function findManifest(filename, fallbackFolder) {
74
- const candidates = isWebpackBuild
75
- ? [
76
- path.resolve(projectRoot, ".dinou/dist3", filename),
77
- path.resolve(projectRoot, ".dinou/public", filename),
78
- path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
79
- ]
80
- : [
81
- path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
82
- path.resolve(projectRoot, ".dinou/dist3", filename),
83
- path.resolve(projectRoot, ".dinou/public", filename),
84
- ];
85
- for (const c of candidates) {
86
- if (fs.existsSync(c)) return c;
87
- }
88
- return null;
97
+ function findManifest(filename, folder) {
98
+ const candidate = path.resolve(projectRoot, ".dinou", folder, filename);
99
+ return fs.existsSync(candidate) ? candidate : null;
89
100
  }
90
101
 
91
- const clientManifestPath = findManifest("react-client-manifest.json", "react_client_manifest");
92
- const sfManifestPath = findManifest("server-functions-manifest.json", "server_functions_manifest");
102
+ const manifestFolder = isDev ? "node-dev" : "dist1";
103
+ const clientManifestPath = findManifest("react-client-manifest.json", manifestFolder);
104
+ const sfManifestPath = findManifest("server-functions-manifest.json", manifestFolder);
93
105
 
94
106
  let parsedClientManifest = {};
95
107
  if (clientManifestPath && fs.existsSync(clientManifestPath)) {
96
108
  try {
97
- parsedClientManifest = JSON.parse(fs.readFileSync(clientManifestPath, "utf8"));
109
+ parsedClientManifest = filterEscapedClientManifest(
110
+ JSON.parse(fs.readFileSync(clientManifestPath, "utf8")),
111
+ projectRoot
112
+ );
98
113
  } catch (e) {}
99
114
  }
100
115
 
@@ -117,7 +132,7 @@ export async function bundleDualEngine(options = {}) {
117
132
  for (const entry of entries) {
118
133
  const full = path.join(dir, entry.name);
119
134
  if (entry.isDirectory()) {
120
- walk(full);
135
+ if (!entry.name.startsWith("_")) walk(full);
121
136
  } else if (/\.[jt]sx?$/.test(entry.name)) {
122
137
  try {
123
138
  const content = fs.readFileSync(full, "utf8");
@@ -323,7 +338,7 @@ export async function bundleDualEngine(options = {}) {
323
338
  manifestInlines += `\nglobalThis.__DINOU_SERVER_FUNCTIONS_MANIFEST__ = {};\n`;
324
339
  }
325
340
 
326
- const assetManifestPath = findManifest("manifest.json", "dist3");
341
+ const assetManifestPath = findManifest("manifest.json", manifestFolder);
327
342
  if (assetManifestPath && fs.existsSync(assetManifestPath)) {
328
343
  const content = fs.readFileSync(assetManifestPath, "utf8");
329
344
  manifestInlines += `\nglobalThis.__DINOU_ASSET_MANIFEST__ = ${content};\n`;
@@ -335,11 +350,21 @@ export async function bundleDualEngine(options = {}) {
335
350
  if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
336
351
  const imports = {};
337
352
  const moduleBasePath = pathToFileURL(projectRoot).href + "/";
353
+ const moduleBasePathLower = moduleBasePath.replace(
354
+ /^file:\/\/\/([a-zA-Z]):/,
355
+ (_, d) => `file:///${d.toLowerCase()}:`
356
+ );
357
+ const moduleBasePathUpper = moduleBasePath.replace(
358
+ /^file:\/\/\/([a-zA-Z]):/,
359
+ (_, d) => `file:///${d.toUpperCase()}:`
360
+ );
338
361
 
339
362
  for (const [key, val] of Object.entries(parsedClientManifest)) {
340
363
  let specifier = key;
341
- if (specifier.startsWith(moduleBasePath)) {
342
- specifier = specifier.slice(moduleBasePath.length);
364
+ if (specifier.startsWith(moduleBasePathUpper)) {
365
+ specifier = specifier.slice(moduleBasePathUpper.length);
366
+ } else if (specifier.startsWith(moduleBasePathLower)) {
367
+ specifier = specifier.slice(moduleBasePathLower.length);
343
368
  }
344
369
  const hashIdx = specifier.indexOf("#");
345
370
  if (hashIdx !== -1) {
@@ -402,31 +427,18 @@ export async function bundleDualEngine(options = {}) {
402
427
 
403
428
  manifestInlines += `\nglobalThis.__DINOU_IMPORT_MAP_HTML__ = ${JSON.stringify(importMapHtml)};\n`;
404
429
 
405
- const discoveredLayouts = [];
406
- function findLayoutRoutes(dir, rel = "") {
407
- if (!fs.existsSync(dir)) return;
408
- const entries = fs.readdirSync(dir, { withFileTypes: true });
409
- for (const entry of entries) {
410
- if (entry.isDirectory()) {
411
- findLayoutRoutes(path.join(dir, entry.name), rel ? `${rel}/${entry.name}` : entry.name);
412
- } else if (/^layout\.[jt]sx?$/.test(entry.name)) {
413
- discoveredLayouts.push(rel);
414
- } else if (entry.name === "no_layout") {
415
- discoveredLayouts.push("!" + rel);
416
- }
417
- }
418
- }
419
- findLayoutRoutes(srcDir);
430
+ const discoveredLayouts = discoverLayoutsFromFs(srcDir, fs);
420
431
  manifestInlines += `\nglobalThis.__DINOU_LAYOUTS__ = ${JSON.stringify(discoveredLayouts)};\n`;
421
432
 
422
433
  // 4. In-memory VFS snapshot for routing
423
434
  const vfsSnapshot = {};
424
435
  function walkVfs(dir) {
425
436
  if (!fs.existsSync(dir)) return;
426
- const entries = fs.readdirSync(dir, { withFileTypes: true });
437
+ const entries = sortEntriesByName(fs.readdirSync(dir, { withFileTypes: true }));
427
438
  const children = [];
428
439
  for (const entry of entries) {
429
440
  const isDir = entry.isDirectory();
441
+ if (isDir && entry.name.startsWith("_")) continue;
430
442
  children.push({ name: entry.name, isDirectory: isDir });
431
443
  const fullPath = path.join(dir, entry.name);
432
444
  const relFromSrc = path.relative(srcDir, fullPath).replace(/\\/g, "/");
@@ -484,10 +496,7 @@ globalThis.__DINOU_VFS__ = ${JSON.stringify(vfsSnapshot)};
484
496
  });
485
497
 
486
498
  const serverFunctionFiles = Object.keys(parsedServerFunctionsManifest);
487
- serverFunctionFiles.forEach((relPath, index) => {
488
- const absPath = path.resolve(projectRoot, relPath).replace(/\\/g, "/");
489
- ssrManifestCode += `import * as sf_${index} from ${JSON.stringify(absPath)};\n`;
490
- });
499
+ ssrManifestCode += generateSsrServerManifestStubs(parsedServerFunctionsManifest);
491
500
 
492
501
  ssrManifestCode += `\nexport const clientModules = {\n`;
493
502
  const emittedClientModules = new Set();
@@ -694,12 +703,30 @@ globalThis.__DINOU_VFS__ = ${JSON.stringify(vfsSnapshot)};
694
703
  fs.writeFileSync(ssrClientManifestPath, ssrManifestCode, "utf8");
695
704
 
696
705
  // 6. Entry Files Generation
706
+ const aotConfigPrelude =
707
+ !isDev && configFile
708
+ ? `import * as __dinouConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};
709
+ const __resolvedDinouCfg = (__dinouConfigMod && __dinouConfigMod.default) ? __dinouConfigMod.default : (__dinouConfigMod || { plugins: [] });
710
+ globalThis.__DINOU_AOT_CONFIG__ = __resolvedDinouCfg;
711
+ globalThis.__DINOU_CONFIG__ = __resolvedDinouCfg;
712
+ `
713
+ : "";
714
+
697
715
  const rscEntryContent = `// Auto-generated RSC Engine entry for Node.js (Dual-Bundle)
698
716
  import "./env-setup.mjs";
699
- import "./route-modules.mjs";
717
+ ${aotConfigPrelude}import "./route-modules.mjs";
700
718
  import * as edgeRenderer from "react-server-dom-webpack/server.edge";
719
+ import {
720
+ handleRequest as coreHandleRequest,
721
+ WebResponseBridge,
722
+ resolvePageFunctionsConfig,
723
+ } from "${dinouDirSlash}/core/handler.js";
701
724
  globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
702
- export { handleRequest } from "${dinouDirSlash}/core/handler.js";
725
+ export function handleRequest(request, platformContext) {
726
+ globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
727
+ return coreHandleRequest(request, platformContext);
728
+ }
729
+ export { WebResponseBridge, resolvePageFunctionsConfig };
703
730
  export { buildStaticPages, getStaticPaths, getStaticLayouts, getStaticMetadata } from "${dinouDirSlash}/core/build-static-pages.js";
704
731
  `;
705
732
  const rscEntryPath = path.join(nodeDir, "rsc-entry.mjs");
@@ -710,7 +737,7 @@ import { renderRscStreamToHtmlStream } from "${dinouDirSlash}/core/edge-ssr.js";
710
737
  import { clientModules, ssrConsumerManifest } from "./ssr-client-manifest.mjs";
711
738
 
712
739
  const lowerMap = new Map();
713
- globalThis.__webpack_require__ = (id) => {
740
+ const localWebpackRequire = (id) => {
714
741
  if (clientModules[id]) return clientModules[id];
715
742
  if (typeof id === "string") {
716
743
  if (lowerMap.size === 0) {
@@ -722,10 +749,12 @@ globalThis.__webpack_require__ = (id) => {
722
749
  console.error("[SSR Engine] Module not found in __webpack_require__:", id);
723
750
  return {};
724
751
  };
725
- globalThis.__webpack_require__.u = (chunkId) => "" + chunkId + ".js";
752
+ localWebpackRequire.u = (chunkId) => "" + chunkId + ".js";
753
+ globalThis.__webpack_require__ = localWebpackRequire;
726
754
  globalThis.__webpack_chunk_load__ = () => Promise.resolve();
727
755
 
728
756
  export async function renderHtml(rscStream, options = {}) {
757
+ globalThis.__webpack_require__ = localWebpackRequire;
729
758
  return renderRscStreamToHtmlStream(rscStream, ssrConsumerManifest, options);
730
759
  }
731
760
  `;
@@ -746,8 +775,8 @@ export async function renderHtml(rscStream, options = {}) {
746
775
  const externalList = [...nodeBuiltins, ...nodeBuiltins.map((b) => "node:" + b)];
747
776
 
748
777
  const commonAlias = {
749
- "@": path.resolve(projectRoot, "src"),
750
778
  "dinou/config": path.resolve(dinouDir, "core/config.js"),
779
+ "dinou/server": path.resolve(dinouDir, "server.js"),
751
780
  dinou: dinouDir,
752
781
  };
753
782
  const commonLoader = {
@@ -755,41 +784,17 @@ export async function renderHtml(rscStream, options = {}) {
755
784
  ".json": "json", ".css": "empty",
756
785
  };
757
786
 
758
- const serverAssetPlugin = {
759
- name: "dinou-server-asset-plugin",
760
- setup(build) {
761
- build.onResolve({ filter: assetRegex }, (args) => {
762
- let resolvedPath;
763
- if (args.path.startsWith("@/")) {
764
- resolvedPath = path.resolve(projectRoot, "src", args.path.slice(2));
765
- } else if (path.isAbsolute(args.path)) {
766
- resolvedPath = args.path;
767
- } else {
768
- resolvedPath = path.resolve(args.resolveDir, args.path);
769
- }
770
- return { path: resolvedPath, namespace: "dinou-server-asset" };
771
- });
772
-
773
- build.onLoad({ filter: /.*/, namespace: "dinou-server-asset" }, (args) => {
774
- const ext = path.extname(args.path);
775
- const base = path.basename(args.path, ext);
776
- const scoped = createScopedName(base, args.path);
777
- const assetUrl = `/assets/${scoped}${ext}`;
778
-
779
- return {
780
- contents: `export default ${JSON.stringify(assetUrl)};`,
781
- loader: "js",
782
- };
783
- });
784
- },
785
- };
787
+ const serverAssetPlugin = createServerAssetPlugin({
788
+ projectRoot,
789
+ dinouConfig,
790
+ });
786
791
 
787
792
  const banner = {
788
793
  js: `import { createRequire as ___createRequire } from 'node:module';
789
794
  import { AsyncLocalStorage as ___AsyncLocalStorage } from 'node:async_hooks';
790
- const require = ___createRequire(import.meta.url || 'file:///server.js');
791
- const __dirname = '';
792
- const __filename = '';
795
+ var require = ___createRequire(import.meta.url || 'file:///server.js');
796
+ var __dirname = '';
797
+ var __filename = '';
793
798
  globalThis.__dinou_require__ = require;
794
799
  if (typeof globalThis.AsyncLocalStorage === 'undefined' && typeof ___AsyncLocalStorage !== 'undefined') {
795
800
  globalThis.AsyncLocalStorage = ___AsyncLocalStorage;
@@ -902,8 +907,9 @@ var __webpack_chunk_load__ = function(chunkId) {
902
907
  let transformed = transformedCode + "\n\n";
903
908
  transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
904
909
  for (const name of exports) {
905
- if (name !== "default") {
906
- transformed += `registerServerReference(${name}, ${JSON.stringify(relativeFileUrl)}, ${JSON.stringify(name)});\n`;
910
+ const localIdent = name === "default" ? sfResult.defaultExportIdentifier : name;
911
+ if (localIdent) {
912
+ transformed += `registerServerReference(${localIdent}, ${JSON.stringify(relativeFileUrl)}, ${JSON.stringify(name)});\n`;
907
913
  }
908
914
  }
909
915
 
@@ -919,42 +925,19 @@ var __webpack_chunk_load__ = function(chunkId) {
919
925
  setup(build) {
920
926
  build.onLoad({ filter: /\.[jt]sx?$/ }, async (args) => {
921
927
  if (args.path.includes("node_modules")) {
922
- if (
923
- args.path.includes("react-server-dom") ||
924
- args.path.includes("@roggc/react-server-dom-esm") ||
925
- args.path.includes("node_modules/react/") ||
926
- args.path.includes("node_modules\\react\\") ||
927
- args.path.includes("node_modules/react-dom/") ||
928
- args.path.includes("node_modules\\react-dom\\")
929
- ) {
930
- return null;
931
- }
928
+ return null;
932
929
  }
933
930
  let code;
934
931
  try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
935
932
  if (!hasServerFunctions(code)) return null;
936
933
 
937
- const sfResult = transformServerFunctions(code, args.path);
938
- if (!sfResult.actions || sfResult.actions.length === 0) return null;
939
-
940
- const transformedCode = sfResult.code;
941
- const exports = sfResult.actions;
942
934
  const absPath = path.resolve(args.path);
943
935
  const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
944
936
  const relativeFileUrl = "file:///" + relPath;
937
+ const stubModule = buildSsrServerReferenceModule(code, args.path, relativeFileUrl);
938
+ if (!stubModule) return null;
945
939
 
946
- let transformed = transformedCode + "\n\n";
947
- transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
948
- for (const name of exports) {
949
- if (name !== "default") {
950
- transformed += `registerServerReference(${name}, ${JSON.stringify(relativeFileUrl + "#" + name)});\n`;
951
- transformed += `registerServerReference(${name}, ${JSON.stringify(pathToFileURL(absPath).href + "#" + name)});\n`;
952
- }
953
- }
954
-
955
- const ext = path.extname(args.path);
956
- const loader = ext === ".ts" ? "ts" : ext === ".tsx" ? "tsx" : ext === ".jsx" ? "jsx" : "js";
957
- return { contents: transformed, loader };
940
+ return { contents: stubModule, loader: "js" };
958
941
  });
959
942
  },
960
943
  };
@@ -962,9 +945,17 @@ var __webpack_chunk_load__ = function(chunkId) {
962
945
  const rscOutfile = path.join(nodeDir, "rsc-engine.mjs");
963
946
  const ssrOutfile = path.join(nodeDir, "ssr-engine.mjs");
964
947
 
948
+ const serverCssModulesPlugin = createServerCssModulesPlugin({ projectRoot });
949
+ const serverTsconfigAliasesPlugin = esbuildTsconfigAliasesPlugin({
950
+ projectRoot,
951
+ assetRegex: getAssetExtensionsInfo(dinouConfig, projectRoot).regex,
952
+ });
965
953
  const buildEnv = isDev ? "development" : "production";
954
+ const resolvedBuildTool = isWebpackBuild
955
+ ? "webpack"
956
+ : process.env.DINOU_BUILD_TOOL || "esbuild";
966
957
 
967
- // Pass A: RSC Engine
958
+ // Pass A: RSC Engine (executes setupFiles once at Line 1 before Pass B & Pass C)
968
959
  await esbuild.build({
969
960
  entryPoints: [rscEntryPath],
970
961
  outfile: rscOutfile,
@@ -973,19 +964,22 @@ var __webpack_chunk_load__ = function(chunkId) {
973
964
  target: "node20",
974
965
  platform: "node",
975
966
  mainFields: ["module", "main"],
976
- conditions: ["node", "worker", "react-server"],
967
+ conditions: ["node", "worker", "react-server", "style"],
977
968
  external: externalList,
978
969
  banner,
979
- inject: setupFiles,
980
- plugins: [clientReferencesPlugin, serverReferencesPlugin, serverAssetPlugin],
970
+ inject: !isDev && setupFiles.length > 0 ? setupFiles : undefined,
971
+ plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, clientReferencesPlugin, serverReferencesPlugin, serverCssModulesPlugin, serverAssetPlugin],
981
972
  alias: commonAlias,
982
973
  loader: commonLoader,
983
974
  jsx: "automatic",
984
- define: {
985
- "process.env.NODE_ENV": JSON.stringify(buildEnv),
986
- "process.env.DINOU_RUNTIME": '"node-bundle"',
987
- "process.env.DINOU_BUILD_TOOL": JSON.stringify(isWebpackBuild ? "webpack" : (process.env.DINOU_BUILD_TOOL || "esbuild")),
988
- },
975
+ define: getEsbuildPublicEnvDefines({
976
+ mode: buildEnv,
977
+ defineProcessEnvObject: false,
978
+ extra: {
979
+ DINOU_RUNTIME: "node-bundle",
980
+ DINOU_BUILD_TOOL: resolvedBuildTool,
981
+ },
982
+ }),
989
983
  logLevel: "warning",
990
984
  });
991
985
 
@@ -998,23 +992,29 @@ var __webpack_chunk_load__ = function(chunkId) {
998
992
  target: "node20",
999
993
  platform: "node",
1000
994
  mainFields: ["module", "main"],
1001
- conditions: ["node", "worker", "browser"],
995
+ conditions: ["node", "worker", "browser", "style"],
1002
996
  external: externalList,
1003
997
  banner,
1004
- inject: setupFiles,
1005
- plugins: [serverReferencesPluginSsr, serverAssetPlugin],
998
+ plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, serverReferencesPluginSsr, serverCssModulesPlugin, serverAssetPlugin],
1006
999
  alias: commonAlias,
1007
1000
  loader: commonLoader,
1008
1001
  jsx: "automatic",
1009
- define: {
1010
- "process.env.NODE_ENV": JSON.stringify(buildEnv),
1011
- "process.env.DINOU_RUNTIME": '"node-bundle"',
1012
- "process.env.DINOU_BUILD_TOOL": JSON.stringify(isWebpackBuild ? "webpack" : (process.env.DINOU_BUILD_TOOL || "esbuild")),
1013
- },
1002
+ define: getEsbuildPublicEnvDefines({
1003
+ mode: buildEnv,
1004
+ defineProcessEnvObject: true,
1005
+ extra: {
1006
+ DINOU_RUNTIME: "node-bundle",
1007
+ DINOU_BUILD_TOOL: resolvedBuildTool,
1008
+ ...(process.env.DINOU_DEBUG
1009
+ ? { DINOU_DEBUG: process.env.DINOU_DEBUG }
1010
+ : {}),
1011
+ },
1012
+ }),
1014
1013
  logLevel: "warning",
1015
1014
  });
1016
1015
 
1017
1016
  return {
1017
+ projectRoot,
1018
1018
  nodeDir,
1019
1019
  rscEnginePath: rscOutfile,
1020
1020
  ssrEnginePath: ssrOutfile,
@@ -1027,9 +1027,271 @@ var __webpack_chunk_load__ = function(chunkId) {
1027
1027
  banner,
1028
1028
  commonAlias,
1029
1029
  commonLoader,
1030
+ serverAssetPlugin,
1031
+ serverTsconfigAliasesPlugin,
1030
1032
  isWebpackBuild,
1031
1033
  setupFiles,
1034
+ configFile,
1035
+ };
1036
+ }
1037
+
1038
+ /**
1039
+ * Compiles self-contained AOT Dual-Bundle server artifacts from Pass A (`rsc-engine.mjs`)
1040
+ * and Pass B (`ssr-engine.mjs`) into:
1041
+ * - `.dinou/netlify/functions/ssr.mjs` (dedicated single-function Netlify Functions v2 directory)
1042
+ * - `.dinou/dist1/server/netlify.js` (backward-compatible Netlify Functions v2 bundle)
1043
+ * - `.dinou/dist1/server/handler.js` (universal Web Standards `(Request) => Promise<Response>` bundle)
1044
+ */
1045
+ export async function bundleServerAndNetlifyAdapters(engineResult) {
1046
+ const {
1047
+ projectRoot = process.cwd(),
1048
+ nodeDir,
1049
+ dinouDirSlash,
1050
+ externalList,
1051
+ commonAlias,
1052
+ commonLoader,
1053
+ serverAssetPlugin,
1054
+ serverTsconfigAliasesPlugin,
1055
+ isWebpackBuild,
1056
+ setupFiles = [],
1057
+ configFile,
1058
+ } = engineResult;
1059
+
1060
+ const resolvedBuildTool = isWebpackBuild
1061
+ ? "webpack"
1062
+ : process.env.DINOU_BUILD_TOOL || "esbuild";
1063
+
1064
+ // Emit pre-transpiled dinou-server-bootstrap.mjs for --omit=dev config fallback if needed
1065
+ if ((setupFiles && setupFiles.length > 0) || configFile) {
1066
+ try {
1067
+ await prepareDist1ServerEntries({
1068
+ projectRoot,
1069
+ setupFiles,
1070
+ handlerPath: path.resolve(dinouDirSlash, "core/handler.js"),
1071
+ netlifyPath: path.resolve(dinouDirSlash, "adapters/netlify.js"),
1072
+ });
1073
+ fs.rmSync(path.resolve(projectRoot, ".dinou/dist1/_entries"), {
1074
+ recursive: true,
1075
+ force: true,
1076
+ });
1077
+ } catch (e) {}
1078
+ }
1079
+
1080
+ const configImportLine = configFile
1081
+ ? `import * as __dinouPassCConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};\nconst __bundledPassCConfig = (__dinouPassCConfigMod && __dinouPassCConfigMod.default) ? __dinouPassCConfigMod.default : (__dinouPassCConfigMod || { plugins: [] });\nglobalThis.__DINOU_AOT_CONFIG__ = __bundledPassCConfig;\nglobalThis.__DINOU_CONFIG__ = __bundledPassCConfig;\n`
1082
+ : "";
1083
+
1084
+ const passCConfigAliasPlugin = configFile
1085
+ ? {
1086
+ name: "dinou-passc-config-alias",
1087
+ setup(build) {
1088
+ const normConfig = path.resolve(configFile).toLowerCase();
1089
+ build.onResolve({ filter: /^dinou$/ }, (args) => {
1090
+ if (
1091
+ args.importer &&
1092
+ path.resolve(args.importer).toLowerCase() === normConfig
1093
+ ) {
1094
+ return { path: path.resolve(dinouDirSlash, "core/config.js") };
1095
+ }
1096
+ return null;
1097
+ });
1098
+ },
1099
+ }
1100
+ : null;
1101
+
1102
+ const handlerEntryCode = `// Auto-generated Universal Web Standards Handler (AOT Dual-Bundle)
1103
+ import path from "node:path";
1104
+ import {
1105
+ handleRequest as rawHandleRequest,
1106
+ WebResponseBridge,
1107
+ resolvePageFunctionsConfig,
1108
+ } from "./rsc-engine.mjs";
1109
+ import { renderHtml } from "./ssr-engine.mjs";
1110
+ import {
1111
+ setStorageAdapter,
1112
+ hasExplicitStorageAdapter,
1113
+ FileSystemStorage,
1114
+ MemoryStorage,
1115
+ } from "${dinouDirSlash}/core/storage-adapter.js";
1116
+ import { loadEnvFiles } from "${dinouDirSlash}/core/env.js";
1117
+ ${configImportLine}
1118
+ const initialCwd =
1119
+ typeof process !== "undefined" && typeof process.cwd === "function"
1120
+ ? process.cwd()
1121
+ : ".";
1122
+ try {
1123
+ loadEnvFiles(initialCwd, { mode: "production" });
1124
+ } catch (e) {}
1125
+
1126
+ if (typeof globalThis !== "undefined") {
1127
+ globalThis.__DINOU_RUNTIME__ = "node-bundle";
1128
+ }
1129
+
1130
+ let storageInitialized = false;
1131
+
1132
+ function initHandlerStorage() {
1133
+ if (!storageInitialized) {
1134
+ if (!hasExplicitStorageAdapter()) {
1135
+ try {
1136
+ const cwd =
1137
+ typeof process !== "undefined" && typeof process.cwd === "function"
1138
+ ? process.cwd()
1139
+ : ".";
1140
+ setStorageAdapter(
1141
+ new FileSystemStorage(path.resolve(cwd, ".dinou/dist2"))
1142
+ );
1143
+ } catch (e) {
1144
+ setStorageAdapter(new MemoryStorage({ hydrateFromDisk: true }));
1145
+ }
1146
+ }
1147
+ storageInitialized = true;
1148
+ }
1149
+ }
1150
+
1151
+ export async function handleRequest(request, platformContext = {}) {
1152
+ initHandlerStorage();
1153
+ const runtimeEnv =
1154
+ platformContext?.env ||
1155
+ (typeof process !== "undefined" && process.env ? process.env : {});
1156
+ return rawHandleRequest(request, {
1157
+ ...platformContext,
1158
+ env: runtimeEnv,
1159
+ runtime: platformContext?.runtime || "node-bundle",
1160
+ renderHtmlStream: platformContext?.renderHtmlStream || renderHtml,
1161
+ });
1162
+ }
1163
+
1164
+ export { WebResponseBridge, resolvePageFunctionsConfig };
1165
+ export default handleRequest;
1166
+ `;
1167
+
1168
+ const netlifyEntryCode = `// Auto-generated Netlify Functions v2 Adapter (AOT Dual-Bundle)
1169
+ import { handleRequest as rawHandleRequest } from "./rsc-engine.mjs";
1170
+ import { renderHtml } from "./ssr-engine.mjs";
1171
+ import {
1172
+ setStorageAdapter,
1173
+ hasExplicitStorageAdapter,
1174
+ MemoryStorage,
1175
+ } from "${dinouDirSlash}/core/storage-adapter.js";
1176
+ import { loadEnvFiles } from "${dinouDirSlash}/core/env.js";
1177
+ ${configImportLine}
1178
+ const initialCwd =
1179
+ typeof process !== "undefined" && typeof process.cwd === "function"
1180
+ ? process.cwd()
1181
+ : ".";
1182
+ try {
1183
+ loadEnvFiles(initialCwd, { mode: "production" });
1184
+ } catch (e) {}
1185
+
1186
+ if (typeof globalThis !== "undefined") {
1187
+ globalThis.__DINOU_RUNTIME__ = "node-bundle";
1188
+ }
1189
+
1190
+ let storageInitialized = false;
1191
+
1192
+ function initNetlifyStorage() {
1193
+ if (!storageInitialized) {
1194
+ if (!hasExplicitStorageAdapter()) {
1195
+ setStorageAdapter(new MemoryStorage({ hydrateFromDisk: true }));
1196
+ }
1197
+ storageInitialized = true;
1198
+ }
1199
+ }
1200
+
1201
+ export default async function netlifyHandler(request, context) {
1202
+ initNetlifyStorage();
1203
+ const baseEnv =
1204
+ typeof process !== "undefined" && process.env ? process.env : {};
1205
+ const runtimeEnv =
1206
+ typeof globalThis !== "undefined" &&
1207
+ globalThis.Netlify &&
1208
+ globalThis.Netlify.env &&
1209
+ typeof globalThis.Netlify.env.toObject === "function"
1210
+ ? { ...baseEnv, ...globalThis.Netlify.env.toObject() }
1211
+ : baseEnv;
1212
+ return rawHandleRequest(request, {
1213
+ env: runtimeEnv,
1214
+ ctx: context || null,
1215
+ runtime: "node-bundle",
1216
+ renderHtmlStream: renderHtml,
1217
+ });
1218
+ }
1219
+
1220
+ export const config = {
1221
+ path: "/*",
1222
+ preferStatic: true,
1223
+ };
1224
+ `;
1225
+
1226
+ const handlerEntryPath = path.join(nodeDir, "dist1-handler-entry.mjs");
1227
+ const netlifyEntryPath = path.join(nodeDir, "netlify-function-entry.mjs");
1228
+ fs.writeFileSync(handlerEntryPath, handlerEntryCode, "utf8");
1229
+ fs.writeFileSync(netlifyEntryPath, netlifyEntryCode, "utf8");
1230
+
1231
+ const dist1ServerDir = path.resolve(projectRoot, ".dinou/dist1/server");
1232
+ const netlifyFunctionsDir = path.resolve(
1233
+ projectRoot,
1234
+ ".dinou/netlify/functions"
1235
+ );
1236
+ fs.rmSync(dist1ServerDir, { recursive: true, force: true });
1237
+ fs.rmSync(netlifyFunctionsDir, { recursive: true, force: true });
1238
+ fs.mkdirSync(dist1ServerDir, { recursive: true });
1239
+ fs.mkdirSync(netlifyFunctionsDir, { recursive: true });
1240
+
1241
+ const sharedPassCOptions = {
1242
+ bundle: true,
1243
+ format: "esm",
1244
+ target: "node20",
1245
+ platform: "node",
1246
+ jsx: "automatic",
1247
+ mainFields: ["module", "main"],
1248
+ conditions: ["node", "worker", "browser"],
1249
+ external: externalList,
1250
+ plugins: [
1251
+ passCConfigAliasPlugin,
1252
+ serverTsconfigAliasesPlugin,
1253
+ serverAssetPlugin,
1254
+ ].filter(Boolean),
1255
+ alias: commonAlias,
1256
+ loader: commonLoader,
1257
+ define: {
1258
+ "process.env.NODE_ENV": '"production"',
1259
+ "process.env.DINOU_RUNTIME": '"node-bundle"',
1260
+ "process.env.DINOU_BUILD_TOOL": JSON.stringify(resolvedBuildTool),
1261
+ },
1262
+ logLevel: "warning",
1263
+ };
1264
+
1265
+ const dist1HandlerOut = path.join(dist1ServerDir, "handler.js");
1266
+ const dist1NetlifyOut = path.join(dist1ServerDir, "netlify.js");
1267
+ const netlifySsrOut = path.join(netlifyFunctionsDir, "ssr.mjs");
1268
+
1269
+ await Promise.all([
1270
+ esbuild.build({
1271
+ ...sharedPassCOptions,
1272
+ entryPoints: [handlerEntryPath],
1273
+ outfile: dist1HandlerOut,
1274
+ sourcemap: true,
1275
+ }),
1276
+ esbuild.build({
1277
+ ...sharedPassCOptions,
1278
+ entryPoints: [netlifyEntryPath],
1279
+ outfile: dist1NetlifyOut,
1280
+ sourcemap: true,
1281
+ }),
1282
+ ]);
1283
+
1284
+ fs.copyFileSync(dist1NetlifyOut, netlifySsrOut);
1285
+
1286
+ const esmPkgJson = JSON.stringify({ type: "module" }, null, 2);
1287
+ fs.writeFileSync(path.join(dist1ServerDir, "package.json"), esmPkgJson);
1288
+ fs.writeFileSync(path.join(netlifyFunctionsDir, "package.json"), esmPkgJson);
1289
+
1290
+ return {
1291
+ dist1HandlerOut,
1292
+ dist1NetlifyOut,
1293
+ netlifySsrOut,
1032
1294
  };
1033
1295
  }
1034
1296
 
1035
- export default { bundleDualEngine };
1297
+ export default { bundleDualEngine, bundleServerAndNetlifyAdapters };