dinou 7.2.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +1 -1
  3. package/cli.js +124 -121
  4. package/dinou/adapters/netlify.js +1 -0
  5. package/dinou/adapters/{node.mjs → node.js} +9 -3
  6. package/dinou/bun/{build.mjs → build.js} +20 -8
  7. package/dinou/cloudflare/{build.mjs → build.js} +23 -8
  8. package/dinou/cloudflare/shims/fs.js +3 -0
  9. package/dinou/constants.js +3 -3
  10. package/dinou/core/asset-extensions.js +5 -5
  11. package/dinou/core/bailout-proxy.js +3 -3
  12. package/dinou/core/build-static-pages.js +21 -17
  13. package/dinou/core/cache-revalidate.js +14 -33
  14. package/dinou/core/cache-slot.js +21 -10
  15. package/dinou/core/config.js +2 -5
  16. package/dinou/core/createScopedName.js +3 -3
  17. package/dinou/core/dinou-paths.js +15 -12
  18. package/dinou/core/generate-route-types.js +8 -3
  19. package/dinou/core/generate-static-page.js +6 -5
  20. package/dinou/core/generate-static-rsc.js +15 -10
  21. package/dinou/core/generate-static.js +11 -10
  22. package/dinou/core/generating-isg.js +12 -11
  23. package/dinou/core/get-abs-path-with-ext.js +8 -6
  24. package/dinou/core/get-asset-from-manifest.js +4 -4
  25. package/dinou/core/get-error-jsx.js +12 -9
  26. package/dinou/core/get-file-path-and-dynamic-params.js +7 -4
  27. package/dinou/core/get-jsx.js +19 -13
  28. package/dinou/core/handler.js +73 -33
  29. package/dinou/core/http-adapter.js +6 -2
  30. package/dinou/core/import-module.js +5 -4
  31. package/dinou/core/layout-functions.js +11 -6
  32. package/dinou/core/load-dinou-config.js +10 -4
  33. package/dinou/core/manifest-provider.js +11 -4
  34. package/dinou/core/parse-exports.js +11 -6
  35. package/dinou/core/path-utils.js +2 -2
  36. package/dinou/core/ppr-context.js +11 -11
  37. package/dinou/core/ppr-runtime.js +10 -6
  38. package/dinou/core/render-jsx-to-client-jsx.js +6 -3
  39. package/dinou/core/request-context.js +11 -7
  40. package/dinou/core/resolve-module-ppr.js +2 -2
  41. package/dinou/core/resolve-setup-files.js +70 -0
  42. package/dinou/core/revalidating.js +14 -25
  43. package/dinou/core/route-generator.js +12 -8
  44. package/dinou/core/rsc-renderer.js +13 -2
  45. package/dinou/core/run-ssg.js +9 -4
  46. package/dinou/core/safe-rename.js +3 -3
  47. package/dinou/core/scan-dependency-components.js +9 -3
  48. package/dinou/core/status-manifest.js +5 -5
  49. package/dinou/core/storage-adapter.js +13 -3
  50. package/dinou/core/url-resolver.js +2 -2
  51. package/dinou/core/vfs.js +7 -7
  52. package/dinou/deno/{build.mjs → build.js} +20 -8
  53. package/dinou/esbuild/{build.mjs → build.js} +4 -4
  54. package/dinou/esbuild/{dev.mjs → dev.js} +6 -6
  55. package/dinou/esbuild/helpers-esbuild/{get-config-esbuild-prod.mjs → get-config-esbuild-prod.js} +7 -7
  56. package/dinou/esbuild/helpers-esbuild/{get-config-esbuild.mjs → get-config-esbuild.js} +8 -8
  57. package/dinou/esbuild/helpers-esbuild/{get-esbuild-entries.mjs → get-esbuild-entries.js} +2 -2
  58. package/dinou/esbuild/plugins-esbuild/{assets-plugin.mjs → assets-plugin.js} +1 -1
  59. package/dinou/esbuild/plugins-esbuild/{stable-chunk-names-and-maps-plugin.mjs → stable-chunk-names-and-maps-plugin.js} +1 -1
  60. package/dinou/esbuild/plugins-esbuild/{write-plugin.mjs → write-plugin.js} +1 -1
  61. package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +4 -3
  62. package/dinou/esbuild/react-refresh/babel-config.js +5 -1
  63. package/dinou/esbuild/react-refresh/esm-hmr/server.js +7 -4
  64. package/dinou/esbuild/react-refresh/{esm-hmr-plugin.mjs → esm-hmr-plugin.js} +4 -4
  65. package/dinou/esbuild/react-refresh/{react-refresh-runtime.mjs → react-refresh-runtime.js} +1 -1
  66. package/dinou/index.d.ts +13 -0
  67. package/dinou/index.js +40 -19
  68. package/dinou/node/{build.mjs → build.js} +10 -6
  69. package/dinou/node/{bundle-dual-engine.mjs → bundle-dual-engine.js} +22 -10
  70. package/dinou/node/{dev.mjs → dev.js} +43 -20
  71. package/dinou/package.json +8 -7
  72. package/dinou/rollup/postcss.config.js +1 -1
  73. package/dinou/rollup/react-refresh/esm-hmr/server.js +7 -4
  74. package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +2 -1
  75. package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +23 -16
  76. package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +6 -5
  77. package/dinou/rollup/rollup-plugins/manifest-generator-plugin.js +2 -1
  78. package/dinou/rollup/rollup-plugins/rollup-plugin-memory.js +3 -2
  79. package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +16 -13
  80. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +7 -6
  81. package/dinou/rollup/rollup-plugins/rollup-plugin-swc.js +6 -3
  82. package/dinou/rollup/rollup.config.js +27 -23
  83. package/dinou/server.js +21 -26
  84. package/dinou/webpack/helpers/get-webpack-entries.js +14 -11
  85. package/dinou/webpack/loaders/server-functions-loader.js +5 -6
  86. package/dinou/webpack/loaders/swc-loader.js +4 -2
  87. package/dinou/webpack/plugins/manifest-generator-plugin.js +3 -1
  88. package/dinou/webpack/plugins/server-functions-plugin.js +4 -3
  89. package/dinou/webpack/plugins/webpack-memory-plugin.js +3 -2
  90. package/dinou/webpack/postcss.config.js +1 -1
  91. package/dinou/webpack/webpack.config.js +22 -20
  92. package/eject.js +198 -191
  93. package/package.json +111 -110
  94. package/dinou/config.js +0 -1
  95. package/dinou/config.mjs +0 -2
  96. package/dinou/core/css-require-hook.js +0 -64
  97. package/dinou/index.mjs +0 -43
  98. package/dinou/server.mjs +0 -30
  99. /package/dinou/core/{export-static.mjs → export-static.js} +0 -0
  100. /package/dinou/esbuild/helpers-esbuild/{normalize-path.mjs → normalize-path.js} +0 -0
  101. /package/dinou/esbuild/helpers-esbuild/{strip-namespace.mjs → strip-namespace.js} +0 -0
  102. /package/dinou/esbuild/helpers-esbuild/{swc-disk-cache.mjs → swc-disk-cache.js} +0 -0
  103. /package/dinou/esbuild/helpers-esbuild/{update-manifest-for-module.mjs → update-manifest-for-module.js} +0 -0
  104. /package/dinou/esbuild/helpers-esbuild/{write.mjs → write.js} +0 -0
  105. /package/dinou/esbuild/plugins-esbuild/{babel-react-compiler-plugin.mjs → babel-react-compiler-plugin.js} +0 -0
  106. /package/dinou/esbuild/plugins-esbuild/{css-processor-plugin.mjs → css-processor-plugin.js} +0 -0
  107. /package/dinou/esbuild/plugins-esbuild/{manifest-generator-plugin.mjs → manifest-generator-plugin.js} +0 -0
  108. /package/dinou/esbuild/plugins-esbuild/{react-client-manifest-plugin.mjs → react-client-manifest-plugin.js} +0 -0
  109. /package/dinou/esbuild/plugins-esbuild/{server-functions-plugin.mjs → server-functions-plugin.js} +0 -0
  110. /package/dinou/esbuild/plugins-esbuild/{skip-missing-entry-points-plugin.mjs → skip-missing-entry-points-plugin.js} +0 -0
  111. /package/dinou/esbuild/react-refresh/esm-hmr/{client.mjs → client.js} +0 -0
  112. /package/dinou/esbuild/react-refresh/{is-react-refresh-boundary.mjs → is-react-refresh-boundary.js} +0 -0
  113. /package/dinou/node/{port-selector.mjs → port-selector.js} +0 -0
  114. /package/dinou/node/{terminal-status.mjs → terminal-status.js} +0 -0
@@ -10,9 +10,9 @@ import {
10
10
  globPattern as assetGlobPattern,
11
11
  } from "../../core/asset-extensions.js";
12
12
  import { getAbsPathWithExt } from "../../core/get-abs-path-with-ext.js";
13
- import normalizePath from "./normalize-path.mjs";
13
+ import normalizePath from "./normalize-path.js";
14
14
  import { useClientRegex, useServerRegex } from "../../constants.js";
15
- import { updateManifestForModule } from "./update-manifest-for-module.mjs";
15
+ import { updateManifestForModule } from "./update-manifest-for-module.js";
16
16
 
17
17
  function hashFilePath(absPath) {
18
18
  return crypto.createHash("sha1").update(normalizePath(absPath)).digest("hex").slice(0, 8);
@@ -4,7 +4,7 @@ import createScopedName from "../../core/createScopedName.js";
4
4
  import { regex } from "../../core/asset-extensions.js";
5
5
  import { getAbsPathWithExt } from "../../core/get-abs-path-with-ext.js";
6
6
  import { pathToFileURL } from "node:url";
7
- import stripNamespace from "../helpers-esbuild/strip-namespace.mjs";
7
+ import stripNamespace from "../helpers-esbuild/strip-namespace.js";
8
8
 
9
9
  const escapeRegExp = (string) => string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
10
10
 
@@ -1,5 +1,5 @@
1
1
  import path from "node:path";
2
- import stripNamespace from "../helpers-esbuild/strip-namespace.mjs";
2
+ import stripNamespace from "../helpers-esbuild/strip-namespace.js";
3
3
 
4
4
  const normKey = (p) => {
5
5
  if (!p) return "";
@@ -1,4 +1,4 @@
1
- import write from "../helpers-esbuild/write.mjs";
1
+ import write from "../helpers-esbuild/write.js";
2
2
 
3
3
  export default function writePlugin() {
4
4
  return {
@@ -1,6 +1,6 @@
1
1
  // postcss-extract-plugin.js
2
- const fs = require("fs");
3
- const path = require("path");
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
4
 
5
5
  let cachedExtractedCSS = "";
6
6
  let cachedCSSBuffer = null;
@@ -71,4 +71,5 @@ const createPostCSSExtractPlugin = (options = {}) => {
71
71
  };
72
72
  };
73
73
 
74
- module.exports = createPostCSSExtractPlugin;
74
+ export { createPostCSSExtractPlugin };
75
+ export default createPostCSSExtractPlugin;
@@ -1,3 +1,6 @@
1
+ import { createRequire } from "node:module";
2
+ const require = createRequire(import.meta.url);
3
+
1
4
  const babelConfig = {
2
5
  presets: [
3
6
  ["@babel/preset-react", { runtime: "automatic" }],
@@ -10,4 +13,5 @@ const babelConfig = {
10
13
  exclude: /node_modules[\\/](?!dinou|react-refresh)/,
11
14
  };
12
15
 
13
- module.exports.babelConfig = babelConfig;
16
+ export { babelConfig };
17
+ export default babelConfig;
@@ -1,4 +1,6 @@
1
- const WebSocket = require("ws");
1
+ import WebSocket, { WebSocketServer } from "ws";
2
+
3
+ const Server = WebSocketServer || WebSocket.Server;
2
4
 
3
5
  /**
4
6
  * @typedef {Object} Dependency
@@ -15,8 +17,8 @@ class EsmHmrEngine {
15
17
  this.clients = set;
16
18
  this.dependencyTree = map;
17
19
  const wss = options.server
18
- ? new WebSocket.Server({ noServer: true })
19
- : new WebSocket.Server({ port: options.port || Number(process.env.HMR_PORT) || 3001 });
20
+ ? new Server({ noServer: true })
21
+ : new Server({ port: options.port || Number(process.env.HMR_PORT) || 3001 });
20
22
 
21
23
  if (options.server) {
22
24
  options.server.on("upgrade", (req, socket, head) => {
@@ -129,6 +131,7 @@ class EsmHmrEngine {
129
131
  }
130
132
  }
131
133
 
132
- module.exports = {
134
+ export {
133
135
  EsmHmrEngine,
134
136
  };
137
+ export default EsmHmrEngine;
@@ -6,9 +6,9 @@ import { transform } from "@swc/core";
6
6
  import { createServer } from "node:http";
7
7
  import { EsmHmrEngine } from "./esm-hmr/server.js";
8
8
  import { fileURLToPath } from "node:url";
9
- import write from "../helpers-esbuild/write.mjs";
10
- import normalizePath from "../helpers-esbuild/normalize-path.mjs";
11
- import stripNamespace from "../helpers-esbuild/strip-namespace.mjs";
9
+ import write from "../helpers-esbuild/write.js";
10
+ import normalizePath from "../helpers-esbuild/normalize-path.js";
11
+ import stripNamespace from "../helpers-esbuild/strip-namespace.js";
12
12
 
13
13
  const norm = (p) => path.resolve(p).replace(/\\/g, "/");
14
14
  const normKey = (p) => {
@@ -155,7 +155,7 @@ export default function esmHmrPlugin({
155
155
  if (!result || !result.outputFiles) return;
156
156
  const clientPath = path.resolve(
157
157
  path.dirname(fileURLToPath(import.meta.url)),
158
- "./esm-hmr/client.mjs",
158
+ "./esm-hmr/client.js",
159
159
  );
160
160
  let clientCode = await fs.readFile(clientPath, "utf8");
161
161
  const isDebug =
@@ -1,5 +1,5 @@
1
1
  import RefreshRuntime from "/react-refresh-entry.js";
2
- import { isReactRefreshBoundary } from "./is-react-refresh-boundary.mjs";
2
+ import { isReactRefreshBoundary } from "./is-react-refresh-boundary.js";
3
3
 
4
4
  if (
5
5
  typeof window !== "undefined" &&
package/dinou/index.d.ts CHANGED
@@ -143,6 +143,12 @@ export interface DinouPlugin {
143
143
  */
144
144
  configureServer?(context: ServerHookContext): Promise<void> | void;
145
145
 
146
+ /**
147
+ * Array of setup/polyfill file paths to be executed at the earliest stage
148
+ * and injected into all bundled engines before any modules are loaded.
149
+ */
150
+ setupFiles?: string[];
151
+
146
152
  /**
147
153
  * Universal Web Standards middleware and webhook handler.
148
154
  * Runs on every incoming HTTP request before React rendering.
@@ -182,6 +188,13 @@ export interface DinouConfig {
182
188
  */
183
189
  storage?: any;
184
190
 
191
+ /**
192
+ * Array of setup/polyfill file paths to be executed at the earliest stage
193
+ * before any server or client components are imported.
194
+ * If provided, overrides the root `dinou.setup.(mjs|js|ts)` convention.
195
+ */
196
+ setupFiles?: string[];
197
+
185
198
  /**
186
199
  * Array of Dinou plugins.
187
200
  */
package/dinou/index.js CHANGED
@@ -1,22 +1,43 @@
1
- const contextModule = require("./core/request-context.js");
2
- const navigationModule = require("./core/navigation.js");
3
- const { defineConfig } = require("./core/config.js");
1
+ import { getContext } from "./core/request-context.js";
2
+ import {
3
+ usePathname,
4
+ useSearchParams,
5
+ useRouter,
6
+ refreshSlot,
7
+ useNavigationLoading,
8
+ } from "./core/navigation.js";
9
+ import { redirect } from "./core/redirect.jsx";
10
+ import { ClientRedirect } from "./core/client-redirect.jsx";
11
+ import { Link } from "./core/link.jsx";
4
12
 
5
- module.exports = {
13
+ function defineConfig(config) {
14
+ return config;
15
+ }
16
+
17
+ const dinou = {
6
18
  defineConfig,
7
- getContext: contextModule.getContext,
8
- usePathname: navigationModule.usePathname,
9
- useSearchParams: navigationModule.useSearchParams,
10
- useRouter: navigationModule.useRouter,
11
- refreshSlot: navigationModule.refreshSlot,
12
- useNavigationLoading: navigationModule.useNavigationLoading,
13
- get redirect() {
14
- return require("./core/redirect.jsx").redirect;
15
- },
16
- get ClientRedirect() {
17
- return require("./core/client-redirect.jsx").ClientRedirect;
18
- },
19
- get Link() {
20
- return require("./core/link.jsx").Link;
21
- },
19
+ getContext,
20
+ usePathname,
21
+ useSearchParams,
22
+ useRouter,
23
+ refreshSlot,
24
+ useNavigationLoading,
25
+ redirect,
26
+ ClientRedirect,
27
+ Link,
22
28
  };
29
+
30
+ export {
31
+ defineConfig,
32
+ getContext,
33
+ usePathname,
34
+ useSearchParams,
35
+ useRouter,
36
+ refreshSlot,
37
+ useNavigationLoading,
38
+ redirect,
39
+ ClientRedirect,
40
+ Link,
41
+ };
42
+
43
+ export default dinou;
@@ -7,7 +7,7 @@ import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import esbuild from "esbuild";
9
9
  import { fileURLToPath } from "node:url";
10
- import { bundleDualEngine } from "./bundle-dual-engine.mjs";
10
+ import { bundleDualEngine } from "./bundle-dual-engine.js";
11
11
 
12
12
  const projectRoot = process.cwd();
13
13
  const nodeDir = path.resolve(projectRoot, ".dinou/node");
@@ -23,7 +23,7 @@ try {
23
23
  outDir: ".dinou/node",
24
24
  });
25
25
 
26
- const { dinouDirSlash, externalList, banner, commonAlias, commonLoader, isWebpackBuild } = engineResult;
26
+ const { dinouDirSlash, externalList, banner, commonAlias, commonLoader, isWebpackBuild, setupFiles } = engineResult;
27
27
 
28
28
  // Pass C: Node Orchestrator Entry
29
29
  const nodeEntryContent = `// Auto-generated main entry for Node.js (Dual-Bundle)
@@ -189,17 +189,20 @@ export async function startServer(port = PORT, host = "0.0.0.0") {
189
189
 
190
190
  export default {
191
191
  port: PORT,
192
- fetch,
193
192
  startServer,
194
193
  };
195
194
 
196
- const isMain = typeof process !== "undefined" &&
197
- process.argv[1] &&
198
- (path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url)));
195
+ const isMain = Boolean(
196
+ (typeof import.meta !== "undefined" && import.meta.main) ||
197
+ (typeof process !== "undefined" &&
198
+ process.argv[1] &&
199
+ (path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))))
200
+ );
199
201
 
200
202
  if (isMain) {
201
203
  startServer(PORT);
202
204
  }
205
+
203
206
  `;
204
207
  const nodeEntryPath = path.join(nodeDir, "node-entry.mjs");
205
208
  fs.writeFileSync(nodeEntryPath, nodeEntryContent, "utf8");
@@ -218,6 +221,7 @@ if (isMain) {
218
221
  conditions: ["node", "worker", "browser"],
219
222
  external: [...externalList, "./rsc-engine.mjs", "./ssr-engine.mjs"],
220
223
  banner,
224
+ inject: setupFiles,
221
225
  alias: commonAlias,
222
226
  loader: commonLoader,
223
227
  define: {
@@ -6,20 +6,21 @@
6
6
  import fs from "node:fs";
7
7
  import path from "node:path";
8
8
  import esbuild from "esbuild";
9
- import { createRequire } from "node:module";
10
9
  import { fileURLToPath, pathToFileURL } from "node:url";
11
10
 
12
- const require = createRequire(import.meta.url);
13
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
14
- const { generateRouteModulesCode, generateRouteTypes } = require("../core/route-generator.js");
15
- const parseExports = require("../core/parse-exports.js");
16
- const { useClientRegex, useServerRegex } = require("../constants.js");
17
- const createScopedName = require("../core/createScopedName.js");
18
- const { regex: assetRegex } = require("../core/asset-extensions.js");
19
- const {
11
+ import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
12
+ import parseExports from "../core/parse-exports.js";
13
+ import { useClientRegex, useServerRegex } from "../constants.js";
14
+ import createScopedName from "../core/createScopedName.js";
15
+ import { regex as assetRegex } from "../core/asset-extensions.js";
16
+ import {
20
17
  isSupportedClientModule,
21
18
  scanProjectDependenciesForClientComponents,
22
- } = require("../core/scan-dependency-components.js");
19
+ } from "../core/scan-dependency-components.js";
20
+ import { getDinouConfig } from "../core/load-dinou-config.js";
21
+ import { resolveSetupFiles } from "../core/resolve-setup-files.js";
22
+
23
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
24
 
24
25
  export async function bundleDualEngine(options = {}) {
25
26
  const isDev = Boolean(options.isDev);
@@ -27,6 +28,12 @@ export async function bundleDualEngine(options = {}) {
27
28
  const nodeDir = path.resolve(projectRoot, options.outDir || ".dinou/node");
28
29
  fs.mkdirSync(nodeDir, { recursive: true });
29
30
 
31
+ const dinouConfig = await getDinouConfig();
32
+ const setupFiles = resolveSetupFiles(projectRoot, dinouConfig);
33
+ if (setupFiles.length > 0) {
34
+ console.log(` 🔌 [Dinou Setup] Active setup files (${setupFiles.length}):`, setupFiles.map((f) => path.relative(projectRoot, f)).join(", "));
35
+ }
36
+
30
37
  try {
31
38
  generateRouteTypes(projectRoot);
32
39
  } catch (e) {}
@@ -687,6 +694,8 @@ globalThis.__DINOU_VFS__ = ${JSON.stringify(vfsSnapshot)};
687
694
  const rscEntryContent = `// Auto-generated RSC Engine entry for Node.js (Dual-Bundle)
688
695
  import "./env-setup.mjs";
689
696
  import "./route-modules.mjs";
697
+ import * as edgeRenderer from "react-server-dom-webpack/server.edge";
698
+ globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
690
699
  export { handleRequest } from "${dinouDirSlash}/core/handler.js";
691
700
  export { buildStaticPages, getStaticPaths, getStaticLayouts, getStaticMetadata } from "${dinouDirSlash}/core/build-static-pages.js";
692
701
  `;
@@ -956,6 +965,7 @@ var __webpack_chunk_load__ = function(chunkId) {
956
965
  conditions: ["node", "worker", "react-server"],
957
966
  external: externalList,
958
967
  banner,
968
+ inject: setupFiles,
959
969
  plugins: [clientReferencesPlugin, serverReferencesPlugin, serverAssetPlugin],
960
970
  alias: commonAlias,
961
971
  loader: commonLoader,
@@ -980,6 +990,7 @@ var __webpack_chunk_load__ = function(chunkId) {
980
990
  conditions: ["node", "worker", "browser"],
981
991
  external: externalList,
982
992
  banner,
993
+ inject: setupFiles,
983
994
  plugins: [serverReferencesPluginSsr, serverAssetPlugin],
984
995
  alias: commonAlias,
985
996
  loader: commonLoader,
@@ -1006,6 +1017,7 @@ var __webpack_chunk_load__ = function(chunkId) {
1006
1017
  commonAlias,
1007
1018
  commonLoader,
1008
1019
  isWebpackBuild,
1020
+ setupFiles,
1009
1021
  };
1010
1022
  }
1011
1023
 
@@ -23,8 +23,22 @@ import {
23
23
  logInfo,
24
24
  showIdleStatus,
25
25
  printReadyBanner,
26
- } from "./terminal-status.mjs";
27
- import { resolveDevPorts } from "./port-selector.mjs";
26
+ } from "./terminal-status.js";
27
+ import { resolveDevPorts } from "./port-selector.js";
28
+ import { getDinouConfig } from "../core/load-dinou-config.js";
29
+ import { resolveSetupFiles } from "../core/resolve-setup-files.js";
30
+ import { generateRouteModulesCode, generateRouteTypes } from "../core/route-generator.js";
31
+ import parseExports from "../core/parse-exports.js";
32
+ import { useClientRegex, useServerRegex } from "../constants.js";
33
+ import { nodeToWebRequest, sendWebResponseToNode } from "../core/http-adapter.js";
34
+ import { setStorageAdapter, FileSystemStorage, MemoryStorage } from "../core/storage-adapter.js";
35
+ import createScopedName from "../core/createScopedName.js";
36
+ import { regex as assetRegex } from "../core/asset-extensions.js";
37
+ import {
38
+ isSupportedClientModule,
39
+ scanProjectDependenciesForClientComponents,
40
+ scanProjectDependenciesForClientComponentsAsync,
41
+ } from "../core/scan-dependency-components.js";
28
42
 
29
43
  // Resolve dev HTTP and HMR ports before initiating background compilation
30
44
  const { port: PORT, hmrPort: HMR_PORT } = await resolveDevPorts();
@@ -76,6 +90,20 @@ const dinouDir = fs.existsSync(path.resolve(projectRoot, "dinou"))
76
90
  : path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
77
91
  const dinouDirSlash = dinouDir.replace(/\\/g, "/");
78
92
 
93
+ // Resolve and execute setupFiles immediately before any compilation
94
+ const dinouConfig = await getDinouConfig();
95
+ const setupFiles = resolveSetupFiles(projectRoot, dinouConfig);
96
+ if (setupFiles.length > 0) {
97
+ console.log(` 🔌 [Dinou Setup] Executing setup files (${setupFiles.length}):`, setupFiles.map((f) => path.relative(projectRoot, f)).join(", "));
98
+ for (const f of setupFiles) {
99
+ try {
100
+ await dynamicImportWithRetry(pathToFileURL(f).href);
101
+ } catch (e) {
102
+ console.error(`❌ [Dinou Dev] Error executing setupFile "${f}":`, e);
103
+ }
104
+ }
105
+ }
106
+
79
107
  function getFallbackChunkId(absPath) {
80
108
  const norm = absPath.replace(/\\/g, "/");
81
109
  const name = path.basename(absPath, path.extname(absPath));
@@ -90,21 +118,9 @@ function getFallbackChunkId(absPath) {
90
118
  return `/${name}-${hash}.js`;
91
119
  }
92
120
 
93
- const { generateRouteModulesCode, generateRouteTypes } = require(path.join(dinouDir, "core/route-generator.js"));
94
121
  try {
95
122
  generateRouteTypes(projectRoot);
96
123
  } catch (e) {}
97
- const parseExports = require(path.join(dinouDir, "core/parse-exports.js"));
98
- const { useClientRegex, useServerRegex } = require(path.join(dinouDir, "constants.js"));
99
- const { nodeToWebRequest, sendWebResponseToNode } = require(path.join(dinouDir, "core/http-adapter.js"));
100
- const { setStorageAdapter, FileSystemStorage, MemoryStorage } = require(path.join(dinouDir, "core/storage-adapter.js"));
101
- const createScopedName = require(path.join(dinouDir, "core/createScopedName.js"));
102
- const { regex: assetRegex } = require(path.join(dinouDir, "core/asset-extensions.js"));
103
- const {
104
- isSupportedClientModule,
105
- scanProjectDependenciesForClientComponents,
106
- scanProjectDependenciesForClientComponentsAsync,
107
- } = require(path.join(dinouDir, "core/scan-dependency-components.js"));
108
124
 
109
125
  const yieldToEventLoop = () => new Promise((resolve) => setImmediate(resolve));
110
126
 
@@ -960,6 +976,8 @@ globalThis.__DINOU_LAYOUTS__ = ${JSON.stringify(discoveredLayouts)};
960
976
  const rscEntryContent = `// Auto-generated RSC Engine entry for Dev (Dual-Bundle)
961
977
  import "./env-setup.mjs";
962
978
  import "./route-modules.mjs";
979
+ import * as edgeRenderer from "react-server-dom-webpack/server.edge";
980
+ globalThis.__DINOU_EDGE_RENDERER__ = edgeRenderer;
963
981
  export { handleRequest } from "${dinouDirSlash}/core/handler.js";
964
982
  `;
965
983
  fs.writeFileSync(path.join(devDir, "rsc-entry.mjs"), rscEntryContent, "utf8");
@@ -1463,6 +1481,7 @@ const ctxA = await esbuild.context({
1463
1481
  conditions: ["node", "worker", "react-server"],
1464
1482
  external: externalList,
1465
1483
  banner,
1484
+ inject: setupFiles,
1466
1485
  plugins: [clientReferencesPlugin, serverReferencesPlugin, serverAssetPlugin, createDevExternalPackagesPlugin(true)],
1467
1486
  alias: commonAlias,
1468
1487
  loader: commonLoader,
@@ -1490,6 +1509,7 @@ const ctxB = await esbuild.context({
1490
1509
  conditions: ["node", "worker", "browser"],
1491
1510
  external: externalList,
1492
1511
  banner,
1512
+ inject: setupFiles,
1493
1513
  plugins: [serverReferencesPluginSsr, serverAssetPlugin, createDevExternalPackagesPlugin(false)],
1494
1514
  alias: commonAlias,
1495
1515
  loader: commonLoader,
@@ -2053,7 +2073,7 @@ async function startClientBundler(tool) {
2053
2073
 
2054
2074
  if (normTool === "esbuild") {
2055
2075
  const { startEsbuildDev } = await import(
2056
- pathToFileURL(path.resolve(dinouDir, "esbuild/dev.mjs")).href
2076
+ pathToFileURL(path.resolve(dinouDir, "esbuild/dev.js")).href
2057
2077
  );
2058
2078
  return await startEsbuildDev({
2059
2079
  onRebuilt: () => onManifestUpdated(),
@@ -2064,9 +2084,12 @@ async function startClientBundler(tool) {
2064
2084
 
2065
2085
  if (normTool === "rollup") {
2066
2086
  const { watch } = require("rollup");
2067
- const getRollupConfig = require(path.resolve(dinouDir, "rollup/rollup.config.js"));
2068
- const { getHmrEngine, closeHmrServer, notifyFileChanged } = require(path.resolve(dinouDir, "rollup/react-refresh/rollup-plugin-esm-hmr.js"));
2069
- const reactClientManifestPlugin = require(path.resolve(dinouDir, "rollup/rollup-plugins/rollup-plugin-react-client-manifest.js"));
2087
+ const rollupConfigMod = await import(pathToFileURL(path.resolve(dinouDir, "rollup/rollup.config.js")).href);
2088
+ const getRollupConfig = rollupConfigMod.default || rollupConfigMod;
2089
+ const hmrMod = await import(pathToFileURL(path.resolve(dinouDir, "rollup/react-refresh/rollup-plugin-esm-hmr.js")).href);
2090
+ const { getHmrEngine, closeHmrServer, notifyFileChanged } = hmrMod;
2091
+ const rcmpMod = await import(pathToFileURL(path.resolve(dinouDir, "rollup/rollup-plugins/rollup-plugin-react-client-manifest.js")).href);
2092
+ const reactClientManifestPlugin = rcmpMod.default || rcmpMod;
2070
2093
  reactClientManifestPlugin.setOnManifestUpdated?.(() => onManifestUpdated());
2071
2094
 
2072
2095
  let currentWatcher = null;
@@ -2213,7 +2236,8 @@ async function startClientBundler(tool) {
2213
2236
  }
2214
2237
  const webpack = require("webpack");
2215
2238
  const WebpackDevServer = require("webpack-dev-server");
2216
- const getWebpackConfig = require(path.resolve(dinouDir, "webpack/webpack.config.js"));
2239
+ const webpackConfigMod = await import(pathToFileURL(path.resolve(dinouDir, "webpack/webpack.config.js")).href);
2240
+ const getWebpackConfig = webpackConfigMod.default || webpackConfigMod;
2217
2241
  const webpackConfig = await getWebpackConfig();
2218
2242
  const compiler = webpack(webpackConfig);
2219
2243
 
@@ -2307,7 +2331,6 @@ const nodeMiddlewares = [];
2307
2331
 
2308
2332
  async function applyServerPlugins(serverInstance) {
2309
2333
  try {
2310
- const { getDinouConfig } = require(path.join(dinouDir, "core/load-dinou-config.js"));
2311
2334
  const config = await getDinouConfig();
2312
2335
  if (config.plugins && Array.isArray(config.plugins)) {
2313
2336
  const serverContext = {
@@ -1,28 +1,29 @@
1
1
  {
2
2
  "name": "dinou-ejected",
3
- "version": "7.2.0",
3
+ "version": "8.0.0",
4
+ "type": "module",
4
5
  "main": "index.js",
5
6
  "private": true,
6
7
  "exports": {
7
8
  ".": {
8
9
  "types": "./index.d.ts",
9
- "import": "./index.mjs",
10
- "require": "./index.js"
10
+ "import": "./index.js",
11
+ "default": "./index.js"
11
12
  },
12
13
  "./env": {
13
14
  "types": "./env.d.ts"
14
15
  },
15
16
  "./server": {
16
17
  "types": "./server.d.ts",
17
- "import": "./server.mjs",
18
- "require": "./server.js"
18
+ "import": "./server.js",
19
+ "default": "./server.js"
19
20
  },
20
21
  "./config": {
21
22
  "types": "./index.d.ts",
22
23
  "import": "./core/config.js",
23
- "require": "./core/config.js"
24
+ "default": "./core/config.js"
24
25
  },
25
- "./adapters/node": "./adapters/node.mjs",
26
+ "./adapters/node": "./adapters/node.js",
26
27
  "./adapters/bun": "./adapters/bun.js",
27
28
  "./adapters/deno": "./adapters/deno.js",
28
29
  "./adapters/cloudflare": "./adapters/cloudflare.js",
@@ -1,4 +1,4 @@
1
- module.exports = {
1
+ export default {
2
2
  plugins: {
3
3
  "@tailwindcss/postcss": {},
4
4
  autoprefixer: {},
@@ -1,4 +1,6 @@
1
- const WebSocket = require("ws");
1
+ import WebSocket, { WebSocketServer } from "ws";
2
+
3
+ const Server = WebSocketServer || WebSocket.Server;
2
4
 
3
5
  /**
4
6
  * @typedef {Object} Dependency
@@ -15,8 +17,8 @@ class EsmHmrEngine {
15
17
  this.clients = set;
16
18
  this.dependencyTree = map;
17
19
  const wss = options.server
18
- ? new WebSocket.Server({ noServer: true })
19
- : new WebSocket.Server({ port: options.port || Number(process.env.HMR_PORT) || 3001 });
20
+ ? new Server({ noServer: true })
21
+ : new Server({ port: options.port || Number(process.env.HMR_PORT) || 3001 });
20
22
 
21
23
  if (options.server) {
22
24
  options.server.on("upgrade", (req, socket, head) => {
@@ -125,6 +127,7 @@ class EsmHmrEngine {
125
127
  }
126
128
  }
127
129
 
128
- module.exports = {
130
+ export {
129
131
  EsmHmrEngine,
130
132
  };
133
+ export default EsmHmrEngine;
@@ -88,5 +88,6 @@ window.$RefreshSig$ = prevRefreshSig;
88
88
  };
89
89
  }
90
90
 
91
- module.exports = reactRefreshWrapModules;
91
+ export { reactRefreshWrapModules };
92
+ export default reactRefreshWrapModules;
92
93
 
@@ -1,8 +1,11 @@
1
- // plugins/rollup-plugin-esm-hmr.cjs
2
- const fs = require("node:fs");
3
- const path = require("node:path");
4
- const { EsmHmrEngine } = require("./esm-hmr/server");
5
- const { createServer } = require("node:http");
1
+ // plugins/rollup-plugin-esm-hmr.js
2
+ import fs from "node:fs";
3
+ import path from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { EsmHmrEngine } from "./esm-hmr/server.js";
6
+ import { createServer } from "node:http";
7
+
8
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
9
  const changedIds = new Set();
7
10
  const pendingUpdateUrls = new Set();
8
11
  let needsFullReload = false;
@@ -227,19 +230,23 @@ function notifyFileChanged(absPath) {
227
230
  }
228
231
  }
229
232
 
230
- module.exports = {
233
+ const getHmrEngine = () => activeHmrEngine;
234
+ const closeHmrServer = () => {
235
+ if (activeServer) {
236
+ try {
237
+ activeServer.close();
238
+ } catch (e) {}
239
+ activeServer = null;
240
+ activeHmrEngine = null;
241
+ }
242
+ };
243
+
244
+ export {
231
245
  esmHmrPlugin,
232
- getHmrEngine: () => activeHmrEngine,
246
+ getHmrEngine,
233
247
  notifyFileChanged,
234
- closeHmrServer: () => {
235
- if (activeServer) {
236
- try {
237
- activeServer.close();
238
- } catch (e) {}
239
- activeServer = null;
240
- activeHmrEngine = null;
241
- }
242
- },
248
+ closeHmrServer,
243
249
  };
250
+ export default esmHmrPlugin;
244
251
 
245
252
 
@@ -1,7 +1,7 @@
1
- const fs = require("fs");
2
- const path = require("path");
3
- const createScopedName = require("../../core/createScopedName.js");
4
- const { regex } = require("../../core/asset-extensions.js");
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import createScopedName from "../../core/createScopedName.js";
4
+ import { regex } from "../../core/asset-extensions.js";
5
5
 
6
6
  function dinouAssetPlugin({ include = regex } = {}) {
7
7
  return {
@@ -32,4 +32,5 @@ function dinouAssetPlugin({ include = regex } = {}) {
32
32
  };
33
33
  }
34
34
 
35
- module.exports = dinouAssetPlugin;
35
+ export { dinouAssetPlugin };
36
+ export default dinouAssetPlugin;
@@ -22,4 +22,5 @@ function manifestGeneratorPlugin() {
22
22
 
23
23
  manifestGeneratorPlugin.manifestData = manifestData;
24
24
 
25
- module.exports = manifestGeneratorPlugin;
25
+ export { manifestGeneratorPlugin };
26
+ export default manifestGeneratorPlugin;