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
package/dinou/deno/build.js
CHANGED
|
@@ -16,21 +16,46 @@ 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 { createServerCssModulesPlugin } from "../core/server-css-modules-plugin.js";
|
|
40
|
+
import {
|
|
41
|
+
createServerAssetPlugin,
|
|
42
|
+
getAssetExtensionsInfo,
|
|
43
|
+
} from "../core/asset-extensions.js";
|
|
44
|
+
import { esbuildTsconfigAliasesPlugin } from "../core/tsconfig-aliases.js";
|
|
45
|
+
import {
|
|
46
|
+
loadEnvFiles,
|
|
47
|
+
getEsbuildPublicEnvDefines,
|
|
48
|
+
} from "../core/env.js";
|
|
26
49
|
|
|
27
50
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
28
51
|
|
|
29
52
|
const projectRoot = process.cwd();
|
|
53
|
+
loadEnvFiles(projectRoot, { mode: "production" });
|
|
30
54
|
const denoDir = path.resolve(projectRoot, ".dinou/deno");
|
|
31
55
|
fs.mkdirSync(denoDir, { recursive: true });
|
|
32
56
|
|
|
33
57
|
const dinouConfig = await getDinouConfig(projectRoot);
|
|
58
|
+
const configFile = findDinouConfigFile(projectRoot);
|
|
34
59
|
const setupFiles = resolveSetupFiles(projectRoot, dinouConfig);
|
|
35
60
|
if (setupFiles.length > 0) {
|
|
36
61
|
console.log(` 🔌 [Dinou Setup] Active setup files (${setupFiles.length}): ${setupFiles.map((f) => path.basename(f)).join(", ")}`);
|
|
@@ -64,65 +89,30 @@ for (const r of candidateDinouRoots) {
|
|
|
64
89
|
candidateSlotPaths.add(path.resolve(r, "core/slot.js"));
|
|
65
90
|
}
|
|
66
91
|
|
|
67
|
-
function copyRecursive(src, dest) {
|
|
68
|
-
if (!fs.existsSync(src)) return 0;
|
|
69
|
-
let count = 0;
|
|
70
|
-
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
71
|
-
for (const entry of entries) {
|
|
72
|
-
const srcPath = path.join(src, entry.name);
|
|
73
|
-
const destPath = path.join(dest, entry.name);
|
|
74
|
-
if (entry.isDirectory()) {
|
|
75
|
-
fs.mkdirSync(destPath, { recursive: true });
|
|
76
|
-
count += copyRecursive(srcPath, destPath);
|
|
77
|
-
} else {
|
|
78
|
-
fs.mkdirSync(path.dirname(destPath), { recursive: true });
|
|
79
|
-
fs.copyFileSync(srcPath, destPath);
|
|
80
|
-
count++;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return count;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
92
|
const isWebpackBuild = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
87
93
|
const bundlerName = isWebpackBuild ? "webpack" : (process.env.DINOU_BUILD_TOOL || "esbuild");
|
|
88
94
|
|
|
89
|
-
const dist2Dir = path.resolve(projectRoot, ".dinou/dist2");
|
|
90
|
-
const dist3Dir = path.resolve(projectRoot, ".dinou/dist3");
|
|
91
95
|
console.log(`\n🦖 Dinou (Deno • ${bundlerName})`);
|
|
92
|
-
if (fs.existsSync(dist2Dir)) {
|
|
93
|
-
const copiedCount = copyRecursive(dist2Dir, dist3Dir);
|
|
94
|
-
console.log(` 📄 Synchronized ${copiedCount} pre-rendered static route(s) to .dinou/dist3`);
|
|
95
|
-
}
|
|
96
96
|
console.log(" ⚡ Generating route modules & manifests...");
|
|
97
97
|
const routeModulesCode = generateRouteModulesCode(projectRoot, "../..");
|
|
98
98
|
const routeModulesPath = path.join(denoDir, "route-modules.js");
|
|
99
99
|
fs.writeFileSync(routeModulesPath, routeModulesCode, "utf8");
|
|
100
100
|
|
|
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;
|
|
101
|
+
function findManifest(filename, folder) {
|
|
102
|
+
const candidate = path.resolve(projectRoot, ".dinou", folder, filename);
|
|
103
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
117
104
|
}
|
|
118
105
|
|
|
119
|
-
const clientManifestPath = findManifest("react-client-manifest.json", "
|
|
120
|
-
const sfManifestPath = findManifest("server-functions-manifest.json", "
|
|
106
|
+
const clientManifestPath = findManifest("react-client-manifest.json", "dist1");
|
|
107
|
+
const sfManifestPath = findManifest("server-functions-manifest.json", "dist1");
|
|
121
108
|
|
|
122
109
|
let parsedClientManifest = {};
|
|
123
110
|
if (clientManifestPath && fs.existsSync(clientManifestPath)) {
|
|
124
111
|
try {
|
|
125
|
-
parsedClientManifest =
|
|
112
|
+
parsedClientManifest = filterEscapedClientManifest(
|
|
113
|
+
JSON.parse(fs.readFileSync(clientManifestPath, "utf8")),
|
|
114
|
+
projectRoot
|
|
115
|
+
);
|
|
126
116
|
} catch (e) {}
|
|
127
117
|
}
|
|
128
118
|
|
|
@@ -150,7 +140,7 @@ function findClientComponents() {
|
|
|
150
140
|
for (const entry of entries) {
|
|
151
141
|
const full = path.join(dir, entry.name);
|
|
152
142
|
if (entry.isDirectory()) {
|
|
153
|
-
walk(full);
|
|
143
|
+
if (!entry.name.startsWith("_")) walk(full);
|
|
154
144
|
} else if (/\.[jt]sx?$/.test(entry.name)) {
|
|
155
145
|
try {
|
|
156
146
|
const content = fs.readFileSync(full, "utf8");
|
|
@@ -371,7 +361,7 @@ if (sfManifestPath && fs.existsSync(sfManifestPath)) {
|
|
|
371
361
|
manifestInlines += `\nglobalThis.__DINOU_SERVER_FUNCTIONS_MANIFEST__ = {};\n`;
|
|
372
362
|
}
|
|
373
363
|
|
|
374
|
-
const assetManifestPath = findManifest("manifest.json", "
|
|
364
|
+
const assetManifestPath = findManifest("manifest.json", "dist1");
|
|
375
365
|
if (assetManifestPath && fs.existsSync(assetManifestPath)) {
|
|
376
366
|
const content = fs.readFileSync(assetManifestPath, "utf8");
|
|
377
367
|
manifestInlines += `\nglobalThis.__DINOU_ASSET_MANIFEST__ = ${content};\n`;
|
|
@@ -383,11 +373,21 @@ let importMapHtml = "";
|
|
|
383
373
|
if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
|
|
384
374
|
const imports = {};
|
|
385
375
|
const moduleBasePath = pathToFileURL(projectRoot).href + "/";
|
|
376
|
+
const moduleBasePathLower = moduleBasePath.replace(
|
|
377
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
378
|
+
(_, d) => `file:///${d.toLowerCase()}:`
|
|
379
|
+
);
|
|
380
|
+
const moduleBasePathUpper = moduleBasePath.replace(
|
|
381
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
382
|
+
(_, d) => `file:///${d.toUpperCase()}:`
|
|
383
|
+
);
|
|
386
384
|
|
|
387
385
|
for (const [key, val] of Object.entries(parsedClientManifest)) {
|
|
388
386
|
let specifier = key;
|
|
389
|
-
if (specifier.startsWith(
|
|
390
|
-
specifier = specifier.slice(
|
|
387
|
+
if (specifier.startsWith(moduleBasePathUpper)) {
|
|
388
|
+
specifier = specifier.slice(moduleBasePathUpper.length);
|
|
389
|
+
} else if (specifier.startsWith(moduleBasePathLower)) {
|
|
390
|
+
specifier = specifier.slice(moduleBasePathLower.length);
|
|
391
391
|
}
|
|
392
392
|
const hashIdx = specifier.indexOf("#");
|
|
393
393
|
if (hashIdx !== -1) {
|
|
@@ -450,21 +450,7 @@ if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
|
|
|
450
450
|
|
|
451
451
|
manifestInlines += `\nglobalThis.__DINOU_IMPORT_MAP_HTML__ = ${JSON.stringify(importMapHtml)};\n`;
|
|
452
452
|
|
|
453
|
-
const discoveredLayouts =
|
|
454
|
-
function findLayoutRoutes(dir, rel = "") {
|
|
455
|
-
if (!fs.existsSync(dir)) return;
|
|
456
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
457
|
-
for (const entry of entries) {
|
|
458
|
-
if (entry.isDirectory()) {
|
|
459
|
-
findLayoutRoutes(path.join(dir, entry.name), rel ? `${rel}/${entry.name}` : entry.name);
|
|
460
|
-
} else if (/^layout\.[jt]sx?$/.test(entry.name)) {
|
|
461
|
-
discoveredLayouts.push(rel);
|
|
462
|
-
} else if (entry.name === "no_layout") {
|
|
463
|
-
discoveredLayouts.push("!" + rel);
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
findLayoutRoutes(srcDir);
|
|
453
|
+
const discoveredLayouts = discoverLayoutsFromFs(srcDir, fs);
|
|
468
454
|
manifestInlines += `\nglobalThis.__DINOU_LAYOUTS__ = ${JSON.stringify(discoveredLayouts)};\n`;
|
|
469
455
|
|
|
470
456
|
if (process.env.DINOU_DEBUG) {
|
|
@@ -474,10 +460,11 @@ if (process.env.DINOU_DEBUG) {
|
|
|
474
460
|
const vfsSnapshot = {};
|
|
475
461
|
function walkVfs(dir) {
|
|
476
462
|
if (!fs.existsSync(dir)) return;
|
|
477
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
463
|
+
const entries = sortEntriesByName(fs.readdirSync(dir, { withFileTypes: true }));
|
|
478
464
|
const children = [];
|
|
479
465
|
for (const entry of entries) {
|
|
480
466
|
const isDir = entry.isDirectory();
|
|
467
|
+
if (isDir && entry.name.startsWith("_")) continue;
|
|
481
468
|
children.push({ name: entry.name, isDirectory: isDir });
|
|
482
469
|
const fullPath = path.join(dir, entry.name);
|
|
483
470
|
const relFromSrc = path.relative(srcDir, fullPath).replace(/\\/g, "/");
|
|
@@ -535,10 +522,7 @@ clientComponents.forEach((compPath, index) => {
|
|
|
535
522
|
});
|
|
536
523
|
|
|
537
524
|
const serverFunctionFiles = Object.keys(parsedServerFunctionsManifest);
|
|
538
|
-
|
|
539
|
-
const absPath = path.resolve(projectRoot, relPath).replace(/\\/g, "/");
|
|
540
|
-
ssrManifestCode += `import * as sf_${index} from ${JSON.stringify(absPath)};\n`;
|
|
541
|
-
});
|
|
525
|
+
ssrManifestCode += generateSsrServerManifestStubs(parsedServerFunctionsManifest);
|
|
542
526
|
|
|
543
527
|
ssrManifestCode += `\nexport const clientModules = {\n`;
|
|
544
528
|
const emittedClientModules = new Set();
|
|
@@ -733,12 +717,23 @@ fs.writeFileSync(ssrClientManifestPath, ssrManifestCode, "utf8");
|
|
|
733
717
|
// Entry Files Generation
|
|
734
718
|
// ====================================================================
|
|
735
719
|
// 1. RSC Engine Entry
|
|
720
|
+
const aotConfigPrelude = configFile
|
|
721
|
+
? `import * as __dinouConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};
|
|
722
|
+
const __resolvedDinouCfg = (__dinouConfigMod && __dinouConfigMod.default) ? __dinouConfigMod.default : (__dinouConfigMod || { plugins: [] });
|
|
723
|
+
globalThis.__DINOU_AOT_CONFIG__ = __resolvedDinouCfg;
|
|
724
|
+
globalThis.__DINOU_CONFIG__ = __resolvedDinouCfg;
|
|
725
|
+
`
|
|
726
|
+
: "";
|
|
736
727
|
const rscEntryContent = `// Auto-generated RSC Engine entry for Deno Deploy / Edge
|
|
737
728
|
import "./env-setup.js";
|
|
738
|
-
import "./route-modules.js";
|
|
729
|
+
${aotConfigPrelude}import "./route-modules.js";
|
|
739
730
|
import * as edgeRenderer from "react-server-dom-webpack/server.edge";
|
|
731
|
+
import { handleRequest as coreHandleRequest } from "${dinouDirSlash}/core/handler.js";
|
|
740
732
|
globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
|
|
741
|
-
export
|
|
733
|
+
export function handleRequest(request, platformContext) {
|
|
734
|
+
globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
|
|
735
|
+
return coreHandleRequest(request, platformContext);
|
|
736
|
+
}
|
|
742
737
|
`;
|
|
743
738
|
const rscEntryPath = path.join(denoDir, "rsc-entry.js");
|
|
744
739
|
fs.writeFileSync(rscEntryPath, rscEntryContent, "utf8");
|
|
@@ -749,7 +744,7 @@ import { renderRscStreamToHtmlStream } from "${dinouDirSlash}/core/edge-ssr.js";
|
|
|
749
744
|
import { clientModules, ssrConsumerManifest } from "./ssr-client-manifest.js";
|
|
750
745
|
|
|
751
746
|
const lowerMap = new Map();
|
|
752
|
-
|
|
747
|
+
const localWebpackRequire = (id) => {
|
|
753
748
|
if (clientModules[id]) return clientModules[id];
|
|
754
749
|
if (typeof id === "string") {
|
|
755
750
|
if (lowerMap.size === 0) {
|
|
@@ -761,10 +756,12 @@ globalThis.__webpack_require__ = (id) => {
|
|
|
761
756
|
console.error("[SSR Engine] Module not found in __webpack_require__:", id);
|
|
762
757
|
return {};
|
|
763
758
|
};
|
|
764
|
-
|
|
759
|
+
localWebpackRequire.u = (chunkId) => "" + chunkId + ".js";
|
|
760
|
+
globalThis.__webpack_require__ = localWebpackRequire;
|
|
765
761
|
globalThis.__webpack_chunk_load__ = () => Promise.resolve();
|
|
766
762
|
|
|
767
763
|
export async function renderHtml(rscStream, options = {}) {
|
|
764
|
+
globalThis.__webpack_require__ = localWebpackRequire;
|
|
768
765
|
return renderRscStreamToHtmlStream(rscStream, ssrConsumerManifest, options);
|
|
769
766
|
}
|
|
770
767
|
`;
|
|
@@ -778,12 +775,26 @@ import { renderHtml } from "./ssr-engine.js";
|
|
|
778
775
|
import {
|
|
779
776
|
getStorageAdapter,
|
|
780
777
|
setStorageAdapter,
|
|
778
|
+
hasExplicitStorageAdapter,
|
|
781
779
|
DenoKVStorage,
|
|
782
780
|
MemoryStorage,
|
|
783
781
|
} from "${dinouDirSlash}/core/storage-adapter.js";
|
|
782
|
+
import {
|
|
783
|
+
getStaticContentType,
|
|
784
|
+
getStaticCacheControl,
|
|
785
|
+
normalizePublicRequestPath,
|
|
786
|
+
parseHttpByteRange,
|
|
787
|
+
resolveConfinedStaticFile,
|
|
788
|
+
} from "${dinouDirSlash}/core/static-assets.js";
|
|
789
|
+
import { loadEnvFiles } from "${dinouDirSlash}/core/env.js";
|
|
784
790
|
import * as path from "node:path";
|
|
785
791
|
import * as fs from "node:fs";
|
|
786
792
|
|
|
793
|
+
try {
|
|
794
|
+
const bootCwd = typeof Deno !== "undefined" && typeof Deno.cwd === "function" ? Deno.cwd() : process.cwd();
|
|
795
|
+
loadEnvFiles(bootCwd, { mode: "production" });
|
|
796
|
+
} catch (e) {}
|
|
797
|
+
|
|
787
798
|
if (typeof globalThis !== "undefined") {
|
|
788
799
|
globalThis.__DINOU_RUNTIME__ = "deno-edge";
|
|
789
800
|
}
|
|
@@ -792,25 +803,27 @@ let storageInitialized = false;
|
|
|
792
803
|
|
|
793
804
|
export async function fetch(req) {
|
|
794
805
|
if (!storageInitialized) {
|
|
795
|
-
if (
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
806
|
+
if (!hasExplicitStorageAdapter()) {
|
|
807
|
+
if (typeof Deno !== "undefined" && typeof Deno.openKv === "function") {
|
|
808
|
+
try {
|
|
809
|
+
const kvUrl = Deno.env.get("DENO_KV_URL");
|
|
810
|
+
let kvInstance;
|
|
811
|
+
if (kvUrl) {
|
|
812
|
+
kvInstance = await Deno.openKv(kvUrl);
|
|
813
|
+
} else if (Deno.env.get("DENO_DEPLOYMENT_ID")) {
|
|
814
|
+
kvInstance = await Deno.openKv();
|
|
815
|
+
} else {
|
|
816
|
+
const cwd = typeof Deno.cwd === "function" ? Deno.cwd() : process.cwd();
|
|
817
|
+
const kvPath = Deno.env.get("DENO_KV_PATH") || path.resolve(cwd, ".dinou/kv.db");
|
|
818
|
+
kvInstance = await Deno.openKv(kvPath);
|
|
819
|
+
}
|
|
820
|
+
setStorageAdapter(new DenoKVStorage(kvInstance));
|
|
821
|
+
} catch (e) {
|
|
822
|
+
setStorageAdapter(new MemoryStorage());
|
|
807
823
|
}
|
|
808
|
-
|
|
809
|
-
} catch (e) {
|
|
824
|
+
} else {
|
|
810
825
|
setStorageAdapter(new MemoryStorage());
|
|
811
826
|
}
|
|
812
|
-
} else {
|
|
813
|
-
setStorageAdapter(new MemoryStorage());
|
|
814
827
|
}
|
|
815
828
|
storageInitialized = true;
|
|
816
829
|
}
|
|
@@ -819,25 +832,65 @@ export async function fetch(req) {
|
|
|
819
832
|
const pathname = url.pathname;
|
|
820
833
|
|
|
821
834
|
// Static assets delivery (if running with local disk access)
|
|
822
|
-
if (
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
const
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
835
|
+
if (
|
|
836
|
+
(req.method === "GET" || req.method === "HEAD") &&
|
|
837
|
+
typeof Deno !== "undefined" &&
|
|
838
|
+
typeof Deno.readFile === "function"
|
|
839
|
+
) {
|
|
840
|
+
const cleanPath = normalizePublicRequestPath(pathname);
|
|
841
|
+
if (cleanPath) {
|
|
842
|
+
try {
|
|
843
|
+
const cwd = typeof Deno.cwd === "function" ? Deno.cwd() : process.cwd();
|
|
844
|
+
const dist3Dir = path.resolve(cwd, ".dinou/dist3");
|
|
845
|
+
const filePath = resolveConfinedStaticFile(dist3Dir, cleanPath);
|
|
846
|
+
if (filePath && fs.existsSync(filePath)) {
|
|
847
|
+
const stat = fs.statSync(filePath);
|
|
848
|
+
if (stat.isFile()) {
|
|
849
|
+
const contentType = getStaticContentType(cleanPath);
|
|
850
|
+
const cacheControl = getStaticCacheControl(cleanPath);
|
|
851
|
+
const rangeHeader = req.method === "GET" ? req.headers.get("range") : null;
|
|
852
|
+
const range = rangeHeader ? parseHttpByteRange(rangeHeader, stat.size) : null;
|
|
853
|
+
|
|
854
|
+
if (range && range.unsatisfiable) {
|
|
855
|
+
return new Response(null, {
|
|
856
|
+
status: 416,
|
|
857
|
+
headers: {
|
|
858
|
+
"content-range": range.contentRange,
|
|
859
|
+
"accept-ranges": "bytes",
|
|
860
|
+
},
|
|
861
|
+
});
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
if (range) {
|
|
865
|
+
const full = await Deno.readFile(filePath);
|
|
866
|
+
const slice = full.subarray(range.start, range.end + 1);
|
|
867
|
+
return new Response(slice, {
|
|
868
|
+
status: 206,
|
|
869
|
+
headers: {
|
|
870
|
+
"content-type": contentType,
|
|
871
|
+
"content-length": String(range.length),
|
|
872
|
+
"content-range": range.contentRange,
|
|
873
|
+
"accept-ranges": "bytes",
|
|
874
|
+
"cache-control": cacheControl,
|
|
875
|
+
},
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
const content =
|
|
880
|
+
req.method === "HEAD" ? null : await Deno.readFile(filePath);
|
|
881
|
+
return new Response(content, {
|
|
882
|
+
headers: {
|
|
883
|
+
"content-type": contentType,
|
|
884
|
+
"content-length": String(stat.size),
|
|
885
|
+
"accept-ranges": "bytes",
|
|
886
|
+
"cache-control": cacheControl,
|
|
887
|
+
},
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
} catch (e) {
|
|
892
|
+
// Fallback to Dinou handler
|
|
838
893
|
}
|
|
839
|
-
} catch (e) {
|
|
840
|
-
// Fallback to Dinou handler
|
|
841
894
|
}
|
|
842
895
|
}
|
|
843
896
|
|
|
@@ -879,8 +932,8 @@ const externalList = [
|
|
|
879
932
|
];
|
|
880
933
|
|
|
881
934
|
const commonAlias = {
|
|
882
|
-
"@": path.resolve(projectRoot, "src"),
|
|
883
935
|
"dinou/config": path.resolve(dinouDir, "core/config.js"),
|
|
936
|
+
"dinou/server": path.resolve(dinouDir, "server.js"),
|
|
884
937
|
dinou: dinouDir,
|
|
885
938
|
};
|
|
886
939
|
|
|
@@ -891,12 +944,6 @@ const commonLoader = {
|
|
|
891
944
|
".tsx": "tsx",
|
|
892
945
|
".json": "json",
|
|
893
946
|
".css": "empty",
|
|
894
|
-
".svg": "dataurl",
|
|
895
|
-
".png": "dataurl",
|
|
896
|
-
".jpg": "dataurl",
|
|
897
|
-
".jpeg": "dataurl",
|
|
898
|
-
".webp": "dataurl",
|
|
899
|
-
".ico": "dataurl",
|
|
900
947
|
};
|
|
901
948
|
|
|
902
949
|
const banner = {
|
|
@@ -1022,8 +1069,9 @@ const serverReferencesPlugin = {
|
|
|
1022
1069
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
|
|
1023
1070
|
|
|
1024
1071
|
for (const name of exports) {
|
|
1025
|
-
|
|
1026
|
-
|
|
1072
|
+
const localIdent = name === "default" ? sfResult.defaultExportIdentifier : name;
|
|
1073
|
+
if (localIdent) {
|
|
1074
|
+
transformed += `registerServerReference(${localIdent}, ${JSON.stringify(relativeFileUrl)}, ${JSON.stringify(name)});\n`;
|
|
1027
1075
|
}
|
|
1028
1076
|
}
|
|
1029
1077
|
|
|
@@ -1054,31 +1102,15 @@ const serverReferencesPluginSsr = {
|
|
|
1054
1102
|
|
|
1055
1103
|
if (!hasServerFunctions(code)) return null;
|
|
1056
1104
|
|
|
1057
|
-
const sfResult = transformServerFunctions(code, args.path);
|
|
1058
|
-
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1059
|
-
|
|
1060
|
-
const transformedCode = sfResult.code;
|
|
1061
|
-
const exports = sfResult.actions;
|
|
1062
1105
|
const absPath = path.resolve(args.path);
|
|
1063
1106
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1064
1107
|
const relativeFileUrl = "file:///" + relPath;
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
|
|
1068
|
-
|
|
1069
|
-
for (const name of exports) {
|
|
1070
|
-
if (name !== "default") {
|
|
1071
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(relativeFileUrl + "#" + name)});\n`;
|
|
1072
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(pathToFileURL(absPath).href + "#" + name)});\n`;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
const ext = path.extname(args.path);
|
|
1077
|
-
const loader = ext === ".ts" ? "ts" : ext === ".tsx" ? "tsx" : ext === ".jsx" ? "jsx" : "js";
|
|
1108
|
+
const stubModule = buildSsrServerReferenceModule(code, args.path, relativeFileUrl);
|
|
1109
|
+
if (!stubModule) return null;
|
|
1078
1110
|
|
|
1079
1111
|
return {
|
|
1080
|
-
contents:
|
|
1081
|
-
loader,
|
|
1112
|
+
contents: stubModule,
|
|
1113
|
+
loader: "js",
|
|
1082
1114
|
};
|
|
1083
1115
|
});
|
|
1084
1116
|
},
|
|
@@ -1088,6 +1120,13 @@ const rscOutfile = path.join(denoDir, "rsc-engine.js");
|
|
|
1088
1120
|
const ssrOutfile = path.join(denoDir, "ssr-engine.js");
|
|
1089
1121
|
const finalOutfile = path.join(denoDir, "main.js");
|
|
1090
1122
|
|
|
1123
|
+
const serverCssModulesPlugin = createServerCssModulesPlugin({ projectRoot });
|
|
1124
|
+
const serverAssetPlugin = createServerAssetPlugin({ projectRoot, dinouConfig });
|
|
1125
|
+
const serverTsconfigAliasesPlugin = esbuildTsconfigAliasesPlugin({
|
|
1126
|
+
projectRoot,
|
|
1127
|
+
assetRegex: getAssetExtensionsInfo(dinouConfig, projectRoot).regex,
|
|
1128
|
+
});
|
|
1129
|
+
|
|
1091
1130
|
try {
|
|
1092
1131
|
// Pass A: RSC Engine
|
|
1093
1132
|
console.log(" ⚡ Bundling Pass A (RSC deno) & Pass B (SSR deno)...");
|
|
@@ -1099,18 +1138,23 @@ try {
|
|
|
1099
1138
|
target: "es2022",
|
|
1100
1139
|
platform: "neutral",
|
|
1101
1140
|
mainFields: ["module", "main"],
|
|
1102
|
-
conditions: ["deno", "worker", "react-server"],
|
|
1141
|
+
conditions: ["deno", "worker", "react-server", "style"],
|
|
1103
1142
|
external: externalList,
|
|
1104
|
-
plugins: [clientReferencesPlugin, serverReferencesPlugin],
|
|
1143
|
+
plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, clientReferencesPlugin, serverReferencesPlugin, serverCssModulesPlugin, serverAssetPlugin],
|
|
1105
1144
|
alias: commonAlias,
|
|
1106
1145
|
loader: commonLoader,
|
|
1107
1146
|
jsx: "automatic",
|
|
1108
1147
|
inject: setupFiles.length > 0 ? setupFiles : undefined,
|
|
1109
|
-
define: {
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1148
|
+
define: getEsbuildPublicEnvDefines({
|
|
1149
|
+
mode: "production",
|
|
1150
|
+
defineProcessEnvObject: false,
|
|
1151
|
+
extra: {
|
|
1152
|
+
DINOU_RUNTIME: "deno-edge",
|
|
1153
|
+
DINOU_BUILD_TOOL: isWebpackBuild
|
|
1154
|
+
? "webpack"
|
|
1155
|
+
: process.env.DINOU_BUILD_TOOL || "esbuild",
|
|
1156
|
+
},
|
|
1157
|
+
}),
|
|
1114
1158
|
logLevel: "warning",
|
|
1115
1159
|
});
|
|
1116
1160
|
|
|
@@ -1123,18 +1167,25 @@ try {
|
|
|
1123
1167
|
target: "es2022",
|
|
1124
1168
|
platform: "neutral",
|
|
1125
1169
|
mainFields: ["module", "main"],
|
|
1126
|
-
conditions: ["deno", "worker", "browser"],
|
|
1170
|
+
conditions: ["deno", "worker", "browser", "style"],
|
|
1127
1171
|
external: externalList,
|
|
1128
|
-
plugins: [serverReferencesPluginSsr],
|
|
1172
|
+
plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, serverReferencesPluginSsr, serverCssModulesPlugin, serverAssetPlugin],
|
|
1129
1173
|
alias: commonAlias,
|
|
1130
1174
|
loader: commonLoader,
|
|
1131
1175
|
jsx: "automatic",
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1176
|
+
define: getEsbuildPublicEnvDefines({
|
|
1177
|
+
mode: "production",
|
|
1178
|
+
defineProcessEnvObject: true,
|
|
1179
|
+
extra: {
|
|
1180
|
+
DINOU_RUNTIME: "deno-edge",
|
|
1181
|
+
DINOU_BUILD_TOOL: isWebpackBuild
|
|
1182
|
+
? "webpack"
|
|
1183
|
+
: process.env.DINOU_BUILD_TOOL || "esbuild",
|
|
1184
|
+
...(process.env.DINOU_DEBUG
|
|
1185
|
+
? { DINOU_DEBUG: process.env.DINOU_DEBUG }
|
|
1186
|
+
: {}),
|
|
1187
|
+
},
|
|
1188
|
+
}),
|
|
1138
1189
|
logLevel: "warning",
|
|
1139
1190
|
});
|
|
1140
1191
|
|
|
@@ -1151,9 +1202,10 @@ try {
|
|
|
1151
1202
|
conditions: ["deno", "worker", "browser"],
|
|
1152
1203
|
external: externalList,
|
|
1153
1204
|
banner,
|
|
1154
|
-
|
|
1205
|
+
plugins: [serverTsconfigAliasesPlugin, serverAssetPlugin],
|
|
1155
1206
|
alias: commonAlias,
|
|
1156
1207
|
loader: commonLoader,
|
|
1208
|
+
jsx: "automatic",
|
|
1157
1209
|
define: {
|
|
1158
1210
|
"process.env.NODE_ENV": '"production"',
|
|
1159
1211
|
"process.env.DINOU_RUNTIME": '"deno-edge"',
|
package/dinou/deno/seed-kv.js
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import * as fs from "node:fs";
|
|
6
|
+
import { loadEnvFiles } from "../core/env.js";
|
|
6
7
|
|
|
7
8
|
const cwd = typeof Deno !== "undefined" && typeof Deno.cwd === "function" ? Deno.cwd() : process.cwd();
|
|
9
|
+
try {
|
|
10
|
+
loadEnvFiles(cwd, { mode: "production" });
|
|
11
|
+
} catch (e) {}
|
|
8
12
|
const kvUrl = typeof Deno !== "undefined" ? Deno.env.get("DENO_KV_URL") : process.env.DENO_KV_URL;
|
|
9
13
|
const dist2Dir = path.resolve(cwd, ".dinou/dist2");
|
|
10
14
|
|
package/dinou/env.d.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
-
// dinou/
|
|
1
|
+
// dinou/env.d.ts
|
|
2
2
|
/// <reference path="./assets.d.ts" />
|
|
3
|
-
/// <reference path="./css.d.ts" />
|
|
3
|
+
/// <reference path="./css.d.ts" />
|
|
4
|
+
|
|
5
|
+
declare var process: NodeJS.Process;
|
|
6
|
+
|
|
7
|
+
declare namespace NodeJS {
|
|
8
|
+
interface Process {
|
|
9
|
+
env: ProcessEnv;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface ProcessEnv {
|
|
13
|
+
NODE_ENV?: "development" | "production" | "test";
|
|
14
|
+
PORT?: string;
|
|
15
|
+
HOST?: string;
|
|
16
|
+
HMR_PORT?: string;
|
|
17
|
+
IDLE_TIMEOUT?: string;
|
|
18
|
+
DINOU_WRITE_TO_DISK?: string;
|
|
19
|
+
DINOU_UNVENDORIZED?: string;
|
|
20
|
+
[key: `DINOU_PUBLIC_${string}`]: string | undefined;
|
|
21
|
+
[key: string]: string | undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|