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.
- package/CHANGELOG.md +196 -0
- package/README.md +157 -132
- package/dinou/adapters/bun.js +34 -5
- package/dinou/adapters/cloudflare.js +110 -17
- package/dinou/adapters/deno.js +46 -8
- package/dinou/adapters/netlify.js +86 -50
- package/dinou/adapters/node.js +8 -0
- package/dinou/assets.d.ts +32 -5
- package/dinou/bun/build.js +190 -106
- package/dinou/cli.js +992 -532
- package/dinou/cloudflare/build.js +187 -106
- package/dinou/compiled/autoprefixer/index.js +509 -517
- package/dinou/compiled/babel-core/index.js +738 -716
- package/dinou/compiled/babel-generator/index.js +341 -299
- package/dinou/compiled/babel-loader/index.js +766 -744
- package/dinou/compiled/babel-parser/index.js +2 -2
- package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
- package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
- package/dinou/compiled/babel-preset-react/index.js +752 -730
- package/dinou/compiled/babel-preset-typescript/index.js +738 -716
- package/dinou/compiled/babel-traverse/index.js +463 -433
- package/dinou/compiled/babel-types/index.js +176 -176
- package/dinou/compiled/chokidar/index.js +4 -4
- package/dinou/compiled/commander/index.js +15 -15
- package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
- package/dinou/compiled/css-loader/index.js +289 -289
- package/dinou/compiled/css-loader/runtime/api.js +85 -0
- package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
- package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
- package/dinou/compiled/css-loader/runtime/package.json +3 -0
- package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
- package/dinou/compiled/fast-glob/index.js +5810 -0
- package/dinou/compiled/generic-names/index.js +16 -16
- package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js → chunk-R6DP5ZYM.js} +36 -36
- package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
- package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
- package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
- package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
- package/dinou/compiled/postcss/index.js +83 -83
- package/dinou/compiled/postcss-import/index.js +147 -117
- package/dinou/compiled/postcss-modules/index.js +216 -216
- package/dinou/compiled/resolve/index.js +1224 -0
- package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
- package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
- package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
- package/dinou/compiled/rollup-plugin-json/index.js +22 -18
- package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
- package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
- package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
- package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
- package/dinou/compiled/vendors-manifest.json +59 -83
- package/dinou/core/asset-extensions.js +482 -33
- package/dinou/core/bailout-proxy.js +21 -2
- package/dinou/core/build-static-pages.js +523 -371
- package/dinou/core/builtin-asset-extensions.js +63 -0
- package/dinou/core/cache-revalidate.js +449 -256
- package/dinou/core/cache-slot.js +289 -79
- package/dinou/core/client-webpack.jsx +470 -39
- package/dinou/core/client.jsx +402 -39
- package/dinou/core/config.js +3 -0
- package/dinou/core/copy-static-dirs.js +98 -0
- package/dinou/core/createScopedName.js +22 -4
- package/dinou/core/dinou-paths.js +1 -1
- package/dinou/core/discover-layouts.js +200 -0
- package/dinou/core/edge-ssr.js +1 -1
- package/dinou/core/ensure-vendor-mode.js +78 -19
- package/dinou/core/env.js +544 -0
- package/dinou/core/export-static.js +41 -9
- package/dinou/core/generate-route-types.js +989 -95
- package/dinou/core/generate-static-rsc.js +5 -6
- package/dinou/core/generate-static.js +45 -6
- package/dinou/core/get-abs-path-with-ext.js +217 -75
- package/dinou/core/get-asset-from-manifest.js +19 -8
- package/dinou/core/get-error-jsx.js +4 -5
- package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
- package/dinou/core/get-jsx.js +220 -53
- package/dinou/core/handler.js +1647 -466
- package/dinou/core/import-module.js +7 -0
- package/dinou/core/layout-functions.js +72 -13
- package/dinou/core/link.jsx +34 -6
- package/dinou/core/load-dinou-config.js +520 -89
- package/dinou/core/manifest-provider.js +4 -14
- package/dinou/core/navigation-utils.js +141 -3
- package/dinou/core/navigation.js +134 -50
- package/dinou/core/node-middleware-runner.js +165 -0
- package/dinou/core/postcss-pipeline.js +236 -0
- package/dinou/core/ppr-context.js +114 -22
- package/dinou/core/ppr-runtime.js +391 -127
- package/dinou/core/redirect.jsx +1 -1
- package/dinou/core/render-jsx-to-client-jsx.js +216 -48
- package/dinou/core/request-context.js +59 -3
- package/dinou/core/resolve-contextual-dinou.js +523 -0
- package/dinou/core/resolve-setup-files.js +85 -27
- package/dinou/core/revalidating.js +10 -2
- package/dinou/core/route-generator.js +6 -2
- package/dinou/core/rsc-renderer.js +4 -1
- package/dinou/core/run-ssg.js +6 -0
- package/dinou/core/runtime-env.js +265 -0
- package/dinou/core/server-css-modules-plugin.js +155 -0
- package/dinou/core/server-function-proxy-webpack.js +27 -2
- package/dinou/core/server-function-proxy.js +27 -2
- package/dinou/core/slot.js +47 -2
- package/dinou/core/static-assets.js +503 -0
- package/dinou/core/storage-adapter.js +452 -24
- package/dinou/core/transform-server-functions.js +272 -24
- package/dinou/core/tsconfig-aliases.js +964 -0
- package/dinou/core/uneject.js +640 -0
- package/dinou/core/url-resolver.js +1 -1
- package/dinou/core/vfs.js +11 -2
- package/dinou/css.d.ts +4 -1
- package/dinou/deno/build.js +205 -153
- package/dinou/deno/seed-kv.js +4 -0
- package/dinou/env.d.ts +22 -2
- package/dinou/esbuild/build.js +40 -50
- package/dinou/esbuild/dev.js +33 -7
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
- package/dinou/esbuild/helpers-esbuild/write.js +13 -3
- package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
- package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
- package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
- package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
- package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
- package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
- package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
- package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
- package/dinou/index.d.ts +1028 -88
- package/dinou/node/build.js +138 -74
- package/dinou/node/bundle-dual-engine.js +393 -131
- package/dinou/node/dev.js +1005 -275
- package/dinou/package.json +11 -34
- package/dinou/rollup/postcss.config.js +3 -4
- package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
- package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
- package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
- package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
- package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
- package/dinou/rollup/rollup.config.js +174 -101
- package/dinou/scripts/build-vendors.js +123 -33
- package/dinou/server.d.ts +126 -15
- package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
- package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
- package/dinou/webpack/loaders/server-functions-loader.js +1 -1
- package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
- package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
- package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
- package/dinou/webpack/postcss.config.js +3 -4
- package/dinou/webpack/webpack.config.js +408 -132
- package/eject.js +6 -224
- package/package.json +7 -9
- package/dinou/compiled/cross-env/index.js +0 -661
- package/dinou/compiled/dotenv/index.js +0 -375
- package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
- package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
- package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
- package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
- 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
|
|
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
|
-
|
|
10
|
-
|
|
11
|
+
getAssetExtensionsInfo,
|
|
12
|
+
resolveAssetImport,
|
|
11
13
|
} from "../../core/asset-extensions.js";
|
|
12
|
-
import {
|
|
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 =
|
|
29
|
+
assetInclude = null,
|
|
30
|
+
dinouConfig = null,
|
|
25
31
|
manifest = {},
|
|
26
32
|
} = {}) {
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
const
|
|
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
|
|
65
|
-
const absImportPathWithExt =
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
221
|
-
|
|
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
|
|
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
|
-
|
|
259
|
-
|
|
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
|
|
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 {
|
|
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
|
|
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
|
-
|
|
91
|
-
await fs.writeFile(targetPath, code, "utf8");
|
|
92
|
-
return targetPath;
|
|
93
|
+
compiledCode = code;
|
|
93
94
|
} catch (err) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
183
|
-
if (!isRelative && !
|
|
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 {
|
|
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
|
-
|
|
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;
|