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/node/dev.js
CHANGED
|
@@ -8,6 +8,14 @@ if (!process.env.NODE_ENV) {
|
|
|
8
8
|
process.env.NODE_ENV = "development";
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
import {
|
|
12
|
+
loadEnvFiles,
|
|
13
|
+
getEsbuildPublicEnvDefines,
|
|
14
|
+
getWebpackPublicEnvDefines,
|
|
15
|
+
isWatchedDotEnvFile,
|
|
16
|
+
} from "../core/env.js";
|
|
17
|
+
loadEnvFiles(process.cwd(), { mode: "development" });
|
|
18
|
+
|
|
11
19
|
import ensureVendorMode from "../core/ensure-vendor-mode.js";
|
|
12
20
|
if (!ensureVendorMode()) {
|
|
13
21
|
await new Promise(() => {});
|
|
@@ -17,6 +25,7 @@ import http from "node:http";
|
|
|
17
25
|
import path from "node:path";
|
|
18
26
|
import fs from "node:fs";
|
|
19
27
|
import crypto from "node:crypto";
|
|
28
|
+
import chokidarModule from "#chokidar";
|
|
20
29
|
import { createRequire } from "node:module";
|
|
21
30
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
22
31
|
import { Readable } from "node:stream";
|
|
@@ -30,16 +39,51 @@ import {
|
|
|
30
39
|
printReadyBanner,
|
|
31
40
|
} from "./terminal-status.js";
|
|
32
41
|
import { resolveDevPorts } from "./port-selector.js";
|
|
33
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
getDinouConfig,
|
|
44
|
+
clearDinouConfigCache,
|
|
45
|
+
isWatchedDinouConfigOrSetupFile,
|
|
46
|
+
} from "../core/load-dinou-config.js";
|
|
34
47
|
import { resolveSetupFiles } from "../core/resolve-setup-files.js";
|
|
48
|
+
import {
|
|
49
|
+
runNodeMiddlewares,
|
|
50
|
+
applyConfigureServerPlugins,
|
|
51
|
+
} from "../core/node-middleware-runner.js";
|
|
35
52
|
import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
|
|
53
|
+
import { discoverLayoutsFromFs } from "../core/discover-layouts.js";
|
|
54
|
+
import { esbuildContextualDinouPlugin, isUnderscoreEscapedSrcPath } from "../core/resolve-contextual-dinou.js";
|
|
55
|
+
import {
|
|
56
|
+
getStaticContentType,
|
|
57
|
+
normalizePublicRequestPath,
|
|
58
|
+
parseHttpByteRange,
|
|
59
|
+
resolveConfinedStaticFile,
|
|
60
|
+
} from "../core/static-assets.js";
|
|
36
61
|
import parseExports from "../core/parse-exports.js";
|
|
37
62
|
import { useClientRegex, useServerRegex } from "../constants.js";
|
|
38
|
-
import {
|
|
63
|
+
import {
|
|
64
|
+
transformServerFunctions,
|
|
65
|
+
hasServerFunctions,
|
|
66
|
+
buildSsrServerReferenceModule,
|
|
67
|
+
generateSsrServerManifestStubs,
|
|
68
|
+
} from "../core/transform-server-functions.js";
|
|
39
69
|
import { nodeToWebRequest, sendWebResponseToNode } from "../core/http-adapter.js";
|
|
40
|
-
import { setStorageAdapter, FileSystemStorage, MemoryStorage } from "../core/storage-adapter.js";
|
|
41
|
-
import
|
|
42
|
-
|
|
70
|
+
import { setStorageAdapter, hasExplicitStorageAdapter, FileSystemStorage, MemoryStorage } from "../core/storage-adapter.js";
|
|
71
|
+
import {
|
|
72
|
+
createServerAssetPlugin,
|
|
73
|
+
getAssetExtensionsInfo,
|
|
74
|
+
} from "../core/asset-extensions.js";
|
|
75
|
+
import {
|
|
76
|
+
clearServerCssModulesCache,
|
|
77
|
+
createServerCssModulesPlugin,
|
|
78
|
+
didCssModuleExportsChange,
|
|
79
|
+
} from "../core/server-css-modules-plugin.js";
|
|
80
|
+
import { resolveStyleImportFromCode } from "../core/get-abs-path-with-ext.js";
|
|
81
|
+
import {
|
|
82
|
+
clearTsconfigAliasCache,
|
|
83
|
+
esbuildTsconfigAliasesPlugin,
|
|
84
|
+
getWatchedTsconfigFiles,
|
|
85
|
+
matchesExplicitUserAlias,
|
|
86
|
+
} from "../core/tsconfig-aliases.js";
|
|
43
87
|
import {
|
|
44
88
|
isSupportedClientModule,
|
|
45
89
|
scanProjectDependenciesForClientComponents,
|
|
@@ -47,16 +91,48 @@ import {
|
|
|
47
91
|
} from "../core/scan-dependency-components.js";
|
|
48
92
|
|
|
49
93
|
// Resolve dev HTTP and HMR ports before initiating background compilation
|
|
50
|
-
const { port: PORT, hmrPort: HMR_PORT } =
|
|
94
|
+
const { port: PORT, hmrPort: HMR_PORT } =
|
|
95
|
+
process.env.DINOU_BUILD_DEV_ONLY === "true"
|
|
96
|
+
? {
|
|
97
|
+
port: Number(process.env.PORT || 0),
|
|
98
|
+
hmrPort: Number(process.env.HMR_PORT || 0),
|
|
99
|
+
}
|
|
100
|
+
: await resolveDevPorts();
|
|
51
101
|
|
|
52
102
|
const devStartTime = Date.now();
|
|
53
103
|
const devTimings = {};
|
|
54
104
|
startSpinner("Initializing Incremental Dual-Bundle Engine (No fork)...");
|
|
55
105
|
|
|
56
106
|
const projectRoot = process.cwd();
|
|
57
|
-
const
|
|
107
|
+
const dinouRequire = createRequire(import.meta.url);
|
|
108
|
+
const projectRequire = createRequire(path.resolve(projectRoot, "package.json"));
|
|
109
|
+
const require = Object.assign(
|
|
110
|
+
(id) => {
|
|
111
|
+
try {
|
|
112
|
+
return dinouRequire(id);
|
|
113
|
+
} catch {
|
|
114
|
+
return projectRequire(id);
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
resolve(id, options) {
|
|
119
|
+
if (options) {
|
|
120
|
+
try {
|
|
121
|
+
return projectRequire.resolve(id, options);
|
|
122
|
+
} catch {
|
|
123
|
+
return dinouRequire.resolve(id, options);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
return dinouRequire.resolve(id);
|
|
128
|
+
} catch {
|
|
129
|
+
return projectRequire.resolve(id);
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
}
|
|
133
|
+
);
|
|
58
134
|
const esbuild = require("esbuild");
|
|
59
|
-
const chokidar =
|
|
135
|
+
const chokidar = chokidarModule?.default || chokidarModule;
|
|
60
136
|
|
|
61
137
|
// Protect file descriptor operations against transient EMFILE spikes on Windows
|
|
62
138
|
try {
|
|
@@ -89,6 +165,18 @@ if (typeof globalThis !== "undefined") {
|
|
|
89
165
|
const isWebpackBuild = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
90
166
|
const devDir = path.resolve(projectRoot, ".dinou/node-dev");
|
|
91
167
|
fs.mkdirSync(devDir, { recursive: true });
|
|
168
|
+
if (process.env.DINOU_STANDALONE_SERVER !== "true") {
|
|
169
|
+
for (const stale of [
|
|
170
|
+
"react-client-manifest.json",
|
|
171
|
+
"react-ssr-manifest.json",
|
|
172
|
+
"server-functions-manifest.json",
|
|
173
|
+
"manifest.json",
|
|
174
|
+
]) {
|
|
175
|
+
try {
|
|
176
|
+
fs.rmSync(path.join(devDir, stale), { force: true });
|
|
177
|
+
} catch (e) {}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
92
180
|
|
|
93
181
|
// Locate Dinou core directory
|
|
94
182
|
const dinouDir = fs.existsSync(path.resolve(projectRoot, "dinou"))
|
|
@@ -96,20 +184,47 @@ const dinouDir = fs.existsSync(path.resolve(projectRoot, "dinou"))
|
|
|
96
184
|
: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
97
185
|
const dinouDirSlash = dinouDir.replace(/\\/g, "/");
|
|
98
186
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
187
|
+
async function executeSetupFilesInDevProcess(files) {
|
|
188
|
+
if (!Array.isArray(files) || files.length === 0) return;
|
|
189
|
+
const setupOutDir = path.join(devDir, "setup-bundles");
|
|
190
|
+
fs.mkdirSync(setupOutDir, { recursive: true });
|
|
191
|
+
for (let i = 0; i < files.length; i++) {
|
|
192
|
+
const f = files[i];
|
|
105
193
|
try {
|
|
106
|
-
|
|
194
|
+
const outPath = path.join(setupOutDir, `setup-${i}.mjs`);
|
|
195
|
+
await esbuild.build({
|
|
196
|
+
entryPoints: [f],
|
|
197
|
+
outfile: outPath,
|
|
198
|
+
bundle: true,
|
|
199
|
+
format: "esm",
|
|
200
|
+
platform: "node",
|
|
201
|
+
target: "node20",
|
|
202
|
+
packages: "external",
|
|
203
|
+
jsx: "automatic",
|
|
204
|
+
plugins: [
|
|
205
|
+
esbuildTsconfigAliasesPlugin({
|
|
206
|
+
projectRoot,
|
|
207
|
+
skipAssets: false,
|
|
208
|
+
}),
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
await dynamicImportWithRetry(
|
|
212
|
+
`${pathToFileURL(outPath).href}?t=${Date.now()}-${i}`
|
|
213
|
+
);
|
|
107
214
|
} catch (e) {
|
|
108
215
|
console.error(`❌ [Dinou Dev] Error executing setupFile "${f}":`, e);
|
|
109
216
|
}
|
|
110
217
|
}
|
|
111
218
|
}
|
|
112
219
|
|
|
220
|
+
// Resolve and execute setupFiles immediately before any compilation
|
|
221
|
+
const dinouConfig = await getDinouConfig();
|
|
222
|
+
const setupFiles = resolveSetupFiles(projectRoot, dinouConfig);
|
|
223
|
+
if (setupFiles.length > 0) {
|
|
224
|
+
console.log(` 🔌 [Dinou Setup] Executing setup files (${setupFiles.length}):`, setupFiles.map((f) => path.relative(projectRoot, f)).join(", "));
|
|
225
|
+
await executeSetupFilesInDevProcess(setupFiles);
|
|
226
|
+
}
|
|
227
|
+
|
|
113
228
|
function getFallbackChunkId(absPath) {
|
|
114
229
|
const norm = absPath.replace(/\\/g, "/");
|
|
115
230
|
const name = path.basename(absPath, path.extname(absPath));
|
|
@@ -134,9 +249,13 @@ const yieldToEventLoop = () => new Promise((resolve) => setImmediate(resolve));
|
|
|
134
249
|
try {
|
|
135
250
|
const dist2Dir = path.resolve(projectRoot, ".dinou/dist2");
|
|
136
251
|
try { fs.rmSync(path.join(dist2Dir, "slots"), { recursive: true, force: true }); } catch (e) {}
|
|
137
|
-
|
|
252
|
+
if (!hasExplicitStorageAdapter()) {
|
|
253
|
+
setStorageAdapter(new FileSystemStorage(dist2Dir));
|
|
254
|
+
}
|
|
138
255
|
} catch (e) {
|
|
139
|
-
|
|
256
|
+
if (!hasExplicitStorageAdapter()) {
|
|
257
|
+
setStorageAdapter(new MemoryStorage());
|
|
258
|
+
}
|
|
140
259
|
}
|
|
141
260
|
|
|
142
261
|
// Candidate Link and Redirect paths
|
|
@@ -177,7 +296,7 @@ async function findClientComponents(parsedClientManifest = {}) {
|
|
|
177
296
|
for (const entry of entries) {
|
|
178
297
|
const full = path.join(dir, entry.name);
|
|
179
298
|
if (entry.isDirectory()) {
|
|
180
|
-
await walk(full);
|
|
299
|
+
if (!entry.name.startsWith("_")) await walk(full);
|
|
181
300
|
} else if (/\.[jt]sx?$/.test(entry.name)) {
|
|
182
301
|
try {
|
|
183
302
|
const content = fs.readFileSync(full, "utf8");
|
|
@@ -237,20 +356,9 @@ async function findClientComponents(parsedClientManifest = {}) {
|
|
|
237
356
|
}
|
|
238
357
|
|
|
239
358
|
// Manifest paths and helpers
|
|
240
|
-
function findManifest(filename,
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
path.resolve(projectRoot, ".dinou/public", filename),
|
|
244
|
-
path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
|
|
245
|
-
]
|
|
246
|
-
: [
|
|
247
|
-
path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
|
|
248
|
-
path.resolve(projectRoot, ".dinou/public", filename),
|
|
249
|
-
];
|
|
250
|
-
for (const c of candidates) {
|
|
251
|
-
if (fs.existsSync(c)) return c;
|
|
252
|
-
}
|
|
253
|
-
return null;
|
|
359
|
+
function findManifest(filename, folder) {
|
|
360
|
+
const candidate = path.resolve(projectRoot, ".dinou", folder, filename);
|
|
361
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
254
362
|
}
|
|
255
363
|
|
|
256
364
|
function readJsonSafe(filePath) {
|
|
@@ -299,11 +407,19 @@ function getCachedFileExports(filePath) {
|
|
|
299
407
|
|
|
300
408
|
async function updateManifestsState(options = {}) {
|
|
301
409
|
const forceRescan = options.forceRescan || false;
|
|
302
|
-
const cPath = findManifest("react-client-manifest.json", "
|
|
303
|
-
const sfPath = findManifest("server-functions-manifest.json", "
|
|
304
|
-
const aPath = findManifest("manifest.json", "
|
|
410
|
+
const cPath = findManifest("react-client-manifest.json", "node-dev");
|
|
411
|
+
const sfPath = findManifest("server-functions-manifest.json", "node-dev");
|
|
412
|
+
const aPath = isWebpackBuild ? findManifest("manifest.json", "node-dev") : null;
|
|
305
413
|
|
|
306
414
|
const rawClient = globalThis.__DINOU_RAW_CLIENT_MANIFEST__ || readJsonSafe(cPath);
|
|
415
|
+
const devBundleEpoch = !isWebpackBuild
|
|
416
|
+
? Number(globalThis.__DINOU_DEV_BUNDLE_EPOCH__ || 0)
|
|
417
|
+
: 0;
|
|
418
|
+
const applyDevEpoch = (chunkUrl) => {
|
|
419
|
+
if (!chunkUrl || devBundleEpoch <= 0) return chunkUrl;
|
|
420
|
+
const base = String(chunkUrl).split("?")[0];
|
|
421
|
+
return base.endsWith(".js") ? `${base}?v=${devBundleEpoch}` : chunkUrl;
|
|
422
|
+
};
|
|
307
423
|
if (rawClient) {
|
|
308
424
|
const cleanClient = {};
|
|
309
425
|
for (const [k, v] of Object.entries(rawClient)) {
|
|
@@ -319,7 +435,10 @@ async function updateManifestsState(options = {}) {
|
|
|
319
435
|
) {
|
|
320
436
|
continue;
|
|
321
437
|
}
|
|
322
|
-
cleanClient[k] =
|
|
438
|
+
cleanClient[k] =
|
|
439
|
+
devBundleEpoch > 0 && v?.id
|
|
440
|
+
? { ...v, id: applyDevEpoch(v.id) }
|
|
441
|
+
: v;
|
|
323
442
|
}
|
|
324
443
|
parsedClientManifest = cleanClient;
|
|
325
444
|
}
|
|
@@ -339,10 +458,10 @@ async function updateManifestsState(options = {}) {
|
|
|
339
458
|
globalThis.__DINOU_RAW_SERVER_FUNCTIONS_MANIFEST__ = parsedServerFunctionsManifest;
|
|
340
459
|
}
|
|
341
460
|
|
|
342
|
-
const rawAsset =
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
}
|
|
461
|
+
const rawAsset = isWebpackBuild
|
|
462
|
+
? globalThis.__DINOU_RAW_ASSET_MANIFEST__ || readJsonSafe(aPath)
|
|
463
|
+
: null;
|
|
464
|
+
parsedAssetManifest = rawAsset || {};
|
|
346
465
|
|
|
347
466
|
// Normalize client manifest
|
|
348
467
|
const normalized = { ...parsedClientManifest };
|
|
@@ -397,10 +516,10 @@ async function updateManifestsState(options = {}) {
|
|
|
397
516
|
|
|
398
517
|
if (!isWebpackBuild) {
|
|
399
518
|
if (!redirectChunkId || redirectChunkId.includes("node_modules")) {
|
|
400
|
-
redirectChunkId = "/dinouClientRedirect.js";
|
|
519
|
+
redirectChunkId = applyDevEpoch("/dinouClientRedirect.js");
|
|
401
520
|
}
|
|
402
521
|
if (!linkChunkId || linkChunkId.includes("node_modules")) {
|
|
403
|
-
linkChunkId = "/dinouLink.js";
|
|
522
|
+
linkChunkId = applyDevEpoch("/dinouLink.js");
|
|
404
523
|
}
|
|
405
524
|
}
|
|
406
525
|
|
|
@@ -439,7 +558,7 @@ async function updateManifestsState(options = {}) {
|
|
|
439
558
|
}
|
|
440
559
|
}
|
|
441
560
|
if (!isWebpackBuild && (!slotChunkId || slotChunkId.includes("node_modules"))) {
|
|
442
|
-
slotChunkId = "/dinouSlot.js";
|
|
561
|
+
slotChunkId = applyDevEpoch("/dinouSlot.js");
|
|
443
562
|
}
|
|
444
563
|
if (slotChunkId) {
|
|
445
564
|
const slotChunks = isWebpackBuild ? (slotEntry?.chunks || [slotChunkId]) : "DinouPageSlot";
|
|
@@ -491,7 +610,11 @@ async function updateManifestsState(options = {}) {
|
|
|
491
610
|
await yieldToEventLoop();
|
|
492
611
|
}
|
|
493
612
|
|
|
494
|
-
const isValidEntryId = (entry) =>
|
|
613
|
+
const isValidEntryId = (entry) =>
|
|
614
|
+
Boolean(
|
|
615
|
+
entry?.id &&
|
|
616
|
+
(isWebpackBuild || String(entry.id).split("?")[0].endsWith(".js"))
|
|
617
|
+
);
|
|
495
618
|
|
|
496
619
|
// Check if parsedClientManifest already has an entry for this component
|
|
497
620
|
let matchedEntry = null;
|
|
@@ -523,7 +646,7 @@ async function updateManifestsState(options = {}) {
|
|
|
523
646
|
|
|
524
647
|
const compId = isValidEntryId(matchedEntry)
|
|
525
648
|
? matchedEntry.id
|
|
526
|
-
: getFallbackChunkId(comp);
|
|
649
|
+
: applyDevEpoch(getFallbackChunkId(comp));
|
|
527
650
|
const compChunks = isWebpackBuild ? (matchedEntry?.chunks || []) : "default";
|
|
528
651
|
|
|
529
652
|
for (const u of urlVariants) {
|
|
@@ -550,7 +673,11 @@ async function updateManifestsState(options = {}) {
|
|
|
550
673
|
}
|
|
551
674
|
} else {
|
|
552
675
|
// Fast path: update normalized mapping for known client components without re-reading files or parsing AST
|
|
553
|
-
const isValidEntryId = (entry) =>
|
|
676
|
+
const isValidEntryId = (entry) =>
|
|
677
|
+
Boolean(
|
|
678
|
+
entry?.id &&
|
|
679
|
+
(isWebpackBuild || String(entry.id).split("?")[0].endsWith(".js"))
|
|
680
|
+
);
|
|
554
681
|
for (const comp of clientComponents) {
|
|
555
682
|
const urlVariants = generateAllUrlVariants(comp);
|
|
556
683
|
const fileExports = getCachedFileExports(comp);
|
|
@@ -587,7 +714,7 @@ async function updateManifestsState(options = {}) {
|
|
|
587
714
|
|
|
588
715
|
const compId = isValidEntryId(matchedEntry)
|
|
589
716
|
? matchedEntry.id
|
|
590
|
-
: getFallbackChunkId(comp);
|
|
717
|
+
: applyDevEpoch(getFallbackChunkId(comp));
|
|
591
718
|
const compChunks = isWebpackBuild ? (matchedEntry?.chunks || []) : "default";
|
|
592
719
|
|
|
593
720
|
for (const u of urlVariants) {
|
|
@@ -626,10 +753,20 @@ async function updateManifestsState(options = {}) {
|
|
|
626
753
|
if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
|
|
627
754
|
const imports = {};
|
|
628
755
|
const moduleBasePath = pathToFileURL(projectRoot).href + "/";
|
|
756
|
+
const moduleBasePathLower = moduleBasePath.replace(
|
|
757
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
758
|
+
(_, d) => `file:///${d.toLowerCase()}:`
|
|
759
|
+
);
|
|
760
|
+
const moduleBasePathUpper = moduleBasePath.replace(
|
|
761
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
762
|
+
(_, d) => `file:///${d.toUpperCase()}:`
|
|
763
|
+
);
|
|
629
764
|
for (const [key, val] of Object.entries(parsedClientManifest)) {
|
|
630
765
|
let specifier = key;
|
|
631
|
-
if (specifier.startsWith(
|
|
632
|
-
specifier = specifier.slice(
|
|
766
|
+
if (specifier.startsWith(moduleBasePathUpper)) {
|
|
767
|
+
specifier = specifier.slice(moduleBasePathUpper.length);
|
|
768
|
+
} else if (specifier.startsWith(moduleBasePathLower)) {
|
|
769
|
+
specifier = specifier.slice(moduleBasePathLower.length);
|
|
633
770
|
}
|
|
634
771
|
const hashIdx = specifier.indexOf("#");
|
|
635
772
|
if (hashIdx !== -1) specifier = specifier.slice(0, hashIdx);
|
|
@@ -687,9 +824,15 @@ async function updateManifestsState(options = {}) {
|
|
|
687
824
|
|
|
688
825
|
const registerModuleMapEntry = (chunkId, fileUrl, expName) => {
|
|
689
826
|
if (!chunkId || !fileUrl) return;
|
|
690
|
-
const
|
|
691
|
-
|
|
692
|
-
|
|
827
|
+
const baseChunkId = String(chunkId).split("?")[0];
|
|
828
|
+
const ids = Array.from(
|
|
829
|
+
new Set([
|
|
830
|
+
chunkId,
|
|
831
|
+
chunkId.startsWith("/") ? chunkId.slice(1) : "/" + chunkId,
|
|
832
|
+
baseChunkId,
|
|
833
|
+
baseChunkId.startsWith("/") ? baseChunkId.slice(1) : "/" + baseChunkId,
|
|
834
|
+
])
|
|
835
|
+
);
|
|
693
836
|
|
|
694
837
|
// Canonicalize fileUrl to 3 slashes (standard file URL)
|
|
695
838
|
let canonicalUrl = fileUrl;
|
|
@@ -737,7 +880,10 @@ async function updateManifestsState(options = {}) {
|
|
|
737
880
|
for (const [k, v] of Object.entries(normalized)) {
|
|
738
881
|
const fileUrl = k.split("#")[0];
|
|
739
882
|
const expName = k.includes("#") ? k.split("#")[1] : null;
|
|
740
|
-
if (
|
|
883
|
+
if (
|
|
884
|
+
v?.id &&
|
|
885
|
+
(isWebpackBuild || String(v.id).split("?")[0].endsWith(".js"))
|
|
886
|
+
) {
|
|
741
887
|
registerModuleMapEntry(v.id, fileUrl, expName);
|
|
742
888
|
}
|
|
743
889
|
}
|
|
@@ -781,24 +927,13 @@ await updateManifestsState({ forceRescan: true });
|
|
|
781
927
|
|
|
782
928
|
// Generate route modules and entry files
|
|
783
929
|
function generateEntryFiles() {
|
|
930
|
+
try {
|
|
931
|
+
generateRouteTypes(projectRoot);
|
|
932
|
+
} catch (e) {}
|
|
784
933
|
const routeModulesCode = generateRouteModulesCode(projectRoot, "../..");
|
|
785
934
|
fs.writeFileSync(path.join(devDir, "route-modules.mjs"), routeModulesCode, "utf8");
|
|
786
935
|
|
|
787
|
-
const discoveredLayouts =
|
|
788
|
-
function findLayoutRoutes(dir, rel = "") {
|
|
789
|
-
if (!fs.existsSync(dir)) return;
|
|
790
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
791
|
-
for (const entry of entries) {
|
|
792
|
-
if (entry.isDirectory()) {
|
|
793
|
-
findLayoutRoutes(path.join(dir, entry.name), rel ? `${rel}/${entry.name}` : entry.name);
|
|
794
|
-
} else if (/^layout\.[jt]sx?$/.test(entry.name)) {
|
|
795
|
-
discoveredLayouts.push(rel);
|
|
796
|
-
} else if (entry.name === "no_layout") {
|
|
797
|
-
discoveredLayouts.push("!" + rel);
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
findLayoutRoutes(srcDir);
|
|
936
|
+
const discoveredLayouts = discoverLayoutsFromFs(srcDir, fs);
|
|
802
937
|
globalThis.__DINOU_LAYOUTS__ = discoveredLayouts;
|
|
803
938
|
|
|
804
939
|
const envSetupContent = `// Auto-generated Dev Environment Setup
|
|
@@ -828,10 +963,7 @@ globalThis.__DINOU_LAYOUTS__ = ${JSON.stringify(discoveredLayouts)};
|
|
|
828
963
|
});
|
|
829
964
|
|
|
830
965
|
const serverFunctionFiles = Object.keys(parsedServerFunctionsManifest);
|
|
831
|
-
|
|
832
|
-
const absPath = path.resolve(projectRoot, relPath).replace(/\\/g, "/");
|
|
833
|
-
ssrManifestCode += `import * as sf_${index} from ${JSON.stringify(absPath)};\n`;
|
|
834
|
-
});
|
|
966
|
+
ssrManifestCode += generateSsrServerManifestStubs(parsedServerFunctionsManifest);
|
|
835
967
|
|
|
836
968
|
ssrManifestCode += `\nexport const clientModules = {\n`;
|
|
837
969
|
const emittedClientModules = new Set();
|
|
@@ -1267,8 +1399,9 @@ const serverReferencesPlugin = {
|
|
|
1267
1399
|
let transformed = transformedCode + "\n\n";
|
|
1268
1400
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
|
|
1269
1401
|
for (const name of exports) {
|
|
1270
|
-
|
|
1271
|
-
|
|
1402
|
+
const localIdent = name === "default" ? sfResult.defaultExportIdentifier : name;
|
|
1403
|
+
if (localIdent) {
|
|
1404
|
+
transformed += `registerServerReference(${localIdent}, ${JSON.stringify(relativeFileUrl)}, ${JSON.stringify(name)});\n`;
|
|
1272
1405
|
}
|
|
1273
1406
|
}
|
|
1274
1407
|
const ext = path.extname(args.path);
|
|
@@ -1289,25 +1422,13 @@ const serverReferencesPluginSsr = {
|
|
|
1289
1422
|
try { code = fs.readFileSync(args.path, "utf8"); } catch (e) { return null; }
|
|
1290
1423
|
if (!hasServerFunctions(code)) return null;
|
|
1291
1424
|
|
|
1292
|
-
const sfResult = transformServerFunctions(code, args.path);
|
|
1293
|
-
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1294
|
-
|
|
1295
|
-
const transformedCode = sfResult.code;
|
|
1296
|
-
const exports = sfResult.actions;
|
|
1297
1425
|
const absPath = path.resolve(args.path);
|
|
1298
1426
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1299
1427
|
const relativeFileUrl = "file:///" + relPath;
|
|
1428
|
+
const stubModule = buildSsrServerReferenceModule(code, args.path, relativeFileUrl);
|
|
1429
|
+
if (!stubModule) return null;
|
|
1300
1430
|
|
|
1301
|
-
|
|
1302
|
-
transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
|
|
1303
|
-
for (const name of exports) {
|
|
1304
|
-
if (name !== "default") {
|
|
1305
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(relativeFileUrl + "#" + name)});\n`;
|
|
1306
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(pathToFileURL(absPath).href + "#" + name)});\n`;
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
const ext = path.extname(args.path);
|
|
1310
|
-
return { contents: transformed, loader: ext === ".ts" ? "ts" : ext === ".tsx" ? "tsx" : ext === ".jsx" ? "jsx" : "js" };
|
|
1431
|
+
return { contents: stubModule, loader: "js" };
|
|
1311
1432
|
});
|
|
1312
1433
|
});
|
|
1313
1434
|
},
|
|
@@ -1326,8 +1447,8 @@ const nodeBuiltins = [
|
|
|
1326
1447
|
const externalList = [...nodeBuiltins, ...nodeBuiltins.map((b) => "node:" + b)];
|
|
1327
1448
|
|
|
1328
1449
|
const commonAlias = {
|
|
1329
|
-
"@": path.resolve(projectRoot, "src"),
|
|
1330
1450
|
"dinou/config": path.resolve(dinouDir, "core/config.js"),
|
|
1451
|
+
"dinou/server": path.resolve(dinouDir, "server.js"),
|
|
1331
1452
|
dinou: dinouDir,
|
|
1332
1453
|
};
|
|
1333
1454
|
const commonLoader = {
|
|
@@ -1335,56 +1456,16 @@ const commonLoader = {
|
|
|
1335
1456
|
".json": "json", ".css": "empty",
|
|
1336
1457
|
};
|
|
1337
1458
|
|
|
1338
|
-
const serverAssetPlugin = {
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
if (args.path.startsWith("@/")) {
|
|
1344
|
-
resolvedPath = path.resolve(projectRoot, "src", args.path.slice(2));
|
|
1345
|
-
} else if (path.isAbsolute(args.path)) {
|
|
1346
|
-
resolvedPath = args.path;
|
|
1347
|
-
} else {
|
|
1348
|
-
resolvedPath = path.resolve(args.resolveDir, args.path);
|
|
1349
|
-
}
|
|
1350
|
-
return { path: resolvedPath, namespace: "dinou-server-asset" };
|
|
1351
|
-
});
|
|
1352
|
-
|
|
1353
|
-
build.onLoad({ filter: /.*/, namespace: "dinou-server-asset" }, (args) => {
|
|
1354
|
-
const ext = path.extname(args.path);
|
|
1355
|
-
const base = path.basename(args.path, ext);
|
|
1356
|
-
const scoped = createScopedName(base, args.path);
|
|
1357
|
-
const assetUrl = `/assets/${scoped}${ext}`;
|
|
1358
|
-
const assetKey = `assets/${scoped}${ext}`;
|
|
1359
|
-
|
|
1360
|
-
try {
|
|
1361
|
-
const fileBuf = fs.readFileSync(args.path);
|
|
1362
|
-
if (typeof globalThis !== "undefined") {
|
|
1363
|
-
if (!globalThis.__DINOU_MEM_FILES__) {
|
|
1364
|
-
globalThis.__DINOU_MEM_FILES__ = new Map();
|
|
1365
|
-
}
|
|
1366
|
-
globalThis.__DINOU_MEM_FILES__.set(assetKey, fileBuf);
|
|
1367
|
-
globalThis.__DINOU_MEM_FILES__.set("/" + assetKey, fileBuf);
|
|
1368
|
-
globalThis.__DINOU_MEM_FILES__.set(`${scoped}${ext}`, fileBuf);
|
|
1369
|
-
}
|
|
1370
|
-
|
|
1371
|
-
if (process.env.DINOU_WRITE_TO_DISK === "true") {
|
|
1372
|
-
const outAssetDir = path.resolve(projectRoot, ".dinou/public/assets");
|
|
1373
|
-
const outAssetPath = path.join(outAssetDir, `${scoped}${ext}`);
|
|
1374
|
-
if (!fs.existsSync(outAssetPath)) {
|
|
1375
|
-
fs.mkdirSync(outAssetDir, { recursive: true });
|
|
1376
|
-
fs.writeFileSync(outAssetPath, fileBuf);
|
|
1377
|
-
}
|
|
1378
|
-
}
|
|
1379
|
-
} catch (e) {}
|
|
1459
|
+
const serverAssetPlugin = createServerAssetPlugin({
|
|
1460
|
+
projectRoot,
|
|
1461
|
+
dinouConfig,
|
|
1462
|
+
emitToDevMemory: true,
|
|
1463
|
+
});
|
|
1380
1464
|
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
});
|
|
1386
|
-
},
|
|
1387
|
-
};
|
|
1465
|
+
const serverTsconfigAliasesPlugin = esbuildTsconfigAliasesPlugin({
|
|
1466
|
+
projectRoot,
|
|
1467
|
+
getAssetRegex: () => getAssetExtensionsInfo(dinouConfig, projectRoot).regex,
|
|
1468
|
+
});
|
|
1388
1469
|
|
|
1389
1470
|
const resolvePkgCache = new Map();
|
|
1390
1471
|
|
|
@@ -1405,13 +1486,31 @@ function createDevExternalPackagesPlugin(isRsc = true) {
|
|
|
1405
1486
|
if (args.path.startsWith("\0") || args.path.startsWith("virtual:")) {
|
|
1406
1487
|
return null;
|
|
1407
1488
|
}
|
|
1408
|
-
// 4.
|
|
1409
|
-
if (args.path.startsWith("@/") || args.path === "@") {
|
|
1410
|
-
return null;
|
|
1411
|
-
}
|
|
1489
|
+
// 4. Framework & tsconfig/jsconfig path aliases
|
|
1412
1490
|
if (args.path === "dinou" || args.path.startsWith("dinou/")) {
|
|
1413
1491
|
return null;
|
|
1414
1492
|
}
|
|
1493
|
+
if (matchesExplicitUserAlias(args.path, projectRoot)) {
|
|
1494
|
+
let pkgExists = false;
|
|
1495
|
+
try {
|
|
1496
|
+
const cacheKey = `${args.path}::${args.resolveDir || projectRoot}`;
|
|
1497
|
+
let resolved = resolvePkgCache.get(cacheKey);
|
|
1498
|
+
if (resolved === undefined) {
|
|
1499
|
+
try {
|
|
1500
|
+
resolved = require.resolve(args.path, {
|
|
1501
|
+
paths: [args.resolveDir || projectRoot],
|
|
1502
|
+
});
|
|
1503
|
+
} catch (e) {
|
|
1504
|
+
resolved = null;
|
|
1505
|
+
}
|
|
1506
|
+
resolvePkgCache.set(cacheKey, resolved);
|
|
1507
|
+
}
|
|
1508
|
+
pkgExists = Boolean(resolved);
|
|
1509
|
+
} catch (e) {}
|
|
1510
|
+
if (!pkgExists) {
|
|
1511
|
+
return null;
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1415
1514
|
// 5. In RSC (ctxA), React packages must remain bundled to preserve react-server condition.
|
|
1416
1515
|
// In SSR (ctxB), React packages MUST be external so client components and the renderer share the same React singleton!
|
|
1417
1516
|
if (isRsc) {
|
|
@@ -1428,10 +1527,18 @@ function createDevExternalPackagesPlugin(isRsc = true) {
|
|
|
1428
1527
|
return null;
|
|
1429
1528
|
}
|
|
1430
1529
|
}
|
|
1431
|
-
// 6. CSS / Stylesheets (handled by esbuild empty loader)
|
|
1530
|
+
// 6. CSS / Stylesheets (handled by server CSS modules plugin / esbuild empty loader)
|
|
1432
1531
|
if (/\.(css|scss|sass|less)$/i.test(args.path)) {
|
|
1433
1532
|
return null;
|
|
1434
1533
|
}
|
|
1534
|
+
if (
|
|
1535
|
+
resolveStyleImportFromCode(
|
|
1536
|
+
args.path,
|
|
1537
|
+
args.importer || path.join(args.resolveDir || projectRoot, "__dinou_dev__.js")
|
|
1538
|
+
)
|
|
1539
|
+
) {
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1435
1542
|
// 7. Client components from node_modules:
|
|
1436
1543
|
// In RSC (ctxA), client components need to be intercepted by clientReferencesPlugin to create the proxy.
|
|
1437
1544
|
if (isRsc) {
|
|
@@ -1503,61 +1610,94 @@ updateSpinner("Initializing Incremental Dual-Bundle Engine (No fork)...");
|
|
|
1503
1610
|
const rscOutfile = path.join(devDir, "rsc-engine.mjs");
|
|
1504
1611
|
const ssrOutfile = path.join(devDir, "ssr-engine.mjs");
|
|
1505
1612
|
|
|
1506
|
-
const
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1613
|
+
const serverCssModulesPlugin = createServerCssModulesPlugin({ projectRoot });
|
|
1614
|
+
|
|
1615
|
+
async function createRscContext() {
|
|
1616
|
+
return esbuild.context({
|
|
1617
|
+
entryPoints: { "rsc-engine": path.join(devDir, "rsc-entry.mjs") },
|
|
1618
|
+
outdir: devDir,
|
|
1619
|
+
splitting: true,
|
|
1620
|
+
outExtension: { ".js": ".mjs" },
|
|
1621
|
+
chunkNames: "chunks/rsc/[name]-[hash]",
|
|
1622
|
+
bundle: true,
|
|
1623
|
+
format: "esm",
|
|
1624
|
+
target: "node20",
|
|
1625
|
+
platform: "node",
|
|
1626
|
+
mainFields: ["module", "main"],
|
|
1627
|
+
conditions: ["node", "worker", "react-server", "style"],
|
|
1628
|
+
external: externalList,
|
|
1629
|
+
banner,
|
|
1630
|
+
plugins: [
|
|
1631
|
+
esbuildContextualDinouPlugin({ projectRoot }),
|
|
1632
|
+
serverTsconfigAliasesPlugin,
|
|
1633
|
+
clientReferencesPlugin,
|
|
1634
|
+
serverReferencesPlugin,
|
|
1635
|
+
serverCssModulesPlugin,
|
|
1636
|
+
serverAssetPlugin,
|
|
1637
|
+
createDevExternalPackagesPlugin(true),
|
|
1638
|
+
],
|
|
1639
|
+
alias: commonAlias,
|
|
1640
|
+
loader: commonLoader,
|
|
1641
|
+
jsx: "automatic",
|
|
1642
|
+
define: {
|
|
1643
|
+
"process.env.NODE_ENV": '"development"',
|
|
1644
|
+
"process.env.DINOU_DEV": '"true"',
|
|
1645
|
+
"process.env.DINOU_RUNTIME": '"node-bundle"',
|
|
1646
|
+
"process.env.DINOU_BUILD_TOOL": JSON.stringify(
|
|
1647
|
+
isWebpackBuild ? "webpack" : process.env.DINOU_BUILD_TOOL || "esbuild"
|
|
1648
|
+
),
|
|
1649
|
+
},
|
|
1650
|
+
logLevel: "warning",
|
|
1651
|
+
});
|
|
1652
|
+
}
|
|
1533
1653
|
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1654
|
+
let ctxA = await createRscContext();
|
|
1655
|
+
|
|
1656
|
+
async function createSsrContext() {
|
|
1657
|
+
return esbuild.context({
|
|
1658
|
+
entryPoints: { "ssr-engine": path.join(devDir, "ssr-entry.mjs") },
|
|
1659
|
+
outdir: devDir,
|
|
1660
|
+
splitting: true,
|
|
1661
|
+
outExtension: { ".js": ".mjs" },
|
|
1662
|
+
chunkNames: "chunks/ssr/[name]-[hash]",
|
|
1663
|
+
bundle: true,
|
|
1664
|
+
format: "esm",
|
|
1665
|
+
target: "node20",
|
|
1666
|
+
platform: "node",
|
|
1667
|
+
mainFields: ["module", "main"],
|
|
1668
|
+
conditions: ["node", "worker", "browser", "style"],
|
|
1669
|
+
external: externalList,
|
|
1670
|
+
banner,
|
|
1671
|
+
plugins: [
|
|
1672
|
+
esbuildContextualDinouPlugin({ projectRoot }),
|
|
1673
|
+
serverTsconfigAliasesPlugin,
|
|
1674
|
+
serverReferencesPluginSsr,
|
|
1675
|
+
serverCssModulesPlugin,
|
|
1676
|
+
serverAssetPlugin,
|
|
1677
|
+
createDevExternalPackagesPlugin(false),
|
|
1678
|
+
],
|
|
1679
|
+
alias: commonAlias,
|
|
1680
|
+
loader: commonLoader,
|
|
1681
|
+
jsx: "automatic",
|
|
1682
|
+
define: getEsbuildPublicEnvDefines({
|
|
1683
|
+
mode: "development",
|
|
1684
|
+
defineProcessEnvObject: true,
|
|
1685
|
+
extra: {
|
|
1686
|
+
DINOU_DEV: "true",
|
|
1687
|
+
DINOU_RUNTIME: "node-bundle",
|
|
1688
|
+
DINOU_BUILD_TOOL: isWebpackBuild
|
|
1689
|
+
? "webpack"
|
|
1690
|
+
: process.env.DINOU_BUILD_TOOL || "esbuild",
|
|
1691
|
+
...(process.env.DINOU_DEBUG
|
|
1692
|
+
? { DINOU_DEBUG: process.env.DINOU_DEBUG }
|
|
1693
|
+
: {}),
|
|
1694
|
+
},
|
|
1695
|
+
}),
|
|
1696
|
+
logLevel: "warning",
|
|
1697
|
+
});
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
let ctxB = await createSsrContext();
|
|
1561
1701
|
|
|
1562
1702
|
let rscModule = null;
|
|
1563
1703
|
let ssrModule = null;
|
|
@@ -1761,6 +1901,32 @@ async function broadcastToClients(msg) {
|
|
|
1761
1901
|
// Trigger an incremental rebuild with batching and queueing
|
|
1762
1902
|
let isRebuilding = false;
|
|
1763
1903
|
const queuedChanges = new Map();
|
|
1904
|
+
let pendingBroadcastReload = false;
|
|
1905
|
+
let pendingBroadcastStyleUpdate = false;
|
|
1906
|
+
const pendingBroadcastRscPaths = new Set();
|
|
1907
|
+
|
|
1908
|
+
async function flushPendingBroadcasts() {
|
|
1909
|
+
if (queuedChanges.size > 0 || pendingSrcChanges.size > 0) {
|
|
1910
|
+
return;
|
|
1911
|
+
}
|
|
1912
|
+
const shouldReload = pendingBroadcastReload;
|
|
1913
|
+
const shouldStyleUpdate = pendingBroadcastStyleUpdate;
|
|
1914
|
+
const rscPaths = Array.from(pendingBroadcastRscPaths);
|
|
1915
|
+
pendingBroadcastReload = false;
|
|
1916
|
+
pendingBroadcastStyleUpdate = false;
|
|
1917
|
+
pendingBroadcastRscPaths.clear();
|
|
1918
|
+
|
|
1919
|
+
if (shouldReload) {
|
|
1920
|
+
await broadcastToClients({ type: "reload" });
|
|
1921
|
+
return;
|
|
1922
|
+
}
|
|
1923
|
+
if (shouldStyleUpdate) {
|
|
1924
|
+
await broadcastToClients({ type: "style-update", url: "/styles.css" });
|
|
1925
|
+
}
|
|
1926
|
+
for (const absFilePath of rscPaths) {
|
|
1927
|
+
await broadcastToClients({ type: "rsc-update", path: absFilePath });
|
|
1928
|
+
}
|
|
1929
|
+
}
|
|
1764
1930
|
|
|
1765
1931
|
async function doRebuildBatch(changesMap) {
|
|
1766
1932
|
const t0 = Date.now();
|
|
@@ -1776,25 +1942,61 @@ async function doRebuildBatch(changesMap) {
|
|
|
1776
1942
|
let hasClientChanges = false;
|
|
1777
1943
|
let hasServerChanges = false;
|
|
1778
1944
|
let hasCssChanges = false;
|
|
1945
|
+
let hasNonCssChanges = false;
|
|
1779
1946
|
const clientRebuildPromises = [];
|
|
1780
1947
|
|
|
1781
1948
|
for (const [absFilePath, eventType] of changesMap) {
|
|
1949
|
+
if (eventType === "addDir") {
|
|
1950
|
+
continue;
|
|
1951
|
+
}
|
|
1952
|
+
if (eventType === "unlinkDir") {
|
|
1953
|
+
needsStructureRebuild = true;
|
|
1954
|
+
hasNonCssChanges = true;
|
|
1955
|
+
const dirPrefix = (absFilePath.endsWith(path.sep) ? absFilePath : absFilePath + path.sep).toLowerCase();
|
|
1956
|
+
for (const cf of Array.from(knownClientFiles)) {
|
|
1957
|
+
if (cf.toLowerCase().startsWith(dirPrefix)) {
|
|
1958
|
+
knownClientFiles.delete(cf);
|
|
1959
|
+
needsClientBundlerRestart = true;
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
for (const sf of Array.from(knownServerFiles)) {
|
|
1963
|
+
if (sf.toLowerCase().startsWith(dirPrefix)) {
|
|
1964
|
+
knownServerFiles.delete(sf);
|
|
1965
|
+
needsClientBundlerRestart = true;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
continue;
|
|
1969
|
+
}
|
|
1782
1970
|
const isStructureChange = eventType === "add" || eventType === "unlink";
|
|
1783
1971
|
if (isStructureChange) {
|
|
1784
1972
|
needsStructureRebuild = true;
|
|
1785
1973
|
}
|
|
1786
1974
|
|
|
1787
1975
|
const normLower = absFilePath.toLowerCase();
|
|
1976
|
+
const activeAssetRegex = getAssetExtensionsInfo(dinouConfig, projectRoot).regex;
|
|
1977
|
+
const isAssetFile = activeAssetRegex.test(absFilePath);
|
|
1788
1978
|
const isCssFile = normLower.endsWith(".css") || normLower.endsWith(".scss") || normLower.endsWith(".less");
|
|
1979
|
+
const isCssModuleFile = normLower.endsWith(".module.css");
|
|
1980
|
+
let cssModuleClassesChanged = false;
|
|
1789
1981
|
if (isCssFile) {
|
|
1790
1982
|
hasCssChanges = true;
|
|
1983
|
+
if (isCssModuleFile) {
|
|
1984
|
+
try {
|
|
1985
|
+
cssModuleClassesChanged = await didCssModuleExportsChange(absFilePath);
|
|
1986
|
+
} catch (e) {
|
|
1987
|
+
cssModuleClassesChanged = true;
|
|
1988
|
+
}
|
|
1989
|
+
}
|
|
1990
|
+
}
|
|
1991
|
+
if (!isCssFile || cssModuleClassesChanged) {
|
|
1992
|
+
hasNonCssChanges = true;
|
|
1791
1993
|
}
|
|
1792
1994
|
|
|
1793
1995
|
let isClientFile = false;
|
|
1794
1996
|
let isServerFile = false;
|
|
1795
1997
|
let currentServerActions = [];
|
|
1796
1998
|
|
|
1797
|
-
if (fs.existsSync(absFilePath)) {
|
|
1999
|
+
if (!isAssetFile && !isCssFile && fs.existsSync(absFilePath)) {
|
|
1798
2000
|
try {
|
|
1799
2001
|
const content = fs.readFileSync(absFilePath, "utf8");
|
|
1800
2002
|
const trimmed = content.trim();
|
|
@@ -1880,6 +2082,7 @@ async function doRebuildBatch(changesMap) {
|
|
|
1880
2082
|
wasClientFile ||
|
|
1881
2083
|
clientDirectiveChanged ||
|
|
1882
2084
|
isCssFile ||
|
|
2085
|
+
isAssetFile ||
|
|
1883
2086
|
(isJsTsSource && !isPageRoute);
|
|
1884
2087
|
|
|
1885
2088
|
if (isClientFile) {
|
|
@@ -1904,12 +2107,21 @@ async function doRebuildBatch(changesMap) {
|
|
|
1904
2107
|
|
|
1905
2108
|
if (clientBundlerHandle?.notifyFileChanged && isClientRelevant) {
|
|
1906
2109
|
clientRebuildPromises.push(clientBundlerHandle.notifyFileChanged(absFilePath));
|
|
2110
|
+
} else if (isJsTsSource && isPageRoute) {
|
|
2111
|
+
if (clientBundlerHandle?.refreshStyles) {
|
|
2112
|
+
clientRebuildPromises.push(clientBundlerHandle.refreshStyles());
|
|
2113
|
+
} else if (clientBundlerHandle?.notifyFileChanged) {
|
|
2114
|
+
clientRebuildPromises.push(clientBundlerHandle.notifyFileChanged(absFilePath));
|
|
2115
|
+
}
|
|
2116
|
+
}
|
|
2117
|
+
if (isAssetFile && clientBundlerHandle?.refreshStyles) {
|
|
2118
|
+
clientRebuildPromises.push(clientBundlerHandle.refreshStyles());
|
|
1907
2119
|
}
|
|
1908
2120
|
|
|
1909
|
-
if (isClientFile) {
|
|
2121
|
+
if (isClientFile || cssModuleClassesChanged || isAssetFile) {
|
|
1910
2122
|
hasClientChanges = true;
|
|
1911
2123
|
}
|
|
1912
|
-
if (isServerFile || (!isClientFile && !isCssFile)) {
|
|
2124
|
+
if (isServerFile || cssModuleClassesChanged || isAssetFile || (!isClientFile && !isCssFile)) {
|
|
1913
2125
|
hasServerChanges = true;
|
|
1914
2126
|
}
|
|
1915
2127
|
}
|
|
@@ -1917,8 +2129,9 @@ async function doRebuildBatch(changesMap) {
|
|
|
1917
2129
|
if (needsClientBundlerRestart && clientBundlerHandle?.restart) {
|
|
1918
2130
|
updateSpinner(`Directive or structure change detected. Recreating client bundle...`);
|
|
1919
2131
|
await clientBundlerHandle.restart();
|
|
1920
|
-
|
|
1921
|
-
|
|
2132
|
+
pendingBroadcastReload = true;
|
|
2133
|
+
if (!needsStructureRebuild) {
|
|
2134
|
+
await flushPendingBroadcasts();
|
|
1922
2135
|
logSuccess(`Recreated bundle for ${baseName} in ${Date.now() - t0}ms`);
|
|
1923
2136
|
return;
|
|
1924
2137
|
}
|
|
@@ -1946,9 +2159,10 @@ async function doRebuildBatch(changesMap) {
|
|
|
1946
2159
|
if (activeClientBuildPromise) {
|
|
1947
2160
|
await activeClientBuildPromise;
|
|
1948
2161
|
}
|
|
1949
|
-
if (
|
|
1950
|
-
|
|
2162
|
+
if (hasNonCssChanges || !hasCssChanges || isWebpackBuild) {
|
|
2163
|
+
pendingBroadcastReload = true;
|
|
1951
2164
|
}
|
|
2165
|
+
await flushPendingBroadcasts();
|
|
1952
2166
|
} else {
|
|
1953
2167
|
if (clientRebuildPromises.length > 0) {
|
|
1954
2168
|
await Promise.all(clientRebuildPromises);
|
|
@@ -1977,17 +2191,33 @@ async function doRebuildBatch(changesMap) {
|
|
|
1977
2191
|
lastClientBuildDetails = "";
|
|
1978
2192
|
logSuccess(`Rebuilt in ${Date.now() - t0}ms (${baseName})${buildDetails}`);
|
|
1979
2193
|
|
|
1980
|
-
if (
|
|
1981
|
-
if (
|
|
1982
|
-
|
|
1983
|
-
|
|
2194
|
+
if (isWebpackBuild) {
|
|
2195
|
+
if (hasClientChanges) {
|
|
2196
|
+
pendingBroadcastReload = true;
|
|
2197
|
+
} else {
|
|
2198
|
+
if (hasCssChanges) {
|
|
2199
|
+
pendingBroadcastStyleUpdate = true;
|
|
2200
|
+
}
|
|
2201
|
+
if (hasServerChanges) {
|
|
2202
|
+
for (const [absFilePath] of changesMap) {
|
|
2203
|
+
pendingBroadcastRscPaths.add(absFilePath);
|
|
2204
|
+
}
|
|
1984
2205
|
}
|
|
1985
|
-
}
|
|
1986
|
-
|
|
1987
|
-
|
|
2206
|
+
}
|
|
2207
|
+
} else if (hasServerChanges) {
|
|
2208
|
+
for (const [absFilePath] of changesMap) {
|
|
2209
|
+
const lowerPath = absFilePath.toLowerCase();
|
|
2210
|
+
const isPureNonModuleCss =
|
|
2211
|
+
(lowerPath.endsWith(".css") ||
|
|
2212
|
+
lowerPath.endsWith(".scss") ||
|
|
2213
|
+
lowerPath.endsWith(".less")) &&
|
|
2214
|
+
!lowerPath.endsWith(".module.css");
|
|
2215
|
+
if (!isPureNonModuleCss) {
|
|
2216
|
+
pendingBroadcastRscPaths.add(absFilePath);
|
|
1988
2217
|
}
|
|
1989
2218
|
}
|
|
1990
2219
|
}
|
|
2220
|
+
await flushPendingBroadcasts();
|
|
1991
2221
|
}
|
|
1992
2222
|
} catch (err) {
|
|
1993
2223
|
stopSpinner();
|
|
@@ -2023,6 +2253,7 @@ async function triggerRebuildBatch(changesMap) {
|
|
|
2023
2253
|
queuedChanges.clear();
|
|
2024
2254
|
await doRebuildBatch(currentBatch);
|
|
2025
2255
|
}
|
|
2256
|
+
await flushPendingBroadcasts();
|
|
2026
2257
|
} finally {
|
|
2027
2258
|
isRebuilding = false;
|
|
2028
2259
|
activeRebuildPromise = null;
|
|
@@ -2059,12 +2290,21 @@ const srcWatcher = chokidar.watch(watchTargets, {
|
|
|
2059
2290
|
srcWatcher.on("all", (event, fullPath) => {
|
|
2060
2291
|
globalThis.__TIMELINE_T0__ = Date.now();
|
|
2061
2292
|
logTimeline(`File change detected: ${event} ${path.basename(fullPath)}`);
|
|
2062
|
-
|
|
2063
|
-
|
|
2293
|
+
const isDirEvt = event === "addDir" || event === "unlinkDir";
|
|
2294
|
+
const isEscapedPath = isUnderscoreEscapedSrcPath(fullPath, projectRoot, { isDirectory: isDirEvt });
|
|
2295
|
+
if (!isEscapedPath && event !== "addDir") {
|
|
2296
|
+
pendingSrcChanges.set(path.resolve(fullPath), event);
|
|
2297
|
+
}
|
|
2298
|
+
if (
|
|
2299
|
+
isDirEvt ||
|
|
2300
|
+
((event === "add" || event === "unlink") &&
|
|
2301
|
+
/(?:^|[\\/])(?:page|page_functions|layout|layout_functions|layout\.functions|error|not_found|dinou)\.(?:[jt]sx?|mjs)$/i.test(fullPath))
|
|
2302
|
+
) {
|
|
2064
2303
|
try {
|
|
2065
2304
|
generateRouteTypes(projectRoot);
|
|
2066
2305
|
} catch (e) {}
|
|
2067
2306
|
}
|
|
2307
|
+
if (pendingSrcChanges.size === 0) return;
|
|
2068
2308
|
if (srcDebounce) clearTimeout(srcDebounce);
|
|
2069
2309
|
srcDebounce = setTimeout(() => {
|
|
2070
2310
|
srcDebounce = null;
|
|
@@ -2075,10 +2315,335 @@ srcWatcher.on("all", (event, fullPath) => {
|
|
|
2075
2315
|
}, 50);
|
|
2076
2316
|
});
|
|
2077
2317
|
|
|
2078
|
-
// Watch
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2318
|
+
// Watch root .env* files for live environment hot-reloading in dev
|
|
2319
|
+
let envDebounce = null;
|
|
2320
|
+
let pendingEnvChangedPath = null;
|
|
2321
|
+
let activeEnvReloadPromise = null;
|
|
2322
|
+
|
|
2323
|
+
async function triggerEnvReload(fullPath) {
|
|
2324
|
+
const prev = activeEnvReloadPromise;
|
|
2325
|
+
const runPromise = (async () => {
|
|
2326
|
+
if (prev) {
|
|
2327
|
+
try {
|
|
2328
|
+
await prev;
|
|
2329
|
+
} catch (e) {}
|
|
2330
|
+
}
|
|
2331
|
+
try {
|
|
2332
|
+
const envName = fullPath ? path.basename(fullPath) : ".env";
|
|
2333
|
+
const reloadRes = loadEnvFiles(projectRoot, {
|
|
2334
|
+
mode: "development",
|
|
2335
|
+
reload: true,
|
|
2336
|
+
});
|
|
2337
|
+
try {
|
|
2338
|
+
generateRouteTypes(projectRoot);
|
|
2339
|
+
} catch (e) {}
|
|
2340
|
+
|
|
2341
|
+
if (!reloadRes.changed && !reloadRes.publicEnvChanged) {
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
try {
|
|
2346
|
+
const dist2Dir = path.resolve(projectRoot, ".dinou/dist2");
|
|
2347
|
+
if (fs.existsSync(dist2Dir)) {
|
|
2348
|
+
fs.rmSync(dist2Dir, { recursive: true, force: true });
|
|
2349
|
+
}
|
|
2350
|
+
} catch (e) {}
|
|
2351
|
+
|
|
2352
|
+
if (reloadRes.publicEnvChanged) {
|
|
2353
|
+
logInfo(`Reloaded ${envName} (DINOU_PUBLIC_* updated). Rebuilding client & SSR...`);
|
|
2354
|
+
globalThis.__DINOU_DEV_BUNDLE_EPOCH__ =
|
|
2355
|
+
Number(globalThis.__DINOU_DEV_BUNDLE_EPOCH__ || 0) + 1;
|
|
2356
|
+
fileTransformCache.clear();
|
|
2357
|
+
if (clientBundlerHandle?.refreshPublicEnv) {
|
|
2358
|
+
await clientBundlerHandle.refreshPublicEnv();
|
|
2359
|
+
} else if (clientBundlerHandle?.restart) {
|
|
2360
|
+
await clientBundlerHandle.restart();
|
|
2361
|
+
}
|
|
2362
|
+
await updateManifestsState({ forceRescan: false });
|
|
2363
|
+
await ctxB.dispose();
|
|
2364
|
+
ctxB = await createSsrContext();
|
|
2365
|
+
await syncSsrEngine();
|
|
2366
|
+
} else {
|
|
2367
|
+
logSuccess(`Reloaded server environment from ${envName}`);
|
|
2368
|
+
}
|
|
2369
|
+
|
|
2370
|
+
clientBundlerHandle?.broadcast?.({ type: "reload" });
|
|
2371
|
+
} catch (err) {
|
|
2372
|
+
console.error("❌ [Dinou Dev] Failed to hot-reload .env file:", err);
|
|
2373
|
+
} finally {
|
|
2374
|
+
if (activeEnvReloadPromise === runPromise) {
|
|
2375
|
+
activeEnvReloadPromise = null;
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
})();
|
|
2379
|
+
activeEnvReloadPromise = runPromise;
|
|
2380
|
+
return runPromise;
|
|
2381
|
+
}
|
|
2382
|
+
|
|
2383
|
+
let tsconfigDebounce = null;
|
|
2384
|
+
let pendingTsconfigChangedPath = null;
|
|
2385
|
+
let activeTsconfigReloadPromise = null;
|
|
2386
|
+
const watchedExternalTsconfigs = new Set();
|
|
2387
|
+
|
|
2388
|
+
function isRootTsconfigOrJsconfig(filePath) {
|
|
2389
|
+
if (!filePath) return false;
|
|
2390
|
+
const resolved = path.resolve(filePath);
|
|
2391
|
+
if (path.dirname(resolved).toLowerCase() !== path.resolve(projectRoot).toLowerCase()) {
|
|
2392
|
+
return false;
|
|
2393
|
+
}
|
|
2394
|
+
const base = path.basename(resolved).toLowerCase();
|
|
2395
|
+
return base === "tsconfig.json" || base === "jsconfig.json";
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
const tsconfigExtendsWatcher = chokidar.watch([], {
|
|
2399
|
+
ignoreInitial: true,
|
|
2400
|
+
awaitWriteFinish: {
|
|
2401
|
+
stabilityThreshold: 20,
|
|
2402
|
+
pollInterval: 10,
|
|
2403
|
+
},
|
|
2404
|
+
});
|
|
2405
|
+
|
|
2406
|
+
function syncWatchedExternalTsconfigs() {
|
|
2407
|
+
try {
|
|
2408
|
+
const nextExternal = new Set();
|
|
2409
|
+
for (const cfgPath of getWatchedTsconfigFiles(projectRoot)) {
|
|
2410
|
+
const absCfg = path.resolve(cfgPath);
|
|
2411
|
+
if (absCfg.includes("node_modules")) continue;
|
|
2412
|
+
if (isRootTsconfigOrJsconfig(absCfg)) continue;
|
|
2413
|
+
nextExternal.add(absCfg);
|
|
2414
|
+
}
|
|
2415
|
+
for (const oldPath of Array.from(watchedExternalTsconfigs)) {
|
|
2416
|
+
if (!nextExternal.has(oldPath)) {
|
|
2417
|
+
watchedExternalTsconfigs.delete(oldPath);
|
|
2418
|
+
try {
|
|
2419
|
+
tsconfigExtendsWatcher.unwatch(oldPath);
|
|
2420
|
+
} catch (e) {}
|
|
2421
|
+
}
|
|
2422
|
+
}
|
|
2423
|
+
for (const newPath of nextExternal) {
|
|
2424
|
+
if (!watchedExternalTsconfigs.has(newPath)) {
|
|
2425
|
+
watchedExternalTsconfigs.add(newPath);
|
|
2426
|
+
try {
|
|
2427
|
+
tsconfigExtendsWatcher.add(newPath);
|
|
2428
|
+
} catch (e) {}
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
} catch (e) {}
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
syncWatchedExternalTsconfigs();
|
|
2435
|
+
|
|
2436
|
+
async function triggerTsconfigReload(fullPath) {
|
|
2437
|
+
const prev = activeTsconfigReloadPromise;
|
|
2438
|
+
const runPromise = (async () => {
|
|
2439
|
+
if (prev) {
|
|
2440
|
+
try {
|
|
2441
|
+
await prev;
|
|
2442
|
+
} catch (e) {}
|
|
2443
|
+
}
|
|
2444
|
+
try {
|
|
2445
|
+
const cfgName = fullPath ? path.basename(fullPath) : "tsconfig.json";
|
|
2446
|
+
clearTsconfigAliasCache(projectRoot);
|
|
2447
|
+
clearServerCssModulesCache();
|
|
2448
|
+
resolvePkgCache.clear();
|
|
2449
|
+
fileTransformCache.clear();
|
|
2450
|
+
syncWatchedExternalTsconfigs();
|
|
2451
|
+
|
|
2452
|
+
try {
|
|
2453
|
+
generateRouteTypes(projectRoot);
|
|
2454
|
+
} catch (e) {}
|
|
2455
|
+
|
|
2456
|
+
try {
|
|
2457
|
+
const dist2Dir = path.resolve(projectRoot, ".dinou/dist2");
|
|
2458
|
+
if (fs.existsSync(dist2Dir)) {
|
|
2459
|
+
fs.rmSync(dist2Dir, { recursive: true, force: true });
|
|
2460
|
+
}
|
|
2461
|
+
} catch (e) {}
|
|
2462
|
+
|
|
2463
|
+
logInfo(`Reloading path aliases from ${cfgName}...`);
|
|
2464
|
+
globalThis.__DINOU_DEV_BUNDLE_EPOCH__ =
|
|
2465
|
+
Number(globalThis.__DINOU_DEV_BUNDLE_EPOCH__ || 0) + 1;
|
|
2466
|
+
|
|
2467
|
+
if (clientBundlerHandle?.refreshAliases) {
|
|
2468
|
+
await clientBundlerHandle.refreshAliases();
|
|
2469
|
+
} else if (clientBundlerHandle?.restart) {
|
|
2470
|
+
await clientBundlerHandle.restart();
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
await updateManifestsState({ forceRescan: true });
|
|
2474
|
+
generateEntryFiles();
|
|
2475
|
+
|
|
2476
|
+
await ctxA.dispose();
|
|
2477
|
+
ctxA = await createRscContext();
|
|
2478
|
+
await ctxA.rebuild();
|
|
2479
|
+
engineVersion++;
|
|
2480
|
+
rscModule = await dynamicImportWithRetry(
|
|
2481
|
+
pathToFileURL(rscOutfile).href + "?v=" + engineVersion
|
|
2482
|
+
);
|
|
2483
|
+
|
|
2484
|
+
await ctxB.dispose();
|
|
2485
|
+
ctxB = await createSsrContext();
|
|
2486
|
+
await syncSsrEngine();
|
|
2487
|
+
|
|
2488
|
+
logSuccess(`Reloaded path aliases from ${cfgName}`);
|
|
2489
|
+
clientBundlerHandle?.broadcast?.({ type: "reload" });
|
|
2490
|
+
} catch (err) {
|
|
2491
|
+
console.error("❌ [Dinou Dev] Failed to hot-reload path aliases:", err);
|
|
2492
|
+
} finally {
|
|
2493
|
+
if (activeTsconfigReloadPromise === runPromise) {
|
|
2494
|
+
activeTsconfigReloadPromise = null;
|
|
2495
|
+
}
|
|
2496
|
+
}
|
|
2497
|
+
})();
|
|
2498
|
+
activeTsconfigReloadPromise = runPromise;
|
|
2499
|
+
return runPromise;
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
function scheduleTsconfigReload(fullPath) {
|
|
2503
|
+
pendingTsconfigChangedPath = fullPath;
|
|
2504
|
+
if (tsconfigDebounce) clearTimeout(tsconfigDebounce);
|
|
2505
|
+
tsconfigDebounce = setTimeout(() => {
|
|
2506
|
+
tsconfigDebounce = null;
|
|
2507
|
+
const changedPath = pendingTsconfigChangedPath;
|
|
2508
|
+
pendingTsconfigChangedPath = null;
|
|
2509
|
+
triggerTsconfigReload(changedPath);
|
|
2510
|
+
}, 50);
|
|
2511
|
+
}
|
|
2512
|
+
|
|
2513
|
+
tsconfigExtendsWatcher.on("all", (event, fullPath) => {
|
|
2514
|
+
if (event === "addDir" || event === "unlinkDir") return;
|
|
2515
|
+
scheduleTsconfigReload(fullPath);
|
|
2516
|
+
});
|
|
2517
|
+
|
|
2518
|
+
const envWatcher = chokidar.watch(projectRoot, {
|
|
2519
|
+
ignoreInitial: true,
|
|
2520
|
+
depth: 0,
|
|
2521
|
+
awaitWriteFinish: {
|
|
2522
|
+
stabilityThreshold: 20,
|
|
2523
|
+
pollInterval: 10,
|
|
2524
|
+
},
|
|
2525
|
+
});
|
|
2526
|
+
|
|
2527
|
+
let configDebounce = null;
|
|
2528
|
+
let pendingConfigChangedPath = null;
|
|
2529
|
+
let activeConfigReloadPromise = null;
|
|
2530
|
+
|
|
2531
|
+
async function triggerDinouConfigReload(fullPath) {
|
|
2532
|
+
const prev = activeConfigReloadPromise;
|
|
2533
|
+
const runPromise = (async () => {
|
|
2534
|
+
if (prev) {
|
|
2535
|
+
try {
|
|
2536
|
+
await prev;
|
|
2537
|
+
} catch (e) {}
|
|
2538
|
+
}
|
|
2539
|
+
try {
|
|
2540
|
+
const cfgName = fullPath ? path.basename(fullPath) : "dinou.config";
|
|
2541
|
+
clearDinouConfigCache(projectRoot);
|
|
2542
|
+
const nextConfig = await getDinouConfig(projectRoot);
|
|
2543
|
+
for (const k of Object.keys(dinouConfig)) {
|
|
2544
|
+
delete dinouConfig[k];
|
|
2545
|
+
}
|
|
2546
|
+
if (nextConfig && typeof nextConfig === "object") {
|
|
2547
|
+
Object.assign(dinouConfig, nextConfig);
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
const nextSetupFiles = resolveSetupFiles(projectRoot, dinouConfig);
|
|
2551
|
+
setupFiles.length = 0;
|
|
2552
|
+
setupFiles.push(...nextSetupFiles);
|
|
2553
|
+
globalThis.__DINOU_CONFIG_RELOAD_SEQ__ =
|
|
2554
|
+
Number(globalThis.__DINOU_CONFIG_RELOAD_SEQ__ || 0) + 1;
|
|
2555
|
+
if (setupFiles.length > 0) {
|
|
2556
|
+
await executeSetupFilesInDevProcess(setupFiles);
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
if (dinouConfig.storage) {
|
|
2560
|
+
setStorageAdapter(dinouConfig.storage);
|
|
2561
|
+
}
|
|
2562
|
+
|
|
2563
|
+
await applyServerPlugins(server);
|
|
2564
|
+
|
|
2565
|
+
try {
|
|
2566
|
+
generateRouteTypes(projectRoot);
|
|
2567
|
+
} catch (e) {}
|
|
2568
|
+
|
|
2569
|
+
try {
|
|
2570
|
+
const dist2Dir = path.resolve(projectRoot, ".dinou/dist2");
|
|
2571
|
+
if (fs.existsSync(dist2Dir)) {
|
|
2572
|
+
fs.rmSync(dist2Dir, { recursive: true, force: true });
|
|
2573
|
+
}
|
|
2574
|
+
} catch (e) {}
|
|
2575
|
+
|
|
2576
|
+
logInfo(`Reloading configuration from ${cfgName}...`);
|
|
2577
|
+
globalThis.__DINOU_DEV_BUNDLE_EPOCH__ =
|
|
2578
|
+
Number(globalThis.__DINOU_DEV_BUNDLE_EPOCH__ || 0) + 1;
|
|
2579
|
+
fileTransformCache.clear();
|
|
2580
|
+
|
|
2581
|
+
if (clientBundlerHandle?.refreshAliases) {
|
|
2582
|
+
await clientBundlerHandle.refreshAliases();
|
|
2583
|
+
} else if (clientBundlerHandle?.restart) {
|
|
2584
|
+
await clientBundlerHandle.restart();
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
await updateManifestsState({ forceRescan: true });
|
|
2588
|
+
generateEntryFiles();
|
|
2589
|
+
|
|
2590
|
+
await ctxA.dispose();
|
|
2591
|
+
ctxA = await createRscContext();
|
|
2592
|
+
await ctxA.rebuild();
|
|
2593
|
+
engineVersion++;
|
|
2594
|
+
rscModule = await dynamicImportWithRetry(
|
|
2595
|
+
pathToFileURL(rscOutfile).href + "?v=" + engineVersion
|
|
2596
|
+
);
|
|
2597
|
+
|
|
2598
|
+
await ctxB.dispose();
|
|
2599
|
+
ctxB = await createSsrContext();
|
|
2600
|
+
await syncSsrEngine();
|
|
2601
|
+
|
|
2602
|
+
logSuccess(`Reloaded configuration from ${cfgName}`);
|
|
2603
|
+
clientBundlerHandle?.broadcast?.({ type: "reload" });
|
|
2604
|
+
} catch (err) {
|
|
2605
|
+
console.error("❌ [Dinou Dev] Failed to hot-reload dinou.config:", err);
|
|
2606
|
+
} finally {
|
|
2607
|
+
if (activeConfigReloadPromise === runPromise) {
|
|
2608
|
+
activeConfigReloadPromise = null;
|
|
2609
|
+
}
|
|
2610
|
+
}
|
|
2611
|
+
})();
|
|
2612
|
+
activeConfigReloadPromise = runPromise;
|
|
2613
|
+
return runPromise;
|
|
2614
|
+
}
|
|
2615
|
+
|
|
2616
|
+
function scheduleDinouConfigReload(fullPath) {
|
|
2617
|
+
pendingConfigChangedPath = fullPath;
|
|
2618
|
+
if (configDebounce) clearTimeout(configDebounce);
|
|
2619
|
+
configDebounce = setTimeout(() => {
|
|
2620
|
+
configDebounce = null;
|
|
2621
|
+
const changedPath = pendingConfigChangedPath;
|
|
2622
|
+
pendingConfigChangedPath = null;
|
|
2623
|
+
triggerDinouConfigReload(changedPath);
|
|
2624
|
+
}, 50);
|
|
2625
|
+
}
|
|
2626
|
+
|
|
2627
|
+
envWatcher.on("all", (event, fullPath) => {
|
|
2628
|
+
if (event === "addDir" || event === "unlinkDir") return;
|
|
2629
|
+
if (isRootTsconfigOrJsconfig(fullPath)) {
|
|
2630
|
+
scheduleTsconfigReload(fullPath);
|
|
2631
|
+
return;
|
|
2632
|
+
}
|
|
2633
|
+
if (isWatchedDinouConfigOrSetupFile(fullPath, projectRoot)) {
|
|
2634
|
+
scheduleDinouConfigReload(fullPath);
|
|
2635
|
+
return;
|
|
2636
|
+
}
|
|
2637
|
+
if (!isWatchedDotEnvFile(fullPath, projectRoot)) return;
|
|
2638
|
+
pendingEnvChangedPath = fullPath;
|
|
2639
|
+
if (envDebounce) clearTimeout(envDebounce);
|
|
2640
|
+
envDebounce = setTimeout(() => {
|
|
2641
|
+
envDebounce = null;
|
|
2642
|
+
const changedPath = pendingEnvChangedPath;
|
|
2643
|
+
pendingEnvChangedPath = null;
|
|
2644
|
+
triggerEnvReload(changedPath);
|
|
2645
|
+
}, 50);
|
|
2646
|
+
});
|
|
2082
2647
|
|
|
2083
2648
|
let clientManifestReady = false;
|
|
2084
2649
|
|
|
@@ -2086,11 +2651,11 @@ function checkClientFilesPresent() {
|
|
|
2086
2651
|
if (globalThis.__DINOU_MEM_FILES__ && globalThis.__DINOU_MEM_FILES__.has("main.js")) {
|
|
2087
2652
|
return true;
|
|
2088
2653
|
}
|
|
2089
|
-
const cPath = findManifest("react-client-manifest.json", "
|
|
2654
|
+
const cPath = findManifest("react-client-manifest.json", "node-dev");
|
|
2090
2655
|
if (!globalThis.__DINOU_RAW_CLIENT_MANIFEST__ && !readJsonSafe(cPath)) return false;
|
|
2091
2656
|
if (isWebpackBuild) {
|
|
2092
2657
|
if (globalThis.__DINOU_RAW_ASSET_MANIFEST__) return true;
|
|
2093
|
-
const mPath = path.resolve(projectRoot, ".dinou/
|
|
2658
|
+
const mPath = path.resolve(projectRoot, ".dinou/node-dev/manifest.json");
|
|
2094
2659
|
return fs.existsSync(mPath);
|
|
2095
2660
|
}
|
|
2096
2661
|
const mainPath = path.resolve(projectRoot, ".dinou/public/main.js");
|
|
@@ -2173,25 +2738,9 @@ if (!fs.existsSync(dotDinouDir)) {
|
|
|
2173
2738
|
fs.mkdirSync(dotDinouDir, { recursive: true });
|
|
2174
2739
|
}
|
|
2175
2740
|
|
|
2176
|
-
const MIME_TYPES = {
|
|
2177
|
-
".js": "application/javascript; charset=utf-8",
|
|
2178
|
-
".mjs": "application/javascript; charset=utf-8",
|
|
2179
|
-
".css": "text/css; charset=utf-8",
|
|
2180
|
-
".json": "application/json",
|
|
2181
|
-
".svg": "image/svg+xml",
|
|
2182
|
-
".png": "image/png",
|
|
2183
|
-
".jpg": "image/jpeg",
|
|
2184
|
-
".jpeg": "image/jpeg",
|
|
2185
|
-
".webp": "image/webp",
|
|
2186
|
-
".ico": "image/x-icon",
|
|
2187
|
-
".txt": "text/plain; charset=utf-8",
|
|
2188
|
-
".woff": "font/woff",
|
|
2189
|
-
".woff2": "font/woff2",
|
|
2190
|
-
};
|
|
2191
|
-
|
|
2192
2741
|
const candidateStaticDirs = [
|
|
2193
|
-
path.resolve(projectRoot, ".dinou/public"),
|
|
2194
2742
|
path.resolve(projectRoot, "public"),
|
|
2743
|
+
path.resolve(projectRoot, ".dinou/public"),
|
|
2195
2744
|
];
|
|
2196
2745
|
|
|
2197
2746
|
function isManifestReady() {
|
|
@@ -2376,6 +2925,11 @@ async function startClientBundler(tool) {
|
|
|
2376
2925
|
const webpackConfigMod = await import(pathToFileURL(path.resolve(dinouDir, "webpack/webpack.config.js")).href);
|
|
2377
2926
|
const getWebpackConfig = webpackConfigMod.default || webpackConfigMod;
|
|
2378
2927
|
const webpackConfig = await getWebpackConfig();
|
|
2928
|
+
const definePlugin = Array.isArray(webpackConfig.plugins)
|
|
2929
|
+
? webpackConfig.plugins.find(
|
|
2930
|
+
(p) => p && p.constructor && p.constructor.name === "DefinePlugin"
|
|
2931
|
+
)
|
|
2932
|
+
: null;
|
|
2379
2933
|
const compiler = webpack(webpackConfig);
|
|
2380
2934
|
|
|
2381
2935
|
let devServer = null;
|
|
@@ -2484,7 +3038,10 @@ async function startClientBundler(tool) {
|
|
|
2484
3038
|
broadcast: (msg) => {
|
|
2485
3039
|
const clients = devServer?.webSocketServer?.clients || devServer?.sockets;
|
|
2486
3040
|
if (devServer?.sendMessage && clients) {
|
|
2487
|
-
devServer.sendMessage(clients, "
|
|
3041
|
+
devServer.sendMessage(clients, "dinou-hmr", msg || { type: "reload" });
|
|
3042
|
+
if (process.env.DINOU_STANDALONE_SERVER === "true" && (!msg || msg.type === "reload")) {
|
|
3043
|
+
devServer.sendMessage(clients, "static-changed");
|
|
3044
|
+
}
|
|
2488
3045
|
}
|
|
2489
3046
|
},
|
|
2490
3047
|
restart: async () => {
|
|
@@ -2499,6 +3056,60 @@ async function startClientBundler(tool) {
|
|
|
2499
3056
|
}
|
|
2500
3057
|
await onManifestUpdated();
|
|
2501
3058
|
},
|
|
3059
|
+
refreshPublicEnv: async () => {
|
|
3060
|
+
if (definePlugin) {
|
|
3061
|
+
definePlugin.definitions = getWebpackPublicEnvDefines({
|
|
3062
|
+
mode: "development",
|
|
3063
|
+
extra: {
|
|
3064
|
+
DINOU_HMR_PORT: String(
|
|
3065
|
+
process.env.HMR_PORT || Number(process.env.PORT || 3000) + 1
|
|
3066
|
+
),
|
|
3067
|
+
},
|
|
3068
|
+
});
|
|
3069
|
+
}
|
|
3070
|
+
if (!globalThis.__DINOU_WEBPACK_MODIFIED_FILES__) {
|
|
3071
|
+
globalThis.__DINOU_WEBPACK_MODIFIED_FILES__ = new Set();
|
|
3072
|
+
}
|
|
3073
|
+
for (const cf of knownClientFiles) {
|
|
3074
|
+
globalThis.__DINOU_WEBPACK_MODIFIED_FILES__.add(
|
|
3075
|
+
path.resolve(cf).replace(/\\/g, "/").toLowerCase()
|
|
3076
|
+
);
|
|
3077
|
+
}
|
|
3078
|
+
const waitP = startBuildWait();
|
|
3079
|
+
try {
|
|
3080
|
+
if (devServer?.middleware?.invalidate) {
|
|
3081
|
+
devServer.middleware.invalidate();
|
|
3082
|
+
} else if (compiler.watching?.invalidate) {
|
|
3083
|
+
compiler.watching.invalidate();
|
|
3084
|
+
}
|
|
3085
|
+
} catch (e) {}
|
|
3086
|
+
await waitP;
|
|
3087
|
+
await onManifestUpdated();
|
|
3088
|
+
},
|
|
3089
|
+
refreshAliases: async () => {
|
|
3090
|
+
clearTsconfigAliasCache(projectRoot);
|
|
3091
|
+
try {
|
|
3092
|
+
compiler.inputFileSystem?.purge?.();
|
|
3093
|
+
} catch (e) {}
|
|
3094
|
+
if (!globalThis.__DINOU_WEBPACK_MODIFIED_FILES__) {
|
|
3095
|
+
globalThis.__DINOU_WEBPACK_MODIFIED_FILES__ = new Set();
|
|
3096
|
+
}
|
|
3097
|
+
for (const cf of knownClientFiles) {
|
|
3098
|
+
globalThis.__DINOU_WEBPACK_MODIFIED_FILES__.add(
|
|
3099
|
+
path.resolve(cf).replace(/\\/g, "/").toLowerCase()
|
|
3100
|
+
);
|
|
3101
|
+
}
|
|
3102
|
+
const waitP = startBuildWait();
|
|
3103
|
+
try {
|
|
3104
|
+
if (devServer?.middleware?.invalidate) {
|
|
3105
|
+
devServer.middleware.invalidate();
|
|
3106
|
+
} else if (compiler.watching?.invalidate) {
|
|
3107
|
+
compiler.watching.invalidate();
|
|
3108
|
+
}
|
|
3109
|
+
} catch (e) {}
|
|
3110
|
+
await waitP;
|
|
3111
|
+
await onManifestUpdated();
|
|
3112
|
+
},
|
|
2502
3113
|
close: async () => {
|
|
2503
3114
|
if (devServer) {
|
|
2504
3115
|
try {
|
|
@@ -2526,26 +3137,35 @@ async function startClientBundler(tool) {
|
|
|
2526
3137
|
|
|
2527
3138
|
// Node.js Middlewares registered by plugins via configureServer
|
|
2528
3139
|
const nodeMiddlewares = [];
|
|
3140
|
+
let baselineServerListeners = null;
|
|
2529
3141
|
|
|
2530
3142
|
async function applyServerPlugins(serverInstance) {
|
|
2531
3143
|
try {
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
const
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
3144
|
+
if (!baselineServerListeners) {
|
|
3145
|
+
baselineServerListeners = new Map();
|
|
3146
|
+
for (const evt of serverInstance.eventNames()) {
|
|
3147
|
+
baselineServerListeners.set(evt, new Set(serverInstance.listeners(evt)));
|
|
3148
|
+
}
|
|
3149
|
+
} else {
|
|
3150
|
+
for (const evt of serverInstance.eventNames()) {
|
|
3151
|
+
const baseSet = baselineServerListeners.get(evt);
|
|
3152
|
+
for (const fn of serverInstance.listeners(evt)) {
|
|
3153
|
+
if (!baseSet || !baseSet.has(fn)) {
|
|
3154
|
+
serverInstance.removeListener(evt, fn);
|
|
2540
3155
|
}
|
|
2541
|
-
},
|
|
2542
|
-
};
|
|
2543
|
-
for (const plugin of config.plugins) {
|
|
2544
|
-
if (typeof plugin.configureServer === "function") {
|
|
2545
|
-
await plugin.configureServer(serverContext);
|
|
2546
3156
|
}
|
|
2547
3157
|
}
|
|
2548
3158
|
}
|
|
3159
|
+
nodeMiddlewares.length = 0;
|
|
3160
|
+
const config = await getDinouConfig(projectRoot);
|
|
3161
|
+
if (config.plugins && Array.isArray(config.plugins)) {
|
|
3162
|
+
await applyConfigureServerPlugins({
|
|
3163
|
+
plugins: config.plugins,
|
|
3164
|
+
server: serverInstance,
|
|
3165
|
+
isDev: true,
|
|
3166
|
+
middlewares: nodeMiddlewares,
|
|
3167
|
+
});
|
|
3168
|
+
}
|
|
2549
3169
|
} catch (err) {
|
|
2550
3170
|
console.error("❌ [Dinou Dev] Error applying plugin configureServer hooks:", err);
|
|
2551
3171
|
}
|
|
@@ -2558,15 +3178,21 @@ const server = http.createServer(async (req, res) => {
|
|
|
2558
3178
|
return;
|
|
2559
3179
|
}
|
|
2560
3180
|
|
|
3181
|
+
if (configDebounce) {
|
|
3182
|
+
clearTimeout(configDebounce);
|
|
3183
|
+
configDebounce = null;
|
|
3184
|
+
const changedCfgPath = pendingConfigChangedPath;
|
|
3185
|
+
pendingConfigChangedPath = null;
|
|
3186
|
+
await triggerDinouConfigReload(changedCfgPath);
|
|
3187
|
+
}
|
|
3188
|
+
if (activeConfigReloadPromise) {
|
|
3189
|
+
await activeConfigReloadPromise;
|
|
3190
|
+
}
|
|
3191
|
+
|
|
2561
3192
|
if (nodeMiddlewares.length > 0) {
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
continued = true;
|
|
2566
|
-
});
|
|
2567
|
-
if (!continued || res.writableEnded || res.headersSent) {
|
|
2568
|
-
return;
|
|
2569
|
-
}
|
|
3193
|
+
const shouldContinue = await runNodeMiddlewares(nodeMiddlewares, req, res);
|
|
3194
|
+
if (!shouldContinue || res.writableEnded || res.headersSent) {
|
|
3195
|
+
return;
|
|
2570
3196
|
}
|
|
2571
3197
|
}
|
|
2572
3198
|
if (clientBundlerPromise) {
|
|
@@ -2586,6 +3212,16 @@ const server = http.createServer(async (req, res) => {
|
|
|
2586
3212
|
pendingSrcChanges.clear();
|
|
2587
3213
|
await triggerRebuildBatch(batch);
|
|
2588
3214
|
}
|
|
3215
|
+
if (envDebounce) {
|
|
3216
|
+
clearTimeout(envDebounce);
|
|
3217
|
+
envDebounce = null;
|
|
3218
|
+
const changedPath = pendingEnvChangedPath;
|
|
3219
|
+
pendingEnvChangedPath = null;
|
|
3220
|
+
await triggerEnvReload(changedPath);
|
|
3221
|
+
}
|
|
3222
|
+
if (activeEnvReloadPromise) {
|
|
3223
|
+
await activeEnvReloadPromise;
|
|
3224
|
+
}
|
|
2589
3225
|
if (activeRebuildPromise) {
|
|
2590
3226
|
await activeRebuildPromise;
|
|
2591
3227
|
}
|
|
@@ -2617,11 +3253,17 @@ const server = http.createServer(async (req, res) => {
|
|
|
2617
3253
|
return;
|
|
2618
3254
|
}
|
|
2619
3255
|
|
|
2620
|
-
// 2. Static files delivery from memory,
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
3256
|
+
// 2. Static files delivery from memory, public/, or .dinou/public
|
|
3257
|
+
const cleanPath =
|
|
3258
|
+
req.method === "GET" || req.method === "HEAD"
|
|
3259
|
+
? normalizePublicRequestPath(pathname)
|
|
3260
|
+
: null;
|
|
3261
|
+
if (cleanPath) {
|
|
3262
|
+
const rawMapped = (parsedAssetManifest && parsedAssetManifest[cleanPath]) || cleanPath;
|
|
3263
|
+
const mappedPath =
|
|
3264
|
+
rawMapped === cleanPath
|
|
3265
|
+
? cleanPath
|
|
3266
|
+
: normalizePublicRequestPath("/" + String(rawMapped).replace(/^\/+/, "")) || cleanPath;
|
|
2625
3267
|
|
|
2626
3268
|
// 2.a In-memory fast path for client bundles and assets generated in dev
|
|
2627
3269
|
if (globalThis.__DINOU_MEM_FILES__) {
|
|
@@ -2643,13 +3285,36 @@ const server = http.createServer(async (req, res) => {
|
|
|
2643
3285
|
}
|
|
2644
3286
|
|
|
2645
3287
|
if (memBuf) {
|
|
2646
|
-
const
|
|
2647
|
-
const
|
|
3288
|
+
const contentType = getStaticContentType(cleanPath);
|
|
3289
|
+
const rangeHeader =
|
|
3290
|
+
req.method === "GET" ? req.headers["range"] : undefined;
|
|
3291
|
+
const range = rangeHeader
|
|
3292
|
+
? parseHttpByteRange(String(rangeHeader), memBuf.length)
|
|
3293
|
+
: null;
|
|
3294
|
+
if (range && range.unsatisfiable) {
|
|
3295
|
+
res.statusCode = 416;
|
|
3296
|
+
res.setHeader("content-range", range.contentRange);
|
|
3297
|
+
res.setHeader("accept-ranges", "bytes");
|
|
3298
|
+
res.end();
|
|
3299
|
+
return;
|
|
3300
|
+
}
|
|
3301
|
+
if (range) {
|
|
3302
|
+
const slice = memBuf.subarray(range.start, range.end + 1);
|
|
3303
|
+
res.statusCode = 206;
|
|
3304
|
+
res.setHeader("content-type", contentType);
|
|
3305
|
+
res.setHeader("content-length", String(slice.length));
|
|
3306
|
+
res.setHeader("content-range", range.contentRange);
|
|
3307
|
+
res.setHeader("accept-ranges", "bytes");
|
|
3308
|
+
res.setHeader("cache-control", "no-store, no-cache, must-revalidate");
|
|
3309
|
+
res.end(slice);
|
|
3310
|
+
return;
|
|
3311
|
+
}
|
|
2648
3312
|
res.statusCode = 200;
|
|
2649
3313
|
res.setHeader("content-type", contentType);
|
|
2650
3314
|
res.setHeader("content-length", String(memBuf.length));
|
|
3315
|
+
res.setHeader("accept-ranges", "bytes");
|
|
2651
3316
|
res.setHeader("cache-control", "no-store, no-cache, must-revalidate");
|
|
2652
|
-
res.end(memBuf);
|
|
3317
|
+
res.end(req.method === "HEAD" ? undefined : memBuf);
|
|
2653
3318
|
return;
|
|
2654
3319
|
}
|
|
2655
3320
|
}
|
|
@@ -2657,8 +3322,8 @@ const server = http.createServer(async (req, res) => {
|
|
|
2657
3322
|
let foundFilePath = null;
|
|
2658
3323
|
for (const baseDir of candidateStaticDirs) {
|
|
2659
3324
|
for (const targetName of [mappedPath, cleanPath]) {
|
|
2660
|
-
const filePath =
|
|
2661
|
-
if (fs.existsSync(filePath)) {
|
|
3325
|
+
const filePath = resolveConfinedStaticFile(baseDir, targetName);
|
|
3326
|
+
if (filePath && fs.existsSync(filePath)) {
|
|
2662
3327
|
try {
|
|
2663
3328
|
if (fs.statSync(filePath).isFile()) {
|
|
2664
3329
|
foundFilePath = filePath;
|
|
@@ -2682,8 +3347,8 @@ const server = http.createServer(async (req, res) => {
|
|
|
2682
3347
|
await new Promise((r) => setTimeout(r, 25));
|
|
2683
3348
|
for (const baseDir of candidateStaticDirs) {
|
|
2684
3349
|
for (const targetName of [mappedPath, cleanPath]) {
|
|
2685
|
-
const filePath =
|
|
2686
|
-
if (fs.existsSync(filePath)) {
|
|
3350
|
+
const filePath = resolveConfinedStaticFile(baseDir, targetName);
|
|
3351
|
+
if (filePath && fs.existsSync(filePath)) {
|
|
2687
3352
|
try {
|
|
2688
3353
|
if (fs.statSync(filePath).isFile()) {
|
|
2689
3354
|
foundFilePath = filePath;
|
|
@@ -2708,14 +3373,66 @@ const server = http.createServer(async (req, res) => {
|
|
|
2708
3373
|
if (foundFilePath) {
|
|
2709
3374
|
try {
|
|
2710
3375
|
const fileExt = path.extname(foundFilePath).toLowerCase();
|
|
2711
|
-
const contentType =
|
|
3376
|
+
const contentType = getStaticContentType(foundFilePath);
|
|
3377
|
+
const isCodeAsset = fileExt === ".js" || fileExt === ".mjs" || fileExt === ".css";
|
|
3378
|
+
|
|
3379
|
+
if (!isCodeAsset) {
|
|
3380
|
+
const stat = fs.statSync(foundFilePath);
|
|
3381
|
+
const rangeHeader =
|
|
3382
|
+
req.method === "GET" ? req.headers["range"] : undefined;
|
|
3383
|
+
const range = rangeHeader
|
|
3384
|
+
? parseHttpByteRange(String(rangeHeader), stat.size)
|
|
3385
|
+
: null;
|
|
3386
|
+
|
|
3387
|
+
if (range && range.unsatisfiable) {
|
|
3388
|
+
res.statusCode = 416;
|
|
3389
|
+
res.setHeader("content-range", range.contentRange);
|
|
3390
|
+
res.setHeader("accept-ranges", "bytes");
|
|
3391
|
+
res.end();
|
|
3392
|
+
return;
|
|
3393
|
+
}
|
|
2712
3394
|
|
|
2713
|
-
|
|
3395
|
+
if (range) {
|
|
3396
|
+
res.statusCode = 206;
|
|
3397
|
+
res.setHeader("content-type", contentType);
|
|
3398
|
+
res.setHeader("content-length", String(range.length));
|
|
3399
|
+
res.setHeader("content-range", range.contentRange);
|
|
3400
|
+
res.setHeader("accept-ranges", "bytes");
|
|
3401
|
+
res.setHeader("cache-control", "no-store, no-cache, must-revalidate");
|
|
3402
|
+
const stream = fs.createReadStream(foundFilePath, {
|
|
3403
|
+
start: range.start,
|
|
3404
|
+
end: range.end,
|
|
3405
|
+
});
|
|
3406
|
+
stream.on("error", () => {
|
|
3407
|
+
if (!res.writableEnded) res.end();
|
|
3408
|
+
});
|
|
3409
|
+
stream.pipe(res);
|
|
3410
|
+
return;
|
|
3411
|
+
}
|
|
3412
|
+
|
|
3413
|
+
res.statusCode = 200;
|
|
3414
|
+
res.setHeader("content-type", contentType);
|
|
3415
|
+
res.setHeader("content-length", String(stat.size));
|
|
3416
|
+
res.setHeader("accept-ranges", "bytes");
|
|
3417
|
+
res.setHeader("cache-control", "no-store, no-cache, must-revalidate");
|
|
3418
|
+
if (req.method === "HEAD") {
|
|
3419
|
+
res.end();
|
|
3420
|
+
return;
|
|
3421
|
+
}
|
|
3422
|
+
const stream = fs.createReadStream(foundFilePath);
|
|
3423
|
+
stream.on("error", () => {
|
|
3424
|
+
if (!res.writableEnded) res.end();
|
|
3425
|
+
});
|
|
3426
|
+
stream.pipe(res);
|
|
3427
|
+
return;
|
|
3428
|
+
}
|
|
3429
|
+
|
|
3430
|
+
// Safely read JS/CSS buffer into memory, retrying briefly if the bundler currently has it truncated or locked
|
|
2714
3431
|
let buf = null;
|
|
2715
3432
|
for (let attempt = 0; attempt < 10; attempt++) {
|
|
2716
3433
|
try {
|
|
2717
3434
|
buf = fs.readFileSync(foundFilePath);
|
|
2718
|
-
if (buf.length > 0
|
|
3435
|
+
if (buf.length > 0) {
|
|
2719
3436
|
break;
|
|
2720
3437
|
}
|
|
2721
3438
|
} catch (readErr) {
|
|
@@ -2728,8 +3445,9 @@ const server = http.createServer(async (req, res) => {
|
|
|
2728
3445
|
res.statusCode = 200;
|
|
2729
3446
|
res.setHeader("content-type", contentType);
|
|
2730
3447
|
res.setHeader("content-length", String(buf.length));
|
|
3448
|
+
res.setHeader("accept-ranges", "bytes");
|
|
2731
3449
|
res.setHeader("cache-control", "no-store, no-cache, must-revalidate");
|
|
2732
|
-
res.end(buf);
|
|
3450
|
+
res.end(req.method === "HEAD" ? undefined : buf);
|
|
2733
3451
|
return;
|
|
2734
3452
|
}
|
|
2735
3453
|
} catch (e) {}
|
|
@@ -2737,6 +3455,16 @@ const server = http.createServer(async (req, res) => {
|
|
|
2737
3455
|
}
|
|
2738
3456
|
|
|
2739
3457
|
// 3. Dynamic RSC + Native SSR Streaming
|
|
3458
|
+
if (envDebounce) {
|
|
3459
|
+
clearTimeout(envDebounce);
|
|
3460
|
+
envDebounce = null;
|
|
3461
|
+
const changedPath = pendingEnvChangedPath;
|
|
3462
|
+
pendingEnvChangedPath = null;
|
|
3463
|
+
await triggerEnvReload(changedPath);
|
|
3464
|
+
}
|
|
3465
|
+
if (activeEnvReloadPromise) {
|
|
3466
|
+
await activeEnvReloadPromise;
|
|
3467
|
+
}
|
|
2740
3468
|
if (activeRebuildPromise) {
|
|
2741
3469
|
await activeRebuildPromise;
|
|
2742
3470
|
}
|
|
@@ -2853,6 +3581,8 @@ async function cleanup() {
|
|
|
2853
3581
|
stopSpinner();
|
|
2854
3582
|
try {
|
|
2855
3583
|
srcWatcher.close();
|
|
3584
|
+
envWatcher.close();
|
|
3585
|
+
tsconfigExtendsWatcher.close();
|
|
2856
3586
|
if (clientBundlerHandle?.close) {
|
|
2857
3587
|
await clientBundlerHandle.close();
|
|
2858
3588
|
}
|