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
package/dinou/cli.js CHANGED
@@ -1,532 +1,992 @@
1
- #!/usr/bin/env node
2
-
3
-
4
- import { program } from "#commander";
5
- import { execSync } from "node:child_process";
6
- import path from "node:path";
7
- import { fileURLToPath } from "node:url";
8
-
9
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
10
- const dinouPath = __dirname;
11
- const projectRoot = process.cwd();
12
-
13
- // Global CLI options for Dinou v9 (Dual-Mode Vendoring)
14
- program
15
- .name("dinou")
16
- .description("Full-stack React 19 framework with native RSC, progressive streaming, and dual-mode vendoring")
17
- .version("9.3.0")
18
- .option("-u, --unvendorized", "Run with standard node_modules dependencies instead of pre-bundled vendor packages");
19
-
20
- const isUnvendorizedRequested = () =>
21
- process.argv.includes("-u") ||
22
- process.argv.includes("--unvendorized") ||
23
- process.env.DINOU_UNVENDORIZED === "true" ||
24
- process.env.DINOU_UNVENDORIZED === "1" ||
25
- Boolean(program.opts?.().unvendorized);
26
-
27
- const pathKey = Object.keys(process.env).find((k) => k.toLowerCase() === "path") || "PATH";
28
- const projectBin = path.join(projectRoot, "node_modules", ".bin");
29
- const dinouBin = path.join(dinouPath, "node_modules", ".bin");
30
- const dinouParentBin = path.resolve(dinouPath, "..", "node_modules", ".bin");
31
- const extendedPath = [projectBin, dinouBin, dinouParentBin, process.env[pathKey]].filter(Boolean).join(path.delimiter);
32
-
33
- const runCommand = (command, options = {}) => {
34
- try {
35
- const unvendorized = isUnvendorizedRequested();
36
- const baseNodeOptions = process.env.NODE_OPTIONS || "";
37
- const nodeOptions = unvendorized && !baseNodeOptions.includes("unvendorized")
38
- ? (baseNodeOptions ? `${baseNodeOptions} ` : "") + "--conditions=unvendorized"
39
- : baseNodeOptions;
40
-
41
- const env = {
42
- ...process.env,
43
- [pathKey]: extendedPath,
44
- Path: extendedPath,
45
- PATH: extendedPath,
46
- ...(unvendorized ? { DINOU_UNVENDORIZED: "true" } : {}),
47
- ...(nodeOptions ? { NODE_OPTIONS: nodeOptions } : {}),
48
- ...(options.env || {}),
49
- };
50
-
51
- let finalCommand = command;
52
- if (unvendorized) {
53
- finalCommand = finalCommand.replace(/(node\s+(?:"[^"]+"|[^\s"&|]+))(?!\s+-u\b)(?=\s|$|[&|;])/g, "$1 -u");
54
- }
55
-
56
- execSync(finalCommand, { stdio: "inherit", cwd: projectRoot, ...options, env });
57
- } catch (error) {
58
- console.error(`Error executing "${command}":`, error.message);
59
- process.exit(1);
60
- }
61
- };
62
-
63
- // Helper paths
64
- const p = (rel) => `"${path.join(dinouPath, rel).replaceAll("\\", "/")}"`;
65
-
66
- // --- DEV ---
67
-
68
- program
69
- .command("dev")
70
- .description("Start development server with Esbuild")
71
- .action(() => {
72
- runCommand(`cross-env DINOU_BUILD_TOOL=esbuild node ${p("node/dev.js")}`);
73
- });
74
-
75
- program
76
- .command("dev:esbuild")
77
- .description("Start development server with Esbuild")
78
- .action(() => {
79
- runCommand(`cross-env DINOU_BUILD_TOOL=esbuild node ${p("node/dev.js")}`);
80
- });
81
-
82
- program
83
- .command("dev:rollup")
84
- .description("Start development server with Rollup")
85
- .action(() => {
86
- runCommand(`cross-env DINOU_BUILD_TOOL=rollup node ${p("node/dev.js")}`);
87
- });
88
-
89
- program
90
- .command("dev:webpack")
91
- .description("Start development server with Webpack")
92
- .action(() => {
93
- runCommand(`cross-env DINOU_BUILD_TOOL=webpack node ${p("node/dev.js")}`);
94
- });
95
-
96
- // --- NODE (BUILD & START) ---
97
-
98
- program
99
- .command("build")
100
- .description("Build the app for Node.js production (using esbuild)")
101
- .action(() => {
102
- runCommand(`cross-env NODE_ENV=production node ${p("esbuild/build.js")} && node ${p("node/build.js")}`);
103
- });
104
-
105
- program
106
- .command("build:node")
107
- .description("Build the app for Node.js production (using esbuild)")
108
- .action(() => {
109
- runCommand(`cross-env NODE_ENV=production node ${p("esbuild/build.js")} && node ${p("node/build.js")}`);
110
- });
111
-
112
- program
113
- .command("build:node:esbuild")
114
- .description("Build the app for Node.js with Esbuild")
115
- .action(() => {
116
- runCommand(`cross-env NODE_ENV=production node ${p("esbuild/build.js")} && node ${p("node/build.js")}`);
117
- });
118
-
119
- program
120
- .command("build:node:rollup")
121
- .description("Build the app for Node.js with Rollup")
122
- .action(() => {
123
- runCommand(`cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")} && node ${p("node/build.js")}`);
124
- });
125
-
126
- program
127
- .command("build:node:webpack")
128
- .description("Build the app for Node.js with Webpack")
129
- .action(() => {
130
- runCommand(`cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")} && cross-env DINOU_BUILD_TOOL=webpack node ${p("node/build.js")}`);
131
- });
132
-
133
- program
134
- .command("start")
135
- .description("Start the app in production mode (Node.js)")
136
- .action(() => {
137
- runCommand(`cross-env NODE_ENV=production node ${p("adapters/node.js")}`);
138
- });
139
-
140
- program
141
- .command("start:node")
142
- .description("Start the app in production mode (Node.js)")
143
- .action(() => {
144
- runCommand(`cross-env NODE_ENV=production node ${p("adapters/node.js")}`);
145
- });
146
-
147
- program
148
- .command("start:node:esbuild")
149
- .description("Start the app in production mode (Esbuild build)")
150
- .action(() => {
151
- runCommand(`cross-env NODE_ENV=production node ${p("adapters/node.js")}`);
152
- });
153
-
154
- program
155
- .command("start:node:rollup")
156
- .description("Start the app in production mode (Rollup build)")
157
- .action(() => {
158
- runCommand(`cross-env NODE_ENV=production node ${p("adapters/node.js")}`);
159
- });
160
-
161
- program
162
- .command("start:node:webpack")
163
- .description("Start the app in production mode (Webpack build)")
164
- .action(() => {
165
- runCommand(`cross-env NODE_ENV=production DINOU_BUILD_TOOL=webpack node ${p("adapters/node.js")}`);
166
- });
167
-
168
- // --- NODE (COMPILE VIA BUN) ---
169
-
170
- const nodeTargets = [
171
- { name: "", flags: "", outfile: "dist/server" },
172
- { name: ":linux", flags: "--target=bun-linux-x64 ", outfile: "dist/server-linux" },
173
- { name: ":linux_arm", flags: "--target=bun-linux-arm64 ", outfile: "dist/server-linux-arm" },
174
- { name: ":mac", flags: "--target=bun-darwin-arm64 ", outfile: "dist/server-mac" },
175
- { name: ":win", flags: "--target=bun-windows-x64 ", outfile: "dist/server-win" },
176
- ];
177
-
178
- const runNodeBuild = (bundler) => {
179
- const bundlerCmd = bundler === "rollup"
180
- ? `cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")}`
181
- : bundler === "webpack"
182
- ? `cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")}`
183
- : `cross-env NODE_ENV=production node ${p("esbuild/build.js")}`;
184
-
185
- const envPrefix = bundler === "webpack" ? "cross-env DINOU_BUILD_TOOL=webpack " : "";
186
- return `${bundlerCmd} && ${envPrefix}node ${p("node/build.js")}`;
187
- };
188
-
189
- for (const t of nodeTargets) {
190
- for (const b of ["esbuild", "rollup", "webpack"]) {
191
- const cmdNames = b === "esbuild"
192
- ? [`build:node:compile${t.name}`, `build:node:compile${t.name}:esbuild`]
193
- : [`build:node:compile${t.name}:${b}`];
194
- for (const cmdName of cmdNames) {
195
- program
196
- .command(cmdName)
197
- .description(`Compile standalone Node.js server executable with Bun (${t.name || "host"}, ${b})`)
198
- .action(() => {
199
- runCommand(`${runNodeBuild(b)} && bun build --compile ${t.flags}.dinou/node/server.mjs --outfile ${t.outfile}`);
200
- });
201
- }
202
- }
203
- }
204
-
205
- // --- NODE (PURE BUN RUNNER COMPILE) ---
206
-
207
- const runNodePureBuild = (bundler) => {
208
- if (bundler === "rollup") {
209
- return `cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")} && bun ${p("node/build.js")}`;
210
- }
211
- if (bundler === "webpack") {
212
- return `cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")} && cross-env DINOU_BUILD_TOOL=webpack bun ${p("node/build.js")}`;
213
- }
214
- return `cross-env NODE_ENV=production bun ${p("esbuild/build.js")} && bun ${p("node/build.js")}`;
215
- };
216
-
217
- program
218
- .command("build:node:pure")
219
- .description("Build the app for Node.js with 100% Bun (using esbuild)")
220
- .action(() => { runCommand(runNodePureBuild("esbuild")); });
221
-
222
- program
223
- .command("build:node:pure:esbuild")
224
- .description("Build the app for Node.js with 100% Bun (Esbuild)")
225
- .action(() => { runCommand(runNodePureBuild("esbuild")); });
226
-
227
- program
228
- .command("build:node:pure:rollup")
229
- .description("Build the app for Node.js with 100% Bun (Rollup)")
230
- .action(() => { runCommand(runNodePureBuild("rollup")); });
231
-
232
- program
233
- .command("build:node:pure:webpack")
234
- .description("Build the app for Node.js with 100% Bun (Webpack)")
235
- .action(() => { runCommand(runNodePureBuild("webpack")); });
236
-
237
- for (const t of nodeTargets) {
238
- for (const b of ["esbuild", "rollup", "webpack"]) {
239
- const cmdNames = b === "esbuild"
240
- ? [`build:node:pure:compile${t.name}`, `build:node:pure:compile${t.name}:esbuild`]
241
- : [`build:node:pure:compile${t.name}:${b}`];
242
- for (const cmdName of cmdNames) {
243
- program
244
- .command(cmdName)
245
- .description(`Compile standalone Node.js server executable with 100% Bun (${t.name || "host"}, ${b})`)
246
- .action(() => {
247
- runCommand(`${runNodePureBuild(b)} && bun build --compile ${t.flags}.dinou/node/server.mjs --outfile ${t.outfile}`);
248
- });
249
- }
250
- }
251
- }
252
-
253
- // --- CLOUDFLARE WORKERS ---
254
-
255
- program
256
- .command("build:cloudflare")
257
- .description("Build the app for Cloudflare Workers (using esbuild)")
258
- .action(() => {
259
- runCommand(`cross-env NODE_ENV=production node ${p("esbuild/build.js")} && node ${p("cloudflare/build.js")}`);
260
- });
261
-
262
- program
263
- .command("build:cloudflare:esbuild")
264
- .description("Build the app for Cloudflare Workers with Esbuild")
265
- .action(() => {
266
- runCommand(`cross-env NODE_ENV=production node ${p("esbuild/build.js")} && node ${p("cloudflare/build.js")}`);
267
- });
268
-
269
- program
270
- .command("build:cloudflare:rollup")
271
- .description("Build the app for Cloudflare Workers with Rollup")
272
- .action(() => {
273
- runCommand(`cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")} && node ${p("cloudflare/build.js")}`);
274
- });
275
-
276
- program
277
- .command("build:cloudflare:webpack")
278
- .description("Build the app for Cloudflare Workers with Webpack")
279
- .action(() => {
280
- runCommand(`cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")} && cross-env DINOU_BUILD_TOOL=webpack node ${p("cloudflare/build.js")}`);
281
- });
282
-
283
- // --- DENO DEPLOY / EDGE ---
284
-
285
- const runDenoBuild = (bundler) => {
286
- const bundlerCmd = bundler === "rollup"
287
- ? `cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")}`
288
- : bundler === "webpack"
289
- ? `cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")}`
290
- : `cross-env NODE_ENV=production node ${p("esbuild/build.js")}`;
291
-
292
- const envPrefix = bundler === "webpack" ? "cross-env DINOU_BUILD_TOOL=webpack " : "";
293
- return `${bundlerCmd} && ${envPrefix}node ${p("deno/build.js")} && deno run --unstable-kv --allow-net --allow-read --allow-write --allow-env ${p("deno/seed-kv.js")}`;
294
- };
295
-
296
- program
297
- .command("build:deno")
298
- .description("Build the app for Deno Deploy / Edge (using esbuild)")
299
- .action(() => { runCommand(runDenoBuild("esbuild")); });
300
-
301
- program
302
- .command("build:deno:esbuild")
303
- .description("Build the app for Deno Deploy with Esbuild")
304
- .action(() => { runCommand(runDenoBuild("esbuild")); });
305
-
306
- program
307
- .command("build:deno:rollup")
308
- .description("Build the app for Deno Deploy with Rollup")
309
- .action(() => { runCommand(runDenoBuild("rollup")); });
310
-
311
- program
312
- .command("build:deno:webpack")
313
- .description("Build the app for Deno Deploy with Webpack")
314
- .action(() => { runCommand(runDenoBuild("webpack")); });
315
-
316
- program
317
- .command("start:deno")
318
- .description("Start the app in production mode with Deno")
319
- .action(() => {
320
- runCommand(`deno run --unstable-kv --allow-net --allow-read --allow-write --allow-env --allow-sys ${p("adapters/deno.js")}`);
321
- });
322
-
323
- // Deno compile commands
324
- const denoTargets = [
325
- { name: "", flags: "", outfile: "dist/deno-server" },
326
- { name: ":linux", flags: "--target x86_64-unknown-linux-gnu ", outfile: "dist/deno-server-linux" },
327
- { name: ":linux_arm", flags: "--target aarch64-unknown-linux-gnu ", outfile: "dist/deno-server-linux-arm" },
328
- { name: ":mac", flags: "--target aarch64-apple-darwin ", outfile: "dist/deno-server-mac" },
329
- { name: ":win", flags: "--target x86_64-pc-windows-msvc ", outfile: "dist/deno-server-win" },
330
- ];
331
-
332
- for (const t of denoTargets) {
333
- for (const b of ["esbuild", "rollup", "webpack"]) {
334
- const cmdNames = b === "esbuild"
335
- ? [`build:deno:compile${t.name}`, `build:deno:compile${t.name}:esbuild`]
336
- : [`build:deno:compile${t.name}:${b}`];
337
- for (const cmdName of cmdNames) {
338
- program
339
- .command(cmdName)
340
- .description(`Compile standalone Deno executable (${t.name || "host"}, ${b})`)
341
- .action(() => {
342
- runCommand(`${runDenoBuild(b)} && deno compile ${t.flags}--unstable-kv --no-check --no-config --allow-net --allow-read --allow-write --allow-env --allow-sys --output ${t.outfile} .dinou/deno/main.js`);
343
- });
344
- }
345
- }
346
- }
347
-
348
- // --- BUN (STANDARD) ---
349
-
350
- const runBunBuild = (bundler) => {
351
- const bundlerCmd = bundler === "rollup"
352
- ? `cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")}`
353
- : bundler === "webpack"
354
- ? `cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")}`
355
- : `cross-env NODE_ENV=production node ${p("esbuild/build.js")}`;
356
-
357
- const envPrefix = bundler === "webpack" ? "cross-env DINOU_BUILD_TOOL=webpack " : "";
358
- return `${bundlerCmd} && ${envPrefix}node ${p("bun/build.js")}`;
359
- };
360
-
361
- program
362
- .command("build:bun")
363
- .description("Build the app for Bun (using esbuild)")
364
- .action(() => { runCommand(runBunBuild("esbuild")); });
365
-
366
- program
367
- .command("build:bun:esbuild")
368
- .description("Build the app for Bun with Esbuild")
369
- .action(() => { runCommand(runBunBuild("esbuild")); });
370
-
371
- program
372
- .command("build:bun:rollup")
373
- .description("Build the app for Bun with Rollup")
374
- .action(() => { runCommand(runBunBuild("rollup")); });
375
-
376
- program
377
- .command("build:bun:webpack")
378
- .description("Build the app for Bun with Webpack")
379
- .action(() => { runCommand(runBunBuild("webpack")); });
380
-
381
- program
382
- .command("start:bun")
383
- .description("Start the app in production mode with Bun")
384
- .action(() => {
385
- runCommand(`cross-env NODE_ENV=production bun ${p("adapters/bun.js")}`);
386
- });
387
-
388
- program
389
- .command("start:bun:esbuild")
390
- .description("Start the app in production mode with Bun (Esbuild)")
391
- .action(() => {
392
- runCommand(`cross-env NODE_ENV=production bun ${p("adapters/bun.js")}`);
393
- });
394
-
395
- program
396
- .command("start:bun:rollup")
397
- .description("Start the app in production mode with Bun (Rollup)")
398
- .action(() => {
399
- runCommand(`cross-env NODE_ENV=production bun ${p("adapters/bun.js")}`);
400
- });
401
-
402
- program
403
- .command("start:bun:webpack")
404
- .description("Start the app in production mode with Bun (Webpack)")
405
- .action(() => {
406
- runCommand(`cross-env NODE_ENV=production DINOU_BUILD_TOOL=webpack bun ${p("adapters/bun.js")}`);
407
- });
408
-
409
- const bunTargets = [
410
- { name: "", flags: "", outfile: "dist/server" },
411
- { name: ":linux", flags: "--target=bun-linux-x64 ", outfile: "dist/server-linux" },
412
- { name: ":linux_arm", flags: "--target=bun-linux-arm64 ", outfile: "dist/server-linux-arm" },
413
- { name: ":mac", flags: "--target=bun-darwin-arm64 ", outfile: "dist/server-mac" },
414
- { name: ":win", flags: "--target=bun-windows-x64 ", outfile: "dist/server-win" },
415
- ];
416
-
417
- for (const t of bunTargets) {
418
- for (const b of ["esbuild", "rollup", "webpack"]) {
419
- const cmdNames = b === "esbuild"
420
- ? [`build:bun:compile${t.name}`, `build:bun:compile${t.name}:esbuild`]
421
- : [`build:bun:compile${t.name}:${b}`];
422
- for (const cmdName of cmdNames) {
423
- program
424
- .command(cmdName)
425
- .description(`Compile standalone Bun executable (${t.name || "host"}, ${b})`)
426
- .action(() => {
427
- runCommand(`${runBunBuild(b)} && bun build --compile ${t.flags}.dinou/bun/server.js --outfile ${t.outfile}`);
428
- });
429
- }
430
- }
431
- }
432
-
433
- // --- BUN (PURE) ---
434
-
435
- const runBunPureBuild = (bundler) => {
436
- if (bundler === "rollup") {
437
- return `cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")} && bun ${p("bun/build.js")}`;
438
- }
439
- if (bundler === "webpack") {
440
- return `cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")} && cross-env DINOU_BUILD_TOOL=webpack bun ${p("bun/build.js")}`;
441
- }
442
- return `cross-env NODE_ENV=production bun ${p("esbuild/build.js")} && bun ${p("bun/build.js")}`;
443
- };
444
-
445
- program
446
- .command("build:bun:pure")
447
- .description("Build the app with 100% Bun (using esbuild)")
448
- .action(() => { runCommand(runBunPureBuild("esbuild")); });
449
-
450
- program
451
- .command("build:bun:pure:esbuild")
452
- .description("Build the app with 100% Bun (Esbuild)")
453
- .action(() => { runCommand(runBunPureBuild("esbuild")); });
454
-
455
- program
456
- .command("build:bun:pure:rollup")
457
- .description("Build the app with 100% Bun (Rollup)")
458
- .action(() => { runCommand(runBunPureBuild("rollup")); });
459
-
460
- program
461
- .command("build:bun:pure:webpack")
462
- .description("Build the app with 100% Bun (Webpack)")
463
- .action(() => { runCommand(runBunPureBuild("webpack")); });
464
-
465
- for (const t of bunTargets) {
466
- for (const b of ["esbuild", "rollup", "webpack"]) {
467
- const cmdNames = b === "esbuild"
468
- ? [`build:bun:pure:compile${t.name}`, `build:bun:pure:compile${t.name}:esbuild`]
469
- : [`build:bun:pure:compile${t.name}:${b}`];
470
- for (const cmdName of cmdNames) {
471
- program
472
- .command(cmdName)
473
- .description(`Compile standalone Bun Pure executable (${t.name || "host"}, ${b})`)
474
- .action(() => {
475
- runCommand(`${runBunPureBuild(b)} && bun build --compile ${t.flags}.dinou/bun/server.js --outfile ${t.outfile}`);
476
- });
477
- }
478
- }
479
- }
480
-
481
- // --- EXPORT STATIC ---
482
-
483
- program
484
- .command("export-static")
485
- .description("Export standalone static website (using esbuild)")
486
- .action(() => {
487
- runCommand(`cross-env NODE_ENV=production node ${p("esbuild/build.js")} && node ${p("core/export-static.js")}`);
488
- });
489
-
490
- program
491
- .command("export-static:esbuild")
492
- .description("Export standalone static website with Esbuild")
493
- .action(() => {
494
- runCommand(`cross-env NODE_ENV=production node ${p("esbuild/build.js")} && node ${p("core/export-static.js")}`);
495
- });
496
-
497
- program
498
- .command("export-static:rollup")
499
- .description("Export standalone static website with Rollup")
500
- .action(() => {
501
- runCommand(`cross-env NODE_ENV=production npx rollup -c ${p("rollup/rollup.config.js")} && node ${p("core/export-static.js")}`);
502
- });
503
-
504
- program
505
- .command("export-static:webpack")
506
- .description("Export standalone static website with Webpack")
507
- .action(() => {
508
- runCommand(`cross-env NODE_ENV=production npx webpack --config ${p("webpack/webpack.config.js")} && node ${p("core/export-static.js")}`);
509
- });
510
-
511
-
512
- // --- VENDORS ---
513
-
514
- program
515
- .command("build:vendors")
516
- .description("Bundle dependencies into dinou/compiled vendors")
517
- .action(() => {
518
- runCommand(`node ${p("scripts/build-vendors.js")}`);
519
- });
520
-
521
- // --- EJECT ---
522
-
523
- program
524
- .command("eject")
525
- .description("Copy the framework to the root of the project")
526
- .action(async () => {
527
- console.log("Executing eject...");
528
- const { eject } = await import("../eject.js");
529
- eject();
530
- });
531
-
532
- program.parse(process.argv);
1
+ #!/usr/bin/env node
2
+
3
+ import ensureVendorMode, {
4
+ isUnvendorizedRequested,
5
+ } from "./core/ensure-vendor-mode.js";
6
+ if (!ensureVendorMode()) {
7
+ await new Promise(() => { });
8
+ }
9
+
10
+ import { program } from "#commander";
11
+ import { spawnSync } from "node:child_process";
12
+ import fs from "node:fs";
13
+ import { createRequire } from "node:module";
14
+ import path from "node:path";
15
+ import { fileURLToPath } from "node:url";
16
+ import { loadEnvFiles } from "./core/env.js";
17
+
18
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
19
+ const dinouPath = __dirname;
20
+ const projectRoot = process.cwd();
21
+
22
+ const dinouRequire = createRequire(import.meta.url);
23
+ const projectRequire = createRequire(path.resolve(projectRoot, "package.json"));
24
+
25
+ function resolveToolBin(specifier) {
26
+ try {
27
+ return dinouRequire.resolve(specifier);
28
+ } catch {
29
+ return projectRequire.resolve(specifier);
30
+ }
31
+ }
32
+
33
+ const dinouScript = (rel) => path.join(dinouPath, rel);
34
+
35
+ // Global CLI options (Dual-Mode Vendoring)
36
+ program
37
+ .name("dinou")
38
+ .description(
39
+ "Full-stack React 19 framework with native RSC, progressive streaming, and dual-mode vendoring"
40
+ )
41
+ .version("10.0.1")
42
+ .option(
43
+ "-u, --unvendorized",
44
+ "Run with standard node_modules dependencies instead of pre-bundled vendor packages"
45
+ );
46
+
47
+ const pathKey =
48
+ Object.keys(process.env).find((k) => k.toLowerCase() === "path") || "PATH";
49
+ const projectBin = path.join(projectRoot, "node_modules", ".bin");
50
+ const dinouBin = path.join(dinouPath, "node_modules", ".bin");
51
+ const dinouParentBin = path.resolve(dinouPath, "..", "node_modules", ".bin");
52
+ const extendedPath = [
53
+ projectBin,
54
+ dinouBin,
55
+ dinouParentBin,
56
+ process.env[pathKey],
57
+ ]
58
+ .filter(Boolean)
59
+ .join(path.delimiter);
60
+
61
+ function buildChildEnv(extraEnv = {}) {
62
+ const unvendorized =
63
+ isUnvendorizedRequested(projectRoot) ||
64
+ Boolean(program.opts?.().unvendorized);
65
+ const baseNodeOptions = process.env.NODE_OPTIONS || "";
66
+ const nodeOptions =
67
+ unvendorized && !baseNodeOptions.includes("unvendorized")
68
+ ? (baseNodeOptions ? `${baseNodeOptions} ` : "") +
69
+ "--conditions=unvendorized"
70
+ : baseNodeOptions;
71
+
72
+ return {
73
+ unvendorized,
74
+ env: {
75
+ ...process.env,
76
+ [pathKey]: extendedPath,
77
+ Path: extendedPath,
78
+ PATH: extendedPath,
79
+ ...(unvendorized ? { DINOU_UNVENDORIZED: "true" } : {}),
80
+ ...(nodeOptions ? { NODE_OPTIONS: nodeOptions } : {}),
81
+ ...extraEnv,
82
+ },
83
+ };
84
+ }
85
+
86
+ function jsStep(runner, scriptOrResolver, args = [], env = {}) {
87
+ return { kind: "js", runner, scriptOrResolver, args, env };
88
+ }
89
+
90
+ function cmdStep(bin, args = [], env = {}) {
91
+ return { kind: "cmd", bin, args, env };
92
+ }
93
+
94
+ function runSteps(steps, baseEnv = {}) {
95
+ const isBunRuntime =
96
+ typeof Bun !== "undefined" || Boolean(process.versions?.bun);
97
+
98
+ for (const step of steps) {
99
+ const mergedExtraEnv = { ...baseEnv, ...(step.env || {}) };
100
+ const { unvendorized, env } = buildChildEnv(mergedExtraEnv);
101
+
102
+ let bin;
103
+ let finalArgs;
104
+
105
+ if (step.kind === "js") {
106
+ const targetScript =
107
+ typeof step.scriptOrResolver === "function"
108
+ ? step.scriptOrResolver()
109
+ : step.scriptOrResolver;
110
+
111
+ if (step.runner === "bun") {
112
+ bin = isBunRuntime ? process.execPath : "bun";
113
+ } else {
114
+ bin = !isBunRuntime ? process.execPath : "node";
115
+ }
116
+
117
+ const conditionPrefix = unvendorized ? ["--conditions=unvendorized"] : [];
118
+ finalArgs = [...conditionPrefix, targetScript, ...(step.args || [])];
119
+ } else {
120
+ bin =
121
+ step.bin === "bun" && isBunRuntime ? process.execPath : step.bin;
122
+ finalArgs = [...(step.args || [])];
123
+ }
124
+
125
+ let result = spawnSync(bin, finalArgs, {
126
+ stdio: "inherit",
127
+ cwd: projectRoot,
128
+ env,
129
+ });
130
+
131
+ if (
132
+ result.error &&
133
+ process.platform === "win32" &&
134
+ !path.isAbsolute(bin) &&
135
+ (result.error.code === "ENOENT" || result.error.code === "EINVAL")
136
+ ) {
137
+ result = spawnSync(bin, finalArgs, {
138
+ stdio: "inherit",
139
+ cwd: projectRoot,
140
+ env,
141
+ shell: true,
142
+ });
143
+ }
144
+
145
+ if (result.error) {
146
+ console.error(
147
+ `Error executing "${bin} ${finalArgs.join(" ")}":`,
148
+ result.error.message
149
+ );
150
+ process.exit(1);
151
+ }
152
+
153
+ if (result.status !== 0) {
154
+ if (result.signal) {
155
+ process.kill(process.pid, result.signal);
156
+ }
157
+ process.exit(result.status ?? 1);
158
+ }
159
+ }
160
+ }
161
+
162
+ const runProdSteps = (steps, extraEnv = {}) =>
163
+ runSteps(steps, { NODE_ENV: "production", ...extraEnv });
164
+
165
+ function bundlerStep(bundler, runner = "node") {
166
+ if (bundler === "rollup") {
167
+ return jsStep(
168
+ runner,
169
+ () => resolveToolBin("rollup/dist/bin/rollup"),
170
+ ["-c", dinouScript("rollup/rollup.config.js")],
171
+ { NODE_ENV: "production", DINOU_BUILD_TOOL: "rollup" }
172
+ );
173
+ }
174
+ if (bundler === "webpack") {
175
+ return jsStep(
176
+ runner,
177
+ () => resolveToolBin("webpack-cli/bin/cli.js"),
178
+ ["--config", dinouScript("webpack/webpack.config.js")],
179
+ { NODE_ENV: "production", DINOU_BUILD_TOOL: "webpack" }
180
+ );
181
+ }
182
+ return jsStep(runner, dinouScript("esbuild/build.js"), [], {
183
+ NODE_ENV: "production",
184
+ DINOU_BUILD_TOOL: "esbuild",
185
+ });
186
+ }
187
+
188
+ // --- DEV ---
189
+
190
+ program
191
+ .command("dev")
192
+ .description("Start development server with Esbuild")
193
+ .action(() => {
194
+ runSteps([
195
+ jsStep("node", dinouScript("node/dev.js"), [], {
196
+ DINOU_BUILD_TOOL: "esbuild",
197
+ }),
198
+ ]);
199
+ });
200
+
201
+ program
202
+ .command("dev:esbuild")
203
+ .description("Start development server with Esbuild")
204
+ .action(() => {
205
+ runSteps([
206
+ jsStep("node", dinouScript("node/dev.js"), [], {
207
+ DINOU_BUILD_TOOL: "esbuild",
208
+ }),
209
+ ]);
210
+ });
211
+
212
+ program
213
+ .command("dev:rollup")
214
+ .description("Start development server with Rollup")
215
+ .action(() => {
216
+ runSteps([
217
+ jsStep("node", dinouScript("node/dev.js"), [], {
218
+ DINOU_BUILD_TOOL: "rollup",
219
+ }),
220
+ ]);
221
+ });
222
+
223
+ program
224
+ .command("dev:webpack")
225
+ .description("Start development server with Webpack")
226
+ .action(() => {
227
+ runSteps([
228
+ jsStep("node", dinouScript("node/dev.js"), [], {
229
+ DINOU_BUILD_TOOL: "webpack",
230
+ }),
231
+ ]);
232
+ });
233
+
234
+ // --- NODE (BUILD & START) ---
235
+
236
+ const buildNodeSteps = (bundler, runner = "node") => [
237
+ bundlerStep(bundler, runner),
238
+ jsStep(runner, dinouScript("node/build.js"), [], {
239
+ NODE_ENV: "production",
240
+ DINOU_BUILD_TOOL: bundler,
241
+ }),
242
+ ];
243
+
244
+ program
245
+ .command("build")
246
+ .description("Build the app for Node.js production (using esbuild)")
247
+ .action(() => {
248
+ runProdSteps(buildNodeSteps("esbuild", "node"));
249
+ });
250
+
251
+ program
252
+ .command("build:node")
253
+ .description("Build the app for Node.js production (using esbuild)")
254
+ .action(() => {
255
+ runProdSteps(buildNodeSteps("esbuild", "node"));
256
+ });
257
+
258
+ program
259
+ .command("build:node:esbuild")
260
+ .description("Build the app for Node.js with Esbuild")
261
+ .action(() => {
262
+ runProdSteps(buildNodeSteps("esbuild", "node"));
263
+ });
264
+
265
+ program
266
+ .command("build:node:rollup")
267
+ .description("Build the app for Node.js with Rollup")
268
+ .action(() => {
269
+ runProdSteps(buildNodeSteps("rollup", "node"));
270
+ });
271
+
272
+ program
273
+ .command("build:node:webpack")
274
+ .description("Build the app for Node.js with Webpack")
275
+ .action(() => {
276
+ runProdSteps(buildNodeSteps("webpack", "node"));
277
+ });
278
+
279
+ program
280
+ .command("start")
281
+ .description("Start the app in production mode (Node.js)")
282
+ .action(() => {
283
+ runProdSteps([jsStep("node", dinouScript("adapters/node.js"))]);
284
+ });
285
+
286
+ program
287
+ .command("start:node")
288
+ .description("Start the app in production mode (Node.js)")
289
+ .action(() => {
290
+ runProdSteps([jsStep("node", dinouScript("adapters/node.js"))]);
291
+ });
292
+
293
+ program
294
+ .command("start:node:esbuild")
295
+ .description("Start the app in production mode (Esbuild build)")
296
+ .action(() => {
297
+ runProdSteps([
298
+ jsStep("node", dinouScript("adapters/node.js"), [], {
299
+ DINOU_BUILD_TOOL: "esbuild",
300
+ }),
301
+ ]);
302
+ });
303
+
304
+ program
305
+ .command("start:node:rollup")
306
+ .description("Start the app in production mode (Rollup build)")
307
+ .action(() => {
308
+ runProdSteps([
309
+ jsStep("node", dinouScript("adapters/node.js"), [], {
310
+ DINOU_BUILD_TOOL: "rollup",
311
+ }),
312
+ ]);
313
+ });
314
+
315
+ program
316
+ .command("start:node:webpack")
317
+ .description("Start the app in production mode (Webpack build)")
318
+ .action(() => {
319
+ runProdSteps([
320
+ jsStep("node", dinouScript("adapters/node.js"), [], {
321
+ DINOU_BUILD_TOOL: "webpack",
322
+ }),
323
+ ]);
324
+ });
325
+
326
+ // --- NODE (COMPILE VIA BUN) ---
327
+
328
+ const nodeTargets = [
329
+ { name: "", args: [], outfile: "dist/server" },
330
+ {
331
+ name: ":linux",
332
+ args: ["--target=bun-linux-x64"],
333
+ outfile: "dist/server-linux",
334
+ },
335
+ {
336
+ name: ":linux_arm",
337
+ args: ["--target=bun-linux-arm64"],
338
+ outfile: "dist/server-linux-arm",
339
+ },
340
+ {
341
+ name: ":mac",
342
+ args: ["--target=bun-darwin-arm64"],
343
+ outfile: "dist/server-mac",
344
+ },
345
+ {
346
+ name: ":win",
347
+ args: ["--target=bun-windows-x64"],
348
+ outfile: "dist/server-win",
349
+ },
350
+ ];
351
+
352
+ for (const t of nodeTargets) {
353
+ for (const b of ["esbuild", "rollup", "webpack"]) {
354
+ const cmdNames =
355
+ b === "esbuild"
356
+ ? [
357
+ `build:node:compile${t.name}`,
358
+ `build:node:compile${t.name}:esbuild`,
359
+ ]
360
+ : [`build:node:compile${t.name}:${b}`];
361
+ for (const cmdName of cmdNames) {
362
+ program
363
+ .command(cmdName)
364
+ .description(
365
+ `Compile standalone Node.js server executable with Bun (${t.name || "host"}, ${b})`
366
+ )
367
+ .action(() => {
368
+ runProdSteps([
369
+ ...buildNodeSteps(b, "node"),
370
+ cmdStep("bun", [
371
+ "build",
372
+ "--compile",
373
+ ...t.args,
374
+ ".dinou/node/server.mjs",
375
+ "--outfile",
376
+ t.outfile,
377
+ ]),
378
+ ]);
379
+ });
380
+ }
381
+ }
382
+ }
383
+
384
+ // --- NODE (PURE BUN RUNNER & COMPILE) ---
385
+
386
+ program
387
+ .command("build:node:pure")
388
+ .description("Build the app for Node.js with 100% Bun (using esbuild)")
389
+ .action(() => {
390
+ runProdSteps(buildNodeSteps("esbuild", "bun"));
391
+ });
392
+
393
+ program
394
+ .command("build:node:pure:esbuild")
395
+ .description("Build the app for Node.js with 100% Bun (Esbuild)")
396
+ .action(() => {
397
+ runProdSteps(buildNodeSteps("esbuild", "bun"));
398
+ });
399
+
400
+ program
401
+ .command("build:node:pure:rollup")
402
+ .description("Build the app for Node.js with 100% Bun (Rollup)")
403
+ .action(() => {
404
+ runProdSteps(buildNodeSteps("rollup", "bun"));
405
+ });
406
+
407
+ program
408
+ .command("build:node:pure:webpack")
409
+ .description("Build the app for Node.js with 100% Bun (Webpack)")
410
+ .action(() => {
411
+ runProdSteps(buildNodeSteps("webpack", "bun"));
412
+ });
413
+
414
+ for (const t of nodeTargets) {
415
+ for (const b of ["esbuild", "rollup", "webpack"]) {
416
+ const cmdNames =
417
+ b === "esbuild"
418
+ ? [
419
+ `build:node:pure:compile${t.name}`,
420
+ `build:node:pure:compile${t.name}:esbuild`,
421
+ ]
422
+ : [`build:node:pure:compile${t.name}:${b}`];
423
+ for (const cmdName of cmdNames) {
424
+ program
425
+ .command(cmdName)
426
+ .description(
427
+ `Compile standalone Node.js server executable with 100% Bun (${t.name || "host"}, ${b})`
428
+ )
429
+ .action(() => {
430
+ runProdSteps([
431
+ ...buildNodeSteps(b, "bun"),
432
+ cmdStep("bun", [
433
+ "build",
434
+ "--compile",
435
+ ...t.args,
436
+ ".dinou/node/server.mjs",
437
+ "--outfile",
438
+ t.outfile,
439
+ ]),
440
+ ]);
441
+ });
442
+ }
443
+ }
444
+ }
445
+
446
+ // --- NETLIFY FUNCTIONS V2 ---
447
+
448
+ const buildNetlifySteps = (bundler) => [bundlerStep(bundler, "node")];
449
+
450
+ program
451
+ .command("build:netlify")
452
+ .description("Build the app for Netlify Serverless Functions v2 (using esbuild)")
453
+ .action(() => {
454
+ runProdSteps(buildNetlifySteps("esbuild"));
455
+ });
456
+
457
+ program
458
+ .command("build:netlify:esbuild")
459
+ .description("Build the app for Netlify Serverless Functions v2 with Esbuild")
460
+ .action(() => {
461
+ runProdSteps(buildNetlifySteps("esbuild"));
462
+ });
463
+
464
+ program
465
+ .command("build:netlify:rollup")
466
+ .description("Build the app for Netlify Serverless Functions v2 with Rollup")
467
+ .action(() => {
468
+ runProdSteps(buildNetlifySteps("rollup"));
469
+ });
470
+
471
+ program
472
+ .command("build:netlify:webpack")
473
+ .description("Build the app for Netlify Serverless Functions v2 with Webpack")
474
+ .action(() => {
475
+ runProdSteps(buildNetlifySteps("webpack"));
476
+ });
477
+
478
+ // --- CLOUDFLARE WORKERS ---
479
+
480
+ const buildCloudflareSteps = (bundler) => [
481
+ bundlerStep(bundler, "node"),
482
+ jsStep("node", dinouScript("cloudflare/build.js"), [], {
483
+ NODE_ENV: "production",
484
+ DINOU_BUILD_TOOL: bundler,
485
+ }),
486
+ ];
487
+
488
+ program
489
+ .command("build:cloudflare")
490
+ .description("Build the app for Cloudflare Workers (using esbuild)")
491
+ .action(() => {
492
+ runProdSteps(buildCloudflareSteps("esbuild"));
493
+ });
494
+
495
+ program
496
+ .command("build:cloudflare:esbuild")
497
+ .description("Build the app for Cloudflare Workers with Esbuild")
498
+ .action(() => {
499
+ runProdSteps(buildCloudflareSteps("esbuild"));
500
+ });
501
+
502
+ program
503
+ .command("build:cloudflare:rollup")
504
+ .description("Build the app for Cloudflare Workers with Rollup")
505
+ .action(() => {
506
+ runProdSteps(buildCloudflareSteps("rollup"));
507
+ });
508
+
509
+ program
510
+ .command("build:cloudflare:webpack")
511
+ .description("Build the app for Cloudflare Workers with Webpack")
512
+ .action(() => {
513
+ runProdSteps(buildCloudflareSteps("webpack"));
514
+ });
515
+
516
+ // --- DENO DEPLOY / EDGE ---
517
+
518
+ const buildDenoSteps = (bundler) => [
519
+ bundlerStep(bundler, "node"),
520
+ jsStep("node", dinouScript("deno/build.js"), [], {
521
+ NODE_ENV: "production",
522
+ DINOU_BUILD_TOOL: bundler,
523
+ }),
524
+ cmdStep(
525
+ "deno",
526
+ [
527
+ "run",
528
+ "--unstable-kv",
529
+ "--allow-net",
530
+ "--allow-read",
531
+ "--allow-write",
532
+ "--allow-env",
533
+ dinouScript("deno/seed-kv.js"),
534
+ ],
535
+ { NODE_ENV: "production", DINOU_BUILD_TOOL: bundler }
536
+ ),
537
+ ];
538
+
539
+ program
540
+ .command("build:deno")
541
+ .description("Build the app for Deno Deploy / Edge (using esbuild)")
542
+ .action(() => {
543
+ runProdSteps(buildDenoSteps("esbuild"));
544
+ });
545
+
546
+ program
547
+ .command("build:deno:esbuild")
548
+ .description("Build the app for Deno Deploy with Esbuild")
549
+ .action(() => {
550
+ runProdSteps(buildDenoSteps("esbuild"));
551
+ });
552
+
553
+ program
554
+ .command("build:deno:rollup")
555
+ .description("Build the app for Deno Deploy with Rollup")
556
+ .action(() => {
557
+ runProdSteps(buildDenoSteps("rollup"));
558
+ });
559
+
560
+ program
561
+ .command("build:deno:webpack")
562
+ .description("Build the app for Deno Deploy with Webpack")
563
+ .action(() => {
564
+ runProdSteps(buildDenoSteps("webpack"));
565
+ });
566
+
567
+ program
568
+ .command("start:deno")
569
+ .description("Start the app in production mode with Deno")
570
+ .action(() => {
571
+ runProdSteps([
572
+ cmdStep("deno", [
573
+ "run",
574
+ "--unstable-kv",
575
+ "--allow-net",
576
+ "--allow-read",
577
+ "--allow-write",
578
+ "--allow-env",
579
+ "--allow-sys",
580
+ dinouScript("adapters/deno.js"),
581
+ ]),
582
+ ]);
583
+ });
584
+
585
+ const denoTargets = [
586
+ { name: "", args: [], outfile: "dist/deno-server" },
587
+ {
588
+ name: ":linux",
589
+ args: ["--target", "x86_64-unknown-linux-gnu"],
590
+ outfile: "dist/deno-server-linux",
591
+ },
592
+ {
593
+ name: ":linux_arm",
594
+ args: ["--target", "aarch64-unknown-linux-gnu"],
595
+ outfile: "dist/deno-server-linux-arm",
596
+ },
597
+ {
598
+ name: ":mac",
599
+ args: ["--target", "aarch64-apple-darwin"],
600
+ outfile: "dist/deno-server-mac",
601
+ },
602
+ {
603
+ name: ":win",
604
+ args: ["--target", "x86_64-pc-windows-msvc"],
605
+ outfile: "dist/deno-server-win",
606
+ },
607
+ ];
608
+
609
+ for (const t of denoTargets) {
610
+ for (const b of ["esbuild", "rollup", "webpack"]) {
611
+ const cmdNames =
612
+ b === "esbuild"
613
+ ? [
614
+ `build:deno:compile${t.name}`,
615
+ `build:deno:compile${t.name}:esbuild`,
616
+ ]
617
+ : [`build:deno:compile${t.name}:${b}`];
618
+ for (const cmdName of cmdNames) {
619
+ program
620
+ .command(cmdName)
621
+ .description(
622
+ `Compile standalone Deno executable (${t.name || "host"}, ${b})`
623
+ )
624
+ .action(() => {
625
+ runProdSteps([
626
+ ...buildDenoSteps(b),
627
+ cmdStep("deno", [
628
+ "compile",
629
+ ...t.args,
630
+ "--unstable-kv",
631
+ "--no-check",
632
+ "--no-config",
633
+ "--allow-net",
634
+ "--allow-read",
635
+ "--allow-write",
636
+ "--allow-env",
637
+ "--allow-sys",
638
+ "--output",
639
+ t.outfile,
640
+ ".dinou/deno/main.js",
641
+ ]),
642
+ ]);
643
+ });
644
+ }
645
+ }
646
+ }
647
+
648
+ // --- BUN (STANDARD & PURE) ---
649
+
650
+ const buildBunSteps = (bundler, runner = "node") => [
651
+ bundlerStep(bundler, runner),
652
+ jsStep(runner, dinouScript("bun/build.js"), [], {
653
+ NODE_ENV: "production",
654
+ DINOU_BUILD_TOOL: bundler,
655
+ }),
656
+ ];
657
+
658
+ program
659
+ .command("build:bun")
660
+ .description("Build the app for Bun (using esbuild)")
661
+ .action(() => {
662
+ runProdSteps(buildBunSteps("esbuild", "node"));
663
+ });
664
+
665
+ program
666
+ .command("build:bun:esbuild")
667
+ .description("Build the app for Bun with Esbuild")
668
+ .action(() => {
669
+ runProdSteps(buildBunSteps("esbuild", "node"));
670
+ });
671
+
672
+ program
673
+ .command("build:bun:rollup")
674
+ .description("Build the app for Bun with Rollup")
675
+ .action(() => {
676
+ runProdSteps(buildBunSteps("rollup", "node"));
677
+ });
678
+
679
+ program
680
+ .command("build:bun:webpack")
681
+ .description("Build the app for Bun with Webpack")
682
+ .action(() => {
683
+ runProdSteps(buildBunSteps("webpack", "node"));
684
+ });
685
+
686
+ program
687
+ .command("start:bun")
688
+ .description("Start the app in production mode with Bun")
689
+ .action(() => {
690
+ runProdSteps([jsStep("bun", dinouScript("adapters/bun.js"))]);
691
+ });
692
+
693
+ program
694
+ .command("start:bun:esbuild")
695
+ .description("Start the app in production mode with Bun (Esbuild)")
696
+ .action(() => {
697
+ runProdSteps([
698
+ jsStep("bun", dinouScript("adapters/bun.js"), [], {
699
+ DINOU_BUILD_TOOL: "esbuild",
700
+ }),
701
+ ]);
702
+ });
703
+
704
+ program
705
+ .command("start:bun:rollup")
706
+ .description("Start the app in production mode with Bun (Rollup)")
707
+ .action(() => {
708
+ runProdSteps([
709
+ jsStep("bun", dinouScript("adapters/bun.js"), [], {
710
+ DINOU_BUILD_TOOL: "rollup",
711
+ }),
712
+ ]);
713
+ });
714
+
715
+ program
716
+ .command("start:bun:webpack")
717
+ .description("Start the app in production mode with Bun (Webpack)")
718
+ .action(() => {
719
+ runProdSteps([
720
+ jsStep("bun", dinouScript("adapters/bun.js"), [], {
721
+ DINOU_BUILD_TOOL: "webpack",
722
+ }),
723
+ ]);
724
+ });
725
+
726
+ const bunTargets = [
727
+ { name: "", args: [], outfile: "dist/server" },
728
+ {
729
+ name: ":linux",
730
+ args: ["--target=bun-linux-x64"],
731
+ outfile: "dist/server-linux",
732
+ },
733
+ {
734
+ name: ":linux_arm",
735
+ args: ["--target=bun-linux-arm64"],
736
+ outfile: "dist/server-linux-arm",
737
+ },
738
+ {
739
+ name: ":mac",
740
+ args: ["--target=bun-darwin-arm64"],
741
+ outfile: "dist/server-mac",
742
+ },
743
+ {
744
+ name: ":win",
745
+ args: ["--target=bun-windows-x64"],
746
+ outfile: "dist/server-win",
747
+ },
748
+ ];
749
+
750
+ for (const t of bunTargets) {
751
+ for (const b of ["esbuild", "rollup", "webpack"]) {
752
+ const cmdNames =
753
+ b === "esbuild"
754
+ ? [
755
+ `build:bun:compile${t.name}`,
756
+ `build:bun:compile${t.name}:esbuild`,
757
+ ]
758
+ : [`build:bun:compile${t.name}:${b}`];
759
+ for (const cmdName of cmdNames) {
760
+ program
761
+ .command(cmdName)
762
+ .description(
763
+ `Compile standalone Bun executable (${t.name || "host"}, ${b})`
764
+ )
765
+ .action(() => {
766
+ runProdSteps([
767
+ ...buildBunSteps(b, "node"),
768
+ cmdStep("bun", [
769
+ "build",
770
+ "--compile",
771
+ ...t.args,
772
+ ".dinou/bun/server.js",
773
+ "--outfile",
774
+ t.outfile,
775
+ ]),
776
+ ]);
777
+ });
778
+ }
779
+ }
780
+ }
781
+
782
+ program
783
+ .command("build:bun:pure")
784
+ .description("Build the app with 100% Bun (using esbuild)")
785
+ .action(() => {
786
+ runProdSteps(buildBunSteps("esbuild", "bun"));
787
+ });
788
+
789
+ program
790
+ .command("build:bun:pure:esbuild")
791
+ .description("Build the app with 100% Bun (Esbuild)")
792
+ .action(() => {
793
+ runProdSteps(buildBunSteps("esbuild", "bun"));
794
+ });
795
+
796
+ program
797
+ .command("build:bun:pure:rollup")
798
+ .description("Build the app with 100% Bun (Rollup)")
799
+ .action(() => {
800
+ runProdSteps(buildBunSteps("rollup", "bun"));
801
+ });
802
+
803
+ program
804
+ .command("build:bun:pure:webpack")
805
+ .description("Build the app with 100% Bun (Webpack)")
806
+ .action(() => {
807
+ runProdSteps(buildBunSteps("webpack", "bun"));
808
+ });
809
+
810
+ for (const t of bunTargets) {
811
+ for (const b of ["esbuild", "rollup", "webpack"]) {
812
+ const cmdNames =
813
+ b === "esbuild"
814
+ ? [
815
+ `build:bun:pure:compile${t.name}`,
816
+ `build:bun:pure:compile${t.name}:esbuild`,
817
+ ]
818
+ : [`build:bun:pure:compile${t.name}:${b}`];
819
+ for (const cmdName of cmdNames) {
820
+ program
821
+ .command(cmdName)
822
+ .description(
823
+ `Compile standalone Bun Pure executable (${t.name || "host"}, ${b})`
824
+ )
825
+ .action(() => {
826
+ runProdSteps([
827
+ ...buildBunSteps(b, "bun"),
828
+ cmdStep("bun", [
829
+ "build",
830
+ "--compile",
831
+ ...t.args,
832
+ ".dinou/bun/server.js",
833
+ "--outfile",
834
+ t.outfile,
835
+ ]),
836
+ ]);
837
+ });
838
+ }
839
+ }
840
+ }
841
+
842
+ // --- EXPORT STATIC ---
843
+
844
+ const exportStaticSteps = (bundler) => [
845
+ bundlerStep(bundler, "node"),
846
+ jsStep("node", dinouScript("core/export-static.js"), [], {
847
+ NODE_ENV: "production",
848
+ DINOU_BUILD_TOOL: bundler,
849
+ }),
850
+ ];
851
+
852
+ program
853
+ .command("export-static")
854
+ .description("Export standalone static website (using esbuild)")
855
+ .action(() => {
856
+ runProdSteps(exportStaticSteps("esbuild"));
857
+ });
858
+
859
+ program
860
+ .command("export-static:esbuild")
861
+ .description("Export standalone static website with Esbuild")
862
+ .action(() => {
863
+ runProdSteps(exportStaticSteps("esbuild"));
864
+ });
865
+
866
+ program
867
+ .command("export-static:rollup")
868
+ .description("Export standalone static website with Rollup")
869
+ .action(() => {
870
+ runProdSteps(exportStaticSteps("rollup"));
871
+ });
872
+
873
+ program
874
+ .command("export-static:webpack")
875
+ .description("Export standalone static website with Webpack")
876
+ .action(() => {
877
+ runProdSteps(exportStaticSteps("webpack"));
878
+ });
879
+
880
+ // --- VENDORS ---
881
+
882
+ program
883
+ .command("build:vendors")
884
+ .description("Bundle dependencies into dinou/compiled vendors")
885
+ .action(() => {
886
+ runSteps([jsStep("node", dinouScript("scripts/build-vendors.js"))]);
887
+ });
888
+
889
+ // --- TYPEGEN ---
890
+
891
+ program
892
+ .command("typegen")
893
+ .description(
894
+ "Generate .dinou/types/routes.d.ts and .dinou/routes/**/dinou.{js,d.ts} from src/"
895
+ )
896
+ .action(async () => {
897
+ loadEnvFiles(projectRoot);
898
+ const { generateRouteTypes } = await import("./core/generate-route-types.js");
899
+ const stats = generateRouteTypes(projectRoot);
900
+ if (stats) {
901
+ console.log(
902
+ `🦖 [Dinou] Generated .dinou/types/routes.d.ts & contextual "./dinou" modules (${stats.totalRoutes} routes, ${stats.layoutCount} layouts, ${stats.slotCount} slots, ${stats.contextualDirCount} route dirs)`
903
+ );
904
+ }
905
+ });
906
+
907
+ // --- EJECT / UNEJECT ---
908
+
909
+ program
910
+ .command("eject")
911
+ .description("Copy the framework into ./dinou at the root of the project")
912
+ .option(
913
+ "-f, --force",
914
+ "Overwrite an existing ./dinou directory when running from node_modules"
915
+ )
916
+ .option(
917
+ "--skip-install",
918
+ "Skip running package manager install after updating package.json"
919
+ )
920
+ .action(async (opts) => {
921
+ const localDinouDir = path.resolve(projectRoot, "dinou");
922
+ const normCurrent = path
923
+ .resolve(dinouPath)
924
+ .replace(/\\/g, "/")
925
+ .toLowerCase();
926
+ const normTarget = localDinouDir.replace(/\\/g, "/").toLowerCase();
927
+
928
+ if (normCurrent === normTarget) {
929
+ console.log(
930
+ 'ℹ️ [Dinou Eject] This project is already ejected in ./dinou. Skipping to prevent overwriting your local framework customizations. (Run "npm run uneject" to revert to node_modules/dinou.)'
931
+ );
932
+ return;
933
+ }
934
+
935
+ if (fs.existsSync(localDinouDir) && !opts.force) {
936
+ console.log(
937
+ 'ℹ️ [Dinou Eject] Directory ./dinou already exists. Skipping to prevent overwriting local changes (pass --force from node_modules/dinou to overwrite, or run "npm run uneject" first).'
938
+ );
939
+ return;
940
+ }
941
+
942
+ let ejectMod;
943
+ try {
944
+ ejectMod = await import("../eject.js");
945
+ } catch (err) {
946
+ if (
947
+ err &&
948
+ (err.code === "ERR_MODULE_NOT_FOUND" ||
949
+ err.code === "MODULE_NOT_FOUND")
950
+ ) {
951
+ console.log(
952
+ 'ℹ️ [Dinou Eject] This project is already running in Ejected Mode (./dinou). Skipping eject to protect local changes. (Run "npm run uneject" to revert to node_modules/dinou.)'
953
+ );
954
+ return;
955
+ }
956
+ throw err;
957
+ }
958
+
959
+ console.log("Executing eject...");
960
+ ejectMod.eject({
961
+ force: Boolean(opts.force),
962
+ skipInstall: Boolean(opts.skipInstall),
963
+ projectRoot,
964
+ });
965
+ });
966
+
967
+ program
968
+ .command("uneject [version]")
969
+ .description(
970
+ "Revert an ejected ./dinou directory back to the node_modules dinou package"
971
+ )
972
+ .option("-y, --yes", "Skip interactive confirmation prompt")
973
+ .option(
974
+ "--skip-install",
975
+ "Update package.json and remove ./dinou without running package manager install"
976
+ )
977
+ .option(
978
+ "--keep-dinou",
979
+ "Keep the local ./dinou directory on disk instead of deleting it"
980
+ )
981
+ .action(async (version, opts) => {
982
+ const { uneject } = await import("./core/uneject.js");
983
+ await uneject({
984
+ spec: version || "latest",
985
+ yes: Boolean(opts.yes),
986
+ skipInstall: Boolean(opts.skipInstall),
987
+ keepDinouDir: Boolean(opts.keepDinou),
988
+ projectRoot,
989
+ });
990
+ });
991
+
992
+ program.parse(process.argv);