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
|
@@ -1,108 +1,539 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
statSync,
|
|
6
|
+
writeFileSync,
|
|
7
|
+
} from "node:fs";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
9
|
import { createRequire } from "node:module";
|
|
5
10
|
|
|
6
|
-
|
|
11
|
+
let require = null;
|
|
12
|
+
let dinouPackageRoot = null;
|
|
13
|
+
try {
|
|
14
|
+
if (typeof import.meta !== "undefined" && import.meta.url) {
|
|
15
|
+
require = createRequire(import.meta.url);
|
|
16
|
+
dinouPackageRoot = path.resolve(
|
|
17
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
18
|
+
".."
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {}
|
|
22
|
+
|
|
23
|
+
export const DINOU_CONFIG_FILENAMES = [
|
|
24
|
+
"dinou.config.ts",
|
|
25
|
+
"dinou.config.mjs",
|
|
26
|
+
"dinou.config.js",
|
|
27
|
+
"dinou.config.cjs",
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
const ROOT_SETUP_FILENAMES = new Set([
|
|
31
|
+
"dinou.setup.mjs",
|
|
32
|
+
"dinou.setup.js",
|
|
33
|
+
"dinou.setup.ts",
|
|
34
|
+
]);
|
|
7
35
|
|
|
8
36
|
let dinouConfig = { plugins: [] };
|
|
9
|
-
|
|
37
|
+
const dinouConfigPromisesByCwd = new Map();
|
|
38
|
+
const devConfigCacheByCwd = new Map();
|
|
39
|
+
let devImportCounter = 0;
|
|
40
|
+
const AUTO_LOADED_PROD_CONFIG = Symbol.for("dinou.autoLoadedProdConfig");
|
|
10
41
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
42
|
+
function resolveCwd(customCwd) {
|
|
43
|
+
return path.resolve(
|
|
44
|
+
customCwd ||
|
|
45
|
+
(typeof process !== "undefined" && typeof process.cwd === "function"
|
|
46
|
+
? process.cwd()
|
|
47
|
+
: ".")
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function isActiveDinouDevServer() {
|
|
52
|
+
if (
|
|
53
|
+
typeof globalThis !== "undefined" &&
|
|
54
|
+
Boolean(globalThis.__DINOU_DEV__)
|
|
55
|
+
) {
|
|
56
|
+
return true;
|
|
14
57
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
58
|
+
if (typeof process !== "undefined" && process.env) {
|
|
59
|
+
return process.env.DINOU_DEV === "true";
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function isDevEnvironment() {
|
|
65
|
+
if (isActiveDinouDevServer()) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
if (typeof process !== "undefined" && process.env) {
|
|
69
|
+
return process.env.NODE_ENV !== "production";
|
|
70
|
+
}
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Finds the active `dinou.config.{ts,mjs,js,cjs}` file in `customCwd`,
|
|
76
|
+
* following Dinou's deterministic extension precedence.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} [customCwd]
|
|
79
|
+
* @returns {string | null}
|
|
80
|
+
*/
|
|
81
|
+
export function findDinouConfigFile(customCwd) {
|
|
82
|
+
const cwd = resolveCwd(customCwd);
|
|
83
|
+
for (const filename of DINOU_CONFIG_FILENAMES) {
|
|
84
|
+
const candidate = path.resolve(cwd, filename);
|
|
85
|
+
if (existsSync(candidate)) {
|
|
86
|
+
return candidate;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Checks whether `filePath` is a root `dinou.config.*` or `dinou.setup.*` file.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} filePath
|
|
96
|
+
* @param {string} [projectRoot]
|
|
97
|
+
* @returns {boolean}
|
|
98
|
+
*/
|
|
99
|
+
export function isWatchedDinouConfigOrSetupFile(filePath, projectRoot) {
|
|
100
|
+
if (!filePath) return false;
|
|
101
|
+
const root = resolveCwd(projectRoot);
|
|
102
|
+
const resolved = path.resolve(filePath);
|
|
103
|
+
if (path.dirname(resolved).toLowerCase() !== root.toLowerCase()) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const base = path.basename(resolved).toLowerCase();
|
|
107
|
+
return (
|
|
108
|
+
DINOU_CONFIG_FILENAMES.includes(base) || ROOT_SETUP_FILENAMES.has(base)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
39
111
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Clears cached Dinou configuration for `customCwd` (or all directories when omitted).
|
|
114
|
+
* Used by `dinou dev` live hot-reloading and test suites.
|
|
115
|
+
*
|
|
116
|
+
* @param {string} [customCwd]
|
|
117
|
+
*/
|
|
118
|
+
export function clearDinouConfigCache(customCwd) {
|
|
119
|
+
if (customCwd) {
|
|
120
|
+
const cwd = resolveCwd(customCwd);
|
|
121
|
+
dinouConfigPromisesByCwd.delete(cwd);
|
|
122
|
+
devConfigCacheByCwd.delete(cwd);
|
|
123
|
+
if (
|
|
124
|
+
typeof globalThis !== "undefined" &&
|
|
125
|
+
!globalThis.__DINOU_AOT_CONFIG__ &&
|
|
126
|
+
(!globalThis.__DINOU_CONFIG_CWD__ ||
|
|
127
|
+
globalThis.__DINOU_CONFIG_CWD__ === cwd)
|
|
128
|
+
) {
|
|
129
|
+
delete globalThis.__DINOU_CONFIG__;
|
|
130
|
+
delete globalThis.__DINOU_CONFIG_CWD__;
|
|
131
|
+
}
|
|
132
|
+
} else {
|
|
133
|
+
dinouConfigPromisesByCwd.clear();
|
|
134
|
+
devConfigCacheByCwd.clear();
|
|
135
|
+
if (
|
|
136
|
+
typeof globalThis !== "undefined" &&
|
|
137
|
+
!globalThis.__DINOU_AOT_CONFIG__
|
|
138
|
+
) {
|
|
139
|
+
delete globalThis.__DINOU_CONFIG__;
|
|
140
|
+
delete globalThis.__DINOU_CONFIG_CWD__;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getLocalEsbuild(cwd) {
|
|
146
|
+
if (
|
|
147
|
+
typeof process === "undefined" ||
|
|
148
|
+
!process.versions ||
|
|
149
|
+
!process.versions.node ||
|
|
150
|
+
(process.env && process.env.DINOU_RUNTIME === "edge")
|
|
151
|
+
) {
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
const esbuildPkg = "esbuild";
|
|
155
|
+
try {
|
|
156
|
+
if (typeof require === "function") {
|
|
157
|
+
return require(esbuildPkg);
|
|
158
|
+
}
|
|
159
|
+
} catch (e) {}
|
|
160
|
+
try {
|
|
161
|
+
const projectReq = createRequire(path.join(cwd, "package.json"));
|
|
162
|
+
return projectReq(esbuildPkg);
|
|
163
|
+
} catch (e) {}
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function resolveActiveDinouRoot(cwd) {
|
|
168
|
+
const ejectedCandidate = path.resolve(cwd, "dinou");
|
|
169
|
+
if (
|
|
170
|
+
existsSync(ejectedCandidate) &&
|
|
171
|
+
existsSync(path.join(ejectedCandidate, "core", "config.js"))
|
|
172
|
+
) {
|
|
173
|
+
return ejectedCandidate;
|
|
174
|
+
}
|
|
175
|
+
if (
|
|
176
|
+
dinouPackageRoot &&
|
|
177
|
+
existsSync(path.join(dinouPackageRoot, "core", "config.js"))
|
|
178
|
+
) {
|
|
179
|
+
return dinouPackageRoot;
|
|
180
|
+
}
|
|
181
|
+
const nmNested = path.resolve(cwd, "node_modules", "dinou", "dinou");
|
|
182
|
+
if (existsSync(path.join(nmNested, "core", "config.js"))) {
|
|
183
|
+
return nmNested;
|
|
184
|
+
}
|
|
185
|
+
const nmFlat = path.resolve(cwd, "node_modules", "dinou");
|
|
186
|
+
if (existsSync(path.join(nmFlat, "core", "config.js"))) {
|
|
187
|
+
return nmFlat;
|
|
188
|
+
}
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function createEsbuildDinouConfigPlugin(cwd, outDir = cwd) {
|
|
193
|
+
const activeDinouRoot = resolveActiveDinouRoot(cwd);
|
|
194
|
+
return {
|
|
195
|
+
name: "dinou-config-alias",
|
|
196
|
+
setup(build) {
|
|
197
|
+
build.onResolve({ filter: /^dinou(?:\/config)?$/ }, () => {
|
|
198
|
+
if (activeDinouRoot) {
|
|
199
|
+
return { path: path.join(activeDinouRoot, "core", "config.js") };
|
|
200
|
+
}
|
|
201
|
+
return { path: "dinou/config", external: true };
|
|
202
|
+
});
|
|
203
|
+
build.onResolve({ filter: /^dinou\/server$/ }, () => {
|
|
204
|
+
if (activeDinouRoot) {
|
|
205
|
+
const serverAbs = path.join(activeDinouRoot, "server.js");
|
|
206
|
+
const rel = path.relative(outDir, serverAbs).replace(/\\/g, "/");
|
|
207
|
+
if (rel && !path.isAbsolute(rel)) {
|
|
208
|
+
return {
|
|
209
|
+
path: rel.startsWith(".") ? rel : "./" + rel,
|
|
210
|
+
external: true,
|
|
211
|
+
};
|
|
84
212
|
}
|
|
85
|
-
|
|
86
|
-
dinouConfig = cfg;
|
|
87
|
-
return cfg;
|
|
88
|
-
} catch (err) {
|
|
89
|
-
console.error(`[Dinou] Error loading ${filename}:`, err);
|
|
213
|
+
return { path: serverAbs };
|
|
90
214
|
}
|
|
215
|
+
return { path: "dinou/server", external: true };
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Emits a pre-transpiled pure-ESM server bootstrap and bundler entry wrappers
|
|
223
|
+
* into `.dinou/dist1/` so Esbuild, Rollup, and Webpack production server builds
|
|
224
|
+
* (`.dinou/dist1/server/handler.js` & `netlify.js`) as well as `--omit=dev`
|
|
225
|
+
* Node runtimes execute `setupFiles` and load `dinou.config.*` without needing
|
|
226
|
+
* `esbuild` or TypeScript loaders at runtime.
|
|
227
|
+
*
|
|
228
|
+
* @param {object} options
|
|
229
|
+
* @param {string} [options.projectRoot]
|
|
230
|
+
* @param {string[]} [options.setupFiles]
|
|
231
|
+
* @param {string} options.handlerPath
|
|
232
|
+
* @param {string} options.netlifyPath
|
|
233
|
+
* @returns {Promise<{ handlerEntry: string, netlifyEntry: string, bootstrapPath: string | null }>}
|
|
234
|
+
*/
|
|
235
|
+
export async function prepareDist1ServerEntries({
|
|
236
|
+
projectRoot,
|
|
237
|
+
setupFiles = [],
|
|
238
|
+
handlerPath,
|
|
239
|
+
netlifyPath,
|
|
240
|
+
}) {
|
|
241
|
+
const cwd = resolveCwd(projectRoot);
|
|
242
|
+
const configFile = findDinouConfigFile(cwd);
|
|
243
|
+
if ((!setupFiles || setupFiles.length === 0) && !configFile) {
|
|
244
|
+
return {
|
|
245
|
+
handlerEntry: handlerPath,
|
|
246
|
+
netlifyEntry: netlifyPath,
|
|
247
|
+
bootstrapPath: null,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const dist1Dir = path.resolve(cwd, ".dinou", "dist1");
|
|
252
|
+
const entriesDir = path.join(dist1Dir, "_entries");
|
|
253
|
+
mkdirSync(entriesDir, { recursive: true });
|
|
254
|
+
|
|
255
|
+
const rawBootstrapPath = path.join(entriesDir, "raw-server-bootstrap.mjs");
|
|
256
|
+
const compiledBootstrapPath = path.join(dist1Dir, "dinou-server-bootstrap.mjs");
|
|
257
|
+
|
|
258
|
+
let rawCode = "// Auto-generated Dinou server bootstrap (setupFiles + dinou.config)\n";
|
|
259
|
+
for (const sf of setupFiles) {
|
|
260
|
+
rawCode += `import ${JSON.stringify(sf.replace(/\\/g, "/"))};\n`;
|
|
261
|
+
}
|
|
262
|
+
if (configFile) {
|
|
263
|
+
rawCode += `import * as __dinouConfigMod from ${JSON.stringify(configFile.replace(/\\/g, "/"))};\n`;
|
|
264
|
+
rawCode += `const __resolvedDinouCfg = (__dinouConfigMod && __dinouConfigMod.default) ? __dinouConfigMod.default : (__dinouConfigMod || { plugins: [] });\n`;
|
|
265
|
+
rawCode += `globalThis.__DINOU_AOT_CONFIG__ = __resolvedDinouCfg;\n`;
|
|
266
|
+
rawCode += `globalThis.__DINOU_CONFIG__ = __resolvedDinouCfg;\n`;
|
|
267
|
+
rawCode += `globalThis.__DINOU_CONFIG_CWD__ = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : "";\n`;
|
|
268
|
+
rawCode += `export default __resolvedDinouCfg;\n`;
|
|
269
|
+
} else {
|
|
270
|
+
rawCode += `export default { plugins: [] };\n`;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
writeFileSync(rawBootstrapPath, rawCode, "utf8");
|
|
274
|
+
|
|
275
|
+
const esbuild = getLocalEsbuild(cwd);
|
|
276
|
+
if (esbuild && typeof esbuild.build === "function") {
|
|
277
|
+
const { esbuildTsconfigAliasesPlugin } = await import(
|
|
278
|
+
"./tsconfig-aliases.js"
|
|
279
|
+
);
|
|
280
|
+
await esbuild.build({
|
|
281
|
+
entryPoints: [rawBootstrapPath],
|
|
282
|
+
outfile: compiledBootstrapPath,
|
|
283
|
+
bundle: true,
|
|
284
|
+
format: "esm",
|
|
285
|
+
platform: "node",
|
|
286
|
+
target: "node20",
|
|
287
|
+
packages: "external",
|
|
288
|
+
jsx: "automatic",
|
|
289
|
+
loader: {
|
|
290
|
+
".js": "jsx",
|
|
291
|
+
".jsx": "jsx",
|
|
292
|
+
".ts": "ts",
|
|
293
|
+
".tsx": "tsx",
|
|
294
|
+
".json": "json",
|
|
295
|
+
".css": "empty",
|
|
296
|
+
},
|
|
297
|
+
plugins: [
|
|
298
|
+
createEsbuildDinouConfigPlugin(cwd, dist1Dir),
|
|
299
|
+
esbuildTsconfigAliasesPlugin({
|
|
300
|
+
projectRoot: cwd,
|
|
301
|
+
skipAssets: false,
|
|
302
|
+
}),
|
|
303
|
+
],
|
|
304
|
+
});
|
|
305
|
+
} else {
|
|
306
|
+
writeFileSync(compiledBootstrapPath, rawCode, "utf8");
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const bootstrapSlash = compiledBootstrapPath.replace(/\\/g, "/");
|
|
310
|
+
const handlerSlash = handlerPath.replace(/\\/g, "/");
|
|
311
|
+
const netlifySlash = netlifyPath.replace(/\\/g, "/");
|
|
312
|
+
|
|
313
|
+
const handlerWrapperPath = path.join(entriesDir, "handler.mjs");
|
|
314
|
+
const netlifyWrapperPath = path.join(entriesDir, "netlify.mjs");
|
|
315
|
+
|
|
316
|
+
writeFileSync(
|
|
317
|
+
handlerWrapperPath,
|
|
318
|
+
`import * as __boot from ${JSON.stringify(bootstrapSlash)};\nglobalThis.__DINOU_BOOTSTRAPPED__ = Boolean(__boot);\nexport * from ${JSON.stringify(handlerSlash)};\nexport { default } from ${JSON.stringify(handlerSlash)};\n`,
|
|
319
|
+
"utf8"
|
|
320
|
+
);
|
|
321
|
+
writeFileSync(
|
|
322
|
+
netlifyWrapperPath,
|
|
323
|
+
`import * as __boot from ${JSON.stringify(bootstrapSlash)};\nglobalThis.__DINOU_BOOTSTRAPPED__ = Boolean(__boot);\nexport * from ${JSON.stringify(netlifySlash)};\nexport { default } from ${JSON.stringify(netlifySlash)};\n`,
|
|
324
|
+
"utf8"
|
|
325
|
+
);
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
handlerEntry: handlerWrapperPath,
|
|
329
|
+
netlifyEntry: netlifyWrapperPath,
|
|
330
|
+
bootstrapPath: compiledBootstrapPath,
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
async function loadConfigFromDisk(cwd, isDev, configFile) {
|
|
335
|
+
if (!configFile) {
|
|
336
|
+
const prebuiltDist1 = path.resolve(
|
|
337
|
+
cwd,
|
|
338
|
+
".dinou",
|
|
339
|
+
"dist1",
|
|
340
|
+
"dinou-server-bootstrap.mjs"
|
|
341
|
+
);
|
|
342
|
+
if (!isDev && existsSync(prebuiltDist1)) {
|
|
343
|
+
try {
|
|
344
|
+
const mod = await import(pathToFileURL(prebuiltDist1).href);
|
|
345
|
+
const cfg = mod && mod.default ? mod.default : mod || { plugins: [] };
|
|
346
|
+
dinouConfig = cfg;
|
|
347
|
+
return cfg;
|
|
348
|
+
} catch (e) {}
|
|
349
|
+
}
|
|
350
|
+
const fallback = { plugins: [] };
|
|
351
|
+
dinouConfig = fallback;
|
|
352
|
+
return fallback;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const filename = path.basename(configFile);
|
|
356
|
+
try {
|
|
357
|
+
let loaded;
|
|
358
|
+
const prebuiltDist1 = path.resolve(
|
|
359
|
+
cwd,
|
|
360
|
+
".dinou",
|
|
361
|
+
"dist1",
|
|
362
|
+
"dinou-server-bootstrap.mjs"
|
|
363
|
+
);
|
|
364
|
+
const esbuild = getLocalEsbuild(cwd);
|
|
365
|
+
|
|
366
|
+
if (!isDev && !esbuild && existsSync(prebuiltDist1)) {
|
|
367
|
+
loaded = await import(pathToFileURL(prebuiltDist1).href);
|
|
368
|
+
} else if (esbuild && typeof esbuild.build === "function") {
|
|
369
|
+
const outDir = path.resolve(cwd, ".dinou");
|
|
370
|
+
if (!existsSync(outDir)) {
|
|
371
|
+
mkdirSync(outDir, { recursive: true });
|
|
372
|
+
}
|
|
373
|
+
const bundledPath = path.resolve(outDir, "dinou.config.bundled.mjs");
|
|
374
|
+
const { esbuildTsconfigAliasesPlugin } = await import(
|
|
375
|
+
"./tsconfig-aliases.js"
|
|
376
|
+
);
|
|
377
|
+
await esbuild.build({
|
|
378
|
+
entryPoints: [configFile],
|
|
379
|
+
outfile: bundledPath,
|
|
380
|
+
bundle: true,
|
|
381
|
+
format: "esm",
|
|
382
|
+
platform: "node",
|
|
383
|
+
packages: "external",
|
|
384
|
+
jsx: "automatic",
|
|
385
|
+
sourcemap: "inline",
|
|
386
|
+
plugins: [
|
|
387
|
+
createEsbuildDinouConfigPlugin(cwd, outDir),
|
|
388
|
+
esbuildTsconfigAliasesPlugin({
|
|
389
|
+
projectRoot: cwd,
|
|
390
|
+
skipAssets: false,
|
|
391
|
+
}),
|
|
392
|
+
],
|
|
393
|
+
});
|
|
394
|
+
const cacheBuster = isDev
|
|
395
|
+
? `?t=${Date.now()}-${++devImportCounter}`
|
|
396
|
+
: "";
|
|
397
|
+
loaded = await import(pathToFileURL(bundledPath).href + cacheBuster);
|
|
398
|
+
} else if (!isDev && existsSync(prebuiltDist1)) {
|
|
399
|
+
loaded = await import(pathToFileURL(prebuiltDist1).href);
|
|
400
|
+
} else if (configFile.endsWith(".mjs")) {
|
|
401
|
+
const cacheBuster = isDev
|
|
402
|
+
? `?t=${Date.now()}-${++devImportCounter}`
|
|
403
|
+
: "";
|
|
404
|
+
loaded = await import(pathToFileURL(configFile).href + cacheBuster);
|
|
405
|
+
} else {
|
|
406
|
+
const nodeReq =
|
|
407
|
+
typeof globalThis !== "undefined" &&
|
|
408
|
+
typeof globalThis.__dinou_require__ === "function"
|
|
409
|
+
? globalThis.__dinou_require__
|
|
410
|
+
: typeof require === "function"
|
|
411
|
+
? require
|
|
412
|
+
: null;
|
|
413
|
+
if (nodeReq && !isDev) {
|
|
414
|
+
try {
|
|
415
|
+
loaded = nodeReq(configFile);
|
|
416
|
+
} catch (e) {
|
|
417
|
+
loaded = await import(pathToFileURL(configFile).href);
|
|
418
|
+
}
|
|
419
|
+
} else {
|
|
420
|
+
const cacheBuster = isDev
|
|
421
|
+
? `?t=${Date.now()}-${++devImportCounter}`
|
|
422
|
+
: "";
|
|
423
|
+
loaded = await import(pathToFileURL(configFile).href + cacheBuster);
|
|
91
424
|
}
|
|
92
425
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
426
|
+
|
|
427
|
+
const cfg =
|
|
428
|
+
loaded && loaded.default ? loaded.default : loaded || { plugins: [] };
|
|
429
|
+
dinouConfig = cfg;
|
|
430
|
+
if (!isDev && typeof globalThis !== "undefined") {
|
|
431
|
+
if (cfg && typeof cfg === "object") {
|
|
432
|
+
try {
|
|
433
|
+
Object.defineProperty(cfg, AUTO_LOADED_PROD_CONFIG, {
|
|
434
|
+
value: true,
|
|
435
|
+
configurable: true,
|
|
436
|
+
});
|
|
437
|
+
} catch (e) {}
|
|
438
|
+
}
|
|
439
|
+
globalThis.__DINOU_CONFIG__ = cfg;
|
|
440
|
+
globalThis.__DINOU_CONFIG_CWD__ = cwd;
|
|
441
|
+
}
|
|
442
|
+
return cfg;
|
|
443
|
+
} catch (err) {
|
|
444
|
+
console.error(`[Dinou] Error loading ${filename}:`, err);
|
|
445
|
+
const fallback = { plugins: [] };
|
|
446
|
+
dinouConfig = fallback;
|
|
447
|
+
return fallback;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
async function getDinouConfig(customCwd) {
|
|
452
|
+
const cwd = resolveCwd(customCwd);
|
|
453
|
+
const isDev = isDevEnvironment();
|
|
454
|
+
|
|
455
|
+
if (
|
|
456
|
+
typeof globalThis !== "undefined" &&
|
|
457
|
+
globalThis.__DINOU_AOT_CONFIG__ &&
|
|
458
|
+
(!globalThis.__DINOU_CONFIG_CWD__ ||
|
|
459
|
+
globalThis.__DINOU_CONFIG_CWD__ === cwd)
|
|
460
|
+
) {
|
|
461
|
+
dinouConfig = globalThis.__DINOU_AOT_CONFIG__;
|
|
462
|
+
return globalThis.__DINOU_AOT_CONFIG__;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (
|
|
466
|
+
typeof globalThis !== "undefined" &&
|
|
467
|
+
globalThis.__DINOU_CONFIG__ &&
|
|
468
|
+
!isActiveDinouDevServer() &&
|
|
469
|
+
(!isDev || !globalThis.__DINOU_CONFIG__[AUTO_LOADED_PROD_CONFIG]) &&
|
|
470
|
+
(!globalThis.__DINOU_CONFIG_CWD__ ||
|
|
471
|
+
globalThis.__DINOU_CONFIG_CWD__ === cwd)
|
|
472
|
+
) {
|
|
473
|
+
dinouConfig = globalThis.__DINOU_CONFIG__;
|
|
474
|
+
return globalThis.__DINOU_CONFIG__;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (!isDev && dinouConfigPromisesByCwd.has(cwd)) {
|
|
478
|
+
return dinouConfigPromisesByCwd.get(cwd);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (isDev) {
|
|
482
|
+
const configFile = findDinouConfigFile(cwd);
|
|
483
|
+
let mtimeMs = 0;
|
|
484
|
+
if (configFile) {
|
|
485
|
+
try {
|
|
486
|
+
mtimeMs = statSync(configFile).mtimeMs;
|
|
487
|
+
} catch (e) {}
|
|
488
|
+
}
|
|
489
|
+
const cachedDev = devConfigCacheByCwd.get(cwd);
|
|
490
|
+
if (
|
|
491
|
+
cachedDev &&
|
|
492
|
+
cachedDev.filePath === configFile &&
|
|
493
|
+
cachedDev.mtimeMs === mtimeMs
|
|
494
|
+
) {
|
|
495
|
+
if (cachedDev.promise) return cachedDev.promise;
|
|
496
|
+
dinouConfig = cachedDev.config;
|
|
497
|
+
return cachedDev.config;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
const devPromise = loadConfigFromDisk(cwd, true, configFile).then((cfg) => {
|
|
501
|
+
devConfigCacheByCwd.set(cwd, {
|
|
502
|
+
filePath: configFile,
|
|
503
|
+
mtimeMs,
|
|
504
|
+
config: cfg,
|
|
505
|
+
promise: null,
|
|
506
|
+
});
|
|
507
|
+
return cfg;
|
|
508
|
+
});
|
|
509
|
+
devConfigCacheByCwd.set(cwd, {
|
|
510
|
+
filePath: configFile,
|
|
511
|
+
mtimeMs,
|
|
512
|
+
config: null,
|
|
513
|
+
promise: devPromise,
|
|
514
|
+
});
|
|
515
|
+
return devPromise;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const configFile = findDinouConfigFile(cwd);
|
|
519
|
+
const loadPromise = loadConfigFromDisk(cwd, false, configFile);
|
|
520
|
+
dinouConfigPromisesByCwd.set(cwd, loadPromise);
|
|
521
|
+
return loadPromise;
|
|
96
522
|
}
|
|
97
523
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
524
|
+
if (
|
|
525
|
+
typeof globalThis !== "undefined" &&
|
|
526
|
+
(globalThis.__DINOU_AOT_CONFIG__ || globalThis.__DINOU_CONFIG__)
|
|
527
|
+
) {
|
|
528
|
+
dinouConfig = globalThis.__DINOU_AOT_CONFIG__ || globalThis.__DINOU_CONFIG__;
|
|
101
529
|
}
|
|
102
530
|
|
|
103
|
-
export {
|
|
104
|
-
getDinouConfig,
|
|
105
|
-
};
|
|
531
|
+
export { getDinouConfig };
|
|
106
532
|
export default {
|
|
107
533
|
getDinouConfig,
|
|
534
|
+
findDinouConfigFile,
|
|
535
|
+
isWatchedDinouConfigOrSetupFile,
|
|
536
|
+
clearDinouConfigCache,
|
|
537
|
+
prepareDist1ServerEntries,
|
|
538
|
+
DINOU_CONFIG_FILENAMES,
|
|
108
539
|
};
|
|
@@ -17,29 +17,19 @@ function isDevMode() {
|
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
function getOutputFolder() {
|
|
21
|
-
return isDevMode() ? ".dinou/public" : ".dinou/dist3";
|
|
22
|
-
}
|
|
23
|
-
|
|
24
20
|
function getClientManifestPath() {
|
|
25
|
-
const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
26
|
-
const outputFolder = getOutputFolder();
|
|
27
21
|
return path.resolve(
|
|
28
22
|
process.cwd(),
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
: `.dinou/react_client_manifest/react-client-manifest.json`
|
|
23
|
+
isDevMode() ? ".dinou/node-dev" : ".dinou/dist1",
|
|
24
|
+
"react-client-manifest.json"
|
|
32
25
|
);
|
|
33
26
|
}
|
|
34
27
|
|
|
35
28
|
function getServerFunctionsManifestPath() {
|
|
36
|
-
const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
|
|
37
|
-
const outputFolder = getOutputFolder();
|
|
38
29
|
return path.resolve(
|
|
39
30
|
process.cwd(),
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
: `.dinou/server_functions_manifest/server-functions-manifest.json`
|
|
31
|
+
isDevMode() ? ".dinou/node-dev" : ".dinou/dist1",
|
|
32
|
+
"server-functions-manifest.json"
|
|
43
33
|
);
|
|
44
34
|
}
|
|
45
35
|
|