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
@@ -1,108 +1,539 @@
1
1
  import path from "node:path";
2
- import { existsSync, mkdirSync } from "node:fs";
3
- import { pathToFileURL } from "node:url";
2
+ import {
3
+ existsSync,
4
+ mkdirSync,
5
+ statSync,
6
+ writeFileSync,
7
+ } from "node:fs";
8
+ import { fileURLToPath, pathToFileURL } from "node:url";
4
9
  import { createRequire } from "node:module";
5
10
 
6
- const require = createRequire(import.meta.url);
11
+ let require = null;
12
+ let dinouPackageRoot = null;
13
+ try {
14
+ if (typeof import.meta !== "undefined" && import.meta.url) {
15
+ require = createRequire(import.meta.url);
16
+ dinouPackageRoot = path.resolve(
17
+ path.dirname(fileURLToPath(import.meta.url)),
18
+ ".."
19
+ );
20
+ }
21
+ } catch (e) {}
22
+
23
+ export const DINOU_CONFIG_FILENAMES = [
24
+ "dinou.config.ts",
25
+ "dinou.config.mjs",
26
+ "dinou.config.js",
27
+ "dinou.config.cjs",
28
+ ];
29
+
30
+ const ROOT_SETUP_FILENAMES = new Set([
31
+ "dinou.setup.mjs",
32
+ "dinou.setup.js",
33
+ "dinou.setup.ts",
34
+ ]);
7
35
 
8
36
  let dinouConfig = { plugins: [] };
9
- let dinouConfigPromise = null;
37
+ const dinouConfigPromisesByCwd = new Map();
38
+ const devConfigCacheByCwd = new Map();
39
+ let devImportCounter = 0;
40
+ const AUTO_LOADED_PROD_CONFIG = Symbol.for("dinou.autoLoadedProdConfig");
10
41
 
11
- async function getDinouConfig() {
12
- if (typeof globalThis !== "undefined" && globalThis.__DINOU_CONFIG__) {
13
- return globalThis.__DINOU_CONFIG__;
42
+ function resolveCwd(customCwd) {
43
+ return path.resolve(
44
+ customCwd ||
45
+ (typeof process !== "undefined" && typeof process.cwd === "function"
46
+ ? process.cwd()
47
+ : ".")
48
+ );
49
+ }
50
+
51
+ function isActiveDinouDevServer() {
52
+ if (
53
+ typeof globalThis !== "undefined" &&
54
+ Boolean(globalThis.__DINOU_DEV__)
55
+ ) {
56
+ return true;
14
57
  }
15
- if (dinouConfigPromise) return dinouConfigPromise;
16
- dinouConfigPromise = (async () => {
17
- const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
18
- for (const filename of ["dinou.config.ts", "dinou.config.mjs", "dinou.config.js", "dinou.config.cjs"]) {
19
- const p = path.resolve(cwd, filename);
20
- if (existsSync(p)) {
21
- try {
22
- let loaded;
23
- const isDev = process.env.NODE_ENV !== "production";
24
- let esbuild;
25
- if (
26
- typeof process !== "undefined" &&
27
- process.versions &&
28
- process.versions.node &&
29
- process.env.DINOU_RUNTIME !== "edge"
30
- ) {
31
- try {
32
- const req = typeof require === "function" ? require : null;
33
- const esbuildPkg = "esbuild";
34
- if (req) {
35
- esbuild = req(esbuildPkg);
36
- }
37
- } catch (e) {}
38
- }
58
+ if (typeof process !== "undefined" && process.env) {
59
+ return process.env.DINOU_DEV === "true";
60
+ }
61
+ return false;
62
+ }
63
+
64
+ function isDevEnvironment() {
65
+ if (isActiveDinouDevServer()) {
66
+ return true;
67
+ }
68
+ if (typeof process !== "undefined" && process.env) {
69
+ return process.env.NODE_ENV !== "production";
70
+ }
71
+ return false;
72
+ }
73
+
74
+ /**
75
+ * Finds the active `dinou.config.{ts,mjs,js,cjs}` file in `customCwd`,
76
+ * following Dinou's deterministic extension precedence.
77
+ *
78
+ * @param {string} [customCwd]
79
+ * @returns {string | null}
80
+ */
81
+ export function findDinouConfigFile(customCwd) {
82
+ const cwd = resolveCwd(customCwd);
83
+ for (const filename of DINOU_CONFIG_FILENAMES) {
84
+ const candidate = path.resolve(cwd, filename);
85
+ if (existsSync(candidate)) {
86
+ return candidate;
87
+ }
88
+ }
89
+ return null;
90
+ }
91
+
92
+ /**
93
+ * Checks whether `filePath` is a root `dinou.config.*` or `dinou.setup.*` file.
94
+ *
95
+ * @param {string} filePath
96
+ * @param {string} [projectRoot]
97
+ * @returns {boolean}
98
+ */
99
+ export function isWatchedDinouConfigOrSetupFile(filePath, projectRoot) {
100
+ if (!filePath) return false;
101
+ const root = resolveCwd(projectRoot);
102
+ const resolved = path.resolve(filePath);
103
+ if (path.dirname(resolved).toLowerCase() !== root.toLowerCase()) {
104
+ return false;
105
+ }
106
+ const base = path.basename(resolved).toLowerCase();
107
+ return (
108
+ DINOU_CONFIG_FILENAMES.includes(base) || ROOT_SETUP_FILENAMES.has(base)
109
+ );
110
+ }
39
111
 
40
- if (esbuild && typeof esbuild.build === "function") {
41
- const outDir = path.resolve(cwd, ".dinou");
42
- if (!existsSync(outDir)) {
43
- mkdirSync(outDir, { recursive: true });
44
- }
45
- const bundledPath = path.resolve(outDir, "dinou.config.bundled.mjs");
46
- await esbuild.build({
47
- entryPoints: [p],
48
- outfile: bundledPath,
49
- bundle: true,
50
- format: "esm",
51
- platform: "node",
52
- packages: "external",
53
- sourcemap: "inline",
54
- plugins: [
55
- {
56
- name: "dinou-config-alias",
57
- setup(build) {
58
- build.onResolve({ filter: /^dinou$/ }, () => {
59
- return { path: "dinou/config", external: true };
60
- });
61
- },
62
- },
63
- ],
64
- });
65
- loaded = await import(pathToFileURL(bundledPath).href + (isDev ? `?t=${Date.now()}` : ""));
66
- } else if (p.endsWith(".mjs")) {
67
- loaded = await import(pathToFileURL(p).href + (isDev ? `?t=${Date.now()}` : ""));
68
- } else {
69
- const nodeReq =
70
- typeof globalThis !== "undefined" && typeof globalThis.__dinou_require__ === "function"
71
- ? globalThis.__dinou_require__
72
- : typeof require === "function"
73
- ? require
74
- : null;
75
- if (nodeReq) {
76
- try {
77
- loaded = nodeReq(p);
78
- } catch (e) {
79
- loaded = await import(pathToFileURL(p).href + (isDev ? `?t=${Date.now()}` : ""));
80
- }
81
- } else {
82
- loaded = await import(pathToFileURL(p).href + (isDev ? `?t=${Date.now()}` : ""));
83
- }
112
+ /**
113
+ * Clears cached Dinou configuration for `customCwd` (or all directories when omitted).
114
+ * Used by `dinou dev` live hot-reloading and test suites.
115
+ *
116
+ * @param {string} [customCwd]
117
+ */
118
+ export function clearDinouConfigCache(customCwd) {
119
+ if (customCwd) {
120
+ const cwd = resolveCwd(customCwd);
121
+ dinouConfigPromisesByCwd.delete(cwd);
122
+ devConfigCacheByCwd.delete(cwd);
123
+ if (
124
+ typeof globalThis !== "undefined" &&
125
+ !globalThis.__DINOU_AOT_CONFIG__ &&
126
+ (!globalThis.__DINOU_CONFIG_CWD__ ||
127
+ globalThis.__DINOU_CONFIG_CWD__ === cwd)
128
+ ) {
129
+ delete globalThis.__DINOU_CONFIG__;
130
+ delete globalThis.__DINOU_CONFIG_CWD__;
131
+ }
132
+ } else {
133
+ dinouConfigPromisesByCwd.clear();
134
+ devConfigCacheByCwd.clear();
135
+ if (
136
+ typeof globalThis !== "undefined" &&
137
+ !globalThis.__DINOU_AOT_CONFIG__
138
+ ) {
139
+ delete globalThis.__DINOU_CONFIG__;
140
+ delete globalThis.__DINOU_CONFIG_CWD__;
141
+ }
142
+ }
143
+ }
144
+
145
+ function getLocalEsbuild(cwd) {
146
+ if (
147
+ typeof process === "undefined" ||
148
+ !process.versions ||
149
+ !process.versions.node ||
150
+ (process.env && process.env.DINOU_RUNTIME === "edge")
151
+ ) {
152
+ return null;
153
+ }
154
+ const esbuildPkg = "esbuild";
155
+ try {
156
+ if (typeof require === "function") {
157
+ return require(esbuildPkg);
158
+ }
159
+ } catch (e) {}
160
+ try {
161
+ const projectReq = createRequire(path.join(cwd, "package.json"));
162
+ return projectReq(esbuildPkg);
163
+ } catch (e) {}
164
+ return null;
165
+ }
166
+
167
+ function resolveActiveDinouRoot(cwd) {
168
+ const ejectedCandidate = path.resolve(cwd, "dinou");
169
+ if (
170
+ existsSync(ejectedCandidate) &&
171
+ existsSync(path.join(ejectedCandidate, "core", "config.js"))
172
+ ) {
173
+ return ejectedCandidate;
174
+ }
175
+ if (
176
+ dinouPackageRoot &&
177
+ existsSync(path.join(dinouPackageRoot, "core", "config.js"))
178
+ ) {
179
+ return dinouPackageRoot;
180
+ }
181
+ const nmNested = path.resolve(cwd, "node_modules", "dinou", "dinou");
182
+ if (existsSync(path.join(nmNested, "core", "config.js"))) {
183
+ return nmNested;
184
+ }
185
+ const nmFlat = path.resolve(cwd, "node_modules", "dinou");
186
+ if (existsSync(path.join(nmFlat, "core", "config.js"))) {
187
+ return nmFlat;
188
+ }
189
+ return null;
190
+ }
191
+
192
+ function createEsbuildDinouConfigPlugin(cwd, outDir = cwd) {
193
+ const activeDinouRoot = resolveActiveDinouRoot(cwd);
194
+ return {
195
+ name: "dinou-config-alias",
196
+ setup(build) {
197
+ build.onResolve({ filter: /^dinou(?:\/config)?$/ }, () => {
198
+ if (activeDinouRoot) {
199
+ return { path: path.join(activeDinouRoot, "core", "config.js") };
200
+ }
201
+ return { path: "dinou/config", external: true };
202
+ });
203
+ build.onResolve({ filter: /^dinou\/server$/ }, () => {
204
+ if (activeDinouRoot) {
205
+ const serverAbs = path.join(activeDinouRoot, "server.js");
206
+ const rel = path.relative(outDir, serverAbs).replace(/\\/g, "/");
207
+ if (rel && !path.isAbsolute(rel)) {
208
+ return {
209
+ path: rel.startsWith(".") ? rel : "./" + rel,
210
+ external: true,
211
+ };
84
212
  }
85
- const cfg = loaded && loaded.default ? loaded.default : loaded || { plugins: [] };
86
- dinouConfig = cfg;
87
- return cfg;
88
- } catch (err) {
89
- console.error(`[Dinou] Error loading ${filename}:`, err);
213
+ return { path: serverAbs };
90
214
  }
215
+ return { path: "dinou/server", external: true };
216
+ });
217
+ },
218
+ };
219
+ }
220
+
221
+ /**
222
+ * Emits a pre-transpiled pure-ESM server bootstrap and bundler entry wrappers
223
+ * into `.dinou/dist1/` so Esbuild, Rollup, and Webpack production server builds
224
+ * (`.dinou/dist1/server/handler.js` & `netlify.js`) as well as `--omit=dev`
225
+ * Node runtimes execute `setupFiles` and load `dinou.config.*` without needing
226
+ * `esbuild` or TypeScript loaders at runtime.
227
+ *
228
+ * @param {object} options
229
+ * @param {string} [options.projectRoot]
230
+ * @param {string[]} [options.setupFiles]
231
+ * @param {string} options.handlerPath
232
+ * @param {string} options.netlifyPath
233
+ * @returns {Promise<{ handlerEntry: string, netlifyEntry: string, bootstrapPath: string | null }>}
234
+ */
235
+ export async function prepareDist1ServerEntries({
236
+ projectRoot,
237
+ setupFiles = [],
238
+ handlerPath,
239
+ netlifyPath,
240
+ }) {
241
+ const cwd = resolveCwd(projectRoot);
242
+ const configFile = findDinouConfigFile(cwd);
243
+ if ((!setupFiles || setupFiles.length === 0) && !configFile) {
244
+ return {
245
+ handlerEntry: handlerPath,
246
+ netlifyEntry: netlifyPath,
247
+ bootstrapPath: null,
248
+ };
249
+ }
250
+
251
+ const dist1Dir = path.resolve(cwd, ".dinou", "dist1");
252
+ const entriesDir = path.join(dist1Dir, "_entries");
253
+ mkdirSync(entriesDir, { recursive: true });
254
+
255
+ const rawBootstrapPath = path.join(entriesDir, "raw-server-bootstrap.mjs");
256
+ const compiledBootstrapPath = path.join(dist1Dir, "dinou-server-bootstrap.mjs");
257
+
258
+ let rawCode = "// Auto-generated Dinou server bootstrap (setupFiles + dinou.config)\n";
259
+ for (const sf of setupFiles) {
260
+ rawCode += `import ${JSON.stringify(sf.replace(/\\/g, "/"))};\n`;
261
+ }
262
+ if (configFile) {
263
+ rawCode += `import * as __dinouConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};\n`;
264
+ rawCode += `const __resolvedDinouCfg = (__dinouConfigMod && __dinouConfigMod.default) ? __dinouConfigMod.default : (__dinouConfigMod || { plugins: [] });\n`;
265
+ rawCode += `globalThis.__DINOU_AOT_CONFIG__ = __resolvedDinouCfg;\n`;
266
+ rawCode += `globalThis.__DINOU_CONFIG__ = __resolvedDinouCfg;\n`;
267
+ rawCode += `globalThis.__DINOU_CONFIG_CWD__ = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";\n`;
268
+ rawCode += `export default __resolvedDinouCfg;\n`;
269
+ } else {
270
+ rawCode += `export default { plugins: [] };\n`;
271
+ }
272
+
273
+ writeFileSync(rawBootstrapPath, rawCode, "utf8");
274
+
275
+ const esbuild = getLocalEsbuild(cwd);
276
+ if (esbuild && typeof esbuild.build === "function") {
277
+ const { esbuildTsconfigAliasesPlugin } = await import(
278
+ "./tsconfig-aliases.js"
279
+ );
280
+ await esbuild.build({
281
+ entryPoints: [rawBootstrapPath],
282
+ outfile: compiledBootstrapPath,
283
+ bundle: true,
284
+ format: "esm",
285
+ platform: "node",
286
+ target: "node20",
287
+ packages: "external",
288
+ jsx: "automatic",
289
+ loader: {
290
+ ".js": "jsx",
291
+ ".jsx": "jsx",
292
+ ".ts": "ts",
293
+ ".tsx": "tsx",
294
+ ".json": "json",
295
+ ".css": "empty",
296
+ },
297
+ plugins: [
298
+ createEsbuildDinouConfigPlugin(cwd, dist1Dir),
299
+ esbuildTsconfigAliasesPlugin({
300
+ projectRoot: cwd,
301
+ skipAssets: false,
302
+ }),
303
+ ],
304
+ });
305
+ } else {
306
+ writeFileSync(compiledBootstrapPath, rawCode, "utf8");
307
+ }
308
+
309
+ const bootstrapSlash = compiledBootstrapPath.replace(/\\/g, "/");
310
+ const handlerSlash = handlerPath.replace(/\\/g, "/");
311
+ const netlifySlash = netlifyPath.replace(/\\/g, "/");
312
+
313
+ const handlerWrapperPath = path.join(entriesDir, "handler.mjs");
314
+ const netlifyWrapperPath = path.join(entriesDir, "netlify.mjs");
315
+
316
+ writeFileSync(
317
+ handlerWrapperPath,
318
+ `import * as __boot from ${JSON.stringify(bootstrapSlash)};\nglobalThis.__DINOU_BOOTSTRAPPED__ = Boolean(__boot);\nexport * from ${JSON.stringify(handlerSlash)};\nexport { default } from ${JSON.stringify(handlerSlash)};\n`,
319
+ "utf8"
320
+ );
321
+ writeFileSync(
322
+ netlifyWrapperPath,
323
+ `import * as __boot from ${JSON.stringify(bootstrapSlash)};\nglobalThis.__DINOU_BOOTSTRAPPED__ = Boolean(__boot);\nexport * from ${JSON.stringify(netlifySlash)};\nexport { default } from ${JSON.stringify(netlifySlash)};\n`,
324
+ "utf8"
325
+ );
326
+
327
+ return {
328
+ handlerEntry: handlerWrapperPath,
329
+ netlifyEntry: netlifyWrapperPath,
330
+ bootstrapPath: compiledBootstrapPath,
331
+ };
332
+ }
333
+
334
+ async function loadConfigFromDisk(cwd, isDev, configFile) {
335
+ if (!configFile) {
336
+ const prebuiltDist1 = path.resolve(
337
+ cwd,
338
+ ".dinou",
339
+ "dist1",
340
+ "dinou-server-bootstrap.mjs"
341
+ );
342
+ if (!isDev && existsSync(prebuiltDist1)) {
343
+ try {
344
+ const mod = await import(pathToFileURL(prebuiltDist1).href);
345
+ const cfg = mod && mod.default ? mod.default : mod || { plugins: [] };
346
+ dinouConfig = cfg;
347
+ return cfg;
348
+ } catch (e) {}
349
+ }
350
+ const fallback = { plugins: [] };
351
+ dinouConfig = fallback;
352
+ return fallback;
353
+ }
354
+
355
+ const filename = path.basename(configFile);
356
+ try {
357
+ let loaded;
358
+ const prebuiltDist1 = path.resolve(
359
+ cwd,
360
+ ".dinou",
361
+ "dist1",
362
+ "dinou-server-bootstrap.mjs"
363
+ );
364
+ const esbuild = getLocalEsbuild(cwd);
365
+
366
+ if (!isDev && !esbuild && existsSync(prebuiltDist1)) {
367
+ loaded = await import(pathToFileURL(prebuiltDist1).href);
368
+ } else if (esbuild && typeof esbuild.build === "function") {
369
+ const outDir = path.resolve(cwd, ".dinou");
370
+ if (!existsSync(outDir)) {
371
+ mkdirSync(outDir, { recursive: true });
372
+ }
373
+ const bundledPath = path.resolve(outDir, "dinou.config.bundled.mjs");
374
+ const { esbuildTsconfigAliasesPlugin } = await import(
375
+ "./tsconfig-aliases.js"
376
+ );
377
+ await esbuild.build({
378
+ entryPoints: [configFile],
379
+ outfile: bundledPath,
380
+ bundle: true,
381
+ format: "esm",
382
+ platform: "node",
383
+ packages: "external",
384
+ jsx: "automatic",
385
+ sourcemap: "inline",
386
+ plugins: [
387
+ createEsbuildDinouConfigPlugin(cwd, outDir),
388
+ esbuildTsconfigAliasesPlugin({
389
+ projectRoot: cwd,
390
+ skipAssets: false,
391
+ }),
392
+ ],
393
+ });
394
+ const cacheBuster = isDev
395
+ ? `?t=${Date.now()}-${++devImportCounter}`
396
+ : "";
397
+ loaded = await import(pathToFileURL(bundledPath).href + cacheBuster);
398
+ } else if (!isDev && existsSync(prebuiltDist1)) {
399
+ loaded = await import(pathToFileURL(prebuiltDist1).href);
400
+ } else if (configFile.endsWith(".mjs")) {
401
+ const cacheBuster = isDev
402
+ ? `?t=${Date.now()}-${++devImportCounter}`
403
+ : "";
404
+ loaded = await import(pathToFileURL(configFile).href + cacheBuster);
405
+ } else {
406
+ const nodeReq =
407
+ typeof globalThis !== "undefined" &&
408
+ typeof globalThis.__dinou_require__ === "function"
409
+ ? globalThis.__dinou_require__
410
+ : typeof require === "function"
411
+ ? require
412
+ : null;
413
+ if (nodeReq && !isDev) {
414
+ try {
415
+ loaded = nodeReq(configFile);
416
+ } catch (e) {
417
+ loaded = await import(pathToFileURL(configFile).href);
418
+ }
419
+ } else {
420
+ const cacheBuster = isDev
421
+ ? `?t=${Date.now()}-${++devImportCounter}`
422
+ : "";
423
+ loaded = await import(pathToFileURL(configFile).href + cacheBuster);
91
424
  }
92
425
  }
93
- return dinouConfig;
94
- })();
95
- return dinouConfigPromise;
426
+
427
+ const cfg =
428
+ loaded && loaded.default ? loaded.default : loaded || { plugins: [] };
429
+ dinouConfig = cfg;
430
+ if (!isDev && typeof globalThis !== "undefined") {
431
+ if (cfg && typeof cfg === "object") {
432
+ try {
433
+ Object.defineProperty(cfg, AUTO_LOADED_PROD_CONFIG, {
434
+ value: true,
435
+ configurable: true,
436
+ });
437
+ } catch (e) {}
438
+ }
439
+ globalThis.__DINOU_CONFIG__ = cfg;
440
+ globalThis.__DINOU_CONFIG_CWD__ = cwd;
441
+ }
442
+ return cfg;
443
+ } catch (err) {
444
+ console.error(`[Dinou] Error loading ${filename}:`, err);
445
+ const fallback = { plugins: [] };
446
+ dinouConfig = fallback;
447
+ return fallback;
448
+ }
449
+ }
450
+
451
+ async function getDinouConfig(customCwd) {
452
+ const cwd = resolveCwd(customCwd);
453
+ const isDev = isDevEnvironment();
454
+
455
+ if (
456
+ typeof globalThis !== "undefined" &&
457
+ globalThis.__DINOU_AOT_CONFIG__ &&
458
+ (!globalThis.__DINOU_CONFIG_CWD__ ||
459
+ globalThis.__DINOU_CONFIG_CWD__ === cwd)
460
+ ) {
461
+ dinouConfig = globalThis.__DINOU_AOT_CONFIG__;
462
+ return globalThis.__DINOU_AOT_CONFIG__;
463
+ }
464
+
465
+ if (
466
+ typeof globalThis !== "undefined" &&
467
+ globalThis.__DINOU_CONFIG__ &&
468
+ !isActiveDinouDevServer() &&
469
+ (!isDev || !globalThis.__DINOU_CONFIG__[AUTO_LOADED_PROD_CONFIG]) &&
470
+ (!globalThis.__DINOU_CONFIG_CWD__ ||
471
+ globalThis.__DINOU_CONFIG_CWD__ === cwd)
472
+ ) {
473
+ dinouConfig = globalThis.__DINOU_CONFIG__;
474
+ return globalThis.__DINOU_CONFIG__;
475
+ }
476
+
477
+ if (!isDev && dinouConfigPromisesByCwd.has(cwd)) {
478
+ return dinouConfigPromisesByCwd.get(cwd);
479
+ }
480
+
481
+ if (isDev) {
482
+ const configFile = findDinouConfigFile(cwd);
483
+ let mtimeMs = 0;
484
+ if (configFile) {
485
+ try {
486
+ mtimeMs = statSync(configFile).mtimeMs;
487
+ } catch (e) {}
488
+ }
489
+ const cachedDev = devConfigCacheByCwd.get(cwd);
490
+ if (
491
+ cachedDev &&
492
+ cachedDev.filePath === configFile &&
493
+ cachedDev.mtimeMs === mtimeMs
494
+ ) {
495
+ if (cachedDev.promise) return cachedDev.promise;
496
+ dinouConfig = cachedDev.config;
497
+ return cachedDev.config;
498
+ }
499
+
500
+ const devPromise = loadConfigFromDisk(cwd, true, configFile).then((cfg) => {
501
+ devConfigCacheByCwd.set(cwd, {
502
+ filePath: configFile,
503
+ mtimeMs,
504
+ config: cfg,
505
+ promise: null,
506
+ });
507
+ return cfg;
508
+ });
509
+ devConfigCacheByCwd.set(cwd, {
510
+ filePath: configFile,
511
+ mtimeMs,
512
+ config: null,
513
+ promise: devPromise,
514
+ });
515
+ return devPromise;
516
+ }
517
+
518
+ const configFile = findDinouConfigFile(cwd);
519
+ const loadPromise = loadConfigFromDisk(cwd, false, configFile);
520
+ dinouConfigPromisesByCwd.set(cwd, loadPromise);
521
+ return loadPromise;
96
522
  }
97
523
 
98
- // Initial sync attempt if already set on globalThis
99
- if (typeof globalThis !== "undefined" && globalThis.__DINOU_CONFIG__) {
100
- dinouConfig = globalThis.__DINOU_CONFIG__;
524
+ if (
525
+ typeof globalThis !== "undefined" &&
526
+ (globalThis.__DINOU_AOT_CONFIG__ || globalThis.__DINOU_CONFIG__)
527
+ ) {
528
+ dinouConfig = globalThis.__DINOU_AOT_CONFIG__ || globalThis.__DINOU_CONFIG__;
101
529
  }
102
530
 
103
- export {
104
- getDinouConfig,
105
- };
531
+ export { getDinouConfig };
106
532
  export default {
107
533
  getDinouConfig,
534
+ findDinouConfigFile,
535
+ isWatchedDinouConfigOrSetupFile,
536
+ clearDinouConfigCache,
537
+ prepareDist1ServerEntries,
538
+ DINOU_CONFIG_FILENAMES,
108
539
  };
@@ -17,29 +17,19 @@ function isDevMode() {
17
17
  );
18
18
  }
19
19
 
20
- function getOutputFolder() {
21
- return isDevMode() ? ".dinou/public" : ".dinou/dist3";
22
- }
23
-
24
20
  function getClientManifestPath() {
25
- const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
26
- const outputFolder = getOutputFolder();
27
21
  return path.resolve(
28
22
  process.cwd(),
29
- isWebpack
30
- ? `${outputFolder}/react-client-manifest.json`
31
- : `.dinou/react_client_manifest/react-client-manifest.json`
23
+ isDevMode() ? ".dinou/node-dev" : ".dinou/dist1",
24
+ "react-client-manifest.json"
32
25
  );
33
26
  }
34
27
 
35
28
  function getServerFunctionsManifestPath() {
36
- const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
37
- const outputFolder = getOutputFolder();
38
29
  return path.resolve(
39
30
  process.cwd(),
40
- isWebpack
41
- ? `${outputFolder}/server-functions-manifest.json`
42
- : `.dinou/server_functions_manifest/server-functions-manifest.json`
31
+ isDevMode() ? ".dinou/node-dev" : ".dinou/dist1",
32
+ "server-functions-manifest.json"
43
33
  );
44
34
  }
45
35