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
@@ -7,8 +7,13 @@ import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import esbuild from "esbuild";
9
9
  import { fileURLToPath } from "node:url";
10
- import { bundleDualEngine } from "./bundle-dual-engine.js";
10
+ import {
11
+ bundleDualEngine,
12
+ bundleServerAndNetlifyAdapters,
13
+ } from "./bundle-dual-engine.js";
14
+ import { loadEnvFiles } from "../core/env.js";
11
15
  import ensureVendorMode from "../core/ensure-vendor-mode.js";
16
+ loadEnvFiles(process.cwd(), { mode: "production" });
12
17
  if (!ensureVendorMode()) {
13
18
  await new Promise(() => {});
14
19
  }
@@ -26,8 +31,24 @@ try {
26
31
  projectRoot,
27
32
  outDir: ".dinou/node",
28
33
  });
34
+ await bundleServerAndNetlifyAdapters(engineResult);
35
+
36
+ const {
37
+ dinouDirSlash,
38
+ externalList,
39
+ banner,
40
+ commonAlias,
41
+ commonLoader,
42
+ serverAssetPlugin,
43
+ serverTsconfigAliasesPlugin,
44
+ isWebpackBuild,
45
+ setupFiles,
46
+ configFile,
47
+ } = engineResult;
29
48
 
30
- const { dinouDirSlash, externalList, banner, commonAlias, commonLoader, isWebpackBuild, setupFiles } = engineResult;
49
+ const nodeConfigImportLine = configFile
50
+ ? `import * as __dinouNodeConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};\nconst __bundledDinouConfig = (__dinouNodeConfigMod && __dinouNodeConfigMod.default) ? __dinouNodeConfigMod.default : (__dinouNodeConfigMod || { plugins: [] });\nglobalThis.__DINOU_AOT_CONFIG__ = __bundledDinouConfig;\nglobalThis.__DINOU_CONFIG__ = __bundledDinouConfig;\n`
51
+ : `const __bundledDinouConfig = { plugins: [] };\n`;
31
52
 
32
53
  // Pass C: Node Orchestrator Entry
33
54
  const nodeEntryContent = `// Auto-generated main entry for Node.js (Dual-Bundle)
@@ -40,6 +61,7 @@ import { handleRequest } from "./rsc-engine.mjs";
40
61
  import { renderHtml } from "./ssr-engine.mjs";
41
62
  import {
42
63
  setStorageAdapter,
64
+ hasExplicitStorageAdapter,
43
65
  FileSystemStorage,
44
66
  MemoryStorage,
45
67
  } from "${dinouDirSlash}/core/storage-adapter.js";
@@ -47,6 +69,22 @@ import {
47
69
  nodeToWebRequest,
48
70
  sendWebResponseToNode,
49
71
  } from "${dinouDirSlash}/core/http-adapter.js";
72
+ import {
73
+ runNodeMiddlewares,
74
+ applyConfigureServerPlugins,
75
+ } from "${dinouDirSlash}/core/node-middleware-runner.js";
76
+ import {
77
+ getStaticContentType,
78
+ getStaticCacheControl,
79
+ normalizePublicRequestPath,
80
+ parseHttpByteRange,
81
+ resolveConfinedStaticFile,
82
+ } from "${dinouDirSlash}/core/static-assets.js";
83
+ import { loadEnvFiles } from "${dinouDirSlash}/core/env.js";
84
+ ${nodeConfigImportLine}
85
+
86
+ const initialCwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
87
+ loadEnvFiles(initialCwd, { mode: "production" });
50
88
 
51
89
  if (typeof globalThis !== "undefined") {
52
90
  globalThis.__DINOU_RUNTIME__ = "node-bundle";
@@ -56,33 +94,19 @@ let storageInitialized = false;
56
94
 
57
95
  function initStorage() {
58
96
  if (!storageInitialized) {
59
- try {
60
- const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
61
- const dist2Dir = path.resolve(cwd, ".dinou/dist2");
62
- setStorageAdapter(new FileSystemStorage(dist2Dir));
63
- } catch (e) {
64
- setStorageAdapter(new MemoryStorage());
97
+ if (!hasExplicitStorageAdapter()) {
98
+ try {
99
+ const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
100
+ const dist2Dir = path.resolve(cwd, ".dinou/dist2");
101
+ setStorageAdapter(new FileSystemStorage(dist2Dir));
102
+ } catch (e) {
103
+ setStorageAdapter(new MemoryStorage());
104
+ }
65
105
  }
66
106
  storageInitialized = true;
67
107
  }
68
108
  }
69
109
 
70
- const MIME_TYPES = {
71
- ".js": "application/javascript; charset=utf-8",
72
- ".mjs": "application/javascript; charset=utf-8",
73
- ".css": "text/css; charset=utf-8",
74
- ".json": "application/json",
75
- ".svg": "image/svg+xml",
76
- ".png": "image/png",
77
- ".jpg": "image/jpeg",
78
- ".jpeg": "image/jpeg",
79
- ".webp": "image/webp",
80
- ".ico": "image/x-icon",
81
- ".txt": "text/plain; charset=utf-8",
82
- ".woff": "font/woff",
83
- ".woff2": "font/woff2",
84
- };
85
-
86
110
  const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
87
111
  const dist3Dir = path.resolve(cwd, ".dinou/dist3");
88
112
 
@@ -93,25 +117,61 @@ export async function fetch(req) {
93
117
  const pathname = url.pathname;
94
118
 
95
119
  // Static assets delivery (Zero-copy with Node streams)
96
- if (pathname !== "/") {
97
- const filePath = path.join(dist3Dir, pathname);
98
- if (fs.existsSync(filePath)) {
99
- try {
100
- const stat = fs.statSync(filePath);
101
- if (stat.isFile()) {
102
- const nodeStream = fs.createReadStream(filePath);
103
- const webStream = Readable.toWeb(nodeStream);
104
- const ext = path.extname(filePath).toLowerCase();
105
- const contentType = MIME_TYPES[ext] || "application/octet-stream";
106
- return new Response(webStream, {
107
- headers: {
108
- "content-type": contentType,
109
- "content-length": String(stat.size),
110
- "cache-control": "public, max-age=31536000, immutable",
111
- },
112
- });
113
- }
114
- } catch (e) {}
120
+ if (req.method === "GET" || req.method === "HEAD") {
121
+ const cleanPath = normalizePublicRequestPath(pathname);
122
+ if (cleanPath) {
123
+ const filePath = resolveConfinedStaticFile(dist3Dir, cleanPath);
124
+ if (filePath && fs.existsSync(filePath)) {
125
+ try {
126
+ const stat = fs.statSync(filePath);
127
+ if (stat.isFile()) {
128
+ const contentType = getStaticContentType(cleanPath);
129
+ const cacheControl = getStaticCacheControl(cleanPath);
130
+ const rangeHeader = req.method === "GET" ? req.headers.get("range") : null;
131
+ const range = rangeHeader ? parseHttpByteRange(rangeHeader, stat.size) : null;
132
+
133
+ if (range && range.unsatisfiable) {
134
+ return new Response(null, {
135
+ status: 416,
136
+ headers: {
137
+ "content-range": range.contentRange,
138
+ "accept-ranges": "bytes",
139
+ },
140
+ });
141
+ }
142
+
143
+ if (range) {
144
+ const stream = fs.createReadStream(filePath, {
145
+ start: range.start,
146
+ end: range.end,
147
+ });
148
+ return new Response(Readable.toWeb(stream), {
149
+ status: 206,
150
+ headers: {
151
+ "content-type": contentType,
152
+ "content-length": String(range.length),
153
+ "content-range": range.contentRange,
154
+ "accept-ranges": "bytes",
155
+ "cache-control": cacheControl,
156
+ },
157
+ });
158
+ }
159
+
160
+ const body =
161
+ req.method === "HEAD"
162
+ ? null
163
+ : Readable.toWeb(fs.createReadStream(filePath));
164
+ return new Response(body, {
165
+ headers: {
166
+ "content-type": contentType,
167
+ "content-length": String(stat.size),
168
+ "accept-ranges": "bytes",
169
+ "cache-control": cacheControl,
170
+ },
171
+ });
172
+ }
173
+ } catch (e) {}
174
+ }
115
175
  }
116
176
  }
117
177
 
@@ -133,14 +193,9 @@ export async function startServer(port = PORT, host = process.env.HOST || undefi
133
193
  }
134
194
 
135
195
  if (nodeMiddlewares.length > 0) {
136
- for (const mw of nodeMiddlewares) {
137
- let continued = false;
138
- await mw(req, res, () => {
139
- continued = true;
140
- });
141
- if (!continued || res.writableEnded || res.headersSent) {
142
- return;
143
- }
196
+ const shouldContinue = await runNodeMiddlewares(nodeMiddlewares, req, res);
197
+ if (!shouldContinue || res.writableEnded || res.headersSent) {
198
+ return;
144
199
  }
145
200
  }
146
201
 
@@ -159,33 +214,19 @@ export async function startServer(port = PORT, host = process.env.HOST || undefi
159
214
  }
160
215
  });
161
216
 
162
- try {
163
- const { getDinouConfig } = await import("${dinouDirSlash}/core/load-dinou-config.js");
164
- const cfg = await getDinouConfig();
165
- if (cfg.plugins && Array.isArray(cfg.plugins)) {
166
- const serverContext = {
167
- server,
168
- isDev: false,
169
- use(middleware) {
170
- if (typeof middleware === "function") {
171
- nodeMiddlewares.push(middleware);
172
- }
173
- },
174
- };
175
- for (const plugin of cfg.plugins) {
176
- if (typeof plugin.configureServer === "function") {
177
- await plugin.configureServer(serverContext);
178
- }
179
- }
180
- }
181
- } catch (err) {
182
- console.error("❌ [Dinou Node Server] Error running configureServer plugins:", err);
217
+ if (__bundledDinouConfig && Array.isArray(__bundledDinouConfig.plugins)) {
218
+ await applyConfigureServerPlugins({
219
+ plugins: __bundledDinouConfig.plugins,
220
+ server,
221
+ isDev: false,
222
+ middlewares: nodeMiddlewares,
223
+ });
183
224
  }
184
225
 
185
226
  return new Promise((resolve, reject) => {
186
227
  server.on("error", reject);
187
228
  server.listen(port, host, () => {
188
- console.log(\`🚀 Dinou (Node.js AOT Dual-Bundle) server running on http://localhost:\${port}\`);
229
+ console.log(\`🚀 Dinou (Node.js AOT Dual-Bundle) server running on http://\${host || "localhost"}:\${port}\`);
189
230
  resolve(server);
190
231
  });
191
232
  });
@@ -211,6 +252,24 @@ if (isMain) {
211
252
  const nodeEntryPath = path.join(nodeDir, "node-entry.mjs");
212
253
  fs.writeFileSync(nodeEntryPath, nodeEntryContent, "utf8");
213
254
 
255
+ const passCConfigAliasPlugin = configFile
256
+ ? {
257
+ name: "dinou-passc-config-alias",
258
+ setup(build) {
259
+ const normConfig = path.resolve(configFile).toLowerCase();
260
+ build.onResolve({ filter: /^dinou$/ }, (args) => {
261
+ if (
262
+ args.importer &&
263
+ path.resolve(args.importer).toLowerCase() === normConfig
264
+ ) {
265
+ return { path: path.resolve(dinouDirSlash, "core/config.js") };
266
+ }
267
+ return null;
268
+ });
269
+ },
270
+ }
271
+ : null;
272
+
214
273
  // Pass C: Final Node Orchestrator
215
274
  const finalOutfile = path.join(nodeDir, "server.mjs");
216
275
  console.log(" 🚀 Bundling Pass C: Node Orchestrator (.dinou/node/server.mjs)...");
@@ -221,11 +280,16 @@ if (isMain) {
221
280
  format: "esm",
222
281
  target: "node20",
223
282
  platform: "node",
283
+ jsx: "automatic",
224
284
  mainFields: ["module", "main"],
225
285
  conditions: ["node", "worker", "browser"],
226
286
  external: [...externalList, "./rsc-engine.mjs", "./ssr-engine.mjs"],
227
287
  banner,
228
- inject: setupFiles,
288
+ plugins: [
289
+ passCConfigAliasPlugin,
290
+ serverTsconfigAliasesPlugin,
291
+ serverAssetPlugin,
292
+ ].filter(Boolean),
229
293
  alias: commonAlias,
230
294
  loader: commonLoader,
231
295
  define: {