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
@@ -35,6 +35,7 @@ async function generateStaticRSC(reqPath, options = {}) {
35
35
  );
36
36
 
37
37
  // 👇 2. MOCK RES (Complete and Robust Version)
38
+ let mockContext;
38
39
  const mockRes = {
39
40
  _statusCode: 200,
40
41
  _headers: {},
@@ -70,6 +71,7 @@ async function generateStaticRSC(reqPath, options = {}) {
70
71
 
71
72
  this._statusCode = status;
72
73
  this._redirectUrl = url;
74
+ if (mockContext) mockContext._hasRedirected = true;
73
75
 
74
76
  console.warn(
75
77
  `⚠️ [ISR] Redirect detected during RSC generation of ${reqPath} -> ${url} (${status})`
@@ -77,7 +79,7 @@ async function generateStaticRSC(reqPath, options = {}) {
77
79
  },
78
80
  };
79
81
 
80
- const mockContext = {
82
+ mockContext = {
81
83
  req: {
82
84
  query: {},
83
85
  cookies: {},
@@ -90,16 +92,13 @@ async function generateStaticRSC(reqPath, options = {}) {
90
92
  method: "GET",
91
93
  },
92
94
  res: mockRes,
95
+ _hasRedirected: false,
93
96
  };
94
97
 
95
98
  try {
96
99
  const manifest = JSON.parse(
97
100
  fs.readFileSync(
98
- path.resolve(
99
- isWebpack
100
- ? ".dinou/dist3/react-client-manifest.json"
101
- : ".dinou/react_client_manifest/react-client-manifest.json"
102
- ),
101
+ path.resolve(".dinou/dist1/react-client-manifest.json"),
103
102
  "utf8"
104
103
  )
105
104
  );
@@ -18,27 +18,37 @@ async function generateStatic() {
18
18
  if (existsSync(distFolder2)) {
19
19
  rmSync(distFolder2, { recursive: true, force: true });
20
20
  }
21
+ mkdirSync(distFolder2, { recursive: true });
21
22
 
22
23
  const { updateBuildProgress, clearBuildProgress, isTTY } = await import(
23
24
  "../node/terminal-status.js"
24
25
  );
25
26
 
26
- // 1. Compile or ensure Dual-Bundle engines (Pass A & Pass B)
27
+ // 1. Compile or ensure Dual-Bundle engines (Pass A & Pass B) + Server/Netlify AOT Adapters
27
28
  updateBuildProgress("[SSG] Compiling Dual-Engine for static generation...");
28
- const { bundleDualEngine } = await import("../node/bundle-dual-engine.js");
29
- const { rscEnginePath, ssrEnginePath } = await bundleDualEngine({
29
+ const {
30
+ bundleDualEngine,
31
+ bundleServerAndNetlifyAdapters,
32
+ } = await import("../node/bundle-dual-engine.js");
33
+ const engineResult = await bundleDualEngine({
30
34
  isDev: false,
31
35
  projectRoot: process.cwd(),
32
36
  outDir: ".dinou/node",
33
37
  });
38
+ const { rscEnginePath, ssrEnginePath } = engineResult;
39
+ await bundleServerAndNetlifyAdapters(engineResult);
34
40
 
35
41
  // 2. Initialize FileSystemStorage for writing .dinou/dist2
42
+ // Guard against dinou.config.* `storage` (e.g. RedisStorage) overriding FileSystemStorage during SSG build
43
+ globalThis.__DINOU_IS_SSG_BUILD__ = true;
36
44
  const storage = new FileSystemStorage(distFolder2);
37
45
  setStorageAdapter(storage);
38
46
 
47
+ try {
39
48
  // 3. Load compiled engines
40
49
  const rscModule = await import(pathToFileURL(rscEnginePath).href);
41
50
  const ssrModule = await import(pathToFileURL(ssrEnginePath).href);
51
+ setStorageAdapter(storage);
42
52
 
43
53
  // 4. Discover static routes and layouts
44
54
  updateBuildProgress("[SSG] Discovering static routes and layouts...");
@@ -58,12 +68,21 @@ async function generateStatic() {
58
68
  ? rscModule.getStaticLayouts()
59
69
  : [];
60
70
 
61
- // 4b. Pre-render all static layout segments (layout.rsc)
71
+ // 4b. Pre-render all static layout segments (layout.rsc) ancestor-first with monotonic timestamps
72
+ let lastSsgLayoutGen = 0;
62
73
  if (layouts.length > 0) {
63
74
  if (!isTTY) {
64
75
  console.log(`⚡ [SSG] Pre-rendering ${layouts.length} static layout(s)...`);
65
76
  }
66
- for (const layoutInfo of layouts) {
77
+ const sortedLayouts = [...layouts].sort((a, b) => {
78
+ const cleanA = String(a?.routePath || "/").replace(/^\/+/, "").replace(/\/+$/, "");
79
+ const cleanB = String(b?.routePath || "/").replace(/^\/+/, "").replace(/\/+$/, "");
80
+ const depthA = cleanA ? cleanA.split("/").filter(Boolean).length : 0;
81
+ const depthB = cleanB ? cleanB.split("/").filter(Boolean).length : 0;
82
+ if (depthA !== depthB) return depthA - depthB;
83
+ return cleanA < cleanB ? -1 : cleanA > cleanB ? 1 : 0;
84
+ });
85
+ for (const layoutInfo of sortedLayouts) {
67
86
  const layoutReqPath = layoutInfo.routePath.startsWith("/")
68
87
  ? layoutInfo.routePath
69
88
  : "/" + layoutInfo.routePath;
@@ -84,9 +103,12 @@ async function generateStatic() {
84
103
  const cleanLayoutPath = layoutReqPath.replace(/^\/+/, "").replace(/\/+$/, "");
85
104
  const layoutRscKey = cleanLayoutPath ? `${cleanLayoutPath}/layout.rsc` : "layout.rsc";
86
105
 
106
+ const ssgLayoutGen = Math.max(Date.now(), lastSsgLayoutGen + 1);
107
+ lastSsgLayoutGen = ssgLayoutGen;
87
108
  let layoutMeta = {
88
109
  status: 200,
89
- generatedAt: Date.now(),
110
+ generatedAt: ssgLayoutGen,
111
+ layoutGeneratedAt: ssgLayoutGen,
90
112
  revalidate: undefined,
91
113
  tags: [],
92
114
  };
@@ -121,8 +143,13 @@ async function generateStatic() {
121
143
  if (suspenseCountHeader !== null) {
122
144
  layoutMeta.suspenseCount = Number(suspenseCountHeader) || 0;
123
145
  }
146
+ if (layoutRes.headers.get("x-dinou-ppr") === "true") {
147
+ layoutMeta.ppr = true;
148
+ }
124
149
  if (layoutRes.headers.get("x-dinou-dynamic") === "true") {
125
150
  layoutMeta.dynamic = true;
151
+ layoutMeta.ppr = false;
152
+ delete layoutMeta.holes;
126
153
  }
127
154
  } catch (e) {}
128
155
 
@@ -153,6 +180,9 @@ async function generateStatic() {
153
180
  );
154
181
  }
155
182
  }
183
+ while (lastSsgLayoutGen > 0 && Date.now() <= lastSsgLayoutGen) {
184
+ await new Promise((r) => setTimeout(r, 1));
185
+ }
156
186
  }
157
187
 
158
188
  if (!isTTY) {
@@ -199,6 +229,9 @@ async function generateStatic() {
199
229
  await storage.set(shellHtmlKey, htmlItem.content, {
200
230
  ...(htmlItem.metadata || {}),
201
231
  ppr: true,
232
+ ...(routeMeta && typeof routeMeta.pagePpr === "boolean"
233
+ ? { pagePpr: routeMeta.pagePpr }
234
+ : {}),
202
235
  holes: effectiveHoles,
203
236
  });
204
237
  }
@@ -208,6 +241,9 @@ async function generateStatic() {
208
241
  metaObj = metaItem ? JSON.parse(metaItem.content || "{}") : {};
209
242
  } catch (e) {}
210
243
  metaObj.ppr = true;
244
+ if (routeMeta && typeof routeMeta.pagePpr === "boolean") {
245
+ metaObj.pagePpr = routeMeta.pagePpr;
246
+ }
211
247
  metaObj.holes =
212
248
  Array.isArray(metaObj.holes) && metaObj.holes.length > 0
213
249
  ? metaObj.holes
@@ -281,6 +317,9 @@ async function generateStatic() {
281
317
  console.log(
282
318
  `✓ [SSG] Pre-rendered ${renderedCount} page(s) and ${layouts.length} layout(s) to .dinou/dist2`
283
319
  );
320
+ } finally {
321
+ delete globalThis.__DINOU_IS_SSG_BUILD__;
322
+ }
284
323
  }
285
324
 
286
325
  export { generateStatic };
@@ -1,107 +1,249 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
+ import { createRequire } from "node:module";
3
4
  import { fileURLToPath, pathToFileURL } from "node:url";
5
+ import resolveModule from "#resolve";
4
6
 
5
- // Reads tsconfig/jsconfig and builds a map of alias -> targetBase
6
- function loadTsconfigAliases() {
7
- const cwd = process.cwd();
8
- const tsconfigPath = path.resolve(cwd, "tsconfig.json");
9
- const jsconfigPath = path.resolve(cwd, "jsconfig.json");
10
- const configFile = fs.existsSync(tsconfigPath)
11
- ? tsconfigPath
12
- : fs.existsSync(jsconfigPath)
13
- ? jsconfigPath
14
- : null;
15
- if (!configFile) return new Map();
16
-
17
- let config;
7
+ const resolve = resolveModule?.default || resolveModule;
8
+ import {
9
+ inferProjectRootFromDir,
10
+ resolveCandidateFile,
11
+ resolveTsconfigAlias,
12
+ stripJsonCommentsAndTrailingCommas,
13
+ } from "./tsconfig-aliases.js";
14
+
15
+ export { stripJsonCommentsAndTrailingCommas };
16
+
17
+ const STYLESHEET_FILE_RE = /\.(css|scss|sass|less)$/i;
18
+
19
+ function getParentDirectory(context) {
20
+ if (context?.parentDir) {
21
+ return path.resolve(context.parentDir);
22
+ }
23
+ const parentURL = context?.parentURL;
24
+ if (!parentURL) return process.cwd();
25
+ const cleanParentURL = parentURL.split("?")[0];
26
+ const fsPath = fileURLToPath(cleanParentURL);
18
27
  try {
19
- config = JSON.parse(fs.readFileSync(configFile, "utf8"));
20
- } catch (err) {
21
- // Malformed json
22
- return new Map();
28
+ if (fs.existsSync(fsPath) && fs.statSync(fsPath).isDirectory()) {
29
+ return fsPath;
30
+ }
31
+ } catch (e) {}
32
+ return path.dirname(fsPath);
33
+ }
34
+
35
+ export function getAbsPathWithExt(specifier, context) {
36
+ const cleanSpecifier = specifier
37
+ ? specifier.split("?")[0].split("#")[0]
38
+ : specifier;
39
+ if (!cleanSpecifier) return null;
40
+
41
+ const parentDir = getParentDirectory(context);
42
+ const projectRoot = inferProjectRootFromDir(parentDir, context?.cwd || null);
43
+ const preferStyles = Boolean(context?.preferStyles);
44
+ const extensions = context?.extensions || null;
45
+
46
+ if (cleanSpecifier.startsWith("./") || cleanSpecifier.startsWith("../")) {
47
+ const absPath = path.resolve(parentDir, cleanSpecifier);
48
+ return resolveCandidateFile(absPath, { extensions, preferStyles });
23
49
  }
24
50
 
25
- const paths = (config.compilerOptions && config.compilerOptions.paths) || {};
26
- const baseUrl =
27
- (config.compilerOptions && config.compilerOptions.baseUrl) || ".";
28
- const absoluteBase = path.resolve(cwd, baseUrl);
51
+ const viaAlias = resolveTsconfigAlias(cleanSpecifier, {
52
+ projectRoot,
53
+ extensions,
54
+ preferStyles,
55
+ });
56
+ if (viaAlias) {
57
+ return viaAlias;
58
+ }
29
59
 
30
- const map = new Map();
60
+ return null;
61
+ }
31
62
 
32
- for (const key of Object.keys(paths)) {
33
- const targets = paths[key];
34
- if (!targets || !targets.length) continue;
63
+ function resolveStyleExportsTarget(expVal) {
64
+ if (!expVal) return null;
65
+ if (typeof expVal === "string") return expVal;
66
+ if (typeof expVal === "object") {
67
+ for (const key of ["style", "css", "import", "default"]) {
68
+ if (expVal[key]) {
69
+ const nested = resolveStyleExportsTarget(expVal[key]);
70
+ if (nested) return nested;
71
+ }
72
+ }
73
+ }
74
+ return null;
75
+ }
35
76
 
36
- // Normalize: the first target is the one we will use
37
- let target = Array.isArray(targets) ? targets[0] : targets;
77
+ function resolveBareStyleFromNodeModules(cleanSpecifier, basedir) {
78
+ if (
79
+ !cleanSpecifier ||
80
+ cleanSpecifier.startsWith(".") ||
81
+ cleanSpecifier.startsWith("/") ||
82
+ cleanSpecifier.startsWith("\\") ||
83
+ path.isAbsolute(cleanSpecifier)
84
+ ) {
85
+ return null;
86
+ }
38
87
 
39
- // Support patterns with /* at the end: "@/*" -> "src/*"
40
- const keyIsWildcard = key.endsWith("/*");
41
- const targetIsWildcard = target.endsWith("/*");
88
+ // 1. Try package.json exports ("style" condition) / "style" field lookup
89
+ const parts = cleanSpecifier.startsWith("@")
90
+ ? cleanSpecifier.split("/").slice(0, 2)
91
+ : [cleanSpecifier.split("/")[0]];
92
+ const pkgName = parts.join("/");
93
+ const subpath = cleanSpecifier.slice(pkgName.length) || ".";
94
+ const normalizedSubpath = subpath === "." ? "." : `.${subpath}`;
42
95
 
43
- const alias = keyIsWildcard ? key.slice(0, -1) : key; // "@/"
44
- const targetBase = targetIsWildcard ? target.slice(0, -1) : target; // "src" or "../lib"
96
+ try {
97
+ const req = createRequire(
98
+ path.join(basedir || process.cwd(), "__dinou_resolve__.js")
99
+ );
100
+ let pkgJsonPath = null;
101
+ try {
102
+ pkgJsonPath = req.resolve(`${pkgName}/package.json`);
103
+ } catch (e) {
104
+ let cur = path.resolve(basedir || process.cwd());
105
+ while (true) {
106
+ const candidate = path.join(cur, "node_modules", pkgName, "package.json");
107
+ if (fs.existsSync(candidate)) {
108
+ pkgJsonPath = candidate;
109
+ break;
110
+ }
111
+ const parent = path.dirname(cur);
112
+ if (parent === cur) break;
113
+ cur = parent;
114
+ }
115
+ }
45
116
 
46
- // we resolve the targetBase relative to baseUrl if it is not absolute
47
- const resolvedTargetBase = path.resolve(absoluteBase, targetBase);
117
+ if (pkgJsonPath && fs.existsSync(pkgJsonPath)) {
118
+ const pkgDir = path.dirname(pkgJsonPath);
119
+ const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf8"));
120
+ if (pkgJson.exports) {
121
+ const exportEntry =
122
+ normalizedSubpath === "."
123
+ ? pkgJson.exports["."] || pkgJson.exports
124
+ : pkgJson.exports[normalizedSubpath];
125
+ const targetRel = resolveStyleExportsTarget(exportEntry);
126
+ if (targetRel) {
127
+ const candidate = path.resolve(pkgDir, targetRel);
128
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
129
+ return candidate;
130
+ }
131
+ }
132
+ }
133
+ if (normalizedSubpath === "." && typeof pkgJson.style === "string") {
134
+ const candidate = path.resolve(pkgDir, pkgJson.style);
135
+ if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
136
+ return candidate;
137
+ }
138
+ }
139
+ if (normalizedSubpath !== ".") {
140
+ const directCandidate = resolveCandidateFile(
141
+ path.resolve(pkgDir, normalizedSubpath),
142
+ { preferStyles: true }
143
+ );
144
+ if (directCandidate && STYLESHEET_FILE_RE.test(directCandidate)) {
145
+ return directCandidate;
146
+ }
147
+ }
148
+ }
149
+ } catch (e) {}
48
150
 
49
- map.set(alias, {
50
- resolvedTargetBase,
51
- keyIsWildcard,
52
- targetIsWildcard,
151
+ // 2. Fallback to resolve.sync with .css extension support
152
+ try {
153
+ return resolve.sync(cleanSpecifier, {
154
+ basedir: basedir || process.cwd(),
155
+ extensions: [".css", ".scss", ".sass", ".less"],
156
+ packageFilter(pkg) {
157
+ if (pkg.style && !pkg.main) {
158
+ pkg.main = pkg.style;
159
+ }
160
+ return pkg;
161
+ },
53
162
  });
163
+ } catch (e) {
164
+ return null;
54
165
  }
55
-
56
- return map;
57
166
  }
58
167
 
59
- const aliasMap = loadTsconfigAliases();
60
-
61
- // Add extensions if they do not exist
62
- function tryExtensions(filePath) {
63
- if (fs.existsSync(filePath) && fs.statSync(filePath).isFile())
64
- return filePath;
65
- const exts = [".js", ".mjs", ".ts", ".jsx", ".tsx"];
66
- for (const ext of exts) {
67
- const f = filePath + ext;
68
- if (fs.existsSync(f) && fs.statSync(f).isFile()) return f;
168
+ export function resolveCssImportSpecifier(specifier, basedir, customCwd = null) {
169
+ const cleanSpecifier = specifier
170
+ ? specifier.split("?")[0].split("#")[0]
171
+ : specifier;
172
+ if (!cleanSpecifier) return specifier;
173
+
174
+ const resolvedAliasOrRel = getAbsPathWithExt(cleanSpecifier, {
175
+ parentDir: basedir || process.cwd(),
176
+ cwd: customCwd || null,
177
+ preferStyles: true,
178
+ });
179
+ if (resolvedAliasOrRel) {
180
+ return resolvedAliasOrRel;
69
181
  }
70
- // If it is a folder, try index.*
71
- if (fs.existsSync(filePath) && fs.statSync(filePath).isDirectory()) {
72
- for (const ext of exts) {
73
- const f = path.join(filePath, "index" + ext);
74
- if (fs.existsSync(f) && fs.statSync(f).isFile()) return f;
182
+
183
+ // Relative CSS import without leading ./ (allowed inside CSS @import "tokens.css")
184
+ if (!cleanSpecifier.startsWith("/")) {
185
+ const localCandidate = resolveCandidateFile(
186
+ path.resolve(basedir || process.cwd(), cleanSpecifier),
187
+ { preferStyles: true }
188
+ );
189
+ if (localCandidate) {
190
+ return localCandidate;
75
191
  }
76
192
  }
77
- return null;
193
+
194
+ const bareResolved = resolveBareStyleFromNodeModules(
195
+ cleanSpecifier,
196
+ basedir || process.cwd()
197
+ );
198
+ if (bareResolved) {
199
+ return bareResolved;
200
+ }
201
+
202
+ throw new Error(
203
+ `[Dinou CSS] Cannot resolve CSS @import "${specifier}" from "${basedir || process.cwd()}"`
204
+ );
78
205
  }
79
206
 
80
- export function getAbsPathWithExt(specifier, context) {
81
- const cleanSpecifier = specifier ? specifier.split("?")[0] : specifier;
207
+ export function resolveStyleImportFromCode(
208
+ specifier,
209
+ importerFilePath,
210
+ customCwd = null
211
+ ) {
212
+ const cleanSpecifier = specifier
213
+ ? specifier.split("?")[0].split("#")[0]
214
+ : specifier;
82
215
  if (!cleanSpecifier) return null;
83
216
 
84
- if (aliasMap.size > 0) {
85
- for (const [alias, info] of aliasMap.entries()) {
86
- if (cleanSpecifier.startsWith(alias)) {
87
- const absPath = path.resolve(
88
- info.resolvedTargetBase,
89
- cleanSpecifier.slice(alias.length)
90
- );
91
- return tryExtensions(absPath);
92
- }
93
- }
217
+ const localOrAlias = getAbsPathWithExt(cleanSpecifier, {
218
+ parentURL: pathToFileURL(importerFilePath).href,
219
+ cwd: customCwd || null,
220
+ preferStyles: true,
221
+ });
222
+ if (localOrAlias && STYLESHEET_FILE_RE.test(localOrAlias)) {
223
+ return localOrAlias;
94
224
  }
95
225
 
96
- if (cleanSpecifier.startsWith("./") || cleanSpecifier.startsWith("../")) {
97
- const parentURL = context?.parentURL || pathToFileURL(process.cwd()).href;
98
- const cleanParentURL = parentURL.split("?")[0];
99
- const parentDir = path.dirname(fileURLToPath(cleanParentURL));
100
- const absPath = path.resolve(parentDir, cleanSpecifier);
101
- return tryExtensions(absPath);
226
+ // Only resolve bare node_modules specifiers when they target stylesheets
227
+ const looksLikeStylesheet =
228
+ STYLESHEET_FILE_RE.test(cleanSpecifier) ||
229
+ /(?:^|\/)(?:styles?|css)(?:$|\/)/i.test(cleanSpecifier);
230
+ if (!looksLikeStylesheet) {
231
+ return null;
102
232
  }
103
233
 
234
+ const resolved = resolveBareStyleFromNodeModules(
235
+ cleanSpecifier,
236
+ path.dirname(importerFilePath)
237
+ );
238
+ if (resolved && STYLESHEET_FILE_RE.test(resolved)) {
239
+ return resolved;
240
+ }
104
241
  return null;
105
242
  }
106
243
 
107
- export default { getAbsPathWithExt };
244
+ export default {
245
+ getAbsPathWithExt,
246
+ resolveCssImportSpecifier,
247
+ resolveStyleImportFromCode,
248
+ stripJsonCommentsAndTrailingCommas,
249
+ };
@@ -6,26 +6,37 @@ let read = false;
6
6
  const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
7
7
 
8
8
  export function getAssetFromManifest(name) {
9
- if (typeof globalThis !== "undefined" && globalThis.__DINOU_ASSET_MANIFEST__) {
10
- return "/" + (globalThis.__DINOU_ASSET_MANIFEST__[name] || name);
11
- }
12
9
  const isDev =
13
10
  process.env.DINOU_DEV === "true" ||
14
11
  (typeof globalThis !== "undefined" && Boolean(globalThis.__DINOU_DEV__));
12
+ const devEpoch =
13
+ isDev && typeof globalThis !== "undefined"
14
+ ? Number(globalThis.__DINOU_DEV_BUNDLE_EPOCH__ || 0)
15
+ : 0;
16
+ const withEpoch = (assetUrl) =>
17
+ devEpoch > 0 && assetUrl.endsWith(".js")
18
+ ? `${assetUrl}?v=${devEpoch}`
19
+ : assetUrl;
20
+
21
+ if (typeof globalThis !== "undefined" && globalThis.__DINOU_ASSET_MANIFEST__) {
22
+ return withEpoch("/" + (globalThis.__DINOU_ASSET_MANIFEST__[name] || name));
23
+ }
15
24
  if (process.env.NODE_ENV === "production" && !isDev && !read) {
16
- const manifestPath = path.resolve(process.cwd(), ".dinou/dist3/manifest.json");
25
+ const manifestPath = path.resolve(process.cwd(), ".dinou/dist1/manifest.json");
17
26
  if (fs.existsSync(manifestPath)) {
18
27
  manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
19
28
  read = true;
20
29
  }
21
- } else if ((isWebpack || isDev) && !read) {
22
- const manifestPath = path.resolve(process.cwd(), ".dinou/public/manifest.json");
30
+ } else if (isWebpack && isDev) {
31
+ if (typeof globalThis !== "undefined" && globalThis.__DINOU_RAW_ASSET_MANIFEST__) {
32
+ return withEpoch("/" + (globalThis.__DINOU_RAW_ASSET_MANIFEST__[name] || name));
33
+ }
34
+ const manifestPath = path.resolve(process.cwd(), ".dinou/node-dev/manifest.json");
23
35
  if (fs.existsSync(manifestPath)) {
24
36
  manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
25
- if (!isDev) read = true;
26
37
  }
27
38
  }
28
- return "/" + (manifest[name] || name);
39
+ return withEpoch("/" + (manifest[name] || name));
29
40
  }
30
41
 
31
42
  export default getAssetFromManifest;
@@ -227,7 +227,7 @@ async function getErrorJSX(reqPath, query, error, isDevelopment = false, options
227
227
  for (const [slotName, slotValue] of Object.entries(slots)) {
228
228
  let updatedSlotElement;
229
229
  const slotFilePath = slotValue?.slotPath || slotValue?.props?.__modulePath;
230
- const slotParams = slotValue?.slotParams || slotValue?.props?.params || {};
230
+ const slotParams = slotValue?.slotParams || slotValue?.props?.params || dParams || {};
231
231
  try {
232
232
  let elementToRender;
233
233
  if (slotValue && slotValue.slotPath) {
@@ -263,7 +263,8 @@ async function getErrorJSX(reqPath, query, error, isDevelopment = false, options
263
263
  true, // withExtension
264
264
  true, // finalDestination
265
265
  undefined, // lastFound
266
- reqSegments.length // TRICK: We force index at the end so that it searches for direct file
266
+ reqSegments.length, // TRICK: We force index at the end so that it searches for direct file
267
+ slotParams
267
268
  );
268
269
 
269
270
  if (slotErrorPath) {
@@ -271,9 +272,7 @@ async function getErrorJSX(reqPath, query, error, isDevelopment = false, options
271
272
  const SlotError = slotErrorModule.default ?? slotErrorModule;
272
273
 
273
274
  const serializedError = {
274
- message: isDevelopment
275
- ? (e.message || "Unknown Error")
276
- : "An error occurred in the Server Components render",
275
+ message: e.message || "Unknown Error",
277
276
  name: e.name,
278
277
  stack: isDevelopment ? e.stack : undefined,
279
278
  };