dinou 6.1.1 → 7.1.0
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 +106 -0
- package/README.md +9352 -1081
- package/cli.js +314 -91
- package/dinou/adapters/bun.js +62 -0
- package/dinou/adapters/cloudflare.js +65 -0
- package/dinou/adapters/deno.js +48 -0
- package/dinou/adapters/netlify.js +85 -0
- package/dinou/adapters/node.mjs +31 -0
- package/dinou/bun/build.mjs +1077 -0
- package/dinou/cloudflare/build.mjs +1121 -0
- package/dinou/cloudflare/shims/child_process.js +14 -0
- package/dinou/cloudflare/shims/empty.js +2 -0
- package/dinou/cloudflare/shims/fs.js +99 -0
- package/dinou/cloudflare/shims/os.js +29 -0
- package/dinou/config.js +1 -0
- package/dinou/config.mjs +2 -0
- package/dinou/constants.js +29 -4
- package/dinou/core/babel-esm-loader.js +66 -37
- package/dinou/core/bailout-proxy.js +61 -0
- package/dinou/core/build-static-pages.js +322 -165
- package/dinou/core/cache-revalidate.js +471 -144
- package/dinou/core/cache-slot.js +387 -0
- package/dinou/core/client-redirect.jsx +12 -7
- package/dinou/core/client-webpack.jsx +457 -82
- package/dinou/core/client.jsx +452 -82
- package/dinou/core/config.js +11 -0
- package/dinou/core/dinou-paths.js +52 -0
- package/dinou/core/edge-ssr.js +122 -0
- package/dinou/core/export-static.mjs +64 -0
- package/dinou/core/generate-route-types.js +252 -0
- package/dinou/core/generate-static-page.js +55 -94
- package/dinou/core/generate-static-rsc.js +47 -15
- package/dinou/core/generate-static.js +212 -10
- package/dinou/core/generating-isg.js +5 -0
- package/dinou/core/get-asset-from-manifest.js +9 -3
- package/dinou/core/get-error-jsx.js +221 -41
- package/dinou/core/get-file-path-and-dynamic-params.js +9 -13
- package/dinou/core/get-jsx.js +175 -96
- package/dinou/core/handler.js +2303 -0
- package/dinou/core/http-adapter.js +115 -0
- package/dinou/core/import-module.js +83 -53
- package/dinou/core/layout-functions.js +183 -0
- package/dinou/core/link.jsx +18 -6
- package/dinou/core/load-dinou-config.js +60 -0
- package/dinou/core/manifest-provider.js +261 -0
- package/dinou/core/navigation-utils.js +4 -0
- package/dinou/core/navigation.js +50 -39
- package/dinou/core/parse-exports.js +252 -2
- package/dinou/core/ppr-context.js +105 -0
- package/dinou/core/ppr-runtime.js +263 -0
- package/dinou/core/redirect.jsx +20 -19
- package/dinou/core/render-jsx-to-client-jsx.js +91 -87
- package/dinou/core/request-context.js +47 -13
- package/dinou/core/resolve-module-ppr.js +34 -0
- package/dinou/core/revalidating.js +28 -9
- package/dinou/core/route-generator.js +107 -0
- package/dinou/core/rsc-renderer.js +90 -0
- package/dinou/core/run-ssg.js +19 -0
- package/dinou/core/scan-dependency-components.js +218 -0
- package/dinou/core/server-function-proxy-webpack.js +3 -0
- package/dinou/core/server-function-proxy.js +3 -0
- package/dinou/core/slot.js +302 -0
- package/dinou/core/status-manifest.js +41 -1
- package/dinou/core/storage-adapter.js +522 -0
- package/dinou/core/url-resolver.js +16 -16
- package/dinou/core/vfs.js +139 -68
- package/dinou/deno/build.mjs +1112 -0
- package/dinou/deno/seed-kv.js +115 -0
- package/dinou/esbuild/build.mjs +51 -1
- package/dinou/esbuild/dev.mjs +290 -224
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.mjs +3 -2
- package/dinou/esbuild/helpers-esbuild/get-config-esbuild.mjs +104 -16
- package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.mjs +31 -19
- package/dinou/esbuild/helpers-esbuild/strip-namespace.mjs +9 -0
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.mjs +225 -0
- package/dinou/esbuild/helpers-esbuild/update-manifest-for-module.mjs +7 -0
- package/dinou/esbuild/helpers-esbuild/write.mjs +111 -2
- package/dinou/esbuild/plugins-esbuild/assets-plugin.mjs +236 -161
- package/dinou/esbuild/plugins-esbuild/css-processor-plugin.mjs +101 -5
- package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.mjs +63 -24
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.mjs +177 -56
- package/dinou/esbuild/plugins-esbuild/skip-missing-entry-points-plugin.mjs +3 -0
- package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.mjs +182 -137
- package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +38 -11
- package/dinou/esbuild/react-refresh/esm-hmr/client.mjs +55 -8
- package/dinou/esbuild/react-refresh/esm-hmr/server.js +1 -1
- package/dinou/esbuild/react-refresh/esm-hmr-plugin.mjs +238 -101
- package/dinou/esbuild/react-refresh/is-react-refresh-boundary.mjs +18 -4
- package/dinou/index.d.ts +315 -11
- package/dinou/index.js +12 -6
- package/dinou/index.mjs +9 -0
- package/dinou/node/build.mjs +195 -0
- package/dinou/node/bundle-dual-engine.mjs +1012 -0
- package/dinou/node/dev.mjs +2589 -0
- package/dinou/node/port-selector.mjs +164 -0
- package/dinou/node/terminal-status.mjs +345 -0
- package/dinou/package.json +16 -14
- package/dinou/rollup/react-refresh/esm-hmr/client.js +66 -10
- package/dinou/rollup/react-refresh/esm-hmr/server.js +1 -1
- package/dinou/rollup/react-refresh/is-react-refresh-boundary.js +24 -5
- package/dinou/rollup/react-refresh/react-refresh-runtime.js +13 -6
- package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +56 -11
- package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +176 -48
- package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +9 -5
- package/dinou/rollup/rollup-plugins/rollup-plugin-memory.js +66 -0
- package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +468 -123
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +44 -12
- package/dinou/rollup/rollup-plugins/rollup-plugin-swc.js +100 -0
- package/dinou/rollup/rollup.config.js +155 -43
- package/dinou/server.d.ts +114 -12
- package/dinou/server.js +35 -10
- package/dinou/server.mjs +30 -9
- package/dinou/webpack/helpers/get-webpack-entries.js +14 -19
- package/dinou/webpack/loaders/server-functions-loader.js +22 -1
- package/dinou/webpack/loaders/swc-loader.js +76 -0
- package/dinou/webpack/plugins/manifest-generator-plugin.js +1 -0
- package/dinou/webpack/plugins/server-functions-plugin.js +75 -19
- package/dinou/webpack/plugins/webpack-memory-plugin.js +66 -0
- package/dinou/webpack/webpack.config.js +227 -29
- package/eject.js +113 -34
- package/package.json +18 -16
- package/dinou/core/asset-require-hook.js +0 -58
- package/dinou/core/client-error-webpack.jsx +0 -432
- package/dinou/core/client-error.jsx +0 -432
- package/dinou/core/concurrency-manager.js +0 -48
- package/dinou/core/context-proxy.js +0 -68
- package/dinou/core/generate-static-pages.js +0 -130
- package/dinou/core/generate-static-rscs.js +0 -151
- package/dinou/core/get-ssg-metadata.js +0 -31
- package/dinou/core/register-loader.mjs +0 -11
- package/dinou/core/register-paths.js +0 -27
- package/dinou/core/render-app-to-html.js +0 -430
- package/dinou/core/render-html.js +0 -407
- package/dinou/core/server.js +0 -1542
- package/dinou/esbuild/plugins-esbuild/write-metafile-plugin.mjs +0 -16
|
@@ -3,26 +3,39 @@ const path = require("path");
|
|
|
3
3
|
const { PassThrough } = require("stream");
|
|
4
4
|
const url = require("url");
|
|
5
5
|
const getJSX = require("./get-jsx.js");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
let _renderToPipeableStream = null;
|
|
7
|
+
function getRenderToPipeableStream() {
|
|
8
|
+
if (!_renderToPipeableStream) {
|
|
9
|
+
const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
10
|
+
const mod = isWebpack
|
|
11
|
+
? require("react-server-dom-webpack/server")
|
|
12
|
+
: require("@roggc/react-server-dom-esm/server");
|
|
13
|
+
_renderToPipeableStream = mod.renderToPipeableStream;
|
|
14
|
+
}
|
|
15
|
+
return _renderToPipeableStream;
|
|
16
|
+
}
|
|
10
17
|
const { requestStorage } = require("./request-context.js");
|
|
11
18
|
|
|
12
19
|
const OUT_DIR = path.resolve(".dinou/dist2");
|
|
13
|
-
|
|
20
|
+
const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
14
21
|
|
|
15
|
-
async function generateStaticRSC(reqPath) {
|
|
22
|
+
async function generateStaticRSC(reqPath, options = {}) {
|
|
16
23
|
const finalReqPath = reqPath.endsWith("/") ? reqPath : reqPath + "/";
|
|
24
|
+
const segment = options.segment || "page";
|
|
25
|
+
const fileName = segment === "layout" ? "layout.rsc" : "page.rsc";
|
|
17
26
|
|
|
18
|
-
const payloadPath = path.join(OUT_DIR, finalReqPath,
|
|
19
|
-
const tempPayloadPath = path.join(
|
|
27
|
+
const payloadPath = path.join(OUT_DIR, finalReqPath, fileName);
|
|
28
|
+
const tempPayloadPath = path.join(
|
|
29
|
+
OUT_DIR,
|
|
30
|
+
finalReqPath,
|
|
31
|
+
`${fileName}.${Date.now()}-${Math.random()}.tmp`
|
|
32
|
+
);
|
|
20
33
|
|
|
21
34
|
// 👇 2. MOCK RES (Complete and Robust Version)
|
|
22
35
|
const mockRes = {
|
|
23
36
|
_statusCode: 200,
|
|
24
37
|
_headers: {},
|
|
25
|
-
_redirectUrl: null,
|
|
38
|
+
_redirectUrl: null,
|
|
26
39
|
_cookies: [],
|
|
27
40
|
|
|
28
41
|
cookie(name, value, options) {
|
|
@@ -41,12 +54,10 @@ async function generateStaticRSC(reqPath) {
|
|
|
41
54
|
this._statusCode = code;
|
|
42
55
|
},
|
|
43
56
|
|
|
44
|
-
// ✅ YOUR ORIGINAL LOGIC (The correct one)
|
|
45
57
|
redirect(arg1, arg2) {
|
|
46
58
|
let status = 302;
|
|
47
59
|
let url = "";
|
|
48
60
|
|
|
49
|
-
// Overload handling: redirect(url) vs redirect(status, url)
|
|
50
61
|
if (typeof arg1 === "number") {
|
|
51
62
|
status = arg1;
|
|
52
63
|
url = arg2;
|
|
@@ -97,7 +108,11 @@ async function generateStaticRSC(reqPath) {
|
|
|
97
108
|
const passThrough = new PassThrough();
|
|
98
109
|
|
|
99
110
|
await requestStorage.run(mockContext, async () => {
|
|
100
|
-
const jsx = await getJSX(finalReqPath, {}, null, false
|
|
111
|
+
const jsx = await getJSX(finalReqPath, {}, null, false, false, {
|
|
112
|
+
segment,
|
|
113
|
+
layoutPath: options.layoutPath,
|
|
114
|
+
});
|
|
115
|
+
const renderToPipeableStream = getRenderToPipeableStream();
|
|
101
116
|
const { pipe } = isWebpack
|
|
102
117
|
? renderToPipeableStream(jsx, manifest)
|
|
103
118
|
: renderToPipeableStream(jsx, url.pathToFileURL(process.cwd()).href + "/");
|
|
@@ -111,23 +126,40 @@ async function generateStaticRSC(reqPath) {
|
|
|
111
126
|
});
|
|
112
127
|
});
|
|
113
128
|
|
|
114
|
-
// 3. RETURN RESULT (We DO NOT rename here)
|
|
129
|
+
// 3. RETURN RESULT (We DO NOT rename here, atomic rename handled by caller)
|
|
115
130
|
const success = mockRes._statusCode !== 500;
|
|
116
131
|
|
|
117
132
|
return {
|
|
118
133
|
success,
|
|
119
134
|
type: "rsc",
|
|
135
|
+
segment,
|
|
136
|
+
fileName,
|
|
120
137
|
reqPath: finalReqPath,
|
|
121
138
|
tempPath: tempPayloadPath,
|
|
122
139
|
finalPath: payloadPath,
|
|
123
140
|
status: mockRes._statusCode,
|
|
124
141
|
};
|
|
125
142
|
} catch (error) {
|
|
126
|
-
console.error(
|
|
143
|
+
console.error(`❌ Error generating ${fileName} payload:`, error);
|
|
127
144
|
// Emergency cleanup
|
|
128
145
|
if (fs.existsSync(tempPayloadPath)) fs.unlinkSync(tempPayloadPath);
|
|
129
|
-
return { success: false, tempPath: tempPayloadPath };
|
|
146
|
+
return { success: false, segment, fileName, tempPath: tempPayloadPath };
|
|
130
147
|
}
|
|
131
148
|
}
|
|
132
149
|
|
|
150
|
+
async function generateStaticPageRSC(reqPath, options = {}) {
|
|
151
|
+
return generateStaticRSC(reqPath, { ...options, segment: "page" });
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
async function generateStaticLayoutRSC(layoutFolderPath, layoutFilePath, options = {}) {
|
|
155
|
+
return generateStaticRSC(layoutFolderPath, {
|
|
156
|
+
...options,
|
|
157
|
+
segment: "layout",
|
|
158
|
+
layoutPath: layoutFilePath,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
|
|
133
162
|
module.exports = generateStaticRSC;
|
|
163
|
+
module.exports.generateStaticRSC = generateStaticRSC;
|
|
164
|
+
module.exports.generateStaticPageRSC = generateStaticPageRSC;
|
|
165
|
+
module.exports.generateStaticLayoutRSC = generateStaticLayoutRSC;
|
|
@@ -1,22 +1,224 @@
|
|
|
1
|
+
// dinou/core/generate-static.js
|
|
2
|
+
// Unified Static Site Generation runner using the in-memory Dual-Bundle Engine.
|
|
3
|
+
// Guarantees 100% parity with runtime Incremental Static Generation (ISG).
|
|
4
|
+
|
|
1
5
|
const path = require("path");
|
|
2
|
-
const { existsSync, rmSync } = require("fs");
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const {
|
|
6
|
+
const { existsSync, rmSync, mkdirSync, renameSync } = require("fs");
|
|
7
|
+
const { pathToFileURL } = require("url");
|
|
8
|
+
const { setStorageAdapter, FileSystemStorage } = require("./storage-adapter.js");
|
|
9
|
+
const {
|
|
10
|
+
generateStaticPageRSC,
|
|
11
|
+
generateStaticLayoutRSC,
|
|
12
|
+
} = require("./generate-static-rsc.js");
|
|
6
13
|
|
|
7
14
|
async function generateStatic() {
|
|
8
15
|
const distFolder2 = path.resolve(process.cwd(), ".dinou/dist2");
|
|
9
16
|
|
|
10
17
|
if (existsSync(distFolder2)) {
|
|
11
18
|
rmSync(distFolder2, { recursive: true, force: true });
|
|
12
|
-
console.log("Deleted existing .dinou/dist2 folder");
|
|
13
19
|
}
|
|
14
20
|
|
|
15
|
-
await
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
const { updateBuildProgress, clearBuildProgress, isTTY } = await import(
|
|
22
|
+
"../node/terminal-status.mjs"
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
// 1. Compile or ensure Dual-Bundle engines (Pass A & Pass B)
|
|
26
|
+
updateBuildProgress("[SSG] Compiling Dual-Engine for static generation...");
|
|
27
|
+
const { bundleDualEngine } = await import("../node/bundle-dual-engine.mjs");
|
|
28
|
+
const { rscEnginePath, ssrEnginePath } = await bundleDualEngine({
|
|
29
|
+
isDev: false,
|
|
30
|
+
projectRoot: process.cwd(),
|
|
31
|
+
outDir: ".dinou/node",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// 2. Initialize FileSystemStorage for writing .dinou/dist2
|
|
35
|
+
const storage = new FileSystemStorage(distFolder2);
|
|
36
|
+
setStorageAdapter(storage);
|
|
37
|
+
|
|
38
|
+
// 3. Load compiled engines
|
|
39
|
+
const rscModule = await import(pathToFileURL(rscEnginePath).href);
|
|
40
|
+
const ssrModule = await import(pathToFileURL(ssrEnginePath).href);
|
|
41
|
+
|
|
42
|
+
// 4. Discover static routes and layouts
|
|
43
|
+
updateBuildProgress("[SSG] Discovering static routes and layouts...");
|
|
44
|
+
await rscModule.buildStaticPages((info) => {
|
|
45
|
+
if (info.phase === "discovering") {
|
|
46
|
+
updateBuildProgress(
|
|
47
|
+
`[SSG] (${info.current}/${info.total}) Discovering: ${info.route}`
|
|
48
|
+
);
|
|
49
|
+
} else if (info.phase === "crawling") {
|
|
50
|
+
updateBuildProgress(`[SSG] Crawling: ${info.route}`);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const routes = rscModule.getStaticPaths();
|
|
55
|
+
const layouts =
|
|
56
|
+
typeof rscModule.getStaticLayouts === "function"
|
|
57
|
+
? rscModule.getStaticLayouts()
|
|
58
|
+
: [];
|
|
59
|
+
|
|
60
|
+
// 4b. Pre-render all static layout segments (layout.rsc)
|
|
61
|
+
if (layouts.length > 0) {
|
|
62
|
+
if (!isTTY) {
|
|
63
|
+
console.log(`⚡ [SSG] Pre-rendering ${layouts.length} static layout(s)...`);
|
|
64
|
+
}
|
|
65
|
+
for (const layoutInfo of layouts) {
|
|
66
|
+
const layoutReqPath = layoutInfo.routePath.startsWith("/")
|
|
67
|
+
? layoutInfo.routePath
|
|
68
|
+
: "/" + layoutInfo.routePath;
|
|
69
|
+
updateBuildProgress(`[SSG] Compiling layout: ${layoutReqPath}`);
|
|
70
|
+
try {
|
|
71
|
+
const layoutReq = new Request(`http://localhost/____rsc_layout____${layoutReqPath}`);
|
|
72
|
+
const layoutRes = await rscModule.handleRequest(layoutReq, {
|
|
73
|
+
runtime: "node-bundle",
|
|
74
|
+
});
|
|
75
|
+
if (layoutRes.status === 200) {
|
|
76
|
+
const layoutRscText = await layoutRes.text();
|
|
77
|
+
const cleanLayoutPath = layoutReqPath.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
78
|
+
const layoutRscKey = cleanLayoutPath ? `${cleanLayoutPath}/layout.rsc` : "layout.rsc";
|
|
79
|
+
|
|
80
|
+
let layoutMeta = {
|
|
81
|
+
status: 200,
|
|
82
|
+
generatedAt: Date.now(),
|
|
83
|
+
revalidate: undefined,
|
|
84
|
+
tags: [],
|
|
85
|
+
};
|
|
86
|
+
try {
|
|
87
|
+
const { resolveLayoutFunctionsConfig } = require("./layout-functions.js");
|
|
88
|
+
const layoutConfig = await resolveLayoutFunctionsConfig(
|
|
89
|
+
layoutInfo.layoutPath,
|
|
90
|
+
layoutInfo.params || {}
|
|
91
|
+
);
|
|
92
|
+
layoutMeta.revalidate = layoutConfig.revalidate;
|
|
93
|
+
layoutMeta.tags = layoutConfig.tags || [];
|
|
94
|
+
} catch (e) {}
|
|
95
|
+
|
|
96
|
+
await storage.set(layoutRscKey, layoutRscText, layoutMeta);
|
|
97
|
+
} else {
|
|
98
|
+
const layoutResult = await generateStaticLayoutRSC(
|
|
99
|
+
layoutReqPath,
|
|
100
|
+
layoutInfo.layoutPath
|
|
101
|
+
);
|
|
102
|
+
if (
|
|
103
|
+
layoutResult &&
|
|
104
|
+
layoutResult.tempPath &&
|
|
105
|
+
layoutResult.finalPath &&
|
|
106
|
+
existsSync(layoutResult.tempPath)
|
|
107
|
+
) {
|
|
108
|
+
mkdirSync(path.dirname(layoutResult.finalPath), { recursive: true });
|
|
109
|
+
renameSync(layoutResult.tempPath, layoutResult.finalPath);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} catch (layoutErr) {
|
|
113
|
+
console.error(
|
|
114
|
+
`❌ [SSG] Error compiling layout ${layoutReqPath}:`,
|
|
115
|
+
layoutErr
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!isTTY) {
|
|
122
|
+
console.log(
|
|
123
|
+
`⚡ [SSG] Pre-rendering ${routes.length} static route(s) with in-memory Dual-Engine...`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 5. Pre-render all routes using Dual-Bundle engine (index.html + page.rsc)
|
|
128
|
+
let renderedCount = 0;
|
|
129
|
+
let currentIndex = 0;
|
|
130
|
+
for (const route of routes) {
|
|
131
|
+
currentIndex++;
|
|
132
|
+
const reqPath = route.startsWith("/") ? route : "/" + route;
|
|
133
|
+
updateBuildProgress(
|
|
134
|
+
`[SSG] (${currentIndex}/${routes.length}) Pre-rendering: ${reqPath}`
|
|
135
|
+
);
|
|
136
|
+
try {
|
|
137
|
+
// A. Pre-render full HTML (index.html) and metadata (metadata.json)
|
|
138
|
+
const webReq = new Request(`http://localhost${reqPath}`);
|
|
139
|
+
const res = await rscModule.handleRequest(webReq, {
|
|
140
|
+
runtime: "node-bundle",
|
|
141
|
+
renderHtmlStream: ssrModule.renderHtml,
|
|
142
|
+
isSSG: true,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const routeMeta = typeof rscModule.getStaticMetadata === "function" ? rscModule.getStaticMetadata(reqPath) : null;
|
|
146
|
+
const isRoutePpr = Boolean(routeMeta?.ppr);
|
|
147
|
+
const cleanPagePath = reqPath.replace(/^\/+/, "").replace(/\/+$/, "");
|
|
148
|
+
|
|
149
|
+
if (res.status === 200) {
|
|
150
|
+
renderedCount++;
|
|
151
|
+
if (isRoutePpr) {
|
|
152
|
+
const indexHtmlKey = cleanPagePath ? `${cleanPagePath}/index.html` : "index.html";
|
|
153
|
+
const shellHtmlKey = cleanPagePath ? `${cleanPagePath}/shell.html` : "shell.html";
|
|
154
|
+
const metaKey = cleanPagePath ? `${cleanPagePath}/metadata.json` : "metadata.json";
|
|
155
|
+
|
|
156
|
+
const htmlItem = await storage.get(indexHtmlKey);
|
|
157
|
+
if (htmlItem) {
|
|
158
|
+
await storage.set(shellHtmlKey, htmlItem.content, { ...(htmlItem.metadata || {}), ppr: true, holes: routeMeta.holes || [] });
|
|
159
|
+
}
|
|
160
|
+
const metaItem = await storage.get(metaKey);
|
|
161
|
+
let metaObj = {};
|
|
162
|
+
try {
|
|
163
|
+
metaObj = metaItem ? JSON.parse(metaItem.content || "{}") : {};
|
|
164
|
+
} catch (e) {}
|
|
165
|
+
metaObj.ppr = true;
|
|
166
|
+
metaObj.holes = routeMeta.holes || [];
|
|
167
|
+
await storage.set(metaKey, JSON.stringify(metaObj));
|
|
168
|
+
}
|
|
169
|
+
} else {
|
|
170
|
+
if (process.env.DINOU_DEBUG) {
|
|
171
|
+
console.warn(`⚠️ [SSG] Route ${reqPath} returned status ${res.status}`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// B. Pre-render isolated page RSC segment (page.rsc)
|
|
176
|
+
try {
|
|
177
|
+
const pageReq = new Request(`http://localhost/____rsc_page____${reqPath}`);
|
|
178
|
+
const pageRes = await rscModule.handleRequest(pageReq, {
|
|
179
|
+
runtime: "node-bundle",
|
|
180
|
+
});
|
|
181
|
+
if (pageRes.status === 200) {
|
|
182
|
+
const pageRscText = await pageRes.text();
|
|
183
|
+
const pageRscKey = cleanPagePath ? `${cleanPagePath}/page.rsc` : "page.rsc";
|
|
184
|
+
await storage.set(pageRscKey, pageRscText);
|
|
185
|
+
if (isRoutePpr) {
|
|
186
|
+
const shellRscKey = cleanPagePath ? `${cleanPagePath}/shell.rsc` : "shell.rsc";
|
|
187
|
+
await storage.set(shellRscKey, pageRscText, { ppr: true });
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
const pageResult = await generateStaticPageRSC(reqPath);
|
|
191
|
+
if (
|
|
192
|
+
pageResult &&
|
|
193
|
+
pageResult.tempPath &&
|
|
194
|
+
pageResult.finalPath &&
|
|
195
|
+
existsSync(pageResult.tempPath)
|
|
196
|
+
) {
|
|
197
|
+
mkdirSync(path.dirname(pageResult.finalPath), { recursive: true });
|
|
198
|
+
renameSync(pageResult.tempPath, pageResult.finalPath);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
} catch (pageErr) {
|
|
202
|
+
const pageResult = await generateStaticPageRSC(reqPath);
|
|
203
|
+
if (
|
|
204
|
+
pageResult &&
|
|
205
|
+
pageResult.tempPath &&
|
|
206
|
+
pageResult.finalPath &&
|
|
207
|
+
existsSync(pageResult.tempPath)
|
|
208
|
+
) {
|
|
209
|
+
mkdirSync(path.dirname(pageResult.finalPath), { recursive: true });
|
|
210
|
+
renameSync(pageResult.tempPath, pageResult.finalPath);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
} catch (err) {
|
|
214
|
+
console.error(`❌ [SSG] Error pre-rendering ${reqPath}:`, err);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
clearBuildProgress();
|
|
219
|
+
console.log(
|
|
220
|
+
`✓ [SSG] Pre-rendered ${renderedCount} page(s) and ${layouts.length} layout(s) to .dinou/dist2`
|
|
221
|
+
);
|
|
20
222
|
}
|
|
21
223
|
|
|
22
224
|
module.exports = generateStatic;
|
|
@@ -18,6 +18,11 @@ function generatingISG(reqPath, isDynamicFromServer) {
|
|
|
18
18
|
path.join(dist2Folder, reqPath, "index.html"),
|
|
19
19
|
path.join(dist2Folder, reqPath, "index._old.html")
|
|
20
20
|
);
|
|
21
|
+
if (existsSync(path.join(dist2Folder, reqPath, "page.rsc")))
|
|
22
|
+
copyFileSync(
|
|
23
|
+
path.join(dist2Folder, reqPath, "page.rsc"),
|
|
24
|
+
path.join(dist2Folder, reqPath, "page._old.rsc")
|
|
25
|
+
);
|
|
21
26
|
if (existsSync(path.join(dist2Folder, reqPath, "rsc.rsc")))
|
|
22
27
|
copyFileSync(
|
|
23
28
|
path.join(dist2Folder, reqPath, "rsc.rsc"),
|
|
@@ -6,17 +6,23 @@ let read = false;
|
|
|
6
6
|
const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
7
7
|
|
|
8
8
|
function getAssetFromManifest(name) {
|
|
9
|
-
if (
|
|
9
|
+
if (typeof globalThis !== "undefined" && globalThis.__DINOU_ASSET_MANIFEST__) {
|
|
10
|
+
return "/" + (globalThis.__DINOU_ASSET_MANIFEST__[name] || name);
|
|
11
|
+
}
|
|
12
|
+
const isDev =
|
|
13
|
+
process.env.DINOU_DEV === "true" ||
|
|
14
|
+
(typeof globalThis !== "undefined" && Boolean(globalThis.__DINOU_DEV__));
|
|
15
|
+
if (process.env.NODE_ENV === "production" && !isDev && !read) {
|
|
10
16
|
const manifestPath = path.resolve(process.cwd(), ".dinou/dist3/manifest.json");
|
|
11
17
|
if (fs.existsSync(manifestPath)) {
|
|
12
18
|
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
13
19
|
read = true;
|
|
14
20
|
}
|
|
15
|
-
} else if (isWebpack && !read) {
|
|
21
|
+
} else if ((isWebpack || isDev) && !read) {
|
|
16
22
|
const manifestPath = path.resolve(process.cwd(), ".dinou/public/manifest.json");
|
|
17
23
|
if (fs.existsSync(manifestPath)) {
|
|
18
24
|
manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
|
|
19
|
-
read = true;
|
|
25
|
+
if (!isDev) read = true;
|
|
20
26
|
}
|
|
21
27
|
}
|
|
22
28
|
return "/" + (manifest[name] || name);
|