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
|
@@ -11,6 +11,8 @@ function collectSourceFiles(dir, baseDir = dir) {
|
|
|
11
11
|
for (const entry of entries) {
|
|
12
12
|
const fullPath = path.join(dir, entry.name);
|
|
13
13
|
if (entry.isDirectory()) {
|
|
14
|
+
// Folders prefixed with "_" are completely ignored by Dinou's router and bundlers
|
|
15
|
+
if (entry.name.startsWith("_")) continue;
|
|
14
16
|
files = files.concat(collectSourceFiles(fullPath, baseDir));
|
|
15
17
|
} else if (/\.(?:[jt]sx?|mjs)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) {
|
|
16
18
|
const relPath = path.relative(baseDir, fullPath).replace(/\\/g, "/");
|
|
@@ -34,7 +36,7 @@ function generateRouteModulesCode(projectRoot = process.cwd(), relativeImportBas
|
|
|
34
36
|
const srcDir = path.resolve(projectRoot, "src");
|
|
35
37
|
const files = collectSourceFiles(srcDir);
|
|
36
38
|
|
|
37
|
-
const configFilenames = ["dinou.config.
|
|
39
|
+
const configFilenames = ["dinou.config.ts", "dinou.config.mjs", "dinou.config.js", "dinou.config.cjs"];
|
|
38
40
|
let foundConfig = null;
|
|
39
41
|
for (const cf of configFilenames) {
|
|
40
42
|
if (fs.existsSync(path.resolve(projectRoot, cf))) {
|
|
@@ -87,7 +89,9 @@ function generateRouteModulesCode(projectRoot = process.cwd(), relativeImportBas
|
|
|
87
89
|
lines.push(" };");
|
|
88
90
|
if (foundConfig) {
|
|
89
91
|
lines.push(" const resolvedConfig = (dinouConfigModule && dinouConfigModule.default) ? dinouConfigModule.default : dinouConfigModule;");
|
|
90
|
-
lines.push(" globalThis.
|
|
92
|
+
lines.push(" if (!globalThis.__DINOU_DEV__ && (typeof process === 'undefined' || !process.env || process.env.DINOU_DEV !== 'true')) {");
|
|
93
|
+
lines.push(" globalThis.__DINOU_CONFIG__ = resolvedConfig;");
|
|
94
|
+
lines.push(" }");
|
|
91
95
|
}
|
|
92
96
|
lines.push("}");
|
|
93
97
|
lines.push("");
|
|
@@ -5,7 +5,10 @@ import { pathToFileURL } from "node:url";
|
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
6
|
import { ensureServerHooksPatched } from "./render-jsx-to-client-jsx.js";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
let require = null;
|
|
9
|
+
try {
|
|
10
|
+
require = createRequire(import.meta.url);
|
|
11
|
+
} catch (e) {}
|
|
9
12
|
|
|
10
13
|
const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
11
14
|
|
package/dinou/core/run-ssg.js
CHANGED
|
@@ -4,6 +4,12 @@ process.env.NODE_ENV = "production";
|
|
|
4
4
|
process.env.DINOU_RUNTIME = "node-bundle";
|
|
5
5
|
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
+
import { loadEnvFiles } from "./env.js";
|
|
8
|
+
import ensureVendorMode from "./ensure-vendor-mode.js";
|
|
9
|
+
loadEnvFiles(process.cwd(), { mode: "production" });
|
|
10
|
+
if (!ensureVendorMode()) {
|
|
11
|
+
await new Promise(() => {});
|
|
12
|
+
}
|
|
7
13
|
import generateStatic from "./generate-static.js";
|
|
8
14
|
|
|
9
15
|
export async function runSSG() {
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// dinou/core/runtime-env.js
|
|
2
|
+
// Runtime-agnostic environment helpers with zero Node filesystem/path imports.
|
|
3
|
+
// Safe across Node.js, Bun, Deno, Cloudflare Workers (workerd), and Browser bundles.
|
|
4
|
+
|
|
5
|
+
export const DINOU_PUBLIC_PREFIX = "DINOU_PUBLIC_";
|
|
6
|
+
|
|
7
|
+
const unifiedEnvCache = typeof WeakMap !== "undefined" ? new WeakMap() : null;
|
|
8
|
+
let defaultServerEnvProxy = null;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns true if a file basename is `.env` or `.env.*` (case-insensitive).
|
|
12
|
+
*/
|
|
13
|
+
export function isDotEnvFileName(name) {
|
|
14
|
+
if (!name || typeof name !== "string") return false;
|
|
15
|
+
const clean = name.replace(/\\/g, "/").split("/").pop() || "";
|
|
16
|
+
const lower = clean.toLowerCase();
|
|
17
|
+
return lower === ".env" || lower.startsWith(".env.");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Safely URL-decodes up to two layers so percent-encoded probes such as
|
|
22
|
+
* `/%2eenv`, `/.%65nv`, or `/%252eenv` cannot bypass the Anti-Bot Shield.
|
|
23
|
+
*/
|
|
24
|
+
function safeDecodePathnameCandidates(pathname) {
|
|
25
|
+
if (!pathname || typeof pathname !== "string") return [];
|
|
26
|
+
const candidates = new Set([pathname]);
|
|
27
|
+
let current = pathname;
|
|
28
|
+
for (let i = 0; i < 2; i++) {
|
|
29
|
+
try {
|
|
30
|
+
const next = decodeURIComponent(current);
|
|
31
|
+
if (next === current) break;
|
|
32
|
+
candidates.add(next);
|
|
33
|
+
current = next;
|
|
34
|
+
} catch {
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return Array.from(candidates);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const BOT_DOT_ENV_SEGMENT_REGEX = /(?:^|\/)\.env(?:\.[a-z0-9_-]+)*(?:\/|$)/i;
|
|
42
|
+
const BOT_TRAILING_ENV_EXT_REGEX = /\.env$/i;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns true when an incoming HTTP URL pathname probes `.env` or `.env.*` files
|
|
46
|
+
* (including nested `/api/.env.local`, `/backup.env`, or URL-encoded `/%2eenv`),
|
|
47
|
+
* without matching legitimate routes such as `/docs/env` or `/docs/env-vars`.
|
|
48
|
+
*/
|
|
49
|
+
export function isBotEnvProbePath(pathname) {
|
|
50
|
+
const candidates = safeDecodePathnameCandidates(pathname);
|
|
51
|
+
for (const candidate of candidates) {
|
|
52
|
+
const normalized = candidate.replace(/\\/g, "/");
|
|
53
|
+
if (
|
|
54
|
+
BOT_DOT_ENV_SEGMENT_REGEX.test(normalized) ||
|
|
55
|
+
BOT_TRAILING_ENV_EXT_REGEX.test(normalized)
|
|
56
|
+
) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Mirrors plain-text string variables from an Edge/Cloudflare `env` object onto
|
|
65
|
+
* `process.env` when `process.env` is available (e.g. `nodejs_compat`) and the key
|
|
66
|
+
* is not yet populated, preserving live resource bindings untouched.
|
|
67
|
+
*/
|
|
68
|
+
export function syncEdgeEnvToProcessEnv(platformEnv) {
|
|
69
|
+
if (
|
|
70
|
+
typeof window !== "undefined" ||
|
|
71
|
+
!platformEnv ||
|
|
72
|
+
typeof platformEnv !== "object"
|
|
73
|
+
) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (
|
|
77
|
+
typeof process === "undefined" ||
|
|
78
|
+
!process ||
|
|
79
|
+
!process.env ||
|
|
80
|
+
typeof process.env !== "object"
|
|
81
|
+
) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const procEnv = process.env;
|
|
85
|
+
try {
|
|
86
|
+
for (const key of Object.keys(platformEnv)) {
|
|
87
|
+
const val = platformEnv[key];
|
|
88
|
+
if (typeof val === "string" && procEnv[key] === undefined) {
|
|
89
|
+
try {
|
|
90
|
+
procEnv[key] = val;
|
|
91
|
+
} catch {}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
} catch {}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function readFallbackServerEnvValue(prop) {
|
|
98
|
+
if (typeof window !== "undefined" || typeof prop !== "string") {
|
|
99
|
+
return undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const globalEdgeEnv =
|
|
103
|
+
typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__ : null;
|
|
104
|
+
if (
|
|
105
|
+
globalEdgeEnv &&
|
|
106
|
+
typeof globalEdgeEnv === "object" &&
|
|
107
|
+
prop in globalEdgeEnv &&
|
|
108
|
+
globalEdgeEnv[prop] !== undefined
|
|
109
|
+
) {
|
|
110
|
+
return globalEdgeEnv[prop];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (
|
|
114
|
+
typeof process !== "undefined" &&
|
|
115
|
+
process &&
|
|
116
|
+
process.env &&
|
|
117
|
+
typeof process.env === "object" &&
|
|
118
|
+
prop in process.env &&
|
|
119
|
+
process.env[prop] !== undefined
|
|
120
|
+
) {
|
|
121
|
+
return process.env[prop];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (
|
|
125
|
+
typeof Deno !== "undefined" &&
|
|
126
|
+
Deno &&
|
|
127
|
+
Deno.env &&
|
|
128
|
+
typeof Deno.env.get === "function"
|
|
129
|
+
) {
|
|
130
|
+
try {
|
|
131
|
+
const val = Deno.env.get(prop);
|
|
132
|
+
if (val !== undefined) return val;
|
|
133
|
+
} catch {}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function collectFallbackServerEnvKeys() {
|
|
140
|
+
const keys = new Set();
|
|
141
|
+
if (typeof window !== "undefined") return keys;
|
|
142
|
+
|
|
143
|
+
const globalEdgeEnv =
|
|
144
|
+
typeof globalThis !== "undefined" ? globalThis.__DINOU_ENV__ : null;
|
|
145
|
+
if (globalEdgeEnv && typeof globalEdgeEnv === "object") {
|
|
146
|
+
try {
|
|
147
|
+
for (const k of Object.keys(globalEdgeEnv)) keys.add(k);
|
|
148
|
+
} catch {}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (
|
|
152
|
+
typeof process !== "undefined" &&
|
|
153
|
+
process &&
|
|
154
|
+
process.env &&
|
|
155
|
+
typeof process.env === "object"
|
|
156
|
+
) {
|
|
157
|
+
try {
|
|
158
|
+
for (const k of Object.keys(process.env)) keys.add(k);
|
|
159
|
+
} catch {}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (
|
|
163
|
+
typeof Deno !== "undefined" &&
|
|
164
|
+
Deno &&
|
|
165
|
+
Deno.env &&
|
|
166
|
+
typeof Deno.env.toObject === "function"
|
|
167
|
+
) {
|
|
168
|
+
try {
|
|
169
|
+
for (const k of Object.keys(Deno.env.toObject())) keys.add(k);
|
|
170
|
+
} catch {}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return keys;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function buildUnifiedEnvProxy(baseTarget) {
|
|
177
|
+
const target = baseTarget && typeof baseTarget === "object" ? baseTarget : {};
|
|
178
|
+
return new Proxy(target, {
|
|
179
|
+
get(t, prop) {
|
|
180
|
+
if (typeof prop === "symbol") {
|
|
181
|
+
return Reflect.get(t, prop, t);
|
|
182
|
+
}
|
|
183
|
+
if (prop in t && t[prop] !== undefined) {
|
|
184
|
+
return Reflect.get(t, prop, t);
|
|
185
|
+
}
|
|
186
|
+
return readFallbackServerEnvValue(prop);
|
|
187
|
+
},
|
|
188
|
+
has(t, prop) {
|
|
189
|
+
if (typeof prop === "symbol") {
|
|
190
|
+
return Reflect.has(t, prop);
|
|
191
|
+
}
|
|
192
|
+
if (prop in t) {
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
return readFallbackServerEnvValue(prop) !== undefined;
|
|
196
|
+
},
|
|
197
|
+
ownKeys(t) {
|
|
198
|
+
const merged = new Set(Reflect.ownKeys(t));
|
|
199
|
+
for (const k of collectFallbackServerEnvKeys()) {
|
|
200
|
+
merged.add(k);
|
|
201
|
+
}
|
|
202
|
+
return Array.from(merged);
|
|
203
|
+
},
|
|
204
|
+
getOwnPropertyDescriptor(t, prop) {
|
|
205
|
+
if (
|
|
206
|
+
typeof prop === "symbol" ||
|
|
207
|
+
Object.prototype.hasOwnProperty.call(t, prop)
|
|
208
|
+
) {
|
|
209
|
+
return Object.getOwnPropertyDescriptor(t, prop);
|
|
210
|
+
}
|
|
211
|
+
const val = readFallbackServerEnvValue(prop);
|
|
212
|
+
if (val !== undefined) {
|
|
213
|
+
return {
|
|
214
|
+
configurable: true,
|
|
215
|
+
enumerable: true,
|
|
216
|
+
writable: false,
|
|
217
|
+
value: val,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
return undefined;
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Creates a zero-copy unified server `env` view for `getContext().env` and `req.env`
|
|
227
|
+
* across Cloudflare Workers (preserving live KV, D1, R2, and ASSETS bindings),
|
|
228
|
+
* Node.js, Bun, Deno, Netlify, and SSG/ISR contexts.
|
|
229
|
+
*/
|
|
230
|
+
export function createUnifiedEnv(platformEnv) {
|
|
231
|
+
if (typeof window !== "undefined") {
|
|
232
|
+
return {};
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const hasCustomTarget =
|
|
236
|
+
platformEnv &&
|
|
237
|
+
typeof platformEnv === "object" &&
|
|
238
|
+
Object.keys(platformEnv).length > 0;
|
|
239
|
+
|
|
240
|
+
if (!hasCustomTarget) {
|
|
241
|
+
if (!defaultServerEnvProxy) {
|
|
242
|
+
defaultServerEnvProxy = buildUnifiedEnvProxy({});
|
|
243
|
+
}
|
|
244
|
+
return defaultServerEnvProxy;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (unifiedEnvCache) {
|
|
248
|
+
const cached = unifiedEnvCache.get(platformEnv);
|
|
249
|
+
if (cached) return cached;
|
|
250
|
+
const created = buildUnifiedEnvProxy(platformEnv);
|
|
251
|
+
unifiedEnvCache.set(platformEnv, created);
|
|
252
|
+
return created;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return buildUnifiedEnvProxy(platformEnv);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export default {
|
|
259
|
+
DINOU_PUBLIC_PREFIX,
|
|
260
|
+
isDotEnvFileName,
|
|
261
|
+
isBotEnvProbePath,
|
|
262
|
+
syncEdgeEnvToProcessEnv,
|
|
263
|
+
createUnifiedEnv,
|
|
264
|
+
};
|
|
265
|
+
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import createScopedName from "./createScopedName.js";
|
|
4
|
+
import { normalizePathCase } from "./path-utils.js";
|
|
5
|
+
import {
|
|
6
|
+
resolveCssImportSpecifier,
|
|
7
|
+
resolveStyleImportFromCode,
|
|
8
|
+
} from "./get-abs-path-with-ext.js";
|
|
9
|
+
import {
|
|
10
|
+
postcss,
|
|
11
|
+
postcssImport,
|
|
12
|
+
postCssModules,
|
|
13
|
+
createHoistCssImportsPlugin,
|
|
14
|
+
} from "./postcss-pipeline.js";
|
|
15
|
+
|
|
16
|
+
const serverCssModuleCache = new Map();
|
|
17
|
+
const lastKnownExportJsonByFile = new Map();
|
|
18
|
+
|
|
19
|
+
export function clearServerCssModulesCache() {
|
|
20
|
+
serverCssModuleCache.clear();
|
|
21
|
+
lastKnownExportJsonByFile.clear();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function normalizeCacheKey(filePath) {
|
|
25
|
+
return normalizePathCase(path.resolve(filePath)).replace(/\\/g, "/");
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getFileMtimeSafe(filePath) {
|
|
29
|
+
try {
|
|
30
|
+
return fs.statSync(filePath).mtimeMs;
|
|
31
|
+
} catch (e) {
|
|
32
|
+
return -1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isCacheEntryFresh(entry, rootPath) {
|
|
37
|
+
if (!entry) return false;
|
|
38
|
+
const currentMtime = getFileMtimeSafe(rootPath);
|
|
39
|
+
if (currentMtime < 0 || currentMtime !== entry.mtimeMs) return false;
|
|
40
|
+
if (Array.isArray(entry.deps)) {
|
|
41
|
+
for (const dep of entry.deps) {
|
|
42
|
+
if (getFileMtimeSafe(dep.path) !== dep.mtimeMs) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function compileCssModuleMap(filePath) {
|
|
51
|
+
const absPath = path.resolve(filePath);
|
|
52
|
+
const key = normalizeCacheKey(absPath);
|
|
53
|
+
const cached = serverCssModuleCache.get(key);
|
|
54
|
+
if (isCacheEntryFresh(cached, absPath)) {
|
|
55
|
+
return {
|
|
56
|
+
map: cached.map,
|
|
57
|
+
contents: cached.contents,
|
|
58
|
+
watchFiles: cached.watchFiles,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const mtimeMs = getFileMtimeSafe(absPath);
|
|
63
|
+
const source = await fs.promises.readFile(absPath, "utf8");
|
|
64
|
+
let map = {};
|
|
65
|
+
|
|
66
|
+
const result = await postcss([
|
|
67
|
+
createHoistCssImportsPlugin(),
|
|
68
|
+
postcssImport({
|
|
69
|
+
resolve: (id, basedir) => resolveCssImportSpecifier(id, basedir),
|
|
70
|
+
}),
|
|
71
|
+
postCssModules({
|
|
72
|
+
generateScopedName: (name, filename) => {
|
|
73
|
+
if (!filename || !/\.module\.css$/i.test(filename)) return name;
|
|
74
|
+
return createScopedName(name, filename);
|
|
75
|
+
},
|
|
76
|
+
getJSON: (_, json) => {
|
|
77
|
+
map = json || {};
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
]).process(source, { from: absPath });
|
|
81
|
+
|
|
82
|
+
const depPaths = new Set();
|
|
83
|
+
if (Array.isArray(result.messages)) {
|
|
84
|
+
for (const msg of result.messages) {
|
|
85
|
+
if (msg && msg.type === "dependency" && msg.file) {
|
|
86
|
+
depPaths.add(path.resolve(msg.file));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
depPaths.delete(absPath);
|
|
91
|
+
|
|
92
|
+
const deps = Array.from(depPaths).map((depPath) => ({
|
|
93
|
+
path: depPath,
|
|
94
|
+
mtimeMs: getFileMtimeSafe(depPath),
|
|
95
|
+
}));
|
|
96
|
+
const watchFiles = [absPath, ...Array.from(depPaths)];
|
|
97
|
+
const mapJson = JSON.stringify(map);
|
|
98
|
+
const contents = `export default ${mapJson};`;
|
|
99
|
+
|
|
100
|
+
lastKnownExportJsonByFile.set(key, mapJson);
|
|
101
|
+
serverCssModuleCache.set(key, {
|
|
102
|
+
mtimeMs,
|
|
103
|
+
deps,
|
|
104
|
+
map,
|
|
105
|
+
mapJson,
|
|
106
|
+
contents,
|
|
107
|
+
watchFiles,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return { map, contents, watchFiles };
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function didCssModuleExportsChange(filePath) {
|
|
114
|
+
const absPath = path.resolve(filePath);
|
|
115
|
+
const key = normalizeCacheKey(absPath);
|
|
116
|
+
const prevJson = lastKnownExportJsonByFile.get(key);
|
|
117
|
+
if (!fs.existsSync(absPath)) {
|
|
118
|
+
lastKnownExportJsonByFile.delete(key);
|
|
119
|
+
serverCssModuleCache.delete(key);
|
|
120
|
+
return prevJson !== undefined;
|
|
121
|
+
}
|
|
122
|
+
const { map } = await compileCssModuleMap(absPath);
|
|
123
|
+
const nextJson = JSON.stringify(map);
|
|
124
|
+
return prevJson === undefined || prevJson !== nextJson;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function createServerCssModulesPlugin({ projectRoot = process.cwd() } = {}) {
|
|
128
|
+
return {
|
|
129
|
+
name: "dinou-server-css-modules",
|
|
130
|
+
setup(build) {
|
|
131
|
+
build.onResolve({ filter: /\.(?:css|scss|sass|less)(?:[?#].*)?$/i }, (args) => {
|
|
132
|
+
if (args.pluginData?.skipDinouServerCssResolve) return null;
|
|
133
|
+
const importer =
|
|
134
|
+
args.importer ||
|
|
135
|
+
path.join(args.resolveDir || projectRoot, "__dinou_server_css__.js");
|
|
136
|
+
const resolved = resolveStyleImportFromCode(args.path, importer);
|
|
137
|
+
if (resolved) {
|
|
138
|
+
return { path: resolved };
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
build.onLoad({ filter: /\.module\.css$/i }, async (args) => {
|
|
144
|
+
const { contents, watchFiles } = await compileCssModuleMap(args.path);
|
|
145
|
+
return {
|
|
146
|
+
contents,
|
|
147
|
+
loader: "js",
|
|
148
|
+
watchFiles,
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default createServerCssModulesPlugin;
|
|
@@ -68,7 +68,27 @@ function createServerFunctionProxy(id) {
|
|
|
68
68
|
body,
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
if (!res.ok)
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
let errorMessage = "Server function failed";
|
|
73
|
+
let errorDigest;
|
|
74
|
+
try {
|
|
75
|
+
const errContentType = res.headers.get("content-type") || "";
|
|
76
|
+
if (errContentType.includes("application/json")) {
|
|
77
|
+
const errData = await res.json();
|
|
78
|
+
if (errData && typeof errData.error === "string" && errData.error) {
|
|
79
|
+
errorMessage = errData.error;
|
|
80
|
+
}
|
|
81
|
+
if (errData && typeof errData.digest === "string") {
|
|
82
|
+
errorDigest = errData.digest;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch (_) {}
|
|
86
|
+
const err = new Error(errorMessage);
|
|
87
|
+
if (errorDigest !== undefined) {
|
|
88
|
+
err.digest = errorDigest;
|
|
89
|
+
}
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
72
92
|
|
|
73
93
|
// Check header first
|
|
74
94
|
const redirectUrl = res.headers.get("X-Dinou-Redirect");
|
|
@@ -178,7 +198,12 @@ function createServerFunctionProxy(id) {
|
|
|
178
198
|
},
|
|
179
199
|
});
|
|
180
200
|
|
|
181
|
-
return createFromFetch(Promise.resolve(new Response(readableStream))
|
|
201
|
+
return createFromFetch(Promise.resolve(new Response(readableStream)), {
|
|
202
|
+
callServer: async (nextId, nextArgs) => {
|
|
203
|
+
const proxy = createServerFunctionProxy(nextId);
|
|
204
|
+
return proxy(...nextArgs);
|
|
205
|
+
},
|
|
206
|
+
});
|
|
182
207
|
}
|
|
183
208
|
return res.json();
|
|
184
209
|
},
|
|
@@ -68,7 +68,27 @@ export function createServerFunctionProxy(id) {
|
|
|
68
68
|
body,
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
if (!res.ok)
|
|
71
|
+
if (!res.ok) {
|
|
72
|
+
let errorMessage = "Server function failed";
|
|
73
|
+
let errorDigest;
|
|
74
|
+
try {
|
|
75
|
+
const errContentType = res.headers.get("content-type") || "";
|
|
76
|
+
if (errContentType.includes("application/json")) {
|
|
77
|
+
const errData = await res.json();
|
|
78
|
+
if (errData && typeof errData.error === "string" && errData.error) {
|
|
79
|
+
errorMessage = errData.error;
|
|
80
|
+
}
|
|
81
|
+
if (errData && typeof errData.digest === "string") {
|
|
82
|
+
errorDigest = errData.digest;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
} catch (_) {}
|
|
86
|
+
const err = new Error(errorMessage);
|
|
87
|
+
if (errorDigest !== undefined) {
|
|
88
|
+
err.digest = errorDigest;
|
|
89
|
+
}
|
|
90
|
+
throw err;
|
|
91
|
+
}
|
|
72
92
|
|
|
73
93
|
// Check header first
|
|
74
94
|
const redirectUrl = res.headers.get("X-Dinou-Redirect");
|
|
@@ -179,7 +199,12 @@ export function createServerFunctionProxy(id) {
|
|
|
179
199
|
},
|
|
180
200
|
});
|
|
181
201
|
|
|
182
|
-
return createFromFetch(Promise.resolve(new Response(readableStream))
|
|
202
|
+
return createFromFetch(Promise.resolve(new Response(readableStream)), {
|
|
203
|
+
callServer: async (nextId, nextArgs) => {
|
|
204
|
+
const proxy = createServerFunctionProxy(nextId);
|
|
205
|
+
return proxy(...nextArgs);
|
|
206
|
+
},
|
|
207
|
+
});
|
|
183
208
|
}
|
|
184
209
|
return res.json();
|
|
185
210
|
},
|
package/dinou/core/slot.js
CHANGED
|
@@ -14,6 +14,34 @@ const createElement = React.createElement;
|
|
|
14
14
|
const Suspense = React.Suspense;
|
|
15
15
|
const Component = typeof React.Component === "function" ? React.Component : class {};
|
|
16
16
|
|
|
17
|
+
export function flushPendingSsrStreams() {
|
|
18
|
+
if (
|
|
19
|
+
typeof window !== "undefined" &&
|
|
20
|
+
typeof window.$RV === "function" &&
|
|
21
|
+
Array.isArray(window.$RB) &&
|
|
22
|
+
window.$RB.length > 0
|
|
23
|
+
) {
|
|
24
|
+
try {
|
|
25
|
+
window.$RV(window.$RB);
|
|
26
|
+
} catch (e) {}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function pruneOrphanedSsrStreams() {
|
|
31
|
+
if (typeof window === "undefined" || !Array.isArray(window.$RB)) return;
|
|
32
|
+
const rb = window.$RB;
|
|
33
|
+
for (let i = rb.length - 2; i >= 0; i -= 2) {
|
|
34
|
+
const boundaryTpl = rb[i];
|
|
35
|
+
const hiddenSlot = rb[i + 1];
|
|
36
|
+
if (!boundaryTpl || !boundaryTpl.parentNode) {
|
|
37
|
+
if (hiddenSlot && hiddenSlot.parentNode) {
|
|
38
|
+
hiddenSlot.parentNode.removeChild(hiddenSlot);
|
|
39
|
+
}
|
|
40
|
+
rb.splice(i, 2);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
17
45
|
export const DinouPageContext =
|
|
18
46
|
typeof globalThis !== "undefined" && globalThis.__DINOU_PAGE_CONTEXT__
|
|
19
47
|
? globalThis.__DINOU_PAGE_CONTEXT__
|
|
@@ -129,13 +157,16 @@ export function DefaultDevError({ error }) {
|
|
|
129
157
|
|
|
130
158
|
function SlotErrorRenderer({ error, reset }) {
|
|
131
159
|
const getErrorRSC = typeof globalThis !== "undefined" ? globalThis.__DINOU_GET_ERROR_RSC_PAYLOAD__ : null;
|
|
160
|
+
const isStaticExport =
|
|
161
|
+
typeof window !== "undefined" &&
|
|
162
|
+
Boolean(window.__DINOU_STATIC_EXPORT__ || window.__DINOU_STATIC_EXPORT_UNLOADING__);
|
|
132
163
|
const errorPromise = useMemo(() => {
|
|
133
|
-
if (typeof getErrorRSC === "function") {
|
|
164
|
+
if (!isStaticExport && typeof getErrorRSC === "function") {
|
|
134
165
|
const route = typeof window !== "undefined" ? window.location.pathname + window.location.search : "";
|
|
135
166
|
return getErrorRSC(route, error);
|
|
136
167
|
}
|
|
137
168
|
return null;
|
|
138
|
-
}, [error]);
|
|
169
|
+
}, [error, isStaticExport]);
|
|
139
170
|
|
|
140
171
|
if (!errorPromise) {
|
|
141
172
|
return createElement(DefaultDevError, { error });
|
|
@@ -189,6 +220,7 @@ class SlotErrorBoundary extends Component {
|
|
|
189
220
|
}
|
|
190
221
|
|
|
191
222
|
componentDidCatch(error, errorInfo) {
|
|
223
|
+
if (typeof window !== "undefined" && window.__DINOU_STATIC_EXPORT_UNLOADING__) return;
|
|
192
224
|
console.error("[Dinou] Page Error caught in Slot:", error, errorInfo);
|
|
193
225
|
}
|
|
194
226
|
|
|
@@ -203,6 +235,9 @@ class SlotErrorBoundary extends Component {
|
|
|
203
235
|
|
|
204
236
|
render() {
|
|
205
237
|
if (this.state.hasError) {
|
|
238
|
+
if (typeof window !== "undefined" && window.__DINOU_STATIC_EXPORT_UNLOADING__) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
206
241
|
const reset = () => this.setState({ hasError: false, error: null });
|
|
207
242
|
return createElement(
|
|
208
243
|
InnerErrorBoundary,
|
|
@@ -221,6 +256,7 @@ class SlotErrorBoundary extends Component {
|
|
|
221
256
|
function PageConsumer({ pagePromise, pageElement }) {
|
|
222
257
|
if (typeof useLayoutEffect === "function" && typeof window !== "undefined") {
|
|
223
258
|
useLayoutEffect(() => {
|
|
259
|
+
pruneOrphanedSsrStreams();
|
|
224
260
|
if (
|
|
225
261
|
typeof document !== "undefined" &&
|
|
226
262
|
document.body &&
|
|
@@ -384,9 +420,18 @@ export function DinouCacheSlotBoundary({ id, tags, children }) {
|
|
|
384
420
|
}
|
|
385
421
|
}
|
|
386
422
|
|
|
423
|
+
if (typeof useLayoutEffect === "function" && isBrowser) {
|
|
424
|
+
useLayoutEffect(() => {
|
|
425
|
+
if (override.content !== null) {
|
|
426
|
+
pruneOrphanedSsrStreams();
|
|
427
|
+
}
|
|
428
|
+
}, [override.content]);
|
|
429
|
+
}
|
|
430
|
+
|
|
387
431
|
useEffect(() => {
|
|
388
432
|
mountedClientSlots.add(id);
|
|
389
433
|
const applyResolved = (resolved, baseRef = childrenRef.current) => {
|
|
434
|
+
flushPendingSsrStreams();
|
|
390
435
|
slotOverrideCache.set(id, {
|
|
391
436
|
baseChildren: baseRef,
|
|
392
437
|
content: resolved,
|