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,33 +1,482 @@
1
- export const extensions = [
2
- "png",
3
- "jpg",
4
- "jpeg",
5
- "gif",
6
- "svg",
7
- "webp",
8
- "avif",
9
- "ico",
10
- "mp4",
11
- "webm",
12
- "ogg",
13
- "mov",
14
- "avi",
15
- "mkv",
16
- "mp3",
17
- "wav",
18
- "flac",
19
- "m4a",
20
- "aac",
21
- "mjpeg",
22
- "mjpg",
23
- ];
24
-
25
- export const globPattern = `**/*.{${extensions.join(",")}}`;
26
-
27
- // 🔹 regex useful for Rollup/PostCSS type plugins
28
- export const regex = new RegExp(`\\.(${extensions.join("|")})$`, "i");
29
-
30
- // 🔹 version with dot for direct comparisons
31
- export const extensionsWithDot = extensions.map((ext) => `.${ext}`);
32
-
33
- export default { extensions, extensionsWithDot, regex, globPattern };
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import crypto from "node:crypto";
4
+ import { createRequire } from "node:module";
5
+ import { normalizePathCase } from "./path-utils.js";
6
+ import {
7
+ getAbsPathWithExt,
8
+ stripJsonCommentsAndTrailingCommas,
9
+ } from "./get-abs-path-with-ext.js";
10
+ import {
11
+ extensions,
12
+ DEFAULT_EXTENSIONS_SET,
13
+ globPattern,
14
+ regex,
15
+ extensionsWithDot,
16
+ } from "./builtin-asset-extensions.js";
17
+
18
+ export { extensions, globPattern, regex, extensionsWithDot };
19
+
20
+ const escapeRegExp = (str) => String(str).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
21
+
22
+ const syncConfigExtCache = new Map();
23
+ const assetHashCache = new Map();
24
+
25
+ export function normalizeAssetExtension(rawExt) {
26
+ if (typeof rawExt !== "string") return null;
27
+ const cleaned = rawExt.trim().replace(/^\.+/, "").toLowerCase();
28
+ if (!cleaned || !/^[a-z0-9][a-z0-9.+-]*$/.test(cleaned)) {
29
+ return null;
30
+ }
31
+ return cleaned;
32
+ }
33
+
34
+ export function normalizeAssetExtensionsList(rawList) {
35
+ if (!Array.isArray(rawList)) return [];
36
+ const result = [];
37
+ const seen = new Set();
38
+ for (const item of rawList) {
39
+ const norm = normalizeAssetExtension(item);
40
+ if (norm && !seen.has(norm)) {
41
+ seen.add(norm);
42
+ result.push(norm);
43
+ }
44
+ }
45
+ return result;
46
+ }
47
+
48
+ /**
49
+ * Synchronously inspects `globalThis.__DINOU_CONFIG__` or `dinou.config.{ts,mjs,js,cjs}`
50
+ * to extract user-configured `assetExtensions` when synchronous tools (like `generateRouteTypes`) run.
51
+ */
52
+ export function readCustomAssetExtensionsSync(projectRoot = process.cwd()) {
53
+ const rootDir = path.resolve(projectRoot || process.cwd());
54
+ if (
55
+ typeof globalThis !== "undefined" &&
56
+ globalThis.__DINOU_CONFIG__ &&
57
+ globalThis.__DINOU_CONFIG_CWD__ === rootDir &&
58
+ Array.isArray(globalThis.__DINOU_CONFIG__.assetExtensions)
59
+ ) {
60
+ return normalizeAssetExtensionsList(
61
+ globalThis.__DINOU_CONFIG__.assetExtensions
62
+ ).filter((ext) => !DEFAULT_EXTENSIONS_SET.has(ext));
63
+ }
64
+
65
+ for (const filename of [
66
+ "dinou.config.ts",
67
+ "dinou.config.mjs",
68
+ "dinou.config.js",
69
+ "dinou.config.cjs",
70
+ ]) {
71
+ const cfgPath = path.join(rootDir, filename);
72
+ if (!fs.existsSync(cfgPath)) continue;
73
+ try {
74
+ const stat = fs.statSync(cfgPath);
75
+ const cached = syncConfigExtCache.get(cfgPath);
76
+ if (cached && cached.mtimeMs === stat.mtimeMs) {
77
+ return cached.customExtensions;
78
+ }
79
+ const raw = fs.readFileSync(cfgPath, "utf8");
80
+ const stripped = stripJsonCommentsAndTrailingCommas(raw);
81
+ const match = stripped.match(/\bassetExtensions\s*:\s*\[([\s\S]*?)\]/);
82
+ const parsed = [];
83
+ if (match && match[1]) {
84
+ const strLiterals = match[1].matchAll(/(?:"([^"]+)"|'([^']+)'|`([^`]+)`)/g);
85
+ for (const lit of strLiterals) {
86
+ const val = lit[1] ?? lit[2] ?? lit[3];
87
+ if (val) parsed.push(val);
88
+ }
89
+ }
90
+ const customExtensions = normalizeAssetExtensionsList(parsed).filter(
91
+ (ext) => !DEFAULT_EXTENSIONS_SET.has(ext)
92
+ );
93
+ syncConfigExtCache.set(cfgPath, {
94
+ mtimeMs: stat.mtimeMs,
95
+ customExtensions,
96
+ });
97
+ return customExtensions;
98
+ } catch (e) {
99
+ return [];
100
+ }
101
+ }
102
+ return [];
103
+ }
104
+
105
+ /**
106
+ * Builds the merged set of built-in + custom `assetExtensions` (from `dinou.config.*`),
107
+ * returning `{ extensions, customExtensions, extensionsWithDot, globPattern, regex, resolveFilterRegex }`.
108
+ */
109
+ export function getAssetExtensionsInfo(
110
+ dinouConfigOrList = null,
111
+ projectRoot = process.cwd()
112
+ ) {
113
+ let rawCustom = [];
114
+ if (Array.isArray(dinouConfigOrList)) {
115
+ rawCustom = dinouConfigOrList;
116
+ } else if (
117
+ dinouConfigOrList &&
118
+ typeof dinouConfigOrList === "object" &&
119
+ Array.isArray(dinouConfigOrList.assetExtensions)
120
+ ) {
121
+ rawCustom = dinouConfigOrList.assetExtensions;
122
+ } else {
123
+ rawCustom = readCustomAssetExtensionsSync(projectRoot);
124
+ }
125
+
126
+ const normalizedCustom = normalizeAssetExtensionsList(rawCustom);
127
+ const customExtensions = normalizedCustom.filter(
128
+ (ext) => !DEFAULT_EXTENSIONS_SET.has(ext)
129
+ );
130
+ const merged =
131
+ customExtensions.length > 0
132
+ ? [...extensions, ...customExtensions]
133
+ : extensions;
134
+
135
+ const escapedAlternation = merged.map(escapeRegExp).join("|");
136
+ return {
137
+ extensions: merged,
138
+ customExtensions,
139
+ extensionsWithDot: merged.map((ext) => `.${ext}`),
140
+ globPattern:
141
+ merged.length === 1
142
+ ? `**/*.${merged[0]}`
143
+ : `**/*.{${merged.join(",")}}`,
144
+ regex: new RegExp(`\\.(${escapedAlternation})$`, "i"),
145
+ resolveFilterRegex: new RegExp(
146
+ `\\.(${escapedAlternation})(?:[?#].*)?$`,
147
+ "i"
148
+ ),
149
+ };
150
+ }
151
+
152
+ function normalizePosixCasePath(p) {
153
+ return normalizePathCase(path.resolve(p)).replace(/\\/g, "/");
154
+ }
155
+
156
+ function sanitizeAssetBaseName(rawBase) {
157
+ const cleaned = String(rawBase || "")
158
+ .replace(/[^a-zA-Z0-9_-]+/g, "-")
159
+ .replace(/-+/g, "-")
160
+ .replace(/^-|-$/g, "");
161
+ return cleaned || "asset";
162
+ }
163
+
164
+ /**
165
+ * Computes a deterministic, OS-independent, content-and-path-addressed asset descriptor:
166
+ * - `fileName`: `"assets/<name>-<8hex>.<ext>"`
167
+ * - `publicUrl`: `"/assets/<name>-<8hex>.<ext>"`
168
+ * - `hash`: 8-character SHA-256 hex digest of `relPosixPath + "\0" + fileBytes`
169
+ *
170
+ * Cached in memory by `(normAbsPath, normProjectRoot, mtimeMs, size)` so repeated lookups
171
+ * across client, CSS, and server passes are O(1) while automatically invalidating on edits in `dinou dev`.
172
+ */
173
+ export function getAssetInfo(
174
+ absFilePath,
175
+ projectRoot = process.cwd(),
176
+ { includeBuffer = false, buffer = null } = {}
177
+ ) {
178
+ const absPath = path.resolve(absFilePath);
179
+ const normAbs = normalizePosixCasePath(absPath);
180
+ const normRoot = normalizePosixCasePath(projectRoot || process.cwd());
181
+ const relForHash = path.posix.relative(normRoot, normAbs) || path.posix.basename(normAbs);
182
+
183
+ let stat = null;
184
+ try {
185
+ stat = fs.statSync(absPath);
186
+ } catch (e) {}
187
+
188
+ if (stat && stat.isFile() && !buffer) {
189
+ const cached = assetHashCache.get(normAbs);
190
+ if (
191
+ cached &&
192
+ cached.normRoot === normRoot &&
193
+ cached.mtimeMs === stat.mtimeMs &&
194
+ cached.size === stat.size
195
+ ) {
196
+ if (!includeBuffer) {
197
+ return {
198
+ hash: cached.hash,
199
+ fileName: cached.fileName,
200
+ publicUrl: cached.publicUrl,
201
+ };
202
+ }
203
+ const freshBuf = fs.readFileSync(absPath);
204
+ return {
205
+ hash: cached.hash,
206
+ fileName: cached.fileName,
207
+ publicUrl: cached.publicUrl,
208
+ buffer: freshBuf,
209
+ };
210
+ }
211
+ }
212
+
213
+ let fileBuf = buffer;
214
+ if (!fileBuf && stat && stat.isFile()) {
215
+ try {
216
+ fileBuf = fs.readFileSync(absPath);
217
+ } catch (e) {
218
+ fileBuf = null;
219
+ }
220
+ }
221
+
222
+ const hasher = crypto.createHash("sha256").update(relForHash);
223
+ if (fileBuf) {
224
+ hasher.update("\0").update(fileBuf);
225
+ }
226
+ const hash = hasher.digest("hex").slice(0, 8);
227
+
228
+ const rawExt = path.extname(absPath);
229
+ const ext = rawExt.toLowerCase();
230
+ const safeBase = sanitizeAssetBaseName(path.basename(absPath, rawExt));
231
+ const fileName = `assets/${safeBase}-${hash}${ext}`;
232
+ const publicUrl = `/${fileName}`;
233
+
234
+ if (stat && stat.isFile()) {
235
+ assetHashCache.set(normAbs, {
236
+ normRoot,
237
+ mtimeMs: stat.mtimeMs,
238
+ size: stat.size,
239
+ hash,
240
+ fileName,
241
+ publicUrl,
242
+ });
243
+ }
244
+
245
+ return includeBuffer
246
+ ? { hash, fileName, publicUrl, buffer: fileBuf }
247
+ : { hash, fileName, publicUrl };
248
+ }
249
+
250
+ export function getAssetFileName(absFilePath, projectRoot = process.cwd()) {
251
+ return getAssetInfo(absFilePath, projectRoot).fileName;
252
+ }
253
+
254
+ export function getAssetPublicUrl(absFilePath, projectRoot = process.cwd()) {
255
+ return getAssetInfo(absFilePath, projectRoot).publicUrl;
256
+ }
257
+
258
+ function mapSwcMirrorDirToOriginal(dirPath, projectRoot) {
259
+ if (!dirPath) return path.resolve(projectRoot);
260
+ const resolvedDir = path.resolve(dirPath);
261
+ const swcRoot = path.resolve(projectRoot, ".dinou", "swc");
262
+ const normDir = normalizePosixCasePath(resolvedDir);
263
+ const normSwc = normalizePosixCasePath(swcRoot);
264
+ if (normDir === normSwc) {
265
+ return path.resolve(projectRoot);
266
+ }
267
+ if (normDir.startsWith(normSwc + "/")) {
268
+ const rel = path.relative(swcRoot, resolvedDir);
269
+ return path.resolve(projectRoot, rel);
270
+ }
271
+ return resolvedDir;
272
+ }
273
+
274
+ function isExistingFile(filePath) {
275
+ if (!filePath) return false;
276
+ try {
277
+ return fs.existsSync(filePath) && fs.statSync(filePath).isFile();
278
+ } catch (e) {
279
+ return false;
280
+ }
281
+ }
282
+
283
+ /**
284
+ * Resolves an asset import specifier (relative, `tsconfig.json`/`jsconfig.json` path alias,
285
+ * `.dinou/swc` mirrored client component import, `@/` fallback, or `node_modules` package asset)
286
+ * to an absolute filesystem path.
287
+ */
288
+ export function resolveAssetImport(
289
+ specifier,
290
+ {
291
+ importer = "",
292
+ resolveDir = "",
293
+ projectRoot = process.cwd(),
294
+ assetRegex = null,
295
+ } = {}
296
+ ) {
297
+ if (!specifier || typeof specifier !== "string") return null;
298
+ const cleanSpec = specifier.split("?")[0].split("#")[0];
299
+ if (!cleanSpec) return null;
300
+
301
+ const rootDir = path.resolve(projectRoot || process.cwd());
302
+ const activeRegex =
303
+ assetRegex || getAssetExtensionsInfo(null, rootDir).regex;
304
+ if (!activeRegex.test(cleanSpec)) {
305
+ return null;
306
+ }
307
+
308
+ if (path.isAbsolute(cleanSpec) && isExistingFile(cleanSpec)) {
309
+ return path.resolve(cleanSpec);
310
+ }
311
+
312
+ const rawImporterDir = importer
313
+ ? path.dirname(importer)
314
+ : resolveDir || rootDir;
315
+ const effectiveImporterDir = mapSwcMirrorDirToOriginal(rawImporterDir, rootDir);
316
+
317
+ // 1. Resolve via tsconfig.json / jsconfig.json path aliases or ./ ../ relative paths
318
+ const viaAliasOrRel = getAbsPathWithExt(cleanSpec, {
319
+ parentDir: effectiveImporterDir,
320
+ cwd: rootDir,
321
+ });
322
+ if (isExistingFile(viaAliasOrRel)) {
323
+ return path.resolve(viaAliasOrRel);
324
+ }
325
+
326
+ // 2. Default `@/` -> `<projectRoot>/src/` fallback when no tsconfig/jsconfig alias matched
327
+ if (cleanSpec.startsWith("@/")) {
328
+ const fallbackAt = path.resolve(rootDir, "src", cleanSpec.slice(2));
329
+ if (isExistingFile(fallbackAt)) {
330
+ return fallbackAt;
331
+ }
332
+ }
333
+ if (cleanSpec.startsWith("~/")) {
334
+ const fallbackTilde = path.resolve(rootDir, "src", cleanSpec.slice(2));
335
+ if (isExistingFile(fallbackTilde)) {
336
+ return fallbackTilde;
337
+ }
338
+ }
339
+
340
+ // 3. Direct relative resolution against effectiveImporterDir
341
+ if (cleanSpec.startsWith("./") || cleanSpec.startsWith("../")) {
342
+ const relCandidate = path.resolve(effectiveImporterDir, cleanSpec);
343
+ if (isExistingFile(relCandidate)) {
344
+ return relCandidate;
345
+ }
346
+ return null;
347
+ }
348
+
349
+ // 4. Bare package asset specifier from node_modules (e.g. "@fontsource/inter/files/inter.woff2")
350
+ if (!cleanSpec.startsWith("/")) {
351
+ try {
352
+ const req = createRequire(
353
+ path.join(effectiveImporterDir, "__dinou_asset_resolve__.js")
354
+ );
355
+ const resolvedPkgAsset = req.resolve(cleanSpec);
356
+ if (isExistingFile(resolvedPkgAsset)) {
357
+ return path.resolve(resolvedPkgAsset);
358
+ }
359
+ } catch (e) {
360
+ let cur = effectiveImporterDir;
361
+ while (true) {
362
+ const directPkgPath = path.join(cur, "node_modules", cleanSpec);
363
+ if (isExistingFile(directPkgPath)) {
364
+ return path.resolve(directPkgPath);
365
+ }
366
+ const parent = path.dirname(cur);
367
+ if (parent === cur) break;
368
+ cur = parent;
369
+ }
370
+ }
371
+ }
372
+
373
+ return null;
374
+ }
375
+
376
+ /**
377
+ * Shared Esbuild plugin for RSC, SSR, and Edge/Server orchestrator passes across
378
+ * Node.js, Cloudflare Workers, Bun, and Deno. Resolves asset imports to the exact
379
+ * same `/assets/<name>-<hash>.<ext>` URL emitted by Dinou's client bundlers.
380
+ */
381
+ export function createServerAssetPlugin({
382
+ projectRoot = process.cwd(),
383
+ dinouConfig = null,
384
+ assetRegex = null,
385
+ emitToDevMemory = false,
386
+ } = {}) {
387
+ const rootDir = path.resolve(projectRoot || process.cwd());
388
+ const lastEmittedKeyBySource = new Map();
389
+
390
+ return {
391
+ name: "dinou-server-asset-plugin",
392
+ setup(build) {
393
+ const extInfo = getAssetExtensionsInfo(dinouConfig, rootDir);
394
+ const cleanRegex = assetRegex || extInfo.regex;
395
+ const filterRegex = assetRegex
396
+ ? new RegExp(
397
+ assetRegex.source.replace(/\\\$$|\$$/, "(?:[?#].*)?$"),
398
+ assetRegex.flags.includes("i") ? "i" : `${assetRegex.flags}i`
399
+ )
400
+ : extInfo.resolveFilterRegex;
401
+
402
+ build.onResolve({ filter: filterRegex }, (args) => {
403
+ const resolved = resolveAssetImport(args.path, {
404
+ importer: args.importer,
405
+ resolveDir: args.resolveDir,
406
+ projectRoot: rootDir,
407
+ assetRegex: cleanRegex,
408
+ });
409
+ if (!resolved) return null;
410
+ return { path: resolved, namespace: "dinou-server-asset" };
411
+ });
412
+
413
+ build.onLoad({ filter: /.*/, namespace: "dinou-server-asset" }, (args) => {
414
+ const info = getAssetInfo(args.path, rootDir, {
415
+ includeBuffer: emitToDevMemory,
416
+ });
417
+
418
+ if (emitToDevMemory && info.buffer) {
419
+ const sourceKey = normalizePosixCasePath(args.path);
420
+ const prevFileName = lastEmittedKeyBySource.get(sourceKey);
421
+ if (
422
+ prevFileName &&
423
+ prevFileName !== info.fileName &&
424
+ typeof globalThis !== "undefined" &&
425
+ globalThis.__DINOU_MEM_FILES__
426
+ ) {
427
+ globalThis.__DINOU_MEM_FILES__.delete(prevFileName);
428
+ globalThis.__DINOU_MEM_FILES__.delete("/" + prevFileName);
429
+ globalThis.__DINOU_MEM_FILES__.delete(path.basename(prevFileName));
430
+ }
431
+ lastEmittedKeyBySource.set(sourceKey, info.fileName);
432
+
433
+ if (typeof globalThis !== "undefined") {
434
+ if (!globalThis.__DINOU_MEM_FILES__) {
435
+ globalThis.__DINOU_MEM_FILES__ = new Map();
436
+ }
437
+ globalThis.__DINOU_MEM_FILES__.set(info.fileName, info.buffer);
438
+ globalThis.__DINOU_MEM_FILES__.set("/" + info.fileName, info.buffer);
439
+ globalThis.__DINOU_MEM_FILES__.set(
440
+ path.basename(info.fileName),
441
+ info.buffer
442
+ );
443
+ }
444
+
445
+ if (process.env.DINOU_WRITE_TO_DISK === "true") {
446
+ try {
447
+ const outAssetPath = path.resolve(
448
+ rootDir,
449
+ ".dinou/public",
450
+ info.fileName
451
+ );
452
+ fs.mkdirSync(path.dirname(outAssetPath), { recursive: true });
453
+ fs.writeFileSync(outAssetPath, info.buffer);
454
+ } catch (e) {}
455
+ }
456
+ }
457
+
458
+ return {
459
+ contents: `export default ${JSON.stringify(info.publicUrl)};`,
460
+ loader: "js",
461
+ watchFiles: [args.path],
462
+ };
463
+ });
464
+ },
465
+ };
466
+ }
467
+
468
+ export default {
469
+ extensions,
470
+ extensionsWithDot,
471
+ regex,
472
+ globPattern,
473
+ normalizeAssetExtension,
474
+ normalizeAssetExtensionsList,
475
+ readCustomAssetExtensionsSync,
476
+ getAssetExtensionsInfo,
477
+ getAssetInfo,
478
+ getAssetFileName,
479
+ getAssetPublicUrl,
480
+ resolveAssetImport,
481
+ createServerAssetPlugin,
482
+ };
@@ -1,13 +1,27 @@
1
- import { isPprBuildActive, isInsideOuterSuspenseOutsideSlot, markDynamicAccess } from "./ppr-context.js";
1
+ import {
2
+ isPprBuildActive,
3
+ isInsideOuterSuspenseOutsideSlot,
4
+ markDynamicAccess,
5
+ isSlotDiscoveryActive,
6
+ } from "./ppr-context.js";
2
7
 
3
8
  function triggerBailout(label, onBailout) {
4
9
  if (isPprBuildActive() && isInsideOuterSuspenseOutsideSlot()) {
5
10
  markDynamicAccess(label);
6
- } else if (typeof onBailout === "function") {
11
+ } else if (!isSlotDiscoveryActive() && typeof onBailout === "function") {
7
12
  onBailout();
8
13
  }
9
14
  }
10
15
 
16
+ export const BAILOUT_RAW_TARGET = Symbol.for("dinou.bailout.raw");
17
+
18
+ export function unwrapBailoutProxy(value) {
19
+ if (value && (typeof value === "object" || typeof value === "function")) {
20
+ return value[BAILOUT_RAW_TARGET] || value;
21
+ }
22
+ return value;
23
+ }
24
+
11
25
  /**
12
26
  * Creates a transparent proxy that spies on property accesses
13
27
  * to detect dynamic usage and trigger a bailout callback.
@@ -22,6 +36,9 @@ export function createBailoutProxy(target, label = "Context", onBailout) {
22
36
 
23
37
  return new Proxy(safeTarget, {
24
38
  get(t, prop, receiver) {
39
+ if (prop === BAILOUT_RAW_TARGET) {
40
+ return t;
41
+ }
25
42
  if (
26
43
  typeof prop === "symbol" ||
27
44
  prop === "inspect" ||
@@ -57,5 +74,7 @@ export function createBailoutProxy(target, label = "Context", onBailout) {
57
74
  }
58
75
 
59
76
  export default {
77
+ BAILOUT_RAW_TARGET,
78
+ unwrapBailoutProxy,
60
79
  createBailoutProxy,
61
80
  };