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
@@ -0,0 +1,640 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import readline from "node:readline";
4
+ import { spawn, spawnSync } from "node:child_process";
5
+
6
+ export const DINOU_CLI_COMMANDS = [
7
+ "dev",
8
+ "build",
9
+ "start",
10
+ "dev:esbuild",
11
+ "dev:rollup",
12
+ "dev:webpack",
13
+ "build:node",
14
+ "build:node:esbuild",
15
+ "build:node:rollup",
16
+ "build:node:webpack",
17
+ "build:node:compile",
18
+ "build:node:compile:esbuild",
19
+ "build:node:compile:rollup",
20
+ "build:node:compile:webpack",
21
+ "build:node:compile:linux",
22
+ "build:node:compile:linux:esbuild",
23
+ "build:node:compile:linux:rollup",
24
+ "build:node:compile:linux:webpack",
25
+ "build:node:compile:linux_arm",
26
+ "build:node:compile:linux_arm:esbuild",
27
+ "build:node:compile:linux_arm:rollup",
28
+ "build:node:compile:linux_arm:webpack",
29
+ "build:node:compile:mac",
30
+ "build:node:compile:mac:esbuild",
31
+ "build:node:compile:mac:rollup",
32
+ "build:node:compile:mac:webpack",
33
+ "build:node:compile:win",
34
+ "build:node:compile:win:esbuild",
35
+ "build:node:compile:win:rollup",
36
+ "build:node:compile:win:webpack",
37
+ "build:node:pure",
38
+ "build:node:pure:esbuild",
39
+ "build:node:pure:rollup",
40
+ "build:node:pure:webpack",
41
+ "build:node:pure:compile",
42
+ "build:node:pure:compile:esbuild",
43
+ "build:node:pure:compile:rollup",
44
+ "build:node:pure:compile:webpack",
45
+ "build:node:pure:compile:linux",
46
+ "build:node:pure:compile:linux:esbuild",
47
+ "build:node:pure:compile:linux:rollup",
48
+ "build:node:pure:compile:linux:webpack",
49
+ "build:node:pure:compile:linux_arm",
50
+ "build:node:pure:compile:linux_arm:esbuild",
51
+ "build:node:pure:compile:linux_arm:rollup",
52
+ "build:node:pure:compile:linux_arm:webpack",
53
+ "build:node:pure:compile:mac",
54
+ "build:node:pure:compile:mac:esbuild",
55
+ "build:node:pure:compile:mac:rollup",
56
+ "build:node:pure:compile:mac:webpack",
57
+ "build:node:pure:compile:win",
58
+ "build:node:pure:compile:win:esbuild",
59
+ "build:node:pure:compile:win:rollup",
60
+ "build:node:pure:compile:win:webpack",
61
+ "start:node",
62
+ "start:node:esbuild",
63
+ "start:node:rollup",
64
+ "start:node:webpack",
65
+ "build:netlify",
66
+ "build:netlify:esbuild",
67
+ "build:netlify:rollup",
68
+ "build:netlify:webpack",
69
+ "build:cloudflare",
70
+ "build:cloudflare:esbuild",
71
+ "build:cloudflare:rollup",
72
+ "build:cloudflare:webpack",
73
+ "build:deno",
74
+ "build:deno:esbuild",
75
+ "build:deno:rollup",
76
+ "build:deno:webpack",
77
+ "build:deno:compile",
78
+ "build:deno:compile:esbuild",
79
+ "build:deno:compile:rollup",
80
+ "build:deno:compile:webpack",
81
+ "build:deno:compile:linux",
82
+ "build:deno:compile:linux:esbuild",
83
+ "build:deno:compile:linux:rollup",
84
+ "build:deno:compile:linux:webpack",
85
+ "build:deno:compile:linux_arm",
86
+ "build:deno:compile:linux_arm:esbuild",
87
+ "build:deno:compile:linux_arm:rollup",
88
+ "build:deno:compile:linux_arm:webpack",
89
+ "build:deno:compile:mac",
90
+ "build:deno:compile:mac:esbuild",
91
+ "build:deno:compile:mac:rollup",
92
+ "build:deno:compile:mac:webpack",
93
+ "build:deno:compile:win",
94
+ "build:deno:compile:win:esbuild",
95
+ "build:deno:compile:win:rollup",
96
+ "build:deno:compile:win:webpack",
97
+ "start:deno",
98
+ "build:bun",
99
+ "build:bun:esbuild",
100
+ "build:bun:rollup",
101
+ "build:bun:webpack",
102
+ "build:bun:compile",
103
+ "build:bun:compile:esbuild",
104
+ "build:bun:compile:rollup",
105
+ "build:bun:compile:webpack",
106
+ "build:bun:compile:linux",
107
+ "build:bun:compile:linux:esbuild",
108
+ "build:bun:compile:linux:rollup",
109
+ "build:bun:compile:linux:webpack",
110
+ "build:bun:compile:linux_arm",
111
+ "build:bun:compile:linux_arm:esbuild",
112
+ "build:bun:compile:linux_arm:rollup",
113
+ "build:bun:compile:linux_arm:webpack",
114
+ "build:bun:compile:mac",
115
+ "build:bun:compile:mac:esbuild",
116
+ "build:bun:compile:mac:rollup",
117
+ "build:bun:compile:mac:webpack",
118
+ "build:bun:compile:win",
119
+ "build:bun:compile:win:esbuild",
120
+ "build:bun:compile:win:rollup",
121
+ "build:bun:compile:win:webpack",
122
+ "build:bun:pure",
123
+ "build:bun:pure:esbuild",
124
+ "build:bun:pure:rollup",
125
+ "build:bun:pure:webpack",
126
+ "build:bun:pure:compile",
127
+ "build:bun:pure:compile:esbuild",
128
+ "build:bun:pure:compile:rollup",
129
+ "build:bun:pure:compile:webpack",
130
+ "build:bun:pure:compile:linux",
131
+ "build:bun:pure:compile:linux:esbuild",
132
+ "build:bun:pure:compile:linux:rollup",
133
+ "build:bun:pure:compile:linux:webpack",
134
+ "build:bun:pure:compile:linux_arm",
135
+ "build:bun:pure:compile:linux_arm:esbuild",
136
+ "build:bun:pure:compile:linux_arm:rollup",
137
+ "build:bun:pure:compile:linux_arm:webpack",
138
+ "build:bun:pure:compile:mac",
139
+ "build:bun:pure:compile:mac:esbuild",
140
+ "build:bun:pure:compile:mac:rollup",
141
+ "build:bun:pure:compile:mac:webpack",
142
+ "build:bun:pure:compile:win",
143
+ "build:bun:pure:compile:win:esbuild",
144
+ "build:bun:pure:compile:win:rollup",
145
+ "build:bun:pure:compile:win:webpack",
146
+ "start:bun",
147
+ "start:bun:esbuild",
148
+ "start:bun:rollup",
149
+ "start:bun:webpack",
150
+ "export-static",
151
+ "export-static:esbuild",
152
+ "export-static:rollup",
153
+ "export-static:webpack",
154
+ "typegen",
155
+ ];
156
+
157
+ const DINOU_CLI_COMMANDS_SET = new Set(DINOU_CLI_COMMANDS);
158
+ const STANDALONE_DINOU_BIN_RE = /(?<![./\\@-])\b(?:npx\s+)?dinou\b(?![/\\.-])/g;
159
+ const EJECTED_DINOU_CLI_RE = /\bnode\s+(?:\.[\\/])?dinou[\\/]cli\.js\b/g;
160
+ const WIN_LOCK_ERROR_CODES = new Set(["EPERM", "EBUSY", "ENOTEMPTY", "EACCES"]);
161
+
162
+ function scheduleDeferredRemoveOnWindows(targetDir) {
163
+ try {
164
+ const script =
165
+ "const fs=require('node:fs');const dir=process.argv[1];" +
166
+ "setTimeout(()=>{try{fs.rmSync(dir,{recursive:true,force:true,maxRetries:20,retryDelay:250});}catch{}},400);";
167
+ const child = spawn(process.execPath, ["-e", script, targetDir], {
168
+ detached: true,
169
+ stdio: "ignore",
170
+ windowsHide: true,
171
+ });
172
+ child.unref();
173
+ return true;
174
+ } catch {
175
+ return false;
176
+ }
177
+ }
178
+
179
+ function removeDinouDirSafely(targetDir, { allowDeferredFallback = false } = {}) {
180
+ try {
181
+ fs.rmSync(targetDir, {
182
+ recursive: true,
183
+ force: true,
184
+ maxRetries: 10,
185
+ retryDelay: 150,
186
+ });
187
+ return { removed: true, deferred: false, error: null };
188
+ } catch (err) {
189
+ const isWinLock =
190
+ process.platform === "win32" &&
191
+ err &&
192
+ typeof err.code === "string" &&
193
+ WIN_LOCK_ERROR_CODES.has(err.code);
194
+
195
+ if (allowDeferredFallback && isWinLock) {
196
+ const deferred = scheduleDeferredRemoveOnWindows(targetDir);
197
+ return { removed: false, deferred, error: err };
198
+ }
199
+
200
+ if (allowDeferredFallback) {
201
+ return { removed: false, deferred: false, error: err };
202
+ }
203
+
204
+ throw err;
205
+ }
206
+ }
207
+
208
+ export function detectPackageManager(projectRoot = process.cwd()) {
209
+ const userAgent = process.env.npm_config_user_agent;
210
+ if (userAgent) {
211
+ if (userAgent.startsWith("yarn")) return "yarn";
212
+ if (userAgent.startsWith("pnpm")) return "pnpm";
213
+ if (userAgent.startsWith("bun")) return "bun";
214
+ if (userAgent.startsWith("npm")) return "npm";
215
+ }
216
+
217
+ if (fs.existsSync(path.join(projectRoot, "yarn.lock"))) return "yarn";
218
+ if (fs.existsSync(path.join(projectRoot, "pnpm-lock.yaml"))) return "pnpm";
219
+ if (
220
+ fs.existsSync(path.join(projectRoot, "bun.lockb")) ||
221
+ fs.existsSync(path.join(projectRoot, "bun.lock"))
222
+ ) {
223
+ return "bun";
224
+ }
225
+ if (fs.existsSync(path.join(projectRoot, "package-lock.json"))) return "npm";
226
+
227
+ return "npm";
228
+ }
229
+
230
+ function quoteShellArg(arg) {
231
+ const str = String(arg);
232
+ if (!/[\s"&|<>^()]/.test(str)) return str;
233
+ return `"${str.replace(/"/g, '\\"')}"`;
234
+ }
235
+
236
+ export function runPackageManager(pm, args, cwd) {
237
+ let result = spawnSync(pm, args, {
238
+ stdio: "inherit",
239
+ cwd,
240
+ env: process.env,
241
+ });
242
+
243
+ if (
244
+ result.error &&
245
+ process.platform === "win32" &&
246
+ (result.error.code === "ENOENT" || result.error.code === "EINVAL")
247
+ ) {
248
+ const cmdLine = [pm, ...args.map(quoteShellArg)].join(" ");
249
+ result = spawnSync(cmdLine, {
250
+ stdio: "inherit",
251
+ cwd,
252
+ env: process.env,
253
+ shell: true,
254
+ });
255
+ }
256
+
257
+ return result;
258
+ }
259
+
260
+ function isProtocolOrTarballSpec(spec) {
261
+ if (!spec || typeof spec !== "string") return false;
262
+ return (
263
+ spec.startsWith("file:") ||
264
+ spec.startsWith("link:") ||
265
+ spec.startsWith("workspace:") ||
266
+ spec.startsWith("http:") ||
267
+ spec.startsWith("https:") ||
268
+ spec.startsWith("git+") ||
269
+ spec.startsWith("github:") ||
270
+ spec.endsWith(".tgz")
271
+ );
272
+ }
273
+
274
+ /**
275
+ * Rewrites `package.json` in place for Ejected Mode:
276
+ * - Only rewrites Dinou scripts that already existed in `pkg.scripts`
277
+ * (comparing against `DINOU_CLI_COMMANDS` as well as custom scripts invoking `dinou`),
278
+ * preserving all non-Dinou scripts (`lint`, `test`, `clean`, etc.) untouched.
279
+ * - Removes `"eject"` and adds `"build:vendors"` + `"uneject"`.
280
+ * - Removes `devDependencies.dinou` if present and sets `dependencies.dinou = "file:./dinou"`.
281
+ */
282
+ export function rewritePackageJsonForEject(pkg) {
283
+ pkg.scripts = pkg.scripts || {};
284
+ delete pkg.scripts.eject;
285
+
286
+ for (const [name, value] of Object.entries(pkg.scripts)) {
287
+ if (typeof value !== "string") continue;
288
+ const trimmed = value.trim();
289
+
290
+ if (DINOU_CLI_COMMANDS_SET.has(name)) {
291
+ if (
292
+ trimmed === `dinou ${name}` ||
293
+ trimmed === `npx dinou ${name}` ||
294
+ trimmed === `node dinou/cli.js ${name}` ||
295
+ trimmed === `node ./dinou/cli.js ${name}` ||
296
+ (name === "dev" && (trimmed === "dinou" || trimmed === "npx dinou"))
297
+ ) {
298
+ pkg.scripts[name] = `node dinou/cli.js ${name}`;
299
+ } else if (STANDALONE_DINOU_BIN_RE.test(value)) {
300
+ STANDALONE_DINOU_BIN_RE.lastIndex = 0;
301
+ pkg.scripts[name] = value.replace(
302
+ STANDALONE_DINOU_BIN_RE,
303
+ "node dinou/cli.js"
304
+ );
305
+ }
306
+ STANDALONE_DINOU_BIN_RE.lastIndex = 0;
307
+ continue;
308
+ }
309
+
310
+ if (STANDALONE_DINOU_BIN_RE.test(value)) {
311
+ STANDALONE_DINOU_BIN_RE.lastIndex = 0;
312
+ pkg.scripts[name] = value.replace(
313
+ STANDALONE_DINOU_BIN_RE,
314
+ "node dinou/cli.js"
315
+ );
316
+ }
317
+ STANDALONE_DINOU_BIN_RE.lastIndex = 0;
318
+ }
319
+
320
+ pkg.scripts["build:vendors"] = "node dinou/cli.js build:vendors";
321
+ pkg.scripts.uneject = "node dinou/cli.js uneject";
322
+
323
+ pkg.dependencies = pkg.dependencies || {};
324
+ if (pkg.devDependencies && "dinou" in pkg.devDependencies) {
325
+ delete pkg.devDependencies.dinou;
326
+ if (Object.keys(pkg.devDependencies).length === 0) {
327
+ delete pkg.devDependencies;
328
+ }
329
+ }
330
+ pkg.dependencies.dinou = "file:./dinou";
331
+
332
+ return pkg;
333
+ }
334
+
335
+ /**
336
+ * Core implementation of `dinou eject`, parameterized by `sourceDinouDir` so:
337
+ * 1. Upstream `<pkgRoot>/eject.js` is a thin wrapper passing `path.resolve(__dirname, "dinou")`.
338
+ * 2. Ejected test workspaces (such as `dinou-e2e`, which contain `./dinou` without a root `eject.js`)
339
+ * can test 100% of the eject implementation directly from `./dinou/core/uneject.js`.
340
+ *
341
+ * @param {object} [options]
342
+ * @param {string} options.sourceDinouDir Path to the source `dinou/` framework directory to copy from.
343
+ * @param {string} [options.projectRoot=process.cwd()] Target project root directory.
344
+ * @param {boolean} [options.force=false] Overwrite an existing `./dinou` directory.
345
+ * @param {boolean} [options.skipInstall=false] Skip running `<pm> install` after updating `package.json`.
346
+ */
347
+ export function runEject(options = {}) {
348
+ const projectRoot = path.resolve(options.projectRoot || process.cwd());
349
+ const sourceDinouDir = path.resolve(
350
+ options.sourceDinouDir || path.resolve(projectRoot, "node_modules", "dinou", "dinou")
351
+ );
352
+ const targetDinouDir = path.resolve(projectRoot, "dinou");
353
+ const pkgPath = path.resolve(projectRoot, "package.json");
354
+ const force = Boolean(options.force);
355
+ const skipInstall =
356
+ Boolean(options.skipInstall) || process.env.DINOU_SKIP_INSTALL === "true";
357
+
358
+ if (!fs.existsSync(sourceDinouDir)) {
359
+ throw new Error(
360
+ `[Dinou Eject] Source framework directory not found at ${sourceDinouDir}`
361
+ );
362
+ }
363
+
364
+ if (!fs.existsSync(pkgPath)) {
365
+ throw new Error(
366
+ `[Dinou Eject] package.json not found in project root (${projectRoot})`
367
+ );
368
+ }
369
+
370
+ const normSource = sourceDinouDir.replace(/\\/g, "/").toLowerCase();
371
+ const normTarget = targetDinouDir.replace(/\\/g, "/").toLowerCase();
372
+ if (normSource === normTarget) {
373
+ console.log(
374
+ "ℹ️ [Dinou Eject] Project is already running from ./dinou. Skipping to protect local customizations."
375
+ );
376
+ return { skipped: true };
377
+ }
378
+
379
+ if (fs.existsSync(targetDinouDir) && !force) {
380
+ console.log(
381
+ 'ℹ️ [Dinou Eject] Directory ./dinou already exists. Skipping to prevent overwriting local customizations (pass --force to overwrite, or run "npm run uneject" first).'
382
+ );
383
+ return { skipped: true };
384
+ }
385
+
386
+ console.log("🚀 Starting Dinou eject process...");
387
+
388
+ if (fs.existsSync(targetDinouDir) && force) {
389
+ removeDinouDirSafely(targetDinouDir, { allowDeferredFallback: false });
390
+ }
391
+
392
+ fs.cpSync(sourceDinouDir, targetDinouDir, {
393
+ recursive: true,
394
+ filter: (src) => {
395
+ const base = path.basename(src);
396
+ return base !== "node_modules" && base !== ".DS_Store";
397
+ },
398
+ });
399
+
400
+ const cliDest = path.join(targetDinouDir, "cli.js");
401
+ if (fs.existsSync(cliDest)) {
402
+ try {
403
+ fs.chmodSync(cliDest, 0o755);
404
+ } catch { }
405
+ }
406
+ console.log("📁 Copied Dinou framework source into ./dinou");
407
+
408
+ const originalPkgContent = fs.readFileSync(pkgPath, "utf8");
409
+ const pkg = JSON.parse(originalPkgContent);
410
+ rewritePackageJsonForEject(pkg);
411
+
412
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
413
+ console.log(
414
+ '✅ Updated package.json scripts (preserved custom scripts + added "build:vendors" and "uneject")'
415
+ );
416
+
417
+ if (!skipInstall) {
418
+ const pm = detectPackageManager(projectRoot);
419
+ console.log(`📦 Package manager detected: ${pm}`);
420
+ console.log(`🔄 Executing '${pm} install' to link ./dinou dependencies...`);
421
+
422
+ const res = runPackageManager(pm, ["install"], projectRoot);
423
+ if (res.error || res.status !== 0) {
424
+ const msg = res.error
425
+ ? res.error.message
426
+ : `exited with code ${res.status ?? 1}`;
427
+ console.warn(
428
+ `⚠️ [Dinou Eject] '${pm} install' did not complete cleanly (${msg}). Run '${pm} install' manually to finish linking ./dinou.`
429
+ );
430
+ return { skipped: false, installFailed: true };
431
+ }
432
+ }
433
+
434
+ console.log(
435
+ '🎉 Eject completed successfully! Edit ./dinou freely, or run "npm run uneject" anytime to revert.'
436
+ );
437
+ return { skipped: false, installFailed: false };
438
+ }
439
+
440
+ /**
441
+ * Rewrites `package.json` in place for Uneject Mode (reverting back to `node_modules/dinou`).
442
+ */
443
+ export function rewritePackageJsonForUneject(pkg, options = {}) {
444
+ const rawSpec =
445
+ typeof options.spec === "string" && options.spec.trim()
446
+ ? options.spec.trim()
447
+ : "latest";
448
+ const skipInstall = Boolean(options.skipInstall);
449
+
450
+ pkg.scripts = pkg.scripts || {};
451
+
452
+ delete pkg.scripts.uneject;
453
+ if (
454
+ !options.hadBuildVendors &&
455
+ (pkg.scripts["build:vendors"] === "node dinou/cli.js build:vendors" ||
456
+ pkg.scripts["build:vendors"] === "node ./dinou/cli.js build:vendors" ||
457
+ pkg.scripts["build:vendors"] === "dinou build:vendors")
458
+ ) {
459
+ delete pkg.scripts["build:vendors"];
460
+ }
461
+
462
+ for (const [key, val] of Object.entries(pkg.scripts)) {
463
+ if (typeof val === "string") {
464
+ pkg.scripts[key] = val.replace(EJECTED_DINOU_CLI_RE, "dinou");
465
+ }
466
+ }
467
+
468
+ pkg.scripts.eject = "dinou eject";
469
+
470
+ pkg.dependencies = pkg.dependencies || {};
471
+ if (pkg.devDependencies && "dinou" in pkg.devDependencies) {
472
+ delete pkg.devDependencies.dinou;
473
+ if (Object.keys(pkg.devDependencies).length === 0) {
474
+ delete pkg.devDependencies;
475
+ }
476
+ }
477
+
478
+ const directSpec = isProtocolOrTarballSpec(rawSpec);
479
+ const normalizedSpec =
480
+ directSpec && rawSpec.endsWith(".tgz") && !rawSpec.includes(":")
481
+ ? `file:${rawSpec}`
482
+ : rawSpec;
483
+
484
+ if (directSpec || skipInstall) {
485
+ pkg.dependencies.dinou = normalizedSpec;
486
+ } else {
487
+ delete pkg.dependencies.dinou;
488
+ }
489
+
490
+ return { pkg, directSpec, normalizedSpec };
491
+ }
492
+
493
+ /**
494
+ * Prompts the user on stdin/stdout to confirm a destructive action (`(y/N)`).
495
+ * Defaults to `false` on Enter, `"n"`, EOF, or `Ctrl+C` / `Ctrl+D`.
496
+ */
497
+ export function promptConfirmation(question) {
498
+ return new Promise((resolve) => {
499
+ if (process.stdin.destroyed || process.stdin.readableEnded) {
500
+ process.stdout.write(question + "\n");
501
+ return resolve(false);
502
+ }
503
+
504
+ let answered = false;
505
+ const rl = readline.createInterface({
506
+ input: process.stdin,
507
+ output: process.stdout,
508
+ });
509
+
510
+ rl.question(question, (answer) => {
511
+ answered = true;
512
+ rl.close();
513
+ const normalized = String(answer || "").trim().toLowerCase();
514
+ resolve(normalized === "y" || normalized === "yes");
515
+ });
516
+
517
+ rl.on("close", () => {
518
+ if (!answered) {
519
+ process.stdout.write("\n");
520
+ resolve(false);
521
+ }
522
+ });
523
+ });
524
+ }
525
+
526
+ /**
527
+ * Reverts an ejected Dinou project back to using the `dinou` package from `node_modules`.
528
+ *
529
+ * @param {object} [options]
530
+ * @param {string} [options.spec="latest"] Version tag, semver range, or `file:...` tarball path.
531
+ * @param {boolean} [options.yes=false] Skip interactive `(y/N)` confirmation prompt.
532
+ * @param {boolean} [options.skipInstall=false] Update `package.json` & remove `./dinou` without running package manager install.
533
+ * @param {boolean} [options.keepDinouDir=false] Keep `./dinou` directory on disk instead of deleting it.
534
+ * @param {string} [options.projectRoot=process.cwd()] Target project root directory.
535
+ * @param {boolean} [options.hadBuildVendors=false] Preserve `build:vendors` if explicitly requested.
536
+ * @param {boolean} [options.throwOnError=false] Throw an Error instead of calling `process.exit(1)` on install failure.
537
+ */
538
+ export async function uneject(options = {}) {
539
+ const projectRoot = path.resolve(options.projectRoot || process.cwd());
540
+ const skipConfirm =
541
+ Boolean(options.yes) || process.env.DINOU_YES === "true";
542
+ const skipInstall =
543
+ Boolean(options.skipInstall) || process.env.DINOU_SKIP_INSTALL === "true";
544
+ const keepDinouDir = Boolean(options.keepDinouDir);
545
+
546
+ const pkgPath = path.join(projectRoot, "package.json");
547
+ if (!fs.existsSync(pkgPath)) {
548
+ throw new Error(`[Dinou Uneject] package.json not found in ${projectRoot}`);
549
+ }
550
+
551
+ const localDinouDir = path.join(projectRoot, "dinou");
552
+
553
+ if (!skipConfirm) {
554
+ const promptMsg =
555
+ !keepDinouDir && fs.existsSync(localDinouDir)
556
+ ? "⚠️ Are you sure you want to uneject? This will permanently delete your local ./dinou directory. (y/N): "
557
+ : "⚠️ Are you sure you want to uneject and restore package.json scripts? (y/N): ";
558
+ const confirmed = await promptConfirmation(promptMsg);
559
+ if (!confirmed) {
560
+ console.log(
561
+ "🚫 Uneject cancelled. Your local ./dinou directory was not modified."
562
+ );
563
+ return { cancelled: true };
564
+ }
565
+ }
566
+
567
+ const originalPkgContent = fs.readFileSync(pkgPath, "utf8");
568
+ const pkg = JSON.parse(originalPkgContent);
569
+
570
+ console.log("🔄 Starting Dinou uneject process...");
571
+
572
+ const { directSpec, normalizedSpec } = rewritePackageJsonForUneject(pkg, {
573
+ ...options,
574
+ skipInstall,
575
+ });
576
+
577
+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2) + "\n", "utf8");
578
+ console.log("✅ Restored package.json scripts to standard Dinou CLI commands");
579
+
580
+ if (!skipInstall) {
581
+ const pm = detectPackageManager(projectRoot);
582
+ console.log(`📦 Package manager detected: ${pm}`);
583
+
584
+ const pmArgs = directSpec
585
+ ? ["install"]
586
+ : pm === "npm"
587
+ ? ["install", `dinou@${normalizedSpec}`]
588
+ : ["add", `dinou@${normalizedSpec}`];
589
+
590
+ console.log(`🔄 Executing '${pm} ${pmArgs.join(" ")}'...`);
591
+ const res = runPackageManager(pm, pmArgs, projectRoot);
592
+
593
+ if (res.error || res.status !== 0) {
594
+ fs.writeFileSync(pkgPath, originalPkgContent, "utf8");
595
+ const msg = res.error
596
+ ? res.error.message
597
+ : `exited with code ${res.status ?? 1}`;
598
+ console.error(
599
+ `❌ [Dinou Uneject] Package installation failed (${msg}). Rolled back package.json and kept ./dinou intact.`
600
+ );
601
+ if (options.throwOnError) {
602
+ throw new Error(`[Dinou Uneject] Package installation failed: ${msg}`);
603
+ }
604
+ process.exit(1);
605
+ }
606
+ console.log("✅ Installed dinou package in node_modules");
607
+ }
608
+
609
+ let dinouDirRemaining = false;
610
+ if (!keepDinouDir && fs.existsSync(localDinouDir)) {
611
+ const rmResult = removeDinouDirSafely(localDinouDir, {
612
+ allowDeferredFallback: true,
613
+ });
614
+ if (rmResult.removed) {
615
+ console.log("🗑️ Removed local ./dinou directory");
616
+ } else {
617
+ dinouDirRemaining = true;
618
+ const code = rmResult.error?.code || "ERROR";
619
+ if (rmResult.deferred) {
620
+ console.warn(
621
+ `⚠️ [Dinou Uneject] ./dinou is currently locked (${code}). Scheduled automatic cleanup after exit — if ./dinou still remains (e.g. held by an open dev server or IDE), you can safely delete it manually.`
622
+ );
623
+ } else {
624
+ console.warn(
625
+ `⚠️ [Dinou Uneject] Could not delete ./dinou automatically (${code}: ${rmResult.error?.message || "locked"}). package.json and node_modules/dinou were updated successfully — please delete ./dinou manually.`
626
+ );
627
+ }
628
+ }
629
+ }
630
+
631
+ console.log(
632
+ "🎉 Uneject completed successfully! Dinou is now running from node_modules/dinou."
633
+ );
634
+ return {
635
+ cancelled: false,
636
+ ...(dinouDirRemaining ? { dinouDirRemaining: true } : {}),
637
+ };
638
+ }
639
+
640
+ export default uneject;
@@ -5,7 +5,7 @@ export function resolveRelativeUrl(href, currentPathname) {
5
5
  if (href.startsWith("/") || href.includes("://")) {
6
6
  return href;
7
7
  }
8
- let base = currentPathname || "/";
8
+ let base = String(currentPathname || "/").split("?")[0].split("#")[0] || "/";
9
9
  if (!base.endsWith("/")) {
10
10
  base += "/";
11
11
  }
package/dinou/core/vfs.js CHANGED
@@ -21,15 +21,24 @@ function normalizeKey(p) {
21
21
  return s;
22
22
  }
23
23
 
24
+ function sortByName(entries) {
25
+ return [...entries].sort((a, b) => {
26
+ const na = typeof a === "string" ? a : a.name;
27
+ const nb = typeof b === "string" ? b : b.name;
28
+ return na < nb ? -1 : na > nb ? 1 : 0;
29
+ });
30
+ }
31
+
24
32
  export function buildVfs(dir, baseDir = dir) {
25
33
  const vfs = getVfs();
26
34
  if (!fs.existsSync(dir)) return;
27
- const entries = fs.readdirSync(dir, { withFileTypes: true });
35
+ const entries = sortByName(fs.readdirSync(dir, { withFileTypes: true }));
28
36
  const children = [];
29
37
 
30
38
  for (const entry of entries) {
31
39
  const fullPath = path.join(dir, entry.name);
32
40
  const isDirectory = entry.isDirectory();
41
+ if (isDirectory && entry.name.startsWith("_")) continue;
33
42
  children.push({
34
43
  name: entry.name,
35
44
  isDirectory
@@ -125,7 +134,7 @@ export function readdirSync(dirPath, options) {
125
134
  try {
126
135
  if (typeof fs.readdirSync === "function") {
127
136
  const res = fs.readdirSync(dirPath, options);
128
- if (res) return res;
137
+ if (res) return Array.isArray(res) ? sortByName(res) : res;
129
138
  }
130
139
  } catch (e) {}
131
140
  return [];
package/dinou/css.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  declare module "*.module.css" {
2
- const classes: { [key: string]: string };
2
+ const classes: { readonly [key: string]: string };
3
3
  export default classes;
4
4
  }
5
+
6
+ // Must stay after "*.module.css" (TS matches equal-prefix wildcards in declaration order)
7
+ declare module "*.css" { }