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,15 +1,20 @@
1
1
  import { readFileSync } from "fs";
2
2
  import path from "node:path";
3
- import glob from "fast-glob";
3
+ import globModule from "#fast-glob";
4
+
5
+ const glob = globModule?.default || globModule;
4
6
  import { pathToFileURL } from "node:url";
5
7
  import parser from "#babel/parser";
6
8
  import traverse from "#babel/traverse";
7
9
  import crypto from "node:crypto";
8
10
  import {
9
- regex as assetRegex,
10
- globPattern as assetGlobPattern,
11
+ getAssetExtensionsInfo,
12
+ resolveAssetImport,
11
13
  } from "../../core/asset-extensions.js";
12
- import { getAbsPathWithExt } from "../../core/get-abs-path-with-ext.js";
14
+ import {
15
+ getAbsPathWithExt,
16
+ resolveStyleImportFromCode,
17
+ } from "../../core/get-abs-path-with-ext.js";
13
18
  import normalizePath from "./normalize-path.js";
14
19
  import { useClientRegex, useServerRegex } from "../../constants.js";
15
20
  import { hasServerFunctions } from "../../core/transform-server-functions.js";
@@ -21,12 +26,18 @@ function hashFilePath(absPath) {
21
26
 
22
27
  export default async function getEsbuildEntries({
23
28
  srcDir = path.resolve("src"),
24
- assetInclude = assetRegex,
29
+ assetInclude = null,
30
+ dinouConfig = null,
25
31
  manifest = {},
26
32
  } = {}) {
27
- const detectedClientEntries = new Set();
28
- const detectedCSSEntries = new Set();
29
- const detectedAssetEntries = new Set();
33
+ const projectRoot = path.dirname(path.resolve(srcDir));
34
+ const extInfo = getAssetExtensionsInfo(dinouConfig, projectRoot);
35
+ const activeAssetInclude = assetInclude || extInfo.regex;
36
+ const activeAssetGlobPattern = extInfo.globPattern;
37
+
38
+ const clientEntryMap = new Map();
39
+ const cssEntryMap = new Map();
40
+ const assetEntryMap = new Map();
30
41
  const serverModules = new Set();
31
42
  const serverFunctions = new Set();
32
43
 
@@ -61,16 +72,44 @@ export default async function getEsbuildEntries({
61
72
  for (const nodePath of importNodes) {
62
73
  const source = nodePath.node.source.value;
63
74
 
64
- // Resolve the import to absolute path (with extension) using your helper
65
- const absImportPathWithExt = getAbsPathWithExt(source, {
66
- parentURL: pathToFileURL(baseFilePath).href,
67
- });
75
+ // Resolve local/aliased imports, bare stylesheet imports, or bare asset imports from node_modules
76
+ const absImportPathWithExt =
77
+ getAbsPathWithExt(source, {
78
+ parentURL: pathToFileURL(baseFilePath).href,
79
+ cwd: projectRoot,
80
+ }) ||
81
+ resolveStyleImportFromCode(source, baseFilePath, projectRoot) ||
82
+ resolveAssetImport(source, {
83
+ importer: baseFilePath,
84
+ projectRoot,
85
+ assetRegex: activeAssetInclude,
86
+ });
68
87
 
69
88
  if (!absImportPathWithExt) {
70
89
  // unresolved - skip
71
90
  continue;
72
91
  }
73
92
 
93
+ if (
94
+ absImportPathWithExt.endsWith(".css") ||
95
+ absImportPathWithExt.endsWith(".scss") ||
96
+ absImportPathWithExt.endsWith(".less")
97
+ ) {
98
+ csss.add(absImportPathWithExt);
99
+ continue;
100
+ }
101
+
102
+ if (activeAssetInclude.test(absImportPathWithExt)) {
103
+ assets.add(absImportPathWithExt);
104
+ continue;
105
+ }
106
+
107
+ // If it is a JSON file, add it to imports without parsing with Babel
108
+ if (absImportPathWithExt.endsWith(".json")) {
109
+ imports.add(absImportPathWithExt);
110
+ continue;
111
+ }
112
+
74
113
  // Read the file ONLY once
75
114
  let importedCode;
76
115
  try {
@@ -110,27 +149,6 @@ export default async function getEsbuildEntries({
110
149
  }
111
150
  }
112
151
 
113
- // For non-client modules, process normally
114
- if (
115
- absImportPathWithExt.endsWith(".css") ||
116
- absImportPathWithExt.endsWith(".scss") ||
117
- absImportPathWithExt.endsWith(".less")
118
- ) {
119
- csss.add(absImportPathWithExt);
120
- continue;
121
- }
122
-
123
- if (assetInclude.test(absImportPathWithExt)) {
124
- assets.add(absImportPathWithExt);
125
- continue;
126
- }
127
-
128
- // 🚨 THE SOLUTION: If it is a JSON file, add it but DO NOT parse it with Babel
129
- if (absImportPathWithExt.endsWith(".json")) {
130
- imports.add(absImportPathWithExt);
131
- continue; // This prevents it from entering Babel recursion
132
- }
133
-
134
152
  imports.add(absImportPathWithExt);
135
153
 
136
154
  // Process imports recursively for non-client modules
@@ -164,6 +182,8 @@ export default async function getEsbuildEntries({
164
182
  return (
165
183
  fileName.startsWith("page.") ||
166
184
  fileName.startsWith("layout.") ||
185
+ fileName.startsWith("error.") ||
186
+ fileName.startsWith("not_found.") ||
167
187
  fileName.startsWith("page_functions.") ||
168
188
  fileName.startsWith("layout_functions.")
169
189
  );
@@ -173,6 +193,7 @@ export default async function getEsbuildEntries({
173
193
  const files = await glob(["**/*.{js,jsx,ts,tsx}"], {
174
194
  cwd: srcDir,
175
195
  absolute: true,
196
+ ignore: ["_*/**", "**/_*/**"],
176
197
  });
177
198
 
178
199
  // Gather client modules and update manifest entries
@@ -189,7 +210,7 @@ export default async function getEsbuildEntries({
189
210
  const name = path.basename(absPath, path.extname(absPath));
190
211
 
191
212
  updateManifestForModule(absPath, code, true, manifest);
192
- detectedClientEntries.add({
213
+ clientEntryMap.set(normalizedPath.toLowerCase(), {
193
214
  absPath: normalizedPath,
194
215
  name,
195
216
  });
@@ -207,18 +228,18 @@ export default async function getEsbuildEntries({
207
228
  absPath,
208
229
  );
209
230
 
210
- if (csss.length > 0) {
211
- detectedCSSEntries.add(
212
- ...csss.map((cssPath) => ({
213
- absPath: normalizePath(cssPath),
214
- name: path.basename(cssPath, path.extname(cssPath)),
215
- })),
216
- );
231
+ for (const cssPath of csss) {
232
+ const normCss = normalizePath(cssPath);
233
+ cssEntryMap.set(normCss.toLowerCase(), {
234
+ absPath: normCss,
235
+ name: path.basename(cssPath, path.extname(cssPath)),
236
+ });
217
237
  }
218
238
 
219
239
  assets.forEach((assetPath) => {
220
- detectedAssetEntries.add({
221
- absPath: normalizePath(assetPath),
240
+ const normAsset = normalizePath(assetPath);
241
+ assetEntryMap.set(normAsset.toLowerCase(), {
242
+ absPath: normAsset,
222
243
  name: path.basename(assetPath, path.extname(assetPath)),
223
244
  });
224
245
  });
@@ -235,32 +256,24 @@ export default async function getEsbuildEntries({
235
256
  }
236
257
  } // end for files
237
258
 
238
- const csss = await glob(["**/*.css"], {
239
- cwd: srcDir,
240
- absolute: true,
241
- });
242
- // console.log("detected css entries from glob:", csss);
243
-
244
- for (const absPath of csss) {
245
- detectedCSSEntries.add({
246
- absPath: normalizePath(absPath),
247
- name: path.basename(absPath, path.extname(absPath)),
248
- });
249
- }
250
- // console.log("final detectedCSSEntries:", detectedCSSEntries);
251
-
252
- const assets = await glob([assetGlobPattern], {
259
+ const assets = await glob([activeAssetGlobPattern], {
253
260
  cwd: srcDir,
254
261
  absolute: true,
262
+ ignore: ["_*/**", "**/_*/**"],
255
263
  });
256
264
 
257
265
  for (const absPath of assets) {
258
- detectedAssetEntries.add({
259
- absPath: normalizePath(absPath),
266
+ const normAsset = normalizePath(absPath);
267
+ assetEntryMap.set(normAsset.toLowerCase(), {
268
+ absPath: normAsset,
260
269
  name: path.basename(absPath, path.extname(absPath)),
261
270
  });
262
271
  }
263
272
 
273
+ const detectedClientEntries = new Set(clientEntryMap.values());
274
+ const detectedCSSEntries = new Set(cssEntryMap.values());
275
+ const detectedAssetEntries = new Set(assetEntryMap.values());
276
+
264
277
  for (const dCE of detectedClientEntries) {
265
278
  const hash = hashFilePath(dCE.absPath);
266
279
  const outfileName = `${dCE.name}-${hash}`;
@@ -1,11 +1,13 @@
1
1
  import fs from "node:fs/promises";
2
2
  import fsSync from "node:fs";
3
3
  import path from "node:path";
4
- import glob from "fast-glob";
4
+ import globModule from "#fast-glob";
5
+
6
+ const glob = globModule?.default || globModule;
5
7
  import { transform } from "@swc/core";
6
8
  import { useClientRegex, useServerRegex } from "../../constants.js";
7
9
  import { hasServerFunctions, extractServerFunctions } from "../../core/transform-server-functions.js";
8
- import { extensions as assetExtensions } from "../../core/asset-extensions.js";
10
+ import { getAssetExtensionsInfo } from "../../core/asset-extensions.js";
9
11
 
10
12
  function isServerFunctionsModule(raw, filename) {
11
13
  const trimmed = raw.trim();
@@ -19,9 +21,7 @@ function isServerFunctionsModule(raw, filename) {
19
21
  }
20
22
 
21
23
  const styleExtensions = ["css", "scss", "less", "sass"];
22
- const fontExtensions = ["woff", "woff2", "ttf", "eot", "otf"];
23
- const redirectExtensions = [...styleExtensions, ...assetExtensions, ...fontExtensions];
24
- const redirectFilter = new RegExp(`\\.(${redirectExtensions.join("|")})$`, "i");
24
+ const redirectFilter = new RegExp(`\\.(${styleExtensions.join("|")})$`, "i");
25
25
 
26
26
  const normPath = (p) => {
27
27
  if (!p) return "";
@@ -71,9 +71,12 @@ export async function transformToDisk(srcPath, projectRoot = process.cwd()) {
71
71
  return null;
72
72
  }
73
73
 
74
+ let compiledCode = raw;
74
75
  try {
75
76
  const { code } = await transform(raw, {
76
77
  filename: normSrc,
78
+ configFile: false,
79
+ swcrc: false,
77
80
  sourceMaps: "inline",
78
81
  jsc: {
79
82
  parser: { syntax: "typescript", tsx: true, dynamicImport: true },
@@ -87,18 +90,27 @@ export async function transformToDisk(srcPath, projectRoot = process.cwd()) {
87
90
  },
88
91
  },
89
92
  });
90
- await fs.mkdir(path.dirname(targetPath), { recursive: true });
91
- await fs.writeFile(targetPath, code, "utf8");
92
- return targetPath;
93
+ compiledCode = code;
93
94
  } catch (err) {
94
- await fs.mkdir(path.dirname(targetPath), { recursive: true });
95
- await fs.writeFile(targetPath, raw, "utf8");
96
- return targetPath;
95
+ compiledCode = raw;
96
+ }
97
+
98
+ const targetDir = path.dirname(targetPath);
99
+ for (let attempt = 0; attempt < 3; attempt++) {
100
+ try {
101
+ await fs.mkdir(targetDir, { recursive: true });
102
+ await fs.writeFile(targetPath, compiledCode, "utf8");
103
+ break;
104
+ } catch (ioErr) {
105
+ if (attempt === 2) throw ioErr;
106
+ await new Promise((r) => setTimeout(r, 15));
107
+ }
97
108
  }
109
+ return targetPath;
98
110
  }
99
111
 
100
112
  export async function syncAllSwcFiles(srcDir = path.resolve("src"), projectRoot = process.cwd()) {
101
- const files = await glob(["**/*.{js,jsx,ts,tsx}"], { cwd: srcDir, absolute: true });
113
+ const files = await glob(["**/*.{js,jsx,ts,tsx}"], { cwd: srcDir, absolute: true, ignore: ["_*/**", "**/_*/**"] });
102
114
  const tasks = [];
103
115
 
104
116
  for (const f of files) {
@@ -161,14 +173,17 @@ export function swcRedirectPlugin({ projectRoot = process.cwd() } = {}) {
161
173
  return {
162
174
  name: "swc-disk-cache-redirect",
163
175
  setup(build) {
176
+ let activeAssetFilter = getAssetExtensionsInfo(null, projectRoot).resolveFilterRegex;
164
177
  build.onStart(() => {
178
+ activeAssetFilter = getAssetExtensionsInfo(null, projectRoot).resolveFilterRegex;
165
179
  resolveCache.clear();
166
180
  redirTime = 0;
167
181
  redirCalls = 0;
168
182
  redirHits = 0;
169
183
  });
170
184
 
171
- // Redirect CSS, assets, and server functions / source files imported from inside .dinou/swc back to src/
185
+ // Redirect CSS and source files imported from inside .dinou/swc back to src/.
186
+ // Never intercept asset imports here so `assetsPlugin` handles them in the `dinou-asset` namespace.
172
187
  build.onResolve(
173
188
  { filter: /.*/ },
174
189
  (args) => {
@@ -177,10 +192,14 @@ export function swcRedirectPlugin({ projectRoot = process.cwd() } = {}) {
177
192
  return null;
178
193
  }
179
194
 
180
- // Only process relative imports or assets
195
+ if (activeAssetFilter.test(args.path)) {
196
+ return null;
197
+ }
198
+
199
+ // Only process relative imports or stylesheets
181
200
  const isRelative = args.path.startsWith(".");
182
- const isAsset = redirectFilter.test(args.path);
183
- if (!isRelative && !isAsset) {
201
+ const isStyle = redirectFilter.test(args.path);
202
+ if (!isRelative && !isStyle) {
184
203
  return null;
185
204
  }
186
205
 
@@ -1,6 +1,6 @@
1
1
  import fs from "node:fs/promises";
2
2
  import path from "node:path";
3
- import { regex } from "../../core/asset-extensions.js";
3
+ import { getAssetExtensionsInfo } from "../../core/asset-extensions.js";
4
4
 
5
5
  function areBuffersEqual(a, b) {
6
6
  if (a === b) return true;
@@ -22,16 +22,19 @@ export default async function write(result) {
22
22
  const skipSet = new Set();
23
23
  const normalizeRel = (p) => p.replace(/\\/g, "/");
24
24
  const cssRegex = /\.(css|scss|less)$/i;
25
+ const activeAssetRegex = getAssetExtensionsInfo(null, process.cwd()).regex;
25
26
  for (const [relPath, info] of Object.entries(result.metafile.outputs)) {
26
27
  if (!info.entryPoint) continue;
27
28
  let entryPointNormalized = info.entryPoint;
28
- if (entryPointNormalized.startsWith("dinou-asset:")) {
29
+ if (entryPointNormalized.startsWith("dinou-asset-entry:")) {
30
+ entryPointNormalized = entryPointNormalized.replace("dinou-asset-entry:", "");
31
+ } else if (entryPointNormalized.startsWith("dinou-asset:")) {
29
32
  entryPointNormalized = entryPointNormalized.replace("dinou-asset:", "");
30
33
  }
31
34
  const inputKeys = Object.keys(info.inputs);
32
35
  // Logic for assets
33
36
  if (
34
- regex.test(entryPointNormalized) &&
37
+ activeAssetRegex.test(entryPointNormalized) &&
35
38
  inputKeys.length === 1 &&
36
39
  inputKeys[0] === info.entryPoint
37
40
  ) {
@@ -117,7 +120,14 @@ export default async function write(result) {
117
120
  }
118
121
 
119
122
  const filesToWrite = [];
123
+ const seenWritePaths = new Set();
120
124
  for (const file of result.outputFiles) {
125
+ const resolvedOutPath = path.resolve(file.path);
126
+ const outKey = process.platform === "win32" ? resolvedOutPath.toLowerCase() : resolvedOutPath;
127
+ if (seenWritePaths.has(outKey)) {
128
+ continue;
129
+ }
130
+ seenWritePaths.add(outKey);
121
131
  const fileRelPath = normalizeRel(path.relative(process.cwd(), file.path));
122
132
  if (skipSet.has(fileRelPath)) {
123
133
  continue;