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
|
@@ -16,21 +16,50 @@ if (!ensureVendorMode()) {
|
|
|
16
16
|
import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
|
|
17
17
|
import parseExports from "../core/parse-exports.js";
|
|
18
18
|
import { useClientRegex, useServerRegex } from "../constants.js";
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
transformServerFunctions,
|
|
21
|
+
hasServerFunctions,
|
|
22
|
+
buildSsrServerReferenceModule,
|
|
23
|
+
generateSsrServerManifestStubs,
|
|
24
|
+
} from "../core/transform-server-functions.js";
|
|
20
25
|
import {
|
|
21
26
|
isSupportedClientModule,
|
|
22
27
|
scanProjectDependenciesForClientComponents,
|
|
23
28
|
} from "../core/scan-dependency-components.js";
|
|
24
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
getDinouConfig,
|
|
31
|
+
findDinouConfigFile,
|
|
32
|
+
} from "../core/load-dinou-config.js";
|
|
25
33
|
import { resolveSetupFiles } from "../core/resolve-setup-files.js";
|
|
34
|
+
import {
|
|
35
|
+
esbuildContextualDinouPlugin,
|
|
36
|
+
filterEscapedClientManifest,
|
|
37
|
+
} from "../core/resolve-contextual-dinou.js";
|
|
38
|
+
import { discoverLayoutsFromFs, sortEntriesByName } from "../core/discover-layouts.js";
|
|
39
|
+
import {
|
|
40
|
+
CLOUDFLARE_DIST2_NAMESPACE,
|
|
41
|
+
shouldExportDist3Entry,
|
|
42
|
+
} from "../core/static-assets.js";
|
|
43
|
+
import { createServerCssModulesPlugin } from "../core/server-css-modules-plugin.js";
|
|
44
|
+
import {
|
|
45
|
+
createServerAssetPlugin,
|
|
46
|
+
getAssetExtensionsInfo,
|
|
47
|
+
} from "../core/asset-extensions.js";
|
|
48
|
+
import { esbuildTsconfigAliasesPlugin } from "../core/tsconfig-aliases.js";
|
|
49
|
+
import {
|
|
50
|
+
loadEnvFiles,
|
|
51
|
+
getEsbuildPublicEnvDefines,
|
|
52
|
+
} from "../core/env.js";
|
|
26
53
|
|
|
27
54
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
28
55
|
|
|
29
56
|
const projectRoot = process.cwd();
|
|
57
|
+
loadEnvFiles(projectRoot, { mode: "production" });
|
|
30
58
|
const cloudflareDir = path.resolve(projectRoot, ".dinou/cloudflare");
|
|
31
59
|
fs.mkdirSync(cloudflareDir, { recursive: true });
|
|
32
60
|
|
|
33
61
|
const dinouConfig = await getDinouConfig(projectRoot);
|
|
62
|
+
const configFile = findDinouConfigFile(projectRoot);
|
|
34
63
|
const setupFiles = resolveSetupFiles(projectRoot, dinouConfig);
|
|
35
64
|
if (setupFiles.length > 0) {
|
|
36
65
|
console.log(` 🔌 [Dinou Setup] Active setup files (${setupFiles.length}): ${setupFiles.map((f) => path.basename(f)).join(", ")}`);
|
|
@@ -64,17 +93,20 @@ for (const r of candidateDinouRoots) {
|
|
|
64
93
|
candidateSlotPaths.add(path.resolve(r, "core/slot.js"));
|
|
65
94
|
}
|
|
66
95
|
|
|
67
|
-
function copyRecursive(src, dest) {
|
|
96
|
+
function copyRecursive(src, dest, filterFile = null, relPrefix = "") {
|
|
68
97
|
if (!fs.existsSync(src)) return 0;
|
|
69
98
|
let count = 0;
|
|
70
99
|
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
71
100
|
for (const entry of entries) {
|
|
101
|
+
const relPosix = relPrefix ? `${relPrefix}/${entry.name}` : entry.name;
|
|
72
102
|
const srcPath = path.join(src, entry.name);
|
|
73
103
|
const destPath = path.join(dest, entry.name);
|
|
74
104
|
if (entry.isDirectory()) {
|
|
75
|
-
|
|
76
|
-
count += copyRecursive(srcPath, destPath);
|
|
105
|
+
count += copyRecursive(srcPath, destPath, filterFile, relPosix);
|
|
77
106
|
} else {
|
|
107
|
+
if (filterFile && !filterFile(relPosix)) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
78
110
|
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
79
111
|
fs.copyFileSync(srcPath, destPath);
|
|
80
112
|
count++;
|
|
@@ -88,41 +120,52 @@ const bundlerName = isWebpackBuild ? "webpack" : (process.env.DINOU_BUILD_TOOL |
|
|
|
88
120
|
|
|
89
121
|
const dist2Dir = path.resolve(projectRoot, ".dinou/dist2");
|
|
90
122
|
const dist3Dir = path.resolve(projectRoot, ".dinou/dist3");
|
|
123
|
+
const cloudflareAssetsDir = path.join(cloudflareDir, "assets");
|
|
124
|
+
const cloudflareDist2AssetsDir = path.join(
|
|
125
|
+
cloudflareAssetsDir,
|
|
126
|
+
CLOUDFLARE_DIST2_NAMESPACE
|
|
127
|
+
);
|
|
128
|
+
|
|
91
129
|
console.log(`\n🦖 Dinou (Cloudflare Workers • ${bundlerName})`);
|
|
130
|
+
fs.rmSync(cloudflareAssetsDir, { recursive: true, force: true });
|
|
131
|
+
fs.mkdirSync(cloudflareAssetsDir, { recursive: true });
|
|
132
|
+
|
|
133
|
+
if (fs.existsSync(dist3Dir)) {
|
|
134
|
+
const staticCount = copyRecursive(
|
|
135
|
+
dist3Dir,
|
|
136
|
+
cloudflareAssetsDir,
|
|
137
|
+
shouldExportDist3Entry
|
|
138
|
+
);
|
|
139
|
+
console.log(
|
|
140
|
+
` 📦 Synchronized ${staticCount} public static asset(s) to .dinou/cloudflare/assets`
|
|
141
|
+
);
|
|
142
|
+
}
|
|
92
143
|
if (fs.existsSync(dist2Dir)) {
|
|
93
|
-
const copiedCount = copyRecursive(dist2Dir,
|
|
94
|
-
console.log(
|
|
144
|
+
const copiedCount = copyRecursive(dist2Dir, cloudflareDist2AssetsDir);
|
|
145
|
+
console.log(
|
|
146
|
+
` 📄 Synchronized ${copiedCount} internal SSG cache file(s) to .dinou/cloudflare/assets/${CLOUDFLARE_DIST2_NAMESPACE}`
|
|
147
|
+
);
|
|
95
148
|
}
|
|
96
149
|
console.log(" ⚡ Generating route modules & manifests...");
|
|
97
150
|
const routeModulesCode = generateRouteModulesCode(projectRoot, "../..");
|
|
98
151
|
const routeModulesPath = path.join(cloudflareDir, "route-modules.js");
|
|
99
152
|
fs.writeFileSync(routeModulesPath, routeModulesCode, "utf8");
|
|
100
153
|
|
|
101
|
-
function findManifest(filename,
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
path.resolve(projectRoot, ".dinou/dist3", filename),
|
|
105
|
-
path.resolve(projectRoot, ".dinou/public", filename),
|
|
106
|
-
path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
|
|
107
|
-
]
|
|
108
|
-
: [
|
|
109
|
-
path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
|
|
110
|
-
path.resolve(projectRoot, ".dinou/dist3", filename),
|
|
111
|
-
path.resolve(projectRoot, ".dinou/public", filename),
|
|
112
|
-
];
|
|
113
|
-
for (const c of candidates) {
|
|
114
|
-
if (fs.existsSync(c)) return c;
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
154
|
+
function findManifest(filename, folder) {
|
|
155
|
+
const candidate = path.resolve(projectRoot, ".dinou", folder, filename);
|
|
156
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
117
157
|
}
|
|
118
158
|
|
|
119
|
-
const clientManifestPath = findManifest("react-client-manifest.json", "
|
|
120
|
-
const sfManifestPath = findManifest("server-functions-manifest.json", "
|
|
159
|
+
const clientManifestPath = findManifest("react-client-manifest.json", "dist1");
|
|
160
|
+
const sfManifestPath = findManifest("server-functions-manifest.json", "dist1");
|
|
121
161
|
|
|
122
162
|
let parsedClientManifest = {};
|
|
123
163
|
if (clientManifestPath && fs.existsSync(clientManifestPath)) {
|
|
124
164
|
try {
|
|
125
|
-
parsedClientManifest =
|
|
165
|
+
parsedClientManifest = filterEscapedClientManifest(
|
|
166
|
+
JSON.parse(fs.readFileSync(clientManifestPath, "utf8")),
|
|
167
|
+
projectRoot
|
|
168
|
+
);
|
|
126
169
|
} catch (e) {}
|
|
127
170
|
}
|
|
128
171
|
|
|
@@ -150,7 +193,7 @@ function findClientComponents() {
|
|
|
150
193
|
for (const entry of entries) {
|
|
151
194
|
const full = path.join(dir, entry.name);
|
|
152
195
|
if (entry.isDirectory()) {
|
|
153
|
-
walk(full);
|
|
196
|
+
if (!entry.name.startsWith("_")) walk(full);
|
|
154
197
|
} else if (/\.[jt]sx?$/.test(entry.name)) {
|
|
155
198
|
try {
|
|
156
199
|
const content = fs.readFileSync(full, "utf8");
|
|
@@ -372,7 +415,7 @@ if (sfManifestPath && fs.existsSync(sfManifestPath)) {
|
|
|
372
415
|
manifestInlines += `\nglobalThis.__DINOU_SERVER_FUNCTIONS_MANIFEST__ = {};\n`;
|
|
373
416
|
}
|
|
374
417
|
|
|
375
|
-
const assetManifestPath = findManifest("manifest.json", "
|
|
418
|
+
const assetManifestPath = findManifest("manifest.json", "dist1");
|
|
376
419
|
if (assetManifestPath && fs.existsSync(assetManifestPath)) {
|
|
377
420
|
const content = fs.readFileSync(assetManifestPath, "utf8");
|
|
378
421
|
manifestInlines += `\nglobalThis.__DINOU_ASSET_MANIFEST__ = ${content};\n`;
|
|
@@ -384,11 +427,21 @@ let importMapHtml = "";
|
|
|
384
427
|
if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
|
|
385
428
|
const imports = {};
|
|
386
429
|
const moduleBasePath = pathToFileURL(projectRoot).href + "/";
|
|
430
|
+
const moduleBasePathLower = moduleBasePath.replace(
|
|
431
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
432
|
+
(_, d) => `file:///${d.toLowerCase()}:`
|
|
433
|
+
);
|
|
434
|
+
const moduleBasePathUpper = moduleBasePath.replace(
|
|
435
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
436
|
+
(_, d) => `file:///${d.toUpperCase()}:`
|
|
437
|
+
);
|
|
387
438
|
|
|
388
439
|
for (const [key, val] of Object.entries(parsedClientManifest)) {
|
|
389
440
|
let specifier = key;
|
|
390
|
-
if (specifier.startsWith(
|
|
391
|
-
specifier = specifier.slice(
|
|
441
|
+
if (specifier.startsWith(moduleBasePathUpper)) {
|
|
442
|
+
specifier = specifier.slice(moduleBasePathUpper.length);
|
|
443
|
+
} else if (specifier.startsWith(moduleBasePathLower)) {
|
|
444
|
+
specifier = specifier.slice(moduleBasePathLower.length);
|
|
392
445
|
}
|
|
393
446
|
const hashIdx = specifier.indexOf("#");
|
|
394
447
|
if (hashIdx !== -1) {
|
|
@@ -451,21 +504,7 @@ if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
|
|
|
451
504
|
|
|
452
505
|
manifestInlines += `\nglobalThis.__DINOU_IMPORT_MAP_HTML__ = ${JSON.stringify(importMapHtml)};\n`;
|
|
453
506
|
|
|
454
|
-
const discoveredLayouts =
|
|
455
|
-
function findLayoutRoutes(dir, rel = "") {
|
|
456
|
-
if (!fs.existsSync(dir)) return;
|
|
457
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
458
|
-
for (const entry of entries) {
|
|
459
|
-
if (entry.isDirectory()) {
|
|
460
|
-
findLayoutRoutes(path.join(dir, entry.name), rel ? `${rel}/${entry.name}` : entry.name);
|
|
461
|
-
} else if (/^layout\.[jt]sx?$/.test(entry.name)) {
|
|
462
|
-
discoveredLayouts.push(rel);
|
|
463
|
-
} else if (entry.name === "no_layout") {
|
|
464
|
-
discoveredLayouts.push("!" + rel);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
findLayoutRoutes(srcDir);
|
|
507
|
+
const discoveredLayouts = discoverLayoutsFromFs(srcDir, fs);
|
|
469
508
|
manifestInlines += `\nglobalThis.__DINOU_LAYOUTS__ = ${JSON.stringify(discoveredLayouts)};\n`;
|
|
470
509
|
|
|
471
510
|
if (process.env.DINOU_DEBUG) {
|
|
@@ -475,10 +514,11 @@ if (process.env.DINOU_DEBUG) {
|
|
|
475
514
|
const vfsSnapshot = {};
|
|
476
515
|
function walkVfs(dir) {
|
|
477
516
|
if (!fs.existsSync(dir)) return;
|
|
478
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
517
|
+
const entries = sortEntriesByName(fs.readdirSync(dir, { withFileTypes: true }));
|
|
479
518
|
const children = [];
|
|
480
519
|
for (const entry of entries) {
|
|
481
520
|
const isDir = entry.isDirectory();
|
|
521
|
+
if (isDir && entry.name.startsWith("_")) continue;
|
|
482
522
|
children.push({ name: entry.name, isDirectory: isDir });
|
|
483
523
|
const fullPath = path.join(dir, entry.name);
|
|
484
524
|
const relFromSrc = path.relative(srcDir, fullPath).replace(/\\/g, "/");
|
|
@@ -536,10 +576,7 @@ clientComponents.forEach((compPath, index) => {
|
|
|
536
576
|
});
|
|
537
577
|
|
|
538
578
|
const serverFunctionFiles = Object.keys(parsedServerFunctionsManifest);
|
|
539
|
-
|
|
540
|
-
const absPath = path.resolve(projectRoot, relPath).replace(/\\/g, "/");
|
|
541
|
-
ssrManifestCode += `import * as sf_${index} from ${JSON.stringify(absPath)};\n`;
|
|
542
|
-
});
|
|
579
|
+
ssrManifestCode += generateSsrServerManifestStubs(parsedServerFunctionsManifest);
|
|
543
580
|
|
|
544
581
|
ssrManifestCode += `\nexport const clientModules = {\n`;
|
|
545
582
|
const emittedClientModules = new Set();
|
|
@@ -734,12 +771,23 @@ fs.writeFileSync(ssrClientManifestPath, ssrManifestCode, "utf8");
|
|
|
734
771
|
// Entry Files Generation
|
|
735
772
|
// ====================================================================
|
|
736
773
|
// 1. RSC Engine Entry
|
|
774
|
+
const aotConfigPrelude = configFile
|
|
775
|
+
? `import * as __dinouConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};
|
|
776
|
+
const __resolvedDinouCfg = (__dinouConfigMod && __dinouConfigMod.default) ? __dinouConfigMod.default : (__dinouConfigMod || { plugins: [] });
|
|
777
|
+
globalThis.__DINOU_AOT_CONFIG__ = __resolvedDinouCfg;
|
|
778
|
+
globalThis.__DINOU_CONFIG__ = __resolvedDinouCfg;
|
|
779
|
+
`
|
|
780
|
+
: "";
|
|
737
781
|
const rscEntryContent = `// Auto-generated RSC Engine entry for Cloudflare Workers
|
|
738
782
|
import "./env-setup.js";
|
|
739
|
-
import "./route-modules.js";
|
|
783
|
+
${aotConfigPrelude}import "./route-modules.js";
|
|
740
784
|
import * as edgeRenderer from "react-server-dom-webpack/server.edge";
|
|
785
|
+
import { handleRequest as coreHandleRequest } from "${dinouDirSlash}/core/handler.js";
|
|
741
786
|
globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
|
|
742
|
-
export
|
|
787
|
+
export function handleRequest(request, platformContext) {
|
|
788
|
+
globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
|
|
789
|
+
return coreHandleRequest(request, platformContext);
|
|
790
|
+
}
|
|
743
791
|
`;
|
|
744
792
|
const rscEntryPath = path.join(cloudflareDir, "rsc-entry.js");
|
|
745
793
|
fs.writeFileSync(rscEntryPath, rscEntryContent, "utf8");
|
|
@@ -750,7 +798,7 @@ import { renderRscStreamToHtmlStream } from "${dinouDirSlash}/core/edge-ssr.js";
|
|
|
750
798
|
import { clientModules, ssrConsumerManifest } from "./ssr-client-manifest.js";
|
|
751
799
|
|
|
752
800
|
const lowerMap = new Map();
|
|
753
|
-
|
|
801
|
+
const localWebpackRequire = (id) => {
|
|
754
802
|
if (clientModules[id]) return clientModules[id];
|
|
755
803
|
if (typeof id === "string") {
|
|
756
804
|
if (lowerMap.size === 0) {
|
|
@@ -762,10 +810,12 @@ globalThis.__webpack_require__ = (id) => {
|
|
|
762
810
|
console.error("[SSR Engine] Module not found in __webpack_require__:", id);
|
|
763
811
|
return {};
|
|
764
812
|
};
|
|
765
|
-
|
|
813
|
+
localWebpackRequire.u = (chunkId) => "" + chunkId + ".js";
|
|
814
|
+
globalThis.__webpack_require__ = localWebpackRequire;
|
|
766
815
|
globalThis.__webpack_chunk_load__ = () => Promise.resolve();
|
|
767
816
|
|
|
768
817
|
export async function renderHtml(rscStream, options = {}) {
|
|
818
|
+
globalThis.__webpack_require__ = localWebpackRequire;
|
|
769
819
|
return renderRscStreamToHtmlStream(rscStream, ssrConsumerManifest, options);
|
|
770
820
|
}
|
|
771
821
|
`;
|
|
@@ -779,9 +829,15 @@ import { renderHtml } from "./ssr-engine.js";
|
|
|
779
829
|
import {
|
|
780
830
|
getStorageAdapter,
|
|
781
831
|
setStorageAdapter,
|
|
832
|
+
hasExplicitStorageAdapter,
|
|
782
833
|
CloudflareKVStorage,
|
|
783
834
|
MemoryStorage,
|
|
784
835
|
} from "${dinouDirSlash}/core/storage-adapter.js";
|
|
836
|
+
import {
|
|
837
|
+
getStaticContentType,
|
|
838
|
+
isPublicStaticAssetRequest,
|
|
839
|
+
isReservedCloudflareDist2RequestPath,
|
|
840
|
+
} from "${dinouDirSlash}/core/static-assets.js";
|
|
785
841
|
|
|
786
842
|
if (typeof globalThis !== "undefined") {
|
|
787
843
|
globalThis.__DINOU_RUNTIME__ = "edge";
|
|
@@ -792,15 +848,20 @@ let storageInitialized = false;
|
|
|
792
848
|
export default {
|
|
793
849
|
async fetch(request, env, ctx) {
|
|
794
850
|
const url = new URL(request.url);
|
|
795
|
-
if (
|
|
851
|
+
if (
|
|
852
|
+
url.pathname.startsWith("/cdn-cgi/") ||
|
|
853
|
+
isReservedCloudflareDist2RequestPath(url.pathname)
|
|
854
|
+
) {
|
|
796
855
|
return new Response(null, { status: 404 });
|
|
797
856
|
}
|
|
798
857
|
|
|
799
858
|
if (!storageInitialized) {
|
|
800
|
-
if (
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
859
|
+
if (!hasExplicitStorageAdapter()) {
|
|
860
|
+
if (env && env.DINOU_CACHE) {
|
|
861
|
+
setStorageAdapter(new CloudflareKVStorage(env.DINOU_CACHE));
|
|
862
|
+
} else {
|
|
863
|
+
setStorageAdapter(new MemoryStorage());
|
|
864
|
+
}
|
|
804
865
|
}
|
|
805
866
|
storageInitialized = true;
|
|
806
867
|
}
|
|
@@ -810,16 +871,30 @@ export default {
|
|
|
810
871
|
url.pathname.includes("____server_function____") ||
|
|
811
872
|
request.headers.get("x-server-function-call") === "1";
|
|
812
873
|
|
|
813
|
-
const
|
|
814
|
-
const isStaticAsset =
|
|
815
|
-
staticExtRegex.test(url.pathname) ||
|
|
816
|
-
url.pathname.startsWith("/assets/") ||
|
|
817
|
-
url.pathname.startsWith("/_dinou/");
|
|
874
|
+
const isStaticAsset = isPublicStaticAssetRequest(url.pathname);
|
|
818
875
|
|
|
819
876
|
if (!isRSCPayload && !isServerFunction && isStaticAsset && env && env.ASSETS && (request.method === "GET" || request.method === "HEAD")) {
|
|
820
877
|
try {
|
|
821
878
|
const assetRes = await env.ASSETS.fetch(request.clone ? request.clone() : request);
|
|
822
879
|
if (assetRes && assetRes.status < 400) {
|
|
880
|
+
const rawCt = (assetRes.headers.get("content-type") || "").trim();
|
|
881
|
+
const lowerCt = rawCt.toLowerCase();
|
|
882
|
+
const expectedCt = getStaticContentType(url.pathname);
|
|
883
|
+
const needsContentTypeFix =
|
|
884
|
+
!rawCt ||
|
|
885
|
+
(lowerCt === "application/octet-stream" &&
|
|
886
|
+
expectedCt !== "application/octet-stream") ||
|
|
887
|
+
(url.pathname.toLowerCase().endsWith("/apple-app-site-association") &&
|
|
888
|
+
!lowerCt.includes("json"));
|
|
889
|
+
if (needsContentTypeFix) {
|
|
890
|
+
const headers = new Headers(assetRes.headers);
|
|
891
|
+
headers.set("content-type", expectedCt);
|
|
892
|
+
return new Response(assetRes.body, {
|
|
893
|
+
status: assetRes.status,
|
|
894
|
+
statusText: assetRes.statusText,
|
|
895
|
+
headers,
|
|
896
|
+
});
|
|
897
|
+
}
|
|
823
898
|
return assetRes;
|
|
824
899
|
}
|
|
825
900
|
} catch (e) {}
|
|
@@ -867,8 +942,8 @@ const externalList = [
|
|
|
867
942
|
const shimsDir = path.resolve(__dirname, "shims");
|
|
868
943
|
|
|
869
944
|
const commonAlias = {
|
|
870
|
-
"@": path.resolve(projectRoot, "src"),
|
|
871
945
|
"dinou/config": path.resolve(dinouDir, "core/config.js"),
|
|
946
|
+
"dinou/server": path.resolve(dinouDir, "server.js"),
|
|
872
947
|
dinou: dinouDir,
|
|
873
948
|
esbuild: path.resolve(shimsDir, "empty.js"),
|
|
874
949
|
fs: path.resolve(shimsDir, "fs.js"),
|
|
@@ -902,18 +977,15 @@ const commonLoader = {
|
|
|
902
977
|
".tsx": "tsx",
|
|
903
978
|
".json": "json",
|
|
904
979
|
".css": "empty",
|
|
905
|
-
".svg": "dataurl",
|
|
906
|
-
".png": "dataurl",
|
|
907
|
-
".jpg": "dataurl",
|
|
908
|
-
".jpeg": "dataurl",
|
|
909
|
-
".webp": "dataurl",
|
|
910
|
-
".ico": "dataurl",
|
|
911
980
|
};
|
|
912
981
|
|
|
913
982
|
const banner = {
|
|
914
983
|
js: `import { createRequire as ___createRequire } from 'node:module';
|
|
915
984
|
import { AsyncLocalStorage as ___AsyncLocalStorage } from 'node:async_hooks';
|
|
916
|
-
|
|
985
|
+
let require = null;
|
|
986
|
+
try {
|
|
987
|
+
require = ___createRequire(import.meta.url || 'file:///worker.js');
|
|
988
|
+
} catch (e) {}
|
|
917
989
|
const __dirname = '';
|
|
918
990
|
const __filename = '';
|
|
919
991
|
globalThis.__dinou_require__ = require;
|
|
@@ -1033,8 +1105,9 @@ const serverReferencesPlugin = {
|
|
|
1033
1105
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
|
|
1034
1106
|
|
|
1035
1107
|
for (const name of exports) {
|
|
1036
|
-
|
|
1037
|
-
|
|
1108
|
+
const localIdent = name === "default" ? sfResult.defaultExportIdentifier : name;
|
|
1109
|
+
if (localIdent) {
|
|
1110
|
+
transformed += `registerServerReference(${localIdent}, ${JSON.stringify(relativeFileUrl)}, ${JSON.stringify(name)});\n`;
|
|
1038
1111
|
}
|
|
1039
1112
|
}
|
|
1040
1113
|
|
|
@@ -1065,31 +1138,15 @@ const serverReferencesPluginSsr = {
|
|
|
1065
1138
|
|
|
1066
1139
|
if (!hasServerFunctions(code)) return null;
|
|
1067
1140
|
|
|
1068
|
-
const sfResult = transformServerFunctions(code, args.path);
|
|
1069
|
-
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1070
|
-
|
|
1071
|
-
const transformedCode = sfResult.code;
|
|
1072
|
-
const exports = sfResult.actions;
|
|
1073
1141
|
const absPath = path.resolve(args.path);
|
|
1074
1142
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1075
1143
|
const relativeFileUrl = "file:///" + relPath;
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
|
|
1079
|
-
|
|
1080
|
-
for (const name of exports) {
|
|
1081
|
-
if (name !== "default") {
|
|
1082
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(relativeFileUrl + "#" + name)});\n`;
|
|
1083
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(pathToFileURL(absPath).href + "#" + name)});\n`;
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
const ext = path.extname(args.path);
|
|
1088
|
-
const loader = ext === ".ts" ? "ts" : ext === ".tsx" ? "tsx" : ext === ".jsx" ? "jsx" : "js";
|
|
1144
|
+
const stubModule = buildSsrServerReferenceModule(code, args.path, relativeFileUrl);
|
|
1145
|
+
if (!stubModule) return null;
|
|
1089
1146
|
|
|
1090
1147
|
return {
|
|
1091
|
-
contents:
|
|
1092
|
-
loader,
|
|
1148
|
+
contents: stubModule,
|
|
1149
|
+
loader: "js",
|
|
1093
1150
|
};
|
|
1094
1151
|
});
|
|
1095
1152
|
},
|
|
@@ -1099,6 +1156,13 @@ const rscOutfile = path.join(cloudflareDir, "rsc-engine.js");
|
|
|
1099
1156
|
const ssrOutfile = path.join(cloudflareDir, "ssr-engine.js");
|
|
1100
1157
|
const finalOutfile = path.join(cloudflareDir, "worker.js");
|
|
1101
1158
|
|
|
1159
|
+
const serverCssModulesPlugin = createServerCssModulesPlugin({ projectRoot });
|
|
1160
|
+
const serverAssetPlugin = createServerAssetPlugin({ projectRoot, dinouConfig });
|
|
1161
|
+
const serverTsconfigAliasesPlugin = esbuildTsconfigAliasesPlugin({
|
|
1162
|
+
projectRoot,
|
|
1163
|
+
assetRegex: getAssetExtensionsInfo(dinouConfig, projectRoot).regex,
|
|
1164
|
+
});
|
|
1165
|
+
|
|
1102
1166
|
try {
|
|
1103
1167
|
// Pass A: RSC Engine
|
|
1104
1168
|
console.log(" ⚡ Bundling Pass A (RSC workerd) & Pass B (SSR workerd)...");
|
|
@@ -1110,17 +1174,24 @@ try {
|
|
|
1110
1174
|
target: "es2022",
|
|
1111
1175
|
platform: "neutral",
|
|
1112
1176
|
mainFields: ["module", "main"],
|
|
1113
|
-
conditions: ["workerd", "worker", "react-server"],
|
|
1177
|
+
conditions: ["workerd", "worker", "react-server", "style"],
|
|
1114
1178
|
external: externalList,
|
|
1115
|
-
plugins: [clientReferencesPlugin, serverReferencesPlugin],
|
|
1179
|
+
plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, clientReferencesPlugin, serverReferencesPlugin, serverCssModulesPlugin, serverAssetPlugin],
|
|
1116
1180
|
alias: commonAlias,
|
|
1117
1181
|
loader: commonLoader,
|
|
1118
1182
|
jsx: "automatic",
|
|
1119
1183
|
inject: setupFiles.length > 0 ? setupFiles : undefined,
|
|
1120
1184
|
define: {
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1185
|
+
...getEsbuildPublicEnvDefines({
|
|
1186
|
+
mode: "production",
|
|
1187
|
+
defineProcessEnvObject: false,
|
|
1188
|
+
extra: {
|
|
1189
|
+
DINOU_RUNTIME: "edge",
|
|
1190
|
+
DINOU_BUILD_TOOL: isWebpackBuild
|
|
1191
|
+
? "webpack"
|
|
1192
|
+
: process.env.DINOU_BUILD_TOOL || "esbuild",
|
|
1193
|
+
},
|
|
1194
|
+
}),
|
|
1124
1195
|
"import.meta.url": '"file:///worker.js"',
|
|
1125
1196
|
},
|
|
1126
1197
|
logLevel: "warning",
|
|
@@ -1135,17 +1206,26 @@ try {
|
|
|
1135
1206
|
target: "es2022",
|
|
1136
1207
|
platform: "neutral",
|
|
1137
1208
|
mainFields: ["module", "main"],
|
|
1138
|
-
conditions: ["workerd", "worker", "browser"],
|
|
1209
|
+
conditions: ["workerd", "worker", "browser", "style"],
|
|
1139
1210
|
external: externalList,
|
|
1140
|
-
plugins: [serverReferencesPluginSsr],
|
|
1211
|
+
plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, serverReferencesPluginSsr, serverCssModulesPlugin, serverAssetPlugin],
|
|
1141
1212
|
alias: commonAlias,
|
|
1142
1213
|
loader: commonLoader,
|
|
1143
1214
|
jsx: "automatic",
|
|
1144
|
-
inject: setupFiles.length > 0 ? setupFiles : undefined,
|
|
1145
1215
|
define: {
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1216
|
+
...getEsbuildPublicEnvDefines({
|
|
1217
|
+
mode: "production",
|
|
1218
|
+
defineProcessEnvObject: true,
|
|
1219
|
+
extra: {
|
|
1220
|
+
DINOU_RUNTIME: "edge",
|
|
1221
|
+
DINOU_BUILD_TOOL: isWebpackBuild
|
|
1222
|
+
? "webpack"
|
|
1223
|
+
: process.env.DINOU_BUILD_TOOL || "esbuild",
|
|
1224
|
+
...(process.env.DINOU_DEBUG
|
|
1225
|
+
? { DINOU_DEBUG: process.env.DINOU_DEBUG }
|
|
1226
|
+
: {}),
|
|
1227
|
+
},
|
|
1228
|
+
}),
|
|
1149
1229
|
"import.meta.url": '"file:///worker.js"',
|
|
1150
1230
|
},
|
|
1151
1231
|
logLevel: "warning",
|
|
@@ -1164,9 +1244,10 @@ try {
|
|
|
1164
1244
|
conditions: ["workerd", "worker", "browser"],
|
|
1165
1245
|
external: externalList,
|
|
1166
1246
|
banner,
|
|
1167
|
-
|
|
1247
|
+
plugins: [serverTsconfigAliasesPlugin, serverAssetPlugin],
|
|
1168
1248
|
alias: commonAlias,
|
|
1169
1249
|
loader: commonLoader,
|
|
1250
|
+
jsx: "automatic",
|
|
1170
1251
|
define: {
|
|
1171
1252
|
"process.env.NODE_ENV": '"production"',
|
|
1172
1253
|
"process.env.DINOU_RUNTIME": '"edge"',
|