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/bun/build.js
CHANGED
|
@@ -16,21 +16,46 @@ if (!ensureVendorMode()) {
|
|
|
16
16
|
import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
|
|
17
17
|
import parseExports from "../core/parse-exports.js";
|
|
18
18
|
import { useClientRegex, useServerRegex } from "../constants.js";
|
|
19
|
-
import {
|
|
19
|
+
import {
|
|
20
|
+
transformServerFunctions,
|
|
21
|
+
hasServerFunctions,
|
|
22
|
+
buildSsrServerReferenceModule,
|
|
23
|
+
generateSsrServerManifestStubs,
|
|
24
|
+
} from "../core/transform-server-functions.js";
|
|
20
25
|
import {
|
|
21
26
|
isSupportedClientModule,
|
|
22
27
|
scanProjectDependenciesForClientComponents,
|
|
23
28
|
} from "../core/scan-dependency-components.js";
|
|
24
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
getDinouConfig,
|
|
31
|
+
findDinouConfigFile,
|
|
32
|
+
} from "../core/load-dinou-config.js";
|
|
25
33
|
import { resolveSetupFiles } from "../core/resolve-setup-files.js";
|
|
34
|
+
import {
|
|
35
|
+
esbuildContextualDinouPlugin,
|
|
36
|
+
filterEscapedClientManifest,
|
|
37
|
+
} from "../core/resolve-contextual-dinou.js";
|
|
38
|
+
import { discoverLayoutsFromFs, sortEntriesByName } from "../core/discover-layouts.js";
|
|
39
|
+
import { createServerCssModulesPlugin } from "../core/server-css-modules-plugin.js";
|
|
40
|
+
import {
|
|
41
|
+
createServerAssetPlugin,
|
|
42
|
+
getAssetExtensionsInfo,
|
|
43
|
+
} from "../core/asset-extensions.js";
|
|
44
|
+
import { esbuildTsconfigAliasesPlugin } from "../core/tsconfig-aliases.js";
|
|
45
|
+
import {
|
|
46
|
+
loadEnvFiles,
|
|
47
|
+
getEsbuildPublicEnvDefines,
|
|
48
|
+
} from "../core/env.js";
|
|
26
49
|
|
|
27
50
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
28
51
|
|
|
29
52
|
const projectRoot = process.cwd();
|
|
53
|
+
loadEnvFiles(projectRoot, { mode: "production" });
|
|
30
54
|
const bunDir = path.resolve(projectRoot, ".dinou/bun");
|
|
31
55
|
fs.mkdirSync(bunDir, { recursive: true });
|
|
32
56
|
|
|
33
57
|
const dinouConfig = await getDinouConfig(projectRoot);
|
|
58
|
+
const configFile = findDinouConfigFile(projectRoot);
|
|
34
59
|
const setupFiles = resolveSetupFiles(projectRoot, dinouConfig);
|
|
35
60
|
if (setupFiles.length > 0) {
|
|
36
61
|
console.log(` 🔌 [Dinou Setup] Active setup files (${setupFiles.length}): ${setupFiles.map((f) => path.basename(f)).join(", ")}`);
|
|
@@ -73,31 +98,21 @@ const routeModulesCode = generateRouteModulesCode(projectRoot, "../..");
|
|
|
73
98
|
const routeModulesPath = path.join(bunDir, "route-modules.js");
|
|
74
99
|
fs.writeFileSync(routeModulesPath, routeModulesCode, "utf8");
|
|
75
100
|
|
|
76
|
-
function findManifest(filename,
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
path.resolve(projectRoot, ".dinou/dist3", filename),
|
|
80
|
-
path.resolve(projectRoot, ".dinou/public", filename),
|
|
81
|
-
path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
|
|
82
|
-
]
|
|
83
|
-
: [
|
|
84
|
-
path.resolve(projectRoot, ".dinou", fallbackFolder, filename),
|
|
85
|
-
path.resolve(projectRoot, ".dinou/dist3", filename),
|
|
86
|
-
path.resolve(projectRoot, ".dinou/public", filename),
|
|
87
|
-
];
|
|
88
|
-
for (const c of candidates) {
|
|
89
|
-
if (fs.existsSync(c)) return c;
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
101
|
+
function findManifest(filename, folder) {
|
|
102
|
+
const candidate = path.resolve(projectRoot, ".dinou", folder, filename);
|
|
103
|
+
return fs.existsSync(candidate) ? candidate : null;
|
|
92
104
|
}
|
|
93
105
|
|
|
94
|
-
const clientManifestPath = findManifest("react-client-manifest.json", "
|
|
95
|
-
const sfManifestPath = findManifest("server-functions-manifest.json", "
|
|
106
|
+
const clientManifestPath = findManifest("react-client-manifest.json", "dist1");
|
|
107
|
+
const sfManifestPath = findManifest("server-functions-manifest.json", "dist1");
|
|
96
108
|
|
|
97
109
|
let parsedClientManifest = {};
|
|
98
110
|
if (clientManifestPath && fs.existsSync(clientManifestPath)) {
|
|
99
111
|
try {
|
|
100
|
-
parsedClientManifest =
|
|
112
|
+
parsedClientManifest = filterEscapedClientManifest(
|
|
113
|
+
JSON.parse(fs.readFileSync(clientManifestPath, "utf8")),
|
|
114
|
+
projectRoot
|
|
115
|
+
);
|
|
101
116
|
} catch (e) {}
|
|
102
117
|
}
|
|
103
118
|
|
|
@@ -125,7 +140,7 @@ function findClientComponents() {
|
|
|
125
140
|
for (const entry of entries) {
|
|
126
141
|
const full = path.join(dir, entry.name);
|
|
127
142
|
if (entry.isDirectory()) {
|
|
128
|
-
walk(full);
|
|
143
|
+
if (!entry.name.startsWith("_")) walk(full);
|
|
129
144
|
} else if (/\.[jt]sx?$/.test(entry.name)) {
|
|
130
145
|
try {
|
|
131
146
|
const content = fs.readFileSync(full, "utf8");
|
|
@@ -345,7 +360,7 @@ if (sfManifestPath && fs.existsSync(sfManifestPath)) {
|
|
|
345
360
|
manifestInlines += `\nglobalThis.__DINOU_SERVER_FUNCTIONS_MANIFEST__ = {};\n`;
|
|
346
361
|
}
|
|
347
362
|
|
|
348
|
-
const assetManifestPath = findManifest("manifest.json", "
|
|
363
|
+
const assetManifestPath = findManifest("manifest.json", "dist1");
|
|
349
364
|
if (assetManifestPath && fs.existsSync(assetManifestPath)) {
|
|
350
365
|
const content = fs.readFileSync(assetManifestPath, "utf8");
|
|
351
366
|
manifestInlines += `\nglobalThis.__DINOU_ASSET_MANIFEST__ = ${content};\n`;
|
|
@@ -357,11 +372,21 @@ let importMapHtml = "";
|
|
|
357
372
|
if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
|
|
358
373
|
const imports = {};
|
|
359
374
|
const moduleBasePath = pathToFileURL(projectRoot).href + "/";
|
|
375
|
+
const moduleBasePathLower = moduleBasePath.replace(
|
|
376
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
377
|
+
(_, d) => `file:///${d.toLowerCase()}:`
|
|
378
|
+
);
|
|
379
|
+
const moduleBasePathUpper = moduleBasePath.replace(
|
|
380
|
+
/^file:\/\/\/([a-zA-Z]):/,
|
|
381
|
+
(_, d) => `file:///${d.toUpperCase()}:`
|
|
382
|
+
);
|
|
360
383
|
|
|
361
384
|
for (const [key, val] of Object.entries(parsedClientManifest)) {
|
|
362
385
|
let specifier = key;
|
|
363
|
-
if (specifier.startsWith(
|
|
364
|
-
specifier = specifier.slice(
|
|
386
|
+
if (specifier.startsWith(moduleBasePathUpper)) {
|
|
387
|
+
specifier = specifier.slice(moduleBasePathUpper.length);
|
|
388
|
+
} else if (specifier.startsWith(moduleBasePathLower)) {
|
|
389
|
+
specifier = specifier.slice(moduleBasePathLower.length);
|
|
365
390
|
}
|
|
366
391
|
const hashIdx = specifier.indexOf("#");
|
|
367
392
|
if (hashIdx !== -1) {
|
|
@@ -424,21 +449,7 @@ if (!isWebpackBuild && Object.keys(parsedClientManifest).length > 0) {
|
|
|
424
449
|
|
|
425
450
|
manifestInlines += `\nglobalThis.__DINOU_IMPORT_MAP_HTML__ = ${JSON.stringify(importMapHtml)};\n`;
|
|
426
451
|
|
|
427
|
-
const discoveredLayouts =
|
|
428
|
-
function findLayoutRoutes(dir, rel = "") {
|
|
429
|
-
if (!fs.existsSync(dir)) return;
|
|
430
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
431
|
-
for (const entry of entries) {
|
|
432
|
-
if (entry.isDirectory()) {
|
|
433
|
-
findLayoutRoutes(path.join(dir, entry.name), rel ? `${rel}/${entry.name}` : entry.name);
|
|
434
|
-
} else if (/^layout\.[jt]sx?$/.test(entry.name)) {
|
|
435
|
-
discoveredLayouts.push(rel);
|
|
436
|
-
} else if (entry.name === "no_layout") {
|
|
437
|
-
discoveredLayouts.push("!" + rel);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
findLayoutRoutes(srcDir);
|
|
452
|
+
const discoveredLayouts = discoverLayoutsFromFs(srcDir, fs);
|
|
442
453
|
manifestInlines += `\nglobalThis.__DINOU_LAYOUTS__ = ${JSON.stringify(discoveredLayouts)};\n`;
|
|
443
454
|
|
|
444
455
|
if (process.env.DINOU_DEBUG) {
|
|
@@ -448,10 +459,11 @@ if (process.env.DINOU_DEBUG) {
|
|
|
448
459
|
const vfsSnapshot = {};
|
|
449
460
|
function walkVfs(dir) {
|
|
450
461
|
if (!fs.existsSync(dir)) return;
|
|
451
|
-
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
462
|
+
const entries = sortEntriesByName(fs.readdirSync(dir, { withFileTypes: true }));
|
|
452
463
|
const children = [];
|
|
453
464
|
for (const entry of entries) {
|
|
454
465
|
const isDir = entry.isDirectory();
|
|
466
|
+
if (isDir && entry.name.startsWith("_")) continue;
|
|
455
467
|
children.push({ name: entry.name, isDirectory: isDir });
|
|
456
468
|
const fullPath = path.join(dir, entry.name);
|
|
457
469
|
const relFromSrc = path.relative(srcDir, fullPath).replace(/\\/g, "/");
|
|
@@ -509,10 +521,7 @@ clientComponents.forEach((compPath, index) => {
|
|
|
509
521
|
});
|
|
510
522
|
|
|
511
523
|
const serverFunctionFiles = Object.keys(parsedServerFunctionsManifest);
|
|
512
|
-
|
|
513
|
-
const absPath = path.resolve(projectRoot, relPath).replace(/\\/g, "/");
|
|
514
|
-
ssrManifestCode += `import * as sf_${index} from ${JSON.stringify(absPath)};\n`;
|
|
515
|
-
});
|
|
524
|
+
ssrManifestCode += generateSsrServerManifestStubs(parsedServerFunctionsManifest);
|
|
516
525
|
|
|
517
526
|
ssrManifestCode += `\nexport const clientModules = {\n`;
|
|
518
527
|
const emittedClientModules = new Set();
|
|
@@ -707,12 +716,23 @@ fs.writeFileSync(ssrClientManifestPath, ssrManifestCode, "utf8");
|
|
|
707
716
|
// Entry Files Generation
|
|
708
717
|
// ====================================================================
|
|
709
718
|
// 1. RSC Engine Entry
|
|
719
|
+
const aotConfigPrelude = configFile
|
|
720
|
+
? `import * as __dinouConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};
|
|
721
|
+
const __resolvedDinouCfg = (__dinouConfigMod && __dinouConfigMod.default) ? __dinouConfigMod.default : (__dinouConfigMod || { plugins: [] });
|
|
722
|
+
globalThis.__DINOU_AOT_CONFIG__ = __resolvedDinouCfg;
|
|
723
|
+
globalThis.__DINOU_CONFIG__ = __resolvedDinouCfg;
|
|
724
|
+
`
|
|
725
|
+
: "";
|
|
710
726
|
const rscEntryContent = `// Auto-generated RSC Engine entry for Bun (Dual-Bundle)
|
|
711
727
|
import "./env-setup.js";
|
|
712
|
-
import "./route-modules.js";
|
|
728
|
+
${aotConfigPrelude}import "./route-modules.js";
|
|
713
729
|
import * as edgeRenderer from "react-server-dom-webpack/server.edge";
|
|
730
|
+
import { handleRequest as coreHandleRequest } from "${dinouDirSlash}/core/handler.js";
|
|
714
731
|
globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
|
|
715
|
-
export
|
|
732
|
+
export function handleRequest(request, platformContext) {
|
|
733
|
+
globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
|
|
734
|
+
return coreHandleRequest(request, platformContext);
|
|
735
|
+
}
|
|
716
736
|
`;
|
|
717
737
|
const rscEntryPath = path.join(bunDir, "rsc-entry.js");
|
|
718
738
|
fs.writeFileSync(rscEntryPath, rscEntryContent, "utf8");
|
|
@@ -723,7 +743,7 @@ import { renderRscStreamToHtmlStream } from "${dinouDirSlash}/core/edge-ssr.js";
|
|
|
723
743
|
import { clientModules, ssrConsumerManifest } from "./ssr-client-manifest.js";
|
|
724
744
|
|
|
725
745
|
const lowerMap = new Map();
|
|
726
|
-
|
|
746
|
+
const localWebpackRequire = (id) => {
|
|
727
747
|
if (clientModules[id]) return clientModules[id];
|
|
728
748
|
if (typeof id === "string") {
|
|
729
749
|
if (lowerMap.size === 0) {
|
|
@@ -735,10 +755,12 @@ globalThis.__webpack_require__ = (id) => {
|
|
|
735
755
|
console.error("[SSR Engine] Module not found in __webpack_require__:", id);
|
|
736
756
|
return {};
|
|
737
757
|
};
|
|
738
|
-
|
|
758
|
+
localWebpackRequire.u = (chunkId) => "" + chunkId + ".js";
|
|
759
|
+
globalThis.__webpack_require__ = localWebpackRequire;
|
|
739
760
|
globalThis.__webpack_chunk_load__ = () => Promise.resolve();
|
|
740
761
|
|
|
741
762
|
export async function renderHtml(rscStream, options = {}) {
|
|
763
|
+
globalThis.__webpack_require__ = localWebpackRequire;
|
|
742
764
|
return renderRscStreamToHtmlStream(rscStream, ssrConsumerManifest, options);
|
|
743
765
|
}
|
|
744
766
|
`;
|
|
@@ -751,9 +773,18 @@ import { handleRequest } from "./rsc-engine.js";
|
|
|
751
773
|
import { renderHtml } from "./ssr-engine.js";
|
|
752
774
|
import {
|
|
753
775
|
setStorageAdapter,
|
|
776
|
+
hasExplicitStorageAdapter,
|
|
754
777
|
FileSystemStorage,
|
|
755
778
|
MemoryStorage,
|
|
756
779
|
} from "${dinouDirSlash}/core/storage-adapter.js";
|
|
780
|
+
import {
|
|
781
|
+
getStaticContentType,
|
|
782
|
+
getStaticCacheControl,
|
|
783
|
+
normalizePublicRequestPath,
|
|
784
|
+
parseHttpByteRange,
|
|
785
|
+
resolveConfinedStaticFile,
|
|
786
|
+
} from "${dinouDirSlash}/core/static-assets.js";
|
|
787
|
+
import { loadEnvFiles } from "${dinouDirSlash}/core/env.js";
|
|
757
788
|
import * as path from "node:path";
|
|
758
789
|
import * as fs from "node:fs";
|
|
759
790
|
|
|
@@ -765,20 +796,25 @@ let storageInitialized = false;
|
|
|
765
796
|
|
|
766
797
|
function initStorage() {
|
|
767
798
|
if (!storageInitialized) {
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
799
|
+
if (!hasExplicitStorageAdapter()) {
|
|
800
|
+
try {
|
|
801
|
+
const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
|
|
802
|
+
const dist2Dir = path.resolve(cwd, ".dinou/dist2");
|
|
803
|
+
setStorageAdapter(new FileSystemStorage(dist2Dir));
|
|
804
|
+
} catch (e) {
|
|
805
|
+
setStorageAdapter(new MemoryStorage());
|
|
806
|
+
}
|
|
774
807
|
}
|
|
775
808
|
storageInitialized = true;
|
|
776
809
|
}
|
|
777
810
|
}
|
|
778
811
|
|
|
812
|
+
const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
|
|
813
|
+
try {
|
|
814
|
+
loadEnvFiles(cwd, { mode: "production" });
|
|
815
|
+
} catch (e) {}
|
|
779
816
|
const PORT = Number(process.env.PORT || 3000);
|
|
780
817
|
const IDLE_TIMEOUT = Number(process.env.IDLE_TIMEOUT || 120);
|
|
781
|
-
const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
|
|
782
818
|
const dist3Dir = path.resolve(cwd, ".dinou/dist3");
|
|
783
819
|
|
|
784
820
|
export async function fetch(req) {
|
|
@@ -788,11 +824,56 @@ export async function fetch(req) {
|
|
|
788
824
|
const pathname = url.pathname;
|
|
789
825
|
|
|
790
826
|
// Static assets delivery (Zero-copy with Bun.file)
|
|
791
|
-
if (
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
827
|
+
if (req.method === "GET" || req.method === "HEAD") {
|
|
828
|
+
const cleanPath = normalizePublicRequestPath(pathname);
|
|
829
|
+
if (cleanPath) {
|
|
830
|
+
const filePath = resolveConfinedStaticFile(dist3Dir, cleanPath);
|
|
831
|
+
if (filePath && fs.existsSync(filePath)) {
|
|
832
|
+
try {
|
|
833
|
+
const stat = fs.statSync(filePath);
|
|
834
|
+
if (stat.isFile()) {
|
|
835
|
+
const contentType = getStaticContentType(cleanPath);
|
|
836
|
+
const cacheControl = getStaticCacheControl(cleanPath);
|
|
837
|
+
const rangeHeader = req.method === "GET" ? req.headers.get("range") : null;
|
|
838
|
+
const range = rangeHeader ? parseHttpByteRange(rangeHeader, stat.size) : null;
|
|
839
|
+
|
|
840
|
+
if (range && range.unsatisfiable) {
|
|
841
|
+
return new Response(null, {
|
|
842
|
+
status: 416,
|
|
843
|
+
headers: {
|
|
844
|
+
"content-range": range.contentRange,
|
|
845
|
+
"accept-ranges": "bytes",
|
|
846
|
+
},
|
|
847
|
+
});
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
const file = Bun.file(filePath);
|
|
851
|
+
if (range) {
|
|
852
|
+
return new Response(file.slice(range.start, range.end + 1), {
|
|
853
|
+
status: 206,
|
|
854
|
+
headers: {
|
|
855
|
+
"content-type": contentType,
|
|
856
|
+
"content-length": String(range.length),
|
|
857
|
+
"content-range": range.contentRange,
|
|
858
|
+
"accept-ranges": "bytes",
|
|
859
|
+
"cache-control": cacheControl,
|
|
860
|
+
"content-disposition": "inline",
|
|
861
|
+
},
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
return new Response(req.method === "HEAD" ? null : file, {
|
|
866
|
+
headers: {
|
|
867
|
+
"content-type": contentType,
|
|
868
|
+
"content-length": String(stat.size),
|
|
869
|
+
"accept-ranges": "bytes",
|
|
870
|
+
"cache-control": cacheControl,
|
|
871
|
+
"content-disposition": "inline",
|
|
872
|
+
},
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
} catch (e) {}
|
|
876
|
+
}
|
|
796
877
|
}
|
|
797
878
|
}
|
|
798
879
|
|
|
@@ -802,6 +883,10 @@ export async function fetch(req) {
|
|
|
802
883
|
});
|
|
803
884
|
}
|
|
804
885
|
|
|
886
|
+
if (typeof import.meta !== "undefined" && import.meta.main) {
|
|
887
|
+
console.log(\`🚀 Dinou (Bun AOT Dual-Bundle) server running on http://\${process.env.HOST || "localhost"}:\${PORT}\`);
|
|
888
|
+
}
|
|
889
|
+
|
|
805
890
|
export default {
|
|
806
891
|
port: PORT, ...(process.env.HOST ? { hostname: process.env.HOST } : {}),
|
|
807
892
|
fetch,
|
|
@@ -845,8 +930,8 @@ const externalList = [
|
|
|
845
930
|
];
|
|
846
931
|
|
|
847
932
|
const commonAlias = {
|
|
848
|
-
"@": path.resolve(projectRoot, "src"),
|
|
849
933
|
"dinou/config": path.resolve(dinouDir, "core/config.js"),
|
|
934
|
+
"dinou/server": path.resolve(dinouDir, "server.js"),
|
|
850
935
|
dinou: dinouDir,
|
|
851
936
|
};
|
|
852
937
|
|
|
@@ -857,12 +942,6 @@ const commonLoader = {
|
|
|
857
942
|
".tsx": "tsx",
|
|
858
943
|
".json": "json",
|
|
859
944
|
".css": "empty",
|
|
860
|
-
".svg": "dataurl",
|
|
861
|
-
".png": "dataurl",
|
|
862
|
-
".jpg": "dataurl",
|
|
863
|
-
".jpeg": "dataurl",
|
|
864
|
-
".webp": "dataurl",
|
|
865
|
-
".ico": "dataurl",
|
|
866
945
|
};
|
|
867
946
|
|
|
868
947
|
const banner = {
|
|
@@ -988,8 +1067,9 @@ const serverReferencesPlugin = {
|
|
|
988
1067
|
transformed += `import { registerServerReference } from "react-server-dom-webpack/server.edge";\n`;
|
|
989
1068
|
|
|
990
1069
|
for (const name of exports) {
|
|
991
|
-
|
|
992
|
-
|
|
1070
|
+
const localIdent = name === "default" ? sfResult.defaultExportIdentifier : name;
|
|
1071
|
+
if (localIdent) {
|
|
1072
|
+
transformed += `registerServerReference(${localIdent}, ${JSON.stringify(relativeFileUrl)}, ${JSON.stringify(name)});\n`;
|
|
993
1073
|
}
|
|
994
1074
|
}
|
|
995
1075
|
|
|
@@ -1020,31 +1100,15 @@ const serverReferencesPluginSsr = {
|
|
|
1020
1100
|
|
|
1021
1101
|
if (!hasServerFunctions(code)) return null;
|
|
1022
1102
|
|
|
1023
|
-
const sfResult = transformServerFunctions(code, args.path);
|
|
1024
|
-
if (!sfResult.actions || sfResult.actions.length === 0) return null;
|
|
1025
|
-
|
|
1026
|
-
const transformedCode = sfResult.code;
|
|
1027
|
-
const exports = sfResult.actions;
|
|
1028
1103
|
const absPath = path.resolve(args.path);
|
|
1029
1104
|
const relPath = path.relative(projectRoot, absPath).replace(/\\/g, "/");
|
|
1030
1105
|
const relativeFileUrl = "file:///" + relPath;
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
transformed += `import { registerServerReference } from "react-server-dom-webpack/client.edge";\n`;
|
|
1034
|
-
|
|
1035
|
-
for (const name of exports) {
|
|
1036
|
-
if (name !== "default") {
|
|
1037
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(relativeFileUrl + "#" + name)});\n`;
|
|
1038
|
-
transformed += `registerServerReference(${name}, ${JSON.stringify(pathToFileURL(absPath).href + "#" + name)});\n`;
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
|
|
1042
|
-
const ext = path.extname(args.path);
|
|
1043
|
-
const loader = ext === ".ts" ? "ts" : ext === ".tsx" ? "tsx" : ext === ".jsx" ? "jsx" : "js";
|
|
1106
|
+
const stubModule = buildSsrServerReferenceModule(code, args.path, relativeFileUrl);
|
|
1107
|
+
if (!stubModule) return null;
|
|
1044
1108
|
|
|
1045
1109
|
return {
|
|
1046
|
-
contents:
|
|
1047
|
-
loader,
|
|
1110
|
+
contents: stubModule,
|
|
1111
|
+
loader: "js",
|
|
1048
1112
|
};
|
|
1049
1113
|
});
|
|
1050
1114
|
},
|
|
@@ -1054,6 +1118,13 @@ const rscOutfile = path.join(bunDir, "rsc-engine.js");
|
|
|
1054
1118
|
const ssrOutfile = path.join(bunDir, "ssr-engine.js");
|
|
1055
1119
|
const finalOutfile = path.join(bunDir, "server.js");
|
|
1056
1120
|
|
|
1121
|
+
const serverCssModulesPlugin = createServerCssModulesPlugin({ projectRoot });
|
|
1122
|
+
const serverAssetPlugin = createServerAssetPlugin({ projectRoot, dinouConfig });
|
|
1123
|
+
const serverTsconfigAliasesPlugin = esbuildTsconfigAliasesPlugin({
|
|
1124
|
+
projectRoot,
|
|
1125
|
+
assetRegex: getAssetExtensionsInfo(dinouConfig, projectRoot).regex,
|
|
1126
|
+
});
|
|
1127
|
+
|
|
1057
1128
|
try {
|
|
1058
1129
|
// Pass A: RSC Engine
|
|
1059
1130
|
console.log(" ⚡ Bundling Pass A (RSC bun) & Pass B (SSR bun)...");
|
|
@@ -1065,18 +1136,23 @@ try {
|
|
|
1065
1136
|
target: "es2022",
|
|
1066
1137
|
platform: "neutral",
|
|
1067
1138
|
mainFields: ["module", "main"],
|
|
1068
|
-
conditions: ["bun", "worker", "react-server"],
|
|
1139
|
+
conditions: ["bun", "worker", "react-server", "style"],
|
|
1069
1140
|
external: externalList,
|
|
1070
|
-
plugins: [clientReferencesPlugin, serverReferencesPlugin],
|
|
1141
|
+
plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, clientReferencesPlugin, serverReferencesPlugin, serverCssModulesPlugin, serverAssetPlugin],
|
|
1071
1142
|
alias: commonAlias,
|
|
1072
1143
|
loader: commonLoader,
|
|
1073
1144
|
jsx: "automatic",
|
|
1074
1145
|
inject: setupFiles.length > 0 ? setupFiles : undefined,
|
|
1075
|
-
define: {
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1146
|
+
define: getEsbuildPublicEnvDefines({
|
|
1147
|
+
mode: "production",
|
|
1148
|
+
defineProcessEnvObject: false,
|
|
1149
|
+
extra: {
|
|
1150
|
+
DINOU_RUNTIME: "bun-bundle",
|
|
1151
|
+
DINOU_BUILD_TOOL: isWebpackBuild
|
|
1152
|
+
? "webpack"
|
|
1153
|
+
: process.env.DINOU_BUILD_TOOL || "esbuild",
|
|
1154
|
+
},
|
|
1155
|
+
}),
|
|
1080
1156
|
logLevel: "warning",
|
|
1081
1157
|
});
|
|
1082
1158
|
|
|
@@ -1089,18 +1165,25 @@ try {
|
|
|
1089
1165
|
target: "es2022",
|
|
1090
1166
|
platform: "neutral",
|
|
1091
1167
|
mainFields: ["module", "main"],
|
|
1092
|
-
conditions: ["bun", "worker", "browser"],
|
|
1168
|
+
conditions: ["bun", "worker", "browser", "style"],
|
|
1093
1169
|
external: externalList,
|
|
1094
|
-
plugins: [serverReferencesPluginSsr],
|
|
1170
|
+
plugins: [esbuildContextualDinouPlugin({ projectRoot }), serverTsconfigAliasesPlugin, serverReferencesPluginSsr, serverCssModulesPlugin, serverAssetPlugin],
|
|
1095
1171
|
alias: commonAlias,
|
|
1096
1172
|
loader: commonLoader,
|
|
1097
1173
|
jsx: "automatic",
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1174
|
+
define: getEsbuildPublicEnvDefines({
|
|
1175
|
+
mode: "production",
|
|
1176
|
+
defineProcessEnvObject: true,
|
|
1177
|
+
extra: {
|
|
1178
|
+
DINOU_RUNTIME: "bun-bundle",
|
|
1179
|
+
DINOU_BUILD_TOOL: isWebpackBuild
|
|
1180
|
+
? "webpack"
|
|
1181
|
+
: process.env.DINOU_BUILD_TOOL || "esbuild",
|
|
1182
|
+
...(process.env.DINOU_DEBUG
|
|
1183
|
+
? { DINOU_DEBUG: process.env.DINOU_DEBUG }
|
|
1184
|
+
: {}),
|
|
1185
|
+
},
|
|
1186
|
+
}),
|
|
1104
1187
|
logLevel: "warning",
|
|
1105
1188
|
});
|
|
1106
1189
|
|
|
@@ -1117,9 +1200,10 @@ try {
|
|
|
1117
1200
|
conditions: ["bun", "worker", "browser"],
|
|
1118
1201
|
external: externalList,
|
|
1119
1202
|
banner,
|
|
1120
|
-
|
|
1203
|
+
plugins: [serverTsconfigAliasesPlugin, serverAssetPlugin],
|
|
1121
1204
|
alias: commonAlias,
|
|
1122
1205
|
loader: commonLoader,
|
|
1206
|
+
jsx: "automatic",
|
|
1123
1207
|
define: {
|
|
1124
1208
|
"process.env.NODE_ENV": '"production"',
|
|
1125
1209
|
"process.env.DINOU_RUNTIME": '"bun-bundle"',
|