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,503 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { isDotEnvFileName } from "./runtime-env.js";
|
|
3
|
+
|
|
4
|
+
export const STATIC_MIME_TYPES = Object.freeze({
|
|
5
|
+
// Scripts, WASM & Source Maps
|
|
6
|
+
".js": "application/javascript; charset=utf-8",
|
|
7
|
+
".mjs": "application/javascript; charset=utf-8",
|
|
8
|
+
".cjs": "application/javascript; charset=utf-8",
|
|
9
|
+
".map": "application/json; charset=utf-8",
|
|
10
|
+
".wasm": "application/wasm",
|
|
11
|
+
|
|
12
|
+
// Styles, Documents, SEO & Web Manifests
|
|
13
|
+
".css": "text/css; charset=utf-8",
|
|
14
|
+
".html": "text/html; charset=utf-8",
|
|
15
|
+
".htm": "text/html; charset=utf-8",
|
|
16
|
+
".txt": "text/plain; charset=utf-8",
|
|
17
|
+
".xml": "application/xml; charset=utf-8",
|
|
18
|
+
".rss": "application/rss+xml; charset=utf-8",
|
|
19
|
+
".atom": "application/atom+xml; charset=utf-8",
|
|
20
|
+
".json": "application/json; charset=utf-8",
|
|
21
|
+
".webmanifest": "application/manifest+json; charset=utf-8",
|
|
22
|
+
".csv": "text/csv; charset=utf-8",
|
|
23
|
+
".md": "text/markdown; charset=utf-8",
|
|
24
|
+
".ics": "text/calendar; charset=utf-8",
|
|
25
|
+
".vtt": "text/vtt; charset=utf-8",
|
|
26
|
+
|
|
27
|
+
// Images & Icons
|
|
28
|
+
".svg": "image/svg+xml",
|
|
29
|
+
".png": "image/png",
|
|
30
|
+
".jpg": "image/jpeg",
|
|
31
|
+
".jpeg": "image/jpeg",
|
|
32
|
+
".gif": "image/gif",
|
|
33
|
+
".webp": "image/webp",
|
|
34
|
+
".avif": "image/avif",
|
|
35
|
+
".ico": "image/x-icon",
|
|
36
|
+
".bmp": "image/bmp",
|
|
37
|
+
".apng": "image/apng",
|
|
38
|
+
".hdr": "image/vnd.radiance",
|
|
39
|
+
|
|
40
|
+
// Fonts
|
|
41
|
+
".woff": "font/woff",
|
|
42
|
+
".woff2": "font/woff2",
|
|
43
|
+
".ttf": "font/ttf",
|
|
44
|
+
".otf": "font/otf",
|
|
45
|
+
".eot": "application/vnd.ms-fontobject",
|
|
46
|
+
|
|
47
|
+
// Documents, 3D Models & Archives
|
|
48
|
+
".pdf": "application/pdf",
|
|
49
|
+
".glb": "model/gltf-binary",
|
|
50
|
+
".gltf": "model/gltf+json",
|
|
51
|
+
".zip": "application/zip",
|
|
52
|
+
".gz": "application/gzip",
|
|
53
|
+
|
|
54
|
+
// Video & Audio
|
|
55
|
+
".mp4": "video/mp4",
|
|
56
|
+
".webm": "video/webm",
|
|
57
|
+
".ogv": "video/ogg",
|
|
58
|
+
".mov": "video/quicktime",
|
|
59
|
+
".avi": "video/x-msvideo",
|
|
60
|
+
".mkv": "video/x-matroska",
|
|
61
|
+
".mjpeg": "video/x-motion-jpeg",
|
|
62
|
+
".mjpg": "video/x-motion-jpeg",
|
|
63
|
+
".mp3": "audio/mpeg",
|
|
64
|
+
".wav": "audio/wav",
|
|
65
|
+
".ogg": "audio/ogg",
|
|
66
|
+
".opus": "audio/opus",
|
|
67
|
+
".m4a": "audio/mp4",
|
|
68
|
+
".aac": "audio/aac",
|
|
69
|
+
".flac": "audio/flac",
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const PUBLIC_STATIC_EXT_REGEX =
|
|
73
|
+
/\.(?:js|mjs|cjs|css|map|wasm|png|jpg|jpeg|gif|svg|ico|webp|avif|bmp|apng|hdr|woff|woff2|ttf|eot|otf|txt|xml|rss|atom|json|webmanifest|html|htm|pdf|glb|gltf|csv|md|ics|vtt|mp4|webm|ogv|mov|avi|mkv|mjpeg|mjpg|mp3|wav|ogg|opus|m4a|aac|flac|zip|gz)$/i;
|
|
74
|
+
|
|
75
|
+
const IMMUTABLE_CHUNK_REGEX =
|
|
76
|
+
/^[^/]+-(?:[A-Z0-9]{8}|[a-f0-9]{16,32}|(?=[A-Za-z0-9_-]{8}\.)(?=[A-Za-z0-9_-]*[A-Z0-9])[A-Za-z0-9_-]{8})\.(?:js|mjs|cjs|css)(?:\.map)?$/;
|
|
77
|
+
|
|
78
|
+
// Reserved internal subdirectory inside `.dinou/cloudflare/assets/` where
|
|
79
|
+
// `dinou build:cloudflare` places pre-rendered `.dinou/dist2` SSG/ISR/PPR/Slot
|
|
80
|
+
// cache files so `.dinou/dist3` stays 100% pure and never collides with `public/`.
|
|
81
|
+
export const CLOUDFLARE_DIST2_NAMESPACE = "__dinou_dist2";
|
|
82
|
+
|
|
83
|
+
const DIST2_EXPORTABLE_BASENAMES = new Set([
|
|
84
|
+
"index.html",
|
|
85
|
+
"page.rsc",
|
|
86
|
+
"layout.rsc",
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
export const STATIC_EXPORT_SCRIPT =
|
|
90
|
+
"<script>window.__DINOU_STATIC_EXPORT__=true;</script>";
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Resolves the HTTP Content-Type header for a static file path or URL pathname.
|
|
94
|
+
* Handles extensionless RFC / Universal Links files such as `apple-app-site-association`.
|
|
95
|
+
*/
|
|
96
|
+
export function getStaticContentType(pathnameOrFilePath) {
|
|
97
|
+
if (!pathnameOrFilePath || typeof pathnameOrFilePath !== "string") {
|
|
98
|
+
return "application/octet-stream";
|
|
99
|
+
}
|
|
100
|
+
const normalized = pathnameOrFilePath.replace(/\\/g, "/");
|
|
101
|
+
const baseLower = (normalized.split("/").pop() || "").toLowerCase();
|
|
102
|
+
if (baseLower === "apple-app-site-association") {
|
|
103
|
+
return "application/json; charset=utf-8";
|
|
104
|
+
}
|
|
105
|
+
const dotIdx = baseLower.lastIndexOf(".");
|
|
106
|
+
if (dotIdx === -1) {
|
|
107
|
+
return "application/octet-stream";
|
|
108
|
+
}
|
|
109
|
+
const ext = baseLower.slice(dotIdx);
|
|
110
|
+
return STATIC_MIME_TYPES[ext] || "application/octet-stream";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Returns true when an incoming URL pathname targets the reserved internal
|
|
115
|
+
* `/__dinou_dist2/*` namespace inside Cloudflare's `env.ASSETS` directory.
|
|
116
|
+
*/
|
|
117
|
+
export function isReservedCloudflareDist2RequestPath(pathname) {
|
|
118
|
+
if (!pathname || typeof pathname !== "string") return false;
|
|
119
|
+
let decoded = pathname;
|
|
120
|
+
try {
|
|
121
|
+
decoded = decodeURIComponent(pathname);
|
|
122
|
+
} catch {}
|
|
123
|
+
const firstSeg =
|
|
124
|
+
decoded.replace(/\\/g, "/").replace(/^\/+/, "").split("/")[0] || "";
|
|
125
|
+
return firstSeg.toLowerCase() === CLOUDFLARE_DIST2_NAMESPACE;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Returns true when a normalized POSIX path refers to an OS metadata file or
|
|
130
|
+
* Dinou's reserved internal `/__dinou_dist2/*` Cloudflare asset namespace,
|
|
131
|
+
* ensuring it is never served publicly.
|
|
132
|
+
*/
|
|
133
|
+
export function isInternalDinouAssetPath(relPosixPath) {
|
|
134
|
+
if (!relPosixPath || typeof relPosixPath !== "string") return true;
|
|
135
|
+
const clean = relPosixPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
136
|
+
if (!clean) return true;
|
|
137
|
+
|
|
138
|
+
const segments = clean.split("/").filter(Boolean);
|
|
139
|
+
if (segments.length === 0) return true;
|
|
140
|
+
|
|
141
|
+
if (segments[0].toLowerCase() === CLOUDFLARE_DIST2_NAMESPACE) {
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const baseLower = segments[segments.length - 1].toLowerCase();
|
|
146
|
+
if (
|
|
147
|
+
baseLower === ".ds_store" ||
|
|
148
|
+
baseLower === "thumbs.db" ||
|
|
149
|
+
isDotEnvFileName(baseLower)
|
|
150
|
+
) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (segments.some((seg) => isDotEnvFileName(seg))) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Safely URL-decodes and validates an incoming HTTP URL `pathname` for public static
|
|
163
|
+
* asset lookup. Rejects malformed `%` encodings, null bytes, backslash separators,
|
|
164
|
+
* `.` / `..` traversal segments, hidden dotfiles (except RFC 8615 `/.well-known/*`),
|
|
165
|
+
* and internal Dinou engine artifacts.
|
|
166
|
+
*
|
|
167
|
+
* @returns {string | null} Clean relative POSIX path (without leading `/`), or `null` if disallowed.
|
|
168
|
+
*/
|
|
169
|
+
export function normalizePublicRequestPath(pathname) {
|
|
170
|
+
if (
|
|
171
|
+
!pathname ||
|
|
172
|
+
typeof pathname !== "string" ||
|
|
173
|
+
!pathname.startsWith("/") ||
|
|
174
|
+
pathname === "/" ||
|
|
175
|
+
pathname.includes("\0")
|
|
176
|
+
) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
let decoded;
|
|
181
|
+
try {
|
|
182
|
+
decoded = decodeURIComponent(pathname);
|
|
183
|
+
} catch {
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (decoded.includes("\0") || decoded.includes("\\")) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const rawSegments = decoded.split("/");
|
|
192
|
+
if (rawSegments.some((seg) => seg === "." || seg === "..")) {
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const segments = rawSegments.filter(Boolean);
|
|
197
|
+
if (segments.length === 0) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Block hidden dotfiles & dot-directories except RFC 8615 /.well-known/<file>
|
|
202
|
+
const hasDotSegment = segments.some((seg) => seg.startsWith("."));
|
|
203
|
+
if (hasDotSegment) {
|
|
204
|
+
const isValidWellKnown =
|
|
205
|
+
segments[0] === ".well-known" &&
|
|
206
|
+
segments.length >= 2 &&
|
|
207
|
+
segments.slice(1).every((seg) => !seg.startsWith("."));
|
|
208
|
+
if (!isValidWellKnown) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const relPosixPath = segments.join("/");
|
|
214
|
+
if (isInternalDinouAssetPath(relPosixPath)) {
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
return relPosixPath;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Resolves a validated relative POSIX path inside `baseDir` and verifies strict
|
|
223
|
+
* filesystem containment so no path can escape `baseDir`.
|
|
224
|
+
*
|
|
225
|
+
* @returns {string | null} Absolute filesystem path inside `baseDir`, or `null` if unsafe.
|
|
226
|
+
*/
|
|
227
|
+
export function resolveConfinedStaticFile(baseDir, relPosixPath) {
|
|
228
|
+
if (
|
|
229
|
+
!baseDir ||
|
|
230
|
+
!relPosixPath ||
|
|
231
|
+
typeof relPosixPath !== "string" ||
|
|
232
|
+
relPosixPath.includes("\0") ||
|
|
233
|
+
relPosixPath.includes("\\")
|
|
234
|
+
) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const segments = relPosixPath.split("/").filter(Boolean);
|
|
238
|
+
if (segments.length === 0 || segments.some((seg) => seg === "." || seg === "..")) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const rootDir = path.resolve(baseDir);
|
|
243
|
+
const rootPrefix = rootDir.endsWith(path.sep) ? rootDir : rootDir + path.sep;
|
|
244
|
+
const resolved = path.resolve(rootDir, ...segments);
|
|
245
|
+
if (!resolved.startsWith(rootPrefix)) {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
return resolved;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Determines whether a relative asset path in `.dinou/dist3` is content-hashed
|
|
253
|
+
* (safe for 1-year `immutable` caching) vs unhashed (`public/` files, `styles.css`).
|
|
254
|
+
*/
|
|
255
|
+
export function isImmutableAssetPath(relPosixPath) {
|
|
256
|
+
if (!relPosixPath || typeof relPosixPath !== "string") return false;
|
|
257
|
+
const clean = relPosixPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
258
|
+
if (!clean) return false;
|
|
259
|
+
return clean.startsWith("assets/") || IMMUTABLE_CHUNK_REGEX.test(clean);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Returns the production `Cache-Control` header value for a static asset.
|
|
264
|
+
* Content-hashed bundler chunks and `/assets/*` receive `immutable`, whereas
|
|
265
|
+
* unhashed `public/` files (`/robots.txt`, `/sitemap.xml`, `/favicon.ico`, etc.)
|
|
266
|
+
* and unhashed stylesheets receive `public, max-age=0, must-revalidate`.
|
|
267
|
+
*/
|
|
268
|
+
export function getStaticCacheControl(relPosixPath) {
|
|
269
|
+
return isImmutableAssetPath(relPosixPath)
|
|
270
|
+
? "public, max-age=31536000, immutable"
|
|
271
|
+
: "public, max-age=0, must-revalidate";
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Determines whether an incoming Edge/Cloudflare Worker request URL `pathname`
|
|
276
|
+
* should be served from the static `env.ASSETS` binding before invoking Dinou's
|
|
277
|
+
* RSC/SSR `handleRequest` pipeline.
|
|
278
|
+
*/
|
|
279
|
+
export function isPublicStaticAssetRequest(pathname) {
|
|
280
|
+
const relPath = normalizePublicRequestPath(pathname);
|
|
281
|
+
if (!relPath) return false;
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
relPath.startsWith("assets/") ||
|
|
285
|
+
relPath.startsWith("_dinou/") ||
|
|
286
|
+
relPath.startsWith(".well-known/") ||
|
|
287
|
+
PUBLIC_STATIC_EXT_REGEX.test(relPath)
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Filter predicate when copying public static assets from `.dinou/dist3` into
|
|
293
|
+
* `out/` (`dinou export-static`) or `.dinou/cloudflare/assets/` (`dinou build:cloudflare`).
|
|
294
|
+
* Excludes OS metadata junk and the reserved `__dinou_dist2` namespace while
|
|
295
|
+
* preserving all `public/` files (including `.well-known/*` and `.nojekyll`) and client chunks.
|
|
296
|
+
*/
|
|
297
|
+
export function shouldExportDist3Entry(relPosixPath) {
|
|
298
|
+
if (!relPosixPath || typeof relPosixPath !== "string") return false;
|
|
299
|
+
const clean = relPosixPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
300
|
+
if (!clean) return false;
|
|
301
|
+
|
|
302
|
+
const segments = clean.split("/").filter(Boolean);
|
|
303
|
+
if (segments.length === 0) return false;
|
|
304
|
+
|
|
305
|
+
if (segments[0].toLowerCase() === CLOUDFLARE_DIST2_NAMESPACE) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const baseLower = segments[segments.length - 1].toLowerCase();
|
|
310
|
+
if (
|
|
311
|
+
baseLower === ".ds_store" ||
|
|
312
|
+
baseLower === "thumbs.db" ||
|
|
313
|
+
isDotEnvFileName(baseLower)
|
|
314
|
+
) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (segments.some((seg) => isDotEnvFileName(seg))) {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
return true;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Filter predicate for `dinou export-static` (`export-static.js`) when copying
|
|
327
|
+
* pre-rendered SSG files from `.dinou/dist2` into `out/`.
|
|
328
|
+
* Strictly allowlists `index.html`, `page.rsc`, and `layout.rsc` (outside the
|
|
329
|
+
* internal `slots/` cache namespace) so internal ISR/PPR/Slot metadata JSONs,
|
|
330
|
+
* `shell.*` templates, `rsc.rsc`, `status-manifest.json`, and `._old.` files
|
|
331
|
+
* are never published to static hosts.
|
|
332
|
+
*/
|
|
333
|
+
export function shouldExportDist2File(relPosixPath) {
|
|
334
|
+
if (!relPosixPath || typeof relPosixPath !== "string") return false;
|
|
335
|
+
const clean = relPosixPath.replace(/\\/g, "/").replace(/^\/+/, "");
|
|
336
|
+
if (!clean) return false;
|
|
337
|
+
|
|
338
|
+
const segments = clean.split("/").filter(Boolean);
|
|
339
|
+
if (segments.length === 0) return false;
|
|
340
|
+
|
|
341
|
+
if (segments[0].toLowerCase() === "slots") {
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
const baseLower = segments[segments.length - 1].toLowerCase();
|
|
346
|
+
return DIST2_EXPORTABLE_BASENAMES.has(baseLower);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Reads an internal `.dinou/dist2` SSG/ISR/PPR/Slot artifact from Cloudflare's
|
|
351
|
+
* `env.ASSETS` binding under the isolated `/__dinou_dist2/<key>` namespace.
|
|
352
|
+
* Handles Cloudflare Static Assets HTML canonicalization for `index.html` keys.
|
|
353
|
+
*/
|
|
354
|
+
export async function fetchCloudflareDist2Asset(
|
|
355
|
+
assetsBinding,
|
|
356
|
+
key,
|
|
357
|
+
baseUrl = "http://localhost"
|
|
358
|
+
) {
|
|
359
|
+
if (!assetsBinding || typeof assetsBinding.fetch !== "function" || !key) {
|
|
360
|
+
return null;
|
|
361
|
+
}
|
|
362
|
+
const cleanKey = String(key).replace(/\\/g, "/").replace(/^\/+/, "");
|
|
363
|
+
if (!cleanKey) return null;
|
|
364
|
+
|
|
365
|
+
const namespacedKey = `${CLOUDFLARE_DIST2_NAMESPACE}/${cleanKey}`;
|
|
366
|
+
const lowerKey = cleanKey.toLowerCase();
|
|
367
|
+
const isIndexHtml =
|
|
368
|
+
lowerKey === "index.html" || lowerKey.endsWith("/index.html");
|
|
369
|
+
|
|
370
|
+
if (!isIndexHtml) {
|
|
371
|
+
const res = await assetsBinding.fetch(
|
|
372
|
+
new Request(new URL(`/${namespacedKey}`, baseUrl))
|
|
373
|
+
);
|
|
374
|
+
return res && res.status === 200 ? res : null;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
const dirRel = cleanKey.slice(0, -"index.html".length).replace(/\/+$/, "");
|
|
378
|
+
const dirNamespace = dirRel
|
|
379
|
+
? `/${CLOUDFLARE_DIST2_NAMESPACE}/${dirRel}`
|
|
380
|
+
: `/${CLOUDFLARE_DIST2_NAMESPACE}`;
|
|
381
|
+
const candidates = [`${dirNamespace}/`, `/${namespacedKey}`, dirNamespace];
|
|
382
|
+
|
|
383
|
+
for (const candidatePath of candidates) {
|
|
384
|
+
const res = await assetsBinding.fetch(
|
|
385
|
+
new Request(new URL(candidatePath, baseUrl))
|
|
386
|
+
);
|
|
387
|
+
if (res && res.status === 200) {
|
|
388
|
+
return res;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Parses an incoming RFC 9110 `Range: bytes=<start>-<end>` HTTP header against `totalSize`.
|
|
396
|
+
* Supports standard `bytes=start-end`, open-ended `bytes=start-`, and suffix `bytes=-length`
|
|
397
|
+
* ranges required by HTML5 `<video>` and `<audio>` scrubbing and Safari media playback.
|
|
398
|
+
*
|
|
399
|
+
* @returns {null | { unsatisfiable: true, contentRange: string } | { unsatisfiable: false, start: number, end: number, length: number, contentRange: string }}
|
|
400
|
+
*/
|
|
401
|
+
export function parseHttpByteRange(rangeHeader, totalSize) {
|
|
402
|
+
if (
|
|
403
|
+
!rangeHeader ||
|
|
404
|
+
typeof rangeHeader !== "string" ||
|
|
405
|
+
typeof totalSize !== "number" ||
|
|
406
|
+
!Number.isFinite(totalSize) ||
|
|
407
|
+
totalSize < 0
|
|
408
|
+
) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
const trimmed = rangeHeader.trim();
|
|
413
|
+
if (!trimmed.toLowerCase().startsWith("bytes=")) {
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
const spec = trimmed.slice(6).trim();
|
|
418
|
+
// Ignore multipart multi-range requests (`bytes=0-50, 100-150`) and serve full 200 per RFC 9110
|
|
419
|
+
if (!spec || spec.includes(",")) {
|
|
420
|
+
return null;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
const dashIdx = spec.indexOf("-");
|
|
424
|
+
if (dashIdx === -1) {
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
const startStr = spec.slice(0, dashIdx).trim();
|
|
429
|
+
const endStr = spec.slice(dashIdx + 1).trim();
|
|
430
|
+
|
|
431
|
+
if (totalSize === 0) {
|
|
432
|
+
return {
|
|
433
|
+
unsatisfiable: true,
|
|
434
|
+
contentRange: "bytes */0",
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
let start;
|
|
439
|
+
let end;
|
|
440
|
+
|
|
441
|
+
if (startStr === "") {
|
|
442
|
+
// Suffix byte-range-spec: `bytes=-500` (last 500 bytes)
|
|
443
|
+
if (!/^\d+$/.test(endStr)) return null;
|
|
444
|
+
const suffixLength = Number(endStr);
|
|
445
|
+
if (!Number.isSafeInteger(suffixLength) || suffixLength <= 0) {
|
|
446
|
+
return {
|
|
447
|
+
unsatisfiable: true,
|
|
448
|
+
contentRange: `bytes */${totalSize}`,
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
start = Math.max(0, totalSize - suffixLength);
|
|
452
|
+
end = totalSize - 1;
|
|
453
|
+
} else {
|
|
454
|
+
if (!/^\d+$/.test(startStr)) return null;
|
|
455
|
+
start = Number(startStr);
|
|
456
|
+
if (!Number.isSafeInteger(start) || start >= totalSize) {
|
|
457
|
+
return {
|
|
458
|
+
unsatisfiable: true,
|
|
459
|
+
contentRange: `bytes */${totalSize}`,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
if (endStr === "") {
|
|
463
|
+
end = totalSize - 1;
|
|
464
|
+
} else {
|
|
465
|
+
if (!/^\d+$/.test(endStr)) return null;
|
|
466
|
+
const parsedEnd = Number(endStr);
|
|
467
|
+
if (!Number.isSafeInteger(parsedEnd) || parsedEnd < start) {
|
|
468
|
+
return {
|
|
469
|
+
unsatisfiable: true,
|
|
470
|
+
contentRange: `bytes */${totalSize}`,
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
end = Math.min(parsedEnd, totalSize - 1);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
return {
|
|
478
|
+
unsatisfiable: false,
|
|
479
|
+
start,
|
|
480
|
+
end,
|
|
481
|
+
length: end - start + 1,
|
|
482
|
+
contentRange: `bytes ${start}-${end}/${totalSize}`,
|
|
483
|
+
};
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Injects `<script>window.__DINOU_STATIC_EXPORT__=true;</script>` into exported
|
|
488
|
+
* `index.html` documents so Dinou's client router resolves `/<route>/page.rsc`
|
|
489
|
+
* and `/<layout>/layout.rsc` directly from static hosting instead of hitting
|
|
490
|
+
* server-only `/____rsc_*` endpoints.
|
|
491
|
+
*/
|
|
492
|
+
export function injectStaticExportFlag(html) {
|
|
493
|
+
if (typeof html !== "string" || html.includes("__DINOU_STATIC_EXPORT__")) {
|
|
494
|
+
return html;
|
|
495
|
+
}
|
|
496
|
+
if (/<\/head>/i.test(html)) {
|
|
497
|
+
return html.replace(/<\/head>/i, (match) => `${STATIC_EXPORT_SCRIPT}${match}`);
|
|
498
|
+
}
|
|
499
|
+
if (/<\/body>/i.test(html)) {
|
|
500
|
+
return html.replace(/<\/body>/i, (match) => `${STATIC_EXPORT_SCRIPT}${match}`);
|
|
501
|
+
}
|
|
502
|
+
return `${STATIC_EXPORT_SCRIPT}${html}`;
|
|
503
|
+
}
|