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.
Files changed (166) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/README.md +157 -132
  3. package/dinou/adapters/bun.js +34 -5
  4. package/dinou/adapters/cloudflare.js +110 -17
  5. package/dinou/adapters/deno.js +46 -8
  6. package/dinou/adapters/netlify.js +86 -50
  7. package/dinou/adapters/node.js +8 -0
  8. package/dinou/assets.d.ts +32 -5
  9. package/dinou/bun/build.js +190 -106
  10. package/dinou/cli.js +992 -532
  11. package/dinou/cloudflare/build.js +187 -106
  12. package/dinou/compiled/autoprefixer/index.js +509 -517
  13. package/dinou/compiled/babel-core/index.js +738 -716
  14. package/dinou/compiled/babel-generator/index.js +341 -299
  15. package/dinou/compiled/babel-loader/index.js +766 -744
  16. package/dinou/compiled/babel-parser/index.js +2 -2
  17. package/dinou/compiled/babel-plugin-react-compiler/index.js +178 -178
  18. package/dinou/compiled/babel-plugin-syntax-import-meta/index.js +4 -4
  19. package/dinou/compiled/babel-preset-react/index.js +752 -730
  20. package/dinou/compiled/babel-preset-typescript/index.js +738 -716
  21. package/dinou/compiled/babel-traverse/index.js +463 -433
  22. package/dinou/compiled/babel-types/index.js +176 -176
  23. package/dinou/compiled/chokidar/index.js +4 -4
  24. package/dinou/compiled/commander/index.js +15 -15
  25. package/dinou/compiled/copy-webpack-plugin/index.js +433 -425
  26. package/dinou/compiled/css-loader/index.js +289 -289
  27. package/dinou/compiled/css-loader/runtime/api.js +85 -0
  28. package/dinou/compiled/css-loader/runtime/getUrl.js +26 -0
  29. package/dinou/compiled/css-loader/runtime/noSourceMaps.js +5 -0
  30. package/dinou/compiled/css-loader/runtime/package.json +3 -0
  31. package/dinou/compiled/css-loader/runtime/sourceMaps.js +16 -0
  32. package/dinou/compiled/fast-glob/index.js +5810 -0
  33. package/dinou/compiled/generic-names/index.js +16 -16
  34. package/dinou/compiled/mini-css-extract-plugin/{chunk-YYEJWYXE.js โ†’ chunk-R6DP5ZYM.js} +36 -36
  35. package/dinou/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +253 -0
  36. package/dinou/compiled/mini-css-extract-plugin/hmr/normalize-url.js +39 -0
  37. package/dinou/compiled/mini-css-extract-plugin/hmr/package.json +3 -0
  38. package/dinou/compiled/mini-css-extract-plugin/index.js +1 -1
  39. package/dinou/compiled/mini-css-extract-plugin/loader.js +5 -5
  40. package/dinou/compiled/postcss/index.js +83 -83
  41. package/dinou/compiled/postcss-import/index.js +147 -117
  42. package/dinou/compiled/postcss-modules/index.js +216 -216
  43. package/dinou/compiled/resolve/index.js +1224 -0
  44. package/dinou/compiled/rollup-plugin-babel/index.js +753 -731
  45. package/dinou/compiled/rollup-plugin-commonjs/index.js +43 -38
  46. package/dinou/compiled/rollup-plugin-delete/index.js +615 -253
  47. package/dinou/compiled/rollup-plugin-json/index.js +22 -18
  48. package/dinou/compiled/rollup-plugin-node-resolve/index.js +130 -100
  49. package/dinou/compiled/rollup-plugin-postcss/index.js +3299 -3277
  50. package/dinou/compiled/rollup-plugin-replace/index.js +34 -29
  51. package/dinou/compiled/tailwindcss-postcss/index.js +214 -211
  52. package/dinou/compiled/vendors-manifest.json +59 -83
  53. package/dinou/core/asset-extensions.js +482 -33
  54. package/dinou/core/bailout-proxy.js +21 -2
  55. package/dinou/core/build-static-pages.js +523 -371
  56. package/dinou/core/builtin-asset-extensions.js +63 -0
  57. package/dinou/core/cache-revalidate.js +449 -256
  58. package/dinou/core/cache-slot.js +289 -79
  59. package/dinou/core/client-webpack.jsx +470 -39
  60. package/dinou/core/client.jsx +402 -39
  61. package/dinou/core/config.js +3 -0
  62. package/dinou/core/copy-static-dirs.js +98 -0
  63. package/dinou/core/createScopedName.js +22 -4
  64. package/dinou/core/dinou-paths.js +1 -1
  65. package/dinou/core/discover-layouts.js +200 -0
  66. package/dinou/core/edge-ssr.js +1 -1
  67. package/dinou/core/ensure-vendor-mode.js +78 -19
  68. package/dinou/core/env.js +544 -0
  69. package/dinou/core/export-static.js +41 -9
  70. package/dinou/core/generate-route-types.js +989 -95
  71. package/dinou/core/generate-static-rsc.js +5 -6
  72. package/dinou/core/generate-static.js +45 -6
  73. package/dinou/core/get-abs-path-with-ext.js +217 -75
  74. package/dinou/core/get-asset-from-manifest.js +19 -8
  75. package/dinou/core/get-error-jsx.js +4 -5
  76. package/dinou/core/get-file-path-and-dynamic-params.js +561 -338
  77. package/dinou/core/get-jsx.js +220 -53
  78. package/dinou/core/handler.js +1647 -466
  79. package/dinou/core/import-module.js +7 -0
  80. package/dinou/core/layout-functions.js +72 -13
  81. package/dinou/core/link.jsx +34 -6
  82. package/dinou/core/load-dinou-config.js +520 -89
  83. package/dinou/core/manifest-provider.js +4 -14
  84. package/dinou/core/navigation-utils.js +141 -3
  85. package/dinou/core/navigation.js +134 -50
  86. package/dinou/core/node-middleware-runner.js +165 -0
  87. package/dinou/core/postcss-pipeline.js +236 -0
  88. package/dinou/core/ppr-context.js +114 -22
  89. package/dinou/core/ppr-runtime.js +391 -127
  90. package/dinou/core/redirect.jsx +1 -1
  91. package/dinou/core/render-jsx-to-client-jsx.js +216 -48
  92. package/dinou/core/request-context.js +59 -3
  93. package/dinou/core/resolve-contextual-dinou.js +523 -0
  94. package/dinou/core/resolve-setup-files.js +85 -27
  95. package/dinou/core/revalidating.js +10 -2
  96. package/dinou/core/route-generator.js +6 -2
  97. package/dinou/core/rsc-renderer.js +4 -1
  98. package/dinou/core/run-ssg.js +6 -0
  99. package/dinou/core/runtime-env.js +265 -0
  100. package/dinou/core/server-css-modules-plugin.js +155 -0
  101. package/dinou/core/server-function-proxy-webpack.js +27 -2
  102. package/dinou/core/server-function-proxy.js +27 -2
  103. package/dinou/core/slot.js +47 -2
  104. package/dinou/core/static-assets.js +503 -0
  105. package/dinou/core/storage-adapter.js +452 -24
  106. package/dinou/core/transform-server-functions.js +272 -24
  107. package/dinou/core/tsconfig-aliases.js +964 -0
  108. package/dinou/core/uneject.js +640 -0
  109. package/dinou/core/url-resolver.js +1 -1
  110. package/dinou/core/vfs.js +11 -2
  111. package/dinou/css.d.ts +4 -1
  112. package/dinou/deno/build.js +205 -153
  113. package/dinou/deno/seed-kv.js +4 -0
  114. package/dinou/env.d.ts +22 -2
  115. package/dinou/esbuild/build.js +40 -50
  116. package/dinou/esbuild/dev.js +33 -7
  117. package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.js +41 -16
  118. package/dinou/esbuild/helpers-esbuild/get-config-esbuild.js +51 -49
  119. package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.js +73 -60
  120. package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +35 -16
  121. package/dinou/esbuild/helpers-esbuild/write.js +13 -3
  122. package/dinou/esbuild/plugins-esbuild/assets-plugin.js +100 -238
  123. package/dinou/esbuild/plugins-esbuild/babel-react-compiler-plugin.js +73 -29
  124. package/dinou/esbuild/plugins-esbuild/css-processor-plugin.js +283 -91
  125. package/dinou/esbuild/plugins-esbuild/manifest-generator-plugin.js +3 -5
  126. package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.js +9 -3
  127. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +4 -3
  128. package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.js +10 -1
  129. package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +84 -21
  130. package/dinou/esbuild/react-refresh/esm-hmr/client.js +31 -10
  131. package/dinou/esbuild/react-refresh/esm-hmr-plugin.js +48 -18
  132. package/dinou/esbuild/react-refresh/is-react-refresh-boundary.js +9 -1
  133. package/dinou/esbuild/react-refresh/react-refresh-runtime.js +13 -7
  134. package/dinou/index.d.ts +1028 -88
  135. package/dinou/node/build.js +138 -74
  136. package/dinou/node/bundle-dual-engine.js +393 -131
  137. package/dinou/node/dev.js +1005 -275
  138. package/dinou/package.json +11 -34
  139. package/dinou/rollup/postcss.config.js +3 -4
  140. package/dinou/rollup/react-refresh/esm-hmr/client.js +31 -10
  141. package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +16 -13
  142. package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +53 -7
  143. package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +58 -20
  144. package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +16 -7
  145. package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +118 -42
  146. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +48 -36
  147. package/dinou/rollup/rollup.config.js +174 -101
  148. package/dinou/scripts/build-vendors.js +123 -33
  149. package/dinou/server.d.ts +126 -15
  150. package/dinou/webpack/helpers/get-webpack-entries.js +87 -41
  151. package/dinou/webpack/helpers/patch-webpack-internals.js +93 -1
  152. package/dinou/webpack/loaders/server-functions-loader.js +1 -1
  153. package/dinou/webpack/plugins/manifest-generator-plugin.js +27 -7
  154. package/dinou/webpack/plugins/server-functions-plugin.js +39 -12
  155. package/dinou/webpack/plugins/webpack-memory-plugin.js +25 -12
  156. package/dinou/webpack/postcss.config.js +3 -4
  157. package/dinou/webpack/webpack.config.js +408 -132
  158. package/eject.js +6 -224
  159. package/package.json +7 -9
  160. package/dinou/compiled/cross-env/index.js +0 -661
  161. package/dinou/compiled/dotenv/index.js +0 -375
  162. package/dinou/compiled/esbuild-copy-static-files/index.js +0 -63
  163. package/dinou/compiled/esbuild-tsconfig-paths/index.js +0 -1314
  164. package/dinou/compiled/rollup-plugin-copy/index.js +0 -12066
  165. package/dinou/compiled/rollup-plugin-tsconfig-paths/index.js +0 -569
  166. package/dinou/compiled/tsconfig-paths-webpack-plugin/index.js +0 -3956
@@ -1,12 +1,22 @@
1
1
  import path from "node:path";
2
2
  import fs from "node:fs";
3
- import { execSync } from "node:child_process";
3
+ import { spawnSync } from "node:child_process";
4
4
  import { fileURLToPath } from "node:url";
5
+ import { isUnvendorizedRequested } from "../core/ensure-vendor-mode.js";
6
+ import esbuild from "esbuild";
5
7
  import postcss from "#rollup-plugin-postcss";
8
+ import {
9
+ createBasePostCssPlugins,
10
+ getRegisteredCssUrlAssets,
11
+ } from "../core/postcss-pipeline.js";
6
12
  import babelModule from "#rollup/plugin-babel";
7
13
  import resolveModule from "#rollup/plugin-node-resolve";
8
14
  import commonjs from "#rollup/plugin-commonjs";
9
- import copy from "#rollup-plugin-copy";
15
+ import {
16
+ copyStaticDirectoriesToOutdir,
17
+ hasPublicStylesCss,
18
+ warnPublicStylesCssCollision,
19
+ } from "../core/copy-static-dirs.js";
10
20
  import reactClientManifest from "./rollup-plugins/rollup-plugin-react-client-manifest.js";
11
21
  import createScopedName from "../core/createScopedName.js";
12
22
  import replace from "#rollup/plugin-replace";
@@ -14,13 +24,29 @@ import json from "#rollup/plugin-json";
14
24
  import reactRefreshWrapModules from "./react-refresh/react-refresh-wrap-modules.js";
15
25
  import { esmHmrPlugin } from "./react-refresh/rollup-plugin-esm-hmr.js";
16
26
  import dinouAssetPlugin from "./rollup-plugins/dinou-asset-plugin.js";
17
- import tsconfigPaths from "#rollup-plugin-tsconfig-paths";
27
+ import { rollupTsconfigAliasesPlugin } from "../core/tsconfig-aliases.js";
18
28
  import serverFunctionsPlugin from "./rollup-plugins/rollup-plugin-server-functions.js";
19
- import { regex } from "../core/asset-extensions.js";
29
+ import { getAssetExtensionsInfo } from "../core/asset-extensions.js";
20
30
  import manifestGeneratorPlugin from "./rollup-plugins/manifest-generator-plugin.js";
21
31
  import rollupMemoryPlugin from "./rollup-plugins/rollup-plugin-memory.js";
22
32
  import rollupSwcPlugin from "./rollup-plugins/rollup-plugin-swc.js";
33
+ import { generateRouteTypes } from "../core/generate-route-types.js";
34
+ import { rollupContextualDinouPlugin } from "../core/resolve-contextual-dinou.js";
35
+ import { getDinouConfig } from "../core/load-dinou-config.js";
36
+ import {
37
+ loadEnvFiles,
38
+ getRollupPublicEnvReplacements,
39
+ } from "../core/env.js";
40
+ import presetReactModule from "#babel/preset-react";
41
+ import presetTypescriptModule from "#babel/preset-typescript";
42
+ import pluginSyntaxImportMetaModule from "#babel/plugin-syntax-import-meta";
43
+ import pluginReactCompilerModule from "#babel-plugin-react-compiler";
23
44
 
45
+ const unwrapBabel = (mod) => mod?.default ?? mod;
46
+ const presetReact = unwrapBabel(presetReactModule);
47
+ const presetTypescript = unwrapBabel(presetTypescriptModule);
48
+ const pluginSyntaxImportMeta = unwrapBabel(pluginSyntaxImportMetaModule);
49
+ const pluginReactCompiler = unwrapBabel(pluginReactCompilerModule);
24
50
  const babel = babelModule?.default || babelModule;
25
51
  const resolve = resolveModule?.default || resolveModule;
26
52
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
@@ -36,10 +62,36 @@ console.log(
36
62
 
37
63
  export default async function () {
38
64
  const isDevelopment = process.env.NODE_ENV !== "production";
65
+ const envMode = isDevelopment ? "development" : "production";
66
+ loadEnvFiles(process.cwd(), { mode: envMode });
67
+ const { exactValues: rollupExactEnv, objectValues: rollupObjectEnv } =
68
+ getRollupPublicEnvReplacements({ mode: envMode });
39
69
  const outputDirectory = isDevelopment ? ".dinou/public" : ".dinou/dist3";
40
70
  const shouldWriteToDisk = process.env.DINOU_WRITE_TO_DISK === "true" || !isDevelopment;
71
+ if (!isDevelopment && shouldWriteToDisk) {
72
+ try {
73
+ fs.rmSync(path.resolve(process.cwd(), ".dinou/dist1"), {
74
+ recursive: true,
75
+ force: true,
76
+ });
77
+ fs.rmSync(path.resolve(process.cwd(), ".dinou/netlify"), {
78
+ recursive: true,
79
+ force: true,
80
+ });
81
+ } catch (e) {}
82
+ }
41
83
  const serverFiles = new Set();
42
- const del = (await import("rollup-plugin-delete")).default;
84
+ const dinouConfig = await getDinouConfig();
85
+ const enableReactCompiler = dinouConfig?.reactCompiler !== false;
86
+ const { regex: activeAssetRegex } = getAssetExtensionsInfo(
87
+ dinouConfig,
88
+ process.cwd()
89
+ );
90
+ try {
91
+ generateRouteTypes(process.cwd());
92
+ } catch (e) {}
93
+ const delModule = await import("#rollup-plugin-delete");
94
+ const del = delModule?.default || delModule;
43
95
  const clientConfig = {
44
96
  input: isDevelopment
45
97
  ? {
@@ -120,6 +172,7 @@ export default async function () {
120
172
  perf: isDevelopment,
121
173
  treeshake: isDevelopment ? false : true,
122
174
  external: [
175
+ "/runtime.js",
123
176
  "/refresh.js",
124
177
  "/__hmr_client__.js",
125
178
  "/__SERVER_FUNCTION_PROXY__",
@@ -129,45 +182,65 @@ export default async function () {
129
182
  del({
130
183
  targets: [
131
184
  `${outputDirectory}/*`,
132
- ".dinou/react_client_manifest/*",
133
- ".dinou/server_functions_manifest/*",
185
+ ...(isDevelopment
186
+ ? [
187
+ ".dinou/node-dev/react-client-manifest.json",
188
+ ".dinou/node-dev/server-functions-manifest.json",
189
+ ".dinou/node-dev/manifest.json",
190
+ ]
191
+ : []),
134
192
  ],
135
193
  runOnce: true,
136
194
  hook: "buildStart",
137
195
  }),
138
- tsconfigPaths(),
196
+ rollupContextualDinouPlugin({ projectRoot: process.cwd() }),
197
+ dinouAssetPlugin({
198
+ include: activeAssetRegex,
199
+ dinouConfig,
200
+ projectRoot: process.cwd(),
201
+ }),
202
+ rollupTsconfigAliasesPlugin({
203
+ projectRoot: process.cwd(),
204
+ assetRegex: activeAssetRegex,
205
+ }),
139
206
  replace({
140
207
  preventAssignment: true,
141
- "process.env.NODE_ENV": JSON.stringify(
142
- isDevelopment ? "development" : "production",
143
- ),
208
+ values: rollupExactEnv,
209
+ }),
210
+ replace({
211
+ preventAssignment: true,
212
+ delimiters: ["(?<!\\.)\\b", "\\b"],
213
+ values: rollupObjectEnv,
144
214
  }),
145
215
  json(),
146
216
  resolve({
147
- extensions: [".js", ".jsx", ".ts", ".tsx"],
217
+ extensions: [".mjs", ".js", ".jsx", ".ts", ".tsx", ".cjs", ".json", ".css"],
218
+ exportConditions: ["style"],
148
219
  browser: true,
149
220
  preferBuiltins: false,
150
221
  }),
151
222
  commonjs({
152
223
  include: isEjected ? [/node_modules/, /dinou/] : /node_modules/,
153
224
  }),
154
- dinouAssetPlugin({
155
- include: regex,
156
- }),
157
225
  isDevelopment
158
226
  ? rollupSwcPlugin()
159
227
  : babel({
160
228
  babelHelpers: "bundled",
229
+ configFile: false,
230
+ babelrc: false,
161
231
  extensions: [".js", ".jsx", ".ts", ".tsx"],
162
232
  presets: [
163
- ["@babel/preset-react", { runtime: "automatic" }],
164
- "@babel/preset-typescript",
233
+ [presetReact, { runtime: "automatic" }],
234
+ presetTypescript,
165
235
  ],
166
236
  plugins: [
167
- "babel-plugin-react-compiler",
168
- "@babel/plugin-syntax-import-meta",
237
+ enableReactCompiler && pluginReactCompiler,
238
+ pluginSyntaxImportMeta,
169
239
  ].filter(Boolean),
170
- exclude: /node_modules[\\/](?!dinou|react-refresh)/,
240
+ exclude: [
241
+ /node_modules[\\/](?!dinou|react-refresh)/,
242
+ /[\\/]dinou[\\/]compiled[\\/]/,
243
+ ],
171
244
  }),
172
245
  postcss({
173
246
  modules: {
@@ -176,29 +249,68 @@ export default async function () {
176
249
  },
177
250
  extract: "styles.css",
178
251
  minimize: !isDevelopment,
179
- config: {
180
- path: path.resolve(__dirname, "postcss.config.js"),
181
- },
252
+ plugins: createBasePostCssPlugins(),
253
+ config: false,
182
254
  }),
183
- shouldWriteToDisk &&
184
- copy({
185
- targets: [
186
- fs.existsSync("public") && {
187
- src: "public/*",
188
- dest: outputDirectory,
189
- },
190
- fs.existsSync("favicons") && {
191
- src: "favicons/*",
192
- dest: outputDirectory,
193
- },
194
- ].filter(Boolean),
195
- flatten: true,
196
- }),
255
+ {
256
+ name: "dinou-rollup-css-assets-and-minify",
257
+ buildStart() {
258
+ getRegisteredCssUrlAssets().clear();
259
+ if (typeof globalThis !== "undefined") {
260
+ globalThis.__DINOU_HAS_COMPILED_STYLES__ = false;
261
+ }
262
+ },
263
+ generateBundle(_options, bundle) {
264
+ const hasCompiledStyles = Boolean(bundle["styles.css"]);
265
+ if (typeof globalThis !== "undefined") {
266
+ globalThis.__DINOU_HAS_COMPILED_STYLES__ = hasCompiledStyles;
267
+ if (!hasCompiledStyles && globalThis.__DINOU_MEM_FILES__) {
268
+ globalThis.__DINOU_MEM_FILES__.delete("styles.css");
269
+ globalThis.__DINOU_MEM_FILES__.delete("/styles.css");
270
+ }
271
+ }
272
+ if (hasCompiledStyles && hasPublicStylesCss(process.cwd())) {
273
+ warnPublicStylesCssCollision(process.cwd());
274
+ }
275
+ for (const [assetFileName, absAssetPath] of getRegisteredCssUrlAssets().entries()) {
276
+ if (!bundle[assetFileName] && fs.existsSync(absAssetPath)) {
277
+ try {
278
+ this.emitFile({
279
+ type: "asset",
280
+ fileName: assetFileName,
281
+ source: fs.readFileSync(absAssetPath),
282
+ });
283
+ } catch (e) {}
284
+ }
285
+ }
286
+ if (!isDevelopment && bundle["styles.css"]?.type === "asset") {
287
+ try {
288
+ const rawCss = Buffer.isBuffer(bundle["styles.css"].source)
289
+ ? bundle["styles.css"].source.toString("utf8")
290
+ : String(bundle["styles.css"].source || "");
291
+ if (rawCss) {
292
+ bundle["styles.css"].source = esbuild.transformSync(rawCss, {
293
+ loader: "css",
294
+ minify: true,
295
+ }).code;
296
+ }
297
+ } catch (e) {}
298
+ }
299
+ },
300
+ },
301
+ shouldWriteToDisk && {
302
+ name: "dinou-copy-static",
303
+ writeBundle() {
304
+ copyStaticDirectoriesToOutdir(process.cwd(), outputDirectory);
305
+ },
306
+ },
197
307
  reactClientManifest({
198
308
  manifestPath: path.join(
199
- ".dinou/react_client_manifest",
309
+ isDevelopment ? ".dinou/node-dev" : ".dinou/dist1",
200
310
  "react-client-manifest.json",
201
311
  ),
312
+ assetInclude: activeAssetRegex,
313
+ dinouConfig,
202
314
  serverFiles,
203
315
  }),
204
316
  isDevelopment && reactRefreshWrapModules(),
@@ -206,6 +318,29 @@ export default async function () {
206
318
  !isDevelopment && manifestGeneratorPlugin(),
207
319
  serverFunctionsPlugin({ serverFiles }),
208
320
  isDevelopment && rollupMemoryPlugin(),
321
+ !isDevelopment && {
322
+ name: "post-build-ssg",
323
+ closeBundle() {
324
+ const ssgArgs = [
325
+ "--conditions=react-server",
326
+ ...(isUnvendorizedRequested() ? ["--conditions=unvendorized"] : []),
327
+ path.resolve(__dirname, "../core/run-ssg.js"),
328
+ ];
329
+ const ssgRes = spawnSync(process.execPath, ssgArgs, {
330
+ stdio: "inherit",
331
+ env: {
332
+ ...process.env,
333
+ NODE_ENV: "production",
334
+ DINOU_BUILD_TOOL: "rollup",
335
+ },
336
+ });
337
+ if (ssgRes.status !== 0) {
338
+ throw new Error(
339
+ `[Dinou SSG] Static generation exited with code ${ssgRes.status ?? 1}`
340
+ );
341
+ }
342
+ },
343
+ },
209
344
  ].filter(Boolean),
210
345
  watch: {
211
346
  buildDelay: 100,
@@ -247,67 +382,5 @@ export default async function () {
247
382
  },
248
383
  };
249
384
 
250
- if (isDevelopment) {
251
- return clientConfig;
252
- }
253
-
254
- const serverConfig = {
255
- input: {
256
- handler: path.resolve(__dirname, "../core/handler.js"),
257
- netlify: path.resolve(__dirname, "../adapters/netlify.js"),
258
- },
259
- output: {
260
- dir: path.resolve(outputDirectory, "server"),
261
- format: "esm",
262
- entryFileNames: "[name].js",
263
- chunkFileNames: "[name]-[hash].js",
264
- sourcemap: true,
265
- banner: "import { createRequire as ___createRequire } from 'node:module'; import { fileURLToPath as ___fileURLToPath } from 'node:url'; import ___path from 'node:path'; const require = ___createRequire(import.meta.url || ___path.resolve(process.cwd(), 'package.json')); globalThis.__dinou_require__ = require; const __filename = import.meta.url ? ___fileURLToPath(import.meta.url) : ___path.resolve(process.cwd(), 'index.js'); const __dirname = ___path.dirname(__filename); process.env.NODE_ENV = process.env.NODE_ENV || 'production';",
266
- },
267
- external: [
268
- "express",
269
- "chokidar",
270
- "dotenv",
271
- "fsevents",
272
- "@swc/core",
273
- "@babel/core",
274
- "esbuild",
275
- ],
276
- plugins: [
277
- replace({
278
- preventAssignment: true,
279
- "process.env.NODE_ENV": JSON.stringify("production"),
280
- }),
281
- json(),
282
- resolve({
283
- exportConditions: ["react-server", "node", "import"],
284
- preferBuiltins: true,
285
- browser: false,
286
- }),
287
- commonjs({
288
- ignoreDynamicRequires: true,
289
- }),
290
- {
291
- name: "post-build-server",
292
- closeBundle() {
293
- fs.writeFileSync(
294
- path.resolve(process.cwd(), ".dinou/dist3/server/package.json"),
295
- JSON.stringify({ type: "module" }, null, 2)
296
- );
297
- execSync(`"${process.execPath}" --conditions=react-server "${path.resolve(__dirname, "../core/run-ssg.js")}"`, {
298
- stdio: "inherit",
299
- env: { ...process.env, NODE_ENV: "production" },
300
- });
301
- },
302
- },
303
- ],
304
- onwarn(warning, warn) {
305
- if (warning.code === "CIRCULAR_DEPENDENCY" || warning.code === "EVAL") {
306
- return;
307
- }
308
- warn(warning);
309
- },
310
- };
311
-
312
- return [clientConfig, serverConfig];
385
+ return clientConfig;
313
386
  };
@@ -1,13 +1,68 @@
1
1
  import esbuild from "esbuild";
2
2
  import path from "node:path";
3
+ import fsSync from "node:fs";
3
4
  import fs from "node:fs/promises";
5
+ import { createRequire } from "node:module";
4
6
  import { fileURLToPath } from "node:url";
5
7
 
6
8
  const __filename = fileURLToPath(import.meta.url);
7
9
  const __dirname = path.dirname(__filename);
8
10
  const DINOU_ROOT = path.resolve(__dirname, "..");
11
+ const PROJECT_ROOT = process.cwd();
9
12
  const COMPILED_DIR = path.join(DINOU_ROOT, "compiled");
10
13
 
14
+ const nmDinouDir = path.resolve(PROJECT_ROOT, "node_modules", "dinou");
15
+ let realNmDinouDir = null;
16
+ if (fsSync.existsSync(nmDinouDir)) {
17
+ try {
18
+ realNmDinouDir = fsSync.realpathSync(nmDinouDir);
19
+ } catch {}
20
+ }
21
+
22
+ const CANDIDATE_ROOTS = Array.from(
23
+ new Set(
24
+ [
25
+ PROJECT_ROOT,
26
+ DINOU_ROOT,
27
+ nmDinouDir,
28
+ realNmDinouDir,
29
+ path.resolve(DINOU_ROOT, ".."),
30
+ ].filter(Boolean)
31
+ )
32
+ );
33
+
34
+ const NODE_PATHS = Array.from(
35
+ new Set(
36
+ [
37
+ ...CANDIDATE_ROOTS.map((r) => path.join(r, "node_modules")),
38
+ realNmDinouDir &&
39
+ path.basename(path.dirname(realNmDinouDir)) === "node_modules"
40
+ ? path.dirname(realNmDinouDir)
41
+ : null,
42
+ ].filter((dir) => dir && fsSync.existsSync(dir))
43
+ )
44
+ );
45
+
46
+ const candidateRequires = CANDIDATE_ROOTS.map((rootDir) => {
47
+ const pkgJson = path.join(rootDir, "package.json");
48
+ if (fsSync.existsSync(pkgJson)) {
49
+ return createRequire(pkgJson);
50
+ }
51
+ return null;
52
+ }).filter(Boolean);
53
+ candidateRequires.push(createRequire(import.meta.url));
54
+
55
+ function resolveVendorModule(specifier) {
56
+ for (const req of candidateRequires) {
57
+ try {
58
+ return req.resolve(specifier);
59
+ } catch {}
60
+ }
61
+ throw new Error(
62
+ `Unable to resolve "${specifier}" from project root (${PROJECT_ROOT}) or Dinou root (${DINOU_ROOT}). Install it first (e.g. npm install -D ${specifier}).`
63
+ );
64
+ }
65
+
11
66
  const BANNER_JS = `
12
67
  import { createRequire as __dinou_createRequire } from "node:module";
13
68
  import { fileURLToPath as __dinou_fileURLToPath } from "node:url";
@@ -47,18 +102,34 @@ const VENDORS = [
47
102
  { name: "rollup-plugin-json", entry: "@rollup/plugin-json" },
48
103
  { name: "rollup-plugin-node-resolve", entry: "@rollup/plugin-node-resolve" },
49
104
  { name: "rollup-plugin-replace", entry: "@rollup/plugin-replace" },
50
- { name: "rollup-plugin-copy", entry: "rollup-plugin-copy" },
51
105
  { name: "rollup-plugin-delete", entry: "rollup-plugin-delete" },
52
106
  { name: "rollup-plugin-postcss", entry: "rollup-plugin-postcss" },
53
- {
54
- name: "rollup-plugin-tsconfig-paths",
55
- entry: "rollup-plugin-tsconfig-paths",
56
- external: ["typescript"]
57
- },
58
107
 
59
108
  // --- Webpack Loaders & Plugins ---
60
109
  { name: "babel-loader", entry: "babel-loader" },
61
- { name: "css-loader", entry: "css-loader" },
110
+ {
111
+ name: "css-loader",
112
+ entry: "css-loader",
113
+ postProcess: async (vendorOutdir) => {
114
+ const indexFile = path.join(vendorOutdir, "index.js");
115
+ let indexContent = await fs.readFile(indexFile, "utf8");
116
+ indexContent = indexContent.replaceAll(
117
+ '"../runtime/getUrl.js"',
118
+ '"./runtime/getUrl.js"'
119
+ );
120
+ await fs.writeFile(indexFile, indexContent, "utf8");
121
+
122
+ const cssLoaderEntry = resolveVendorModule("css-loader");
123
+ const srcRuntimeDir = path.join(path.dirname(cssLoaderEntry), "runtime");
124
+ const destRuntimeDir = path.join(vendorOutdir, "runtime");
125
+ await fs.cp(srcRuntimeDir, destRuntimeDir, { recursive: true });
126
+ await fs.writeFile(
127
+ path.join(destRuntimeDir, "package.json"),
128
+ JSON.stringify({ type: "commonjs" }, null, 2),
129
+ "utf8"
130
+ );
131
+ }
132
+ },
62
133
  {
63
134
  name: "mini-css-extract-plugin",
64
135
  entries: {
@@ -74,33 +145,27 @@ const VENDORS = [
74
145
  "const _loader = require_loader();\nexport default _loader;\nexport const pitch = _loader.pitch;\nexport const hotLoader = _loader.hotLoader;\n"
75
146
  );
76
147
  await fs.writeFile(loaderFile, content, "utf8");
148
+
149
+ const mcepEntry = resolveVendorModule("mini-css-extract-plugin");
150
+ const srcHmrDir = path.join(path.dirname(mcepEntry), "hmr");
151
+ const destHmrDir = path.join(vendorOutdir, "hmr");
152
+ await fs.cp(srcHmrDir, destHmrDir, { recursive: true });
153
+ await fs.writeFile(
154
+ path.join(destHmrDir, "package.json"),
155
+ JSON.stringify({ type: "commonjs" }, null, 2),
156
+ "utf8"
157
+ );
77
158
  },
78
159
  external: ["webpack", "schema-utils"]
79
160
  },
80
161
  { name: "copy-webpack-plugin", entry: "copy-webpack-plugin" },
81
- {
82
- name: "tsconfig-paths-webpack-plugin",
83
- entry: "tsconfig-paths-webpack-plugin",
84
- external: ["enhanced-resolve*", "typescript"]
85
- },
86
162
 
87
- // --- CLI & Utilities ---
163
+ // --- CLI & Core Utilities ---
88
164
  { name: "commander", entry: "commander" },
89
- { name: "dotenv", entry: "dotenv" },
90
- { name: "cross-env", entry: "cross-env" },
91
165
  { name: "ws", entry: "ws" },
92
166
  { name: "chokidar", entry: "chokidar" },
93
- { name: "esbuild-copy-static-files", entry: "esbuild-copy-static-files" },
94
- {
95
- name: "esbuild-tsconfig-paths",
96
- wrapper: `
97
- import pkg from "@esbuild-plugins/tsconfig-paths";
98
- const actual = pkg?.default || pkg;
99
- export const TsconfigPathsPlugin = actual.TsconfigPathsPlugin || actual;
100
- export default actual;
101
- `,
102
- external: ["typescript"]
103
- }
167
+ { name: "fast-glob", entry: "fast-glob" },
168
+ { name: "resolve", entry: "resolve" }
104
169
  ];
105
170
 
106
171
  const GLOBAL_EXTERNALS = [
@@ -113,10 +178,22 @@ const GLOBAL_EXTERNALS = [
113
178
  ];
114
179
 
115
180
  async function buildVendors() {
116
- console.log("๐Ÿฆ– [Dinou v9] Compiling vendor dependencies with esbuild...\n");
181
+ console.log("๐Ÿฆ– [Dinou] Compiling vendor dependencies with esbuild...\n");
117
182
  const startTime = Date.now();
118
183
  await fs.mkdir(COMPILED_DIR, { recursive: true });
119
184
 
185
+ const activeVendorNames = new Set(VENDORS.map((v) => v.name));
186
+ const existingEntries = await fs.readdir(COMPILED_DIR, { withFileTypes: true });
187
+ for (const entry of existingEntries) {
188
+ if (entry.isDirectory() && !activeVendorNames.has(entry.name)) {
189
+ await fs.rm(path.join(COMPILED_DIR, entry.name), {
190
+ recursive: true,
191
+ force: true,
192
+ });
193
+ console.log(` ๐Ÿงน Removed obsolete vendor directory: ${entry.name}`);
194
+ }
195
+ }
196
+
120
197
  const manifest = {};
121
198
  let successCount = 0;
122
199
  let failCount = 0;
@@ -133,11 +210,12 @@ async function buildVendors() {
133
210
 
134
211
  try {
135
212
  if (vendor.wrapper) {
136
- // Custom wrapper for synthesized named exports
137
213
  await esbuild.build({
214
+ absWorkingDir: PROJECT_ROOT,
215
+ nodePaths: NODE_PATHS,
138
216
  stdin: {
139
217
  contents: vendor.wrapper,
140
- resolveDir: DINOU_ROOT,
218
+ resolveDir: PROJECT_ROOT,
141
219
  sourcefile: `${vendor.name}-wrapper.js`
142
220
  },
143
221
  bundle: true,
@@ -149,9 +227,16 @@ async function buildVendors() {
149
227
  external: externals
150
228
  });
151
229
  } else if (vendor.entries) {
152
- // Multi-entrypoint vendor (e.g. mini-css-extract-plugin with loader.js)
230
+ const resolvedEntries = Object.fromEntries(
231
+ Object.entries(vendor.entries).map(([key, spec]) => [
232
+ key,
233
+ resolveVendorModule(spec),
234
+ ])
235
+ );
153
236
  await esbuild.build({
154
- entryPoints: vendor.entries,
237
+ absWorkingDir: PROJECT_ROOT,
238
+ nodePaths: NODE_PATHS,
239
+ entryPoints: resolvedEntries,
155
240
  bundle: true,
156
241
  platform: "node",
157
242
  target: "node18",
@@ -165,9 +250,11 @@ async function buildVendors() {
165
250
  await vendor.postProcess(vendorOutdir);
166
251
  }
167
252
  } else {
168
- // Single entrypoint vendor
253
+ const resolvedEntry = resolveVendorModule(vendor.entry);
169
254
  await esbuild.build({
170
- entryPoints: [vendor.entry],
255
+ absWorkingDir: PROJECT_ROOT,
256
+ nodePaths: NODE_PATHS,
257
+ entryPoints: [resolvedEntry],
171
258
  bundle: true,
172
259
  platform: "node",
173
260
  target: "node18",
@@ -176,6 +263,9 @@ async function buildVendors() {
176
263
  banner: { js: BANNER_JS },
177
264
  external: externals
178
265
  });
266
+ if (vendor.postProcess) {
267
+ await vendor.postProcess(vendorOutdir);
268
+ }
179
269
  }
180
270
 
181
271
  const elapsed = Date.now() - t0;