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
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { isDotEnvFileName } from "./runtime-env.js";
|
|
4
|
+
|
|
5
|
+
const IGNORED_OS_BASENAMES = new Set([".ds_store", "thumbs.db"]);
|
|
6
|
+
const warnedCollisionRoots = new Set();
|
|
7
|
+
|
|
8
|
+
function shouldCopyStaticEntry(srcPath) {
|
|
9
|
+
const baseLower = path.basename(srcPath).toLowerCase();
|
|
10
|
+
if (IGNORED_OS_BASENAMES.has(baseLower) || isDotEnvFileName(baseLower)) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function hasPublicStylesCss(projectRoot = process.cwd()) {
|
|
17
|
+
const publicDir = path.resolve(projectRoot || process.cwd(), "public");
|
|
18
|
+
if (!fs.existsSync(publicDir)) return false;
|
|
19
|
+
try {
|
|
20
|
+
const entries = fs.readdirSync(publicDir, { withFileTypes: true });
|
|
21
|
+
return entries.some(
|
|
22
|
+
(entry) =>
|
|
23
|
+
(entry.isFile() || entry.isSymbolicLink()) &&
|
|
24
|
+
entry.name.toLowerCase() === "styles.css"
|
|
25
|
+
);
|
|
26
|
+
} catch (e) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function warnPublicStylesCssCollision(projectRoot = process.cwd()) {
|
|
32
|
+
const rootDir = path.resolve(projectRoot || process.cwd());
|
|
33
|
+
const rootKey = rootDir.toLowerCase();
|
|
34
|
+
if (warnedCollisionRoots.has(rootKey)) return;
|
|
35
|
+
if (!hasPublicStylesCss(rootDir)) return;
|
|
36
|
+
warnedCollisionRoots.add(rootKey);
|
|
37
|
+
console.warn(
|
|
38
|
+
'⚠️ [Dinou] Detected "public/styles.css" alongside CSS imported in "src/". ' +
|
|
39
|
+
'"/styles.css" is used by Dinou\'s compiled stylesheet bundle, so "public/styles.css" was ignored. ' +
|
|
40
|
+
'Rename the file in "public/" (e.g. "public/custom.css") or import it from "src/".'
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Recursively copies the project's `public/` directory into `outdir`, preserving
|
|
46
|
+
* nested subdirectories and dotfiles (such as `public/.well-known/*` or `public/.nojekyll`).
|
|
47
|
+
* If Dinou already emitted a compiled `styles.css` from `src/`, root `public/styles.css`
|
|
48
|
+
* is skipped with a warning so compiled styles are never overwritten.
|
|
49
|
+
*/
|
|
50
|
+
export function copyStaticDirectoriesToOutdir(projectRoot, outdir, options = {}) {
|
|
51
|
+
const rootDir = path.resolve(projectRoot || process.cwd());
|
|
52
|
+
const srcDir = path.resolve(rootDir, "public");
|
|
53
|
+
if (!fs.existsSync(srcDir)) return false;
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
if (!fs.statSync(srcDir).isDirectory()) return false;
|
|
57
|
+
const destDir = path.resolve(rootDir, outdir);
|
|
58
|
+
fs.mkdirSync(destDir, { recursive: true });
|
|
59
|
+
|
|
60
|
+
const compiledStylesExists =
|
|
61
|
+
Boolean(options.hasCompiledStyles) ||
|
|
62
|
+
Boolean(
|
|
63
|
+
typeof globalThis !== "undefined" && globalThis.__DINOU_HAS_COMPILED_STYLES__
|
|
64
|
+
) ||
|
|
65
|
+
fs.existsSync(path.join(destDir, "styles.css"));
|
|
66
|
+
|
|
67
|
+
if (compiledStylesExists && hasPublicStylesCss(rootDir)) {
|
|
68
|
+
warnPublicStylesCssCollision(rootDir);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fs.cpSync(srcDir, destDir, {
|
|
72
|
+
recursive: true,
|
|
73
|
+
force: true,
|
|
74
|
+
dereference: true,
|
|
75
|
+
preserveTimestamps: true,
|
|
76
|
+
filter: (srcPath) => {
|
|
77
|
+
if (!shouldCopyStaticEntry(srcPath)) return false;
|
|
78
|
+
if (compiledStylesExists) {
|
|
79
|
+
const rel = path.relative(srcDir, srcPath);
|
|
80
|
+
if (
|
|
81
|
+
rel &&
|
|
82
|
+
!rel.includes(path.sep) &&
|
|
83
|
+
!rel.includes("/") &&
|
|
84
|
+
rel.toLowerCase() === "styles.css"
|
|
85
|
+
) {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
return true;
|
|
93
|
+
} catch (e) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default copyStaticDirectoriesToOutdir;
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import genericNames from "#generic-names";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import { normalizePathCase } from "./path-utils.js";
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const generatorCache = new Map();
|
|
6
|
+
|
|
7
|
+
function normalizeForHash(p) {
|
|
8
|
+
if (!p || typeof p !== "string") return "";
|
|
9
|
+
return normalizePathCase(path.resolve(p)).replace(/\\/g, "/");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function getGenerator(contextDir) {
|
|
13
|
+
let gen = generatorCache.get(contextDir);
|
|
14
|
+
if (!gen) {
|
|
15
|
+
gen = genericNames("[hash:base64]", { context: contextDir });
|
|
16
|
+
generatorCache.set(contextDir, gen);
|
|
17
|
+
}
|
|
18
|
+
return gen;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default function createScopedName(localName, filepath) {
|
|
22
|
+
const contextDir = normalizeForHash(path.resolve(process.cwd(), "src"));
|
|
23
|
+
const normalizedFilepath = filepath ? normalizeForHash(filepath) : filepath;
|
|
24
|
+
return getGenerator(contextDir)(localName, normalizedFilepath);
|
|
25
|
+
}
|
|
7
26
|
|
|
8
|
-
export default generate;
|
|
@@ -33,7 +33,7 @@ export function getDinouCoreDir() {
|
|
|
33
33
|
if (fs.existsSync && fs.existsSync(resolvedCore)) return resolvedCore;
|
|
34
34
|
} catch (e) { }
|
|
35
35
|
|
|
36
|
-
// 4. Modo bundle de
|
|
36
|
+
// 4. Modo bundle de servidor (ej. corriendo desde .dinou/dist1/server/handler.js)
|
|
37
37
|
// La estructura del paquete instalado es node_modules/dinou/dinou/core
|
|
38
38
|
try {
|
|
39
39
|
const cwd = typeof process !== "undefined" && process.cwd ? process.cwd() : "";
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
|
|
4
|
+
export function sortEntriesByName(entries) {
|
|
5
|
+
return [...entries].sort((a, b) => {
|
|
6
|
+
const na = typeof a === "string" ? a : a.name;
|
|
7
|
+
const nb = typeof b === "string" ? b : b.name;
|
|
8
|
+
return na < nb ? -1 : na > nb ? 1 : 0;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function stripGroups(rel) {
|
|
13
|
+
return rel
|
|
14
|
+
.split("/")
|
|
15
|
+
.filter(Boolean)
|
|
16
|
+
.filter((s) => !(s.startsWith("(") && s.endsWith(")")));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getSegmentTier(seg) {
|
|
20
|
+
if (seg.startsWith("[[...") && seg.endsWith("]]")) return 5;
|
|
21
|
+
if (seg.startsWith("[...") && seg.endsWith("]")) return 4;
|
|
22
|
+
if (seg.startsWith("[[") && seg.endsWith("]]")) return 3;
|
|
23
|
+
if (seg.startsWith("[") && seg.endsWith("]")) return 2;
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function compareRouteSegments(aSegs, bSegs) {
|
|
28
|
+
const minLen = Math.min(aSegs.length, bSegs.length);
|
|
29
|
+
for (let i = 0; i < minLen; i++) {
|
|
30
|
+
const ta = getSegmentTier(aSegs[i]);
|
|
31
|
+
const tb = getSegmentTier(bSegs[i]);
|
|
32
|
+
if (ta !== tb) return ta - tb;
|
|
33
|
+
if (ta === 1 && aSegs[i] !== bSegs[i]) {
|
|
34
|
+
return aSegs[i] < bSegs[i] ? -1 : 1;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (aSegs.length !== bSegs.length) {
|
|
38
|
+
return bSegs.length - aSegs.length;
|
|
39
|
+
}
|
|
40
|
+
const ja = aSegs.join("/");
|
|
41
|
+
const jb = bSegs.join("/");
|
|
42
|
+
return ja < jb ? -1 : ja > jb ? 1 : 0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function discoverLayoutsFromFileRelPaths(rawPaths) {
|
|
46
|
+
const normalized = [];
|
|
47
|
+
for (const raw of rawPaths) {
|
|
48
|
+
if (!raw || typeof raw !== "string") continue;
|
|
49
|
+
const clean = raw
|
|
50
|
+
.replace(/\\/g, "/")
|
|
51
|
+
.replace(/^\/+/, "")
|
|
52
|
+
.replace(/^src\/+/, "");
|
|
53
|
+
if (clean) normalized.push(clean);
|
|
54
|
+
}
|
|
55
|
+
normalized.sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
56
|
+
|
|
57
|
+
const discovered = [];
|
|
58
|
+
const layoutDirs = new Set();
|
|
59
|
+
const noLayoutDirs = new Set();
|
|
60
|
+
const pageDirs = new Set();
|
|
61
|
+
|
|
62
|
+
for (const relFile of normalized) {
|
|
63
|
+
const parts = relFile.split("/").filter(Boolean);
|
|
64
|
+
if (parts.length === 0) continue;
|
|
65
|
+
const fileName = parts[parts.length - 1];
|
|
66
|
+
const dirParts = parts.slice(0, -1);
|
|
67
|
+
const dirRel = dirParts.join("/");
|
|
68
|
+
|
|
69
|
+
const isSlotOrPrivate = dirParts.some(
|
|
70
|
+
(seg) => seg.startsWith("@") || seg.startsWith("_")
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (/^layout\.(?:[jt]sx?|mjs)$/.test(fileName)) {
|
|
74
|
+
if (!isSlotOrPrivate && !layoutDirs.has(dirRel)) {
|
|
75
|
+
layoutDirs.add(dirRel);
|
|
76
|
+
discovered.push(dirRel);
|
|
77
|
+
}
|
|
78
|
+
} else if (fileName === "no_layout") {
|
|
79
|
+
if (!isSlotOrPrivate && !noLayoutDirs.has(dirRel)) {
|
|
80
|
+
noLayoutDirs.add(dirRel);
|
|
81
|
+
discovered.push("!" + dirRel);
|
|
82
|
+
}
|
|
83
|
+
} else if (/^page\.(?:[jt]sx?|mjs)$/.test(fileName)) {
|
|
84
|
+
if (!isSlotOrPrivate) {
|
|
85
|
+
pageDirs.add(dirRel);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const pageRules = [];
|
|
91
|
+
for (const pageDir of pageDirs) {
|
|
92
|
+
const cleanPageSegs = stripGroups(pageDir);
|
|
93
|
+
let hasNoLayoutAtDestination = noLayoutDirs.has(pageDir);
|
|
94
|
+
if (!hasNoLayoutAtDestination && pageDir) {
|
|
95
|
+
let checkDir = pageDir;
|
|
96
|
+
while (checkDir) {
|
|
97
|
+
const lastSlash = checkDir.lastIndexOf("/");
|
|
98
|
+
const lastSeg =
|
|
99
|
+
lastSlash === -1 ? checkDir : checkDir.slice(lastSlash + 1);
|
|
100
|
+
if (!(lastSeg.startsWith("(") && lastSeg.endsWith(")"))) break;
|
|
101
|
+
checkDir = lastSlash === -1 ? "" : checkDir.slice(0, lastSlash);
|
|
102
|
+
if (noLayoutDirs.has(checkDir)) {
|
|
103
|
+
hasNoLayoutAtDestination = true;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let spec = "-1";
|
|
110
|
+
if (!hasNoLayoutAtDestination) {
|
|
111
|
+
let curr = pageDir;
|
|
112
|
+
while (true) {
|
|
113
|
+
if (layoutDirs.has(curr)) {
|
|
114
|
+
const cleanLayoutSegs = stripGroups(curr);
|
|
115
|
+
const hasCatchAll = cleanLayoutSegs.some(
|
|
116
|
+
(s) =>
|
|
117
|
+
(s.startsWith("[...") && s.endsWith("]")) ||
|
|
118
|
+
(s.startsWith("[[...") && s.endsWith("]]"))
|
|
119
|
+
);
|
|
120
|
+
if (hasCatchAll) {
|
|
121
|
+
const trailing = Math.max(
|
|
122
|
+
0,
|
|
123
|
+
cleanPageSegs.length - cleanLayoutSegs.length
|
|
124
|
+
);
|
|
125
|
+
spec = `*-${trailing}`;
|
|
126
|
+
} else {
|
|
127
|
+
spec = String(cleanLayoutSegs.length);
|
|
128
|
+
}
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
if (curr === "") break;
|
|
132
|
+
const slashIdx = curr.lastIndexOf("/");
|
|
133
|
+
curr = slashIdx === -1 ? "" : curr.slice(0, slashIdx);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
pageRules.push({
|
|
138
|
+
cleanPageSegs,
|
|
139
|
+
rawPageDir: pageDir,
|
|
140
|
+
pattern: cleanPageSegs.join("/"),
|
|
141
|
+
spec,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
pageRules.sort((a, b) => {
|
|
146
|
+
const cmp = compareRouteSegments(a.cleanPageSegs, b.cleanPageSegs);
|
|
147
|
+
if (cmp !== 0) return cmp;
|
|
148
|
+
return a.rawPageDir < b.rawPageDir
|
|
149
|
+
? -1
|
|
150
|
+
: a.rawPageDir > b.rawPageDir
|
|
151
|
+
? 1
|
|
152
|
+
: 0;
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
const seenPatterns = new Set();
|
|
156
|
+
for (const rule of pageRules) {
|
|
157
|
+
if (seenPatterns.has(rule.pattern)) continue;
|
|
158
|
+
seenPatterns.add(rule.pattern);
|
|
159
|
+
discovered.push(`=${rule.pattern}:${rule.spec}`);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return discovered;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function discoverLayoutsFromFs(srcDir, fsImpl = fs) {
|
|
166
|
+
const relFiles = [];
|
|
167
|
+
function walk(dir, rel = "") {
|
|
168
|
+
if (!fsImpl.existsSync(dir)) return;
|
|
169
|
+
let entries;
|
|
170
|
+
try {
|
|
171
|
+
entries = sortEntriesByName(
|
|
172
|
+
fsImpl.readdirSync(dir, { withFileTypes: true })
|
|
173
|
+
);
|
|
174
|
+
} catch {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
for (const entry of entries) {
|
|
178
|
+
const childRel = rel ? `${rel}/${entry.name}` : entry.name;
|
|
179
|
+
if (entry.isDirectory()) {
|
|
180
|
+
if (entry.name.startsWith("_") || entry.name.startsWith("@")) continue;
|
|
181
|
+
walk(path.join(dir, entry.name), childRel);
|
|
182
|
+
} else if (
|
|
183
|
+
/^layout\.(?:[jt]sx?|mjs)$/.test(entry.name) ||
|
|
184
|
+
/^page\.(?:[jt]sx?|mjs)$/.test(entry.name) ||
|
|
185
|
+
entry.name === "no_layout"
|
|
186
|
+
) {
|
|
187
|
+
relFiles.push(childRel);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
walk(srcDir);
|
|
192
|
+
return discoverLayoutsFromFileRelPaths(relFiles);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
export default {
|
|
196
|
+
sortEntriesByName,
|
|
197
|
+
discoverLayoutsFromFileRelPaths,
|
|
198
|
+
discoverLayoutsFromFs,
|
|
199
|
+
};
|
|
200
|
+
|
package/dinou/core/edge-ssr.js
CHANGED
|
@@ -123,7 +123,7 @@ export async function renderRscStreamToHtmlStream(rscStream, consumerManifest, o
|
|
|
123
123
|
await htmlStream.allReady;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
const importMapHtml = options.importMapHtml
|
|
126
|
+
const importMapHtml = options.importMapHtml !== undefined ? options.importMapHtml : ((typeof globalThis !== "undefined" && globalThis.__DINOU_IMPORT_MAP_HTML__) || "");
|
|
127
127
|
if (importMapHtml) {
|
|
128
128
|
const encoder = new TextEncoder();
|
|
129
129
|
const importMapBytes = encoder.encode(importMapHtml);
|
|
@@ -1,27 +1,86 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { readEnvFilesMap } from "./env.js";
|
|
2
3
|
|
|
3
|
-
export function
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
export function hasUnvendorizedInArgs(args = []) {
|
|
5
|
+
for (let i = 0; i < args.length; i++) {
|
|
6
|
+
const arg = String(args[i] || "");
|
|
7
|
+
if (
|
|
8
|
+
arg === "--conditions=unvendorized" ||
|
|
9
|
+
arg === "-C=unvendorized" ||
|
|
10
|
+
(arg.startsWith("--conditions=") &&
|
|
11
|
+
arg.slice("--conditions=".length).split(",").includes("unvendorized")) ||
|
|
12
|
+
(arg.startsWith("-C=") &&
|
|
13
|
+
arg.slice("-C=".length).split(",").includes("unvendorized"))
|
|
14
|
+
) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
if ((arg === "--conditions" || arg === "-C") && args[i + 1]) {
|
|
18
|
+
if (String(args[i + 1]).split(",").includes("unvendorized")) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function isUnvendorizedRequested(
|
|
27
|
+
projectRoot = process.cwd(),
|
|
28
|
+
argv = process.argv
|
|
29
|
+
) {
|
|
30
|
+
if (
|
|
6
31
|
argv.includes("-u") ||
|
|
7
32
|
argv.includes("--unvendorized") ||
|
|
8
33
|
process.env.DINOU_UNVENDORIZED === "true" ||
|
|
9
|
-
process.env.DINOU_UNVENDORIZED === "1"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
process.env.DINOU_UNVENDORIZED === "1" ||
|
|
35
|
+
hasUnvendorizedInArgs(process.execArgv)
|
|
36
|
+
) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const dotEnvMap = readEnvFilesMap(projectRoot).values;
|
|
41
|
+
return (
|
|
42
|
+
dotEnvMap.DINOU_UNVENDORIZED === "true" ||
|
|
43
|
+
dotEnvMap.DINOU_UNVENDORIZED === "1"
|
|
44
|
+
);
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function isUnvendorizedConditionActive() {
|
|
51
|
+
const isBunRuntime =
|
|
52
|
+
typeof Bun !== "undefined" || Boolean(process.versions?.bun);
|
|
53
|
+
if (hasUnvendorizedInArgs(process.execArgv)) {
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
if (!isBunRuntime && process.env.NODE_OPTIONS) {
|
|
57
|
+
return /(?:^|\s)(?:--conditions[=\s]|-C[=\s])[^\s]*\bunvendorized\b/.test(
|
|
58
|
+
process.env.NODE_OPTIONS
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function ensureVendorMode() {
|
|
65
|
+
if (isUnvendorizedRequested() && !isUnvendorizedConditionActive()) {
|
|
66
|
+
const baseNodeOptions = process.env.NODE_OPTIONS || "";
|
|
67
|
+
const nodeOptions = baseNodeOptions.includes("unvendorized")
|
|
68
|
+
? baseNodeOptions
|
|
69
|
+
: (baseNodeOptions ? `${baseNodeOptions} ` : "") +
|
|
70
|
+
"--conditions=unvendorized";
|
|
71
|
+
|
|
72
|
+
const child = spawn(
|
|
73
|
+
process.execPath,
|
|
74
|
+
[...process.execArgv, "--conditions=unvendorized", ...process.argv.slice(1)],
|
|
75
|
+
{
|
|
76
|
+
stdio: "inherit",
|
|
77
|
+
env: {
|
|
78
|
+
...process.env,
|
|
79
|
+
NODE_OPTIONS: nodeOptions,
|
|
80
|
+
DINOU_UNVENDORIZED: "true",
|
|
81
|
+
},
|
|
82
|
+
}
|
|
83
|
+
);
|
|
25
84
|
|
|
26
85
|
child.on("exit", (code, signal) => {
|
|
27
86
|
if (signal) process.kill(process.pid, signal);
|