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,17 +1,27 @@
1
1
  // dinou/adapters/bun.js
2
- // Native Bun Adapter for Dinou v7 (Pre-bundled AOT).
2
+ // Native Bun Adapter for Dinou (Pre-bundled AOT).
3
3
  // Serves the standalone pre-bundled server from .dinou/bun/server.js.
4
4
 
5
5
  import * as path from "node:path";
6
6
  import * as fs from "node:fs";
7
7
  import { pathToFileURL } from "node:url";
8
8
  import { AsyncLocalStorage } from "node:async_hooks";
9
+ import { loadEnvFiles } from "../core/env.js";
9
10
 
10
- if (typeof globalThis.AsyncLocalStorage === "undefined" && typeof AsyncLocalStorage !== "undefined") {
11
+ const cwd =
12
+ typeof process !== "undefined" && typeof process.cwd === "function"
13
+ ? process.cwd()
14
+ : ".";
15
+ loadEnvFiles(cwd, { mode: "production" });
16
+
17
+ if (
18
+ typeof globalThis.AsyncLocalStorage === "undefined" &&
19
+ typeof AsyncLocalStorage !== "undefined"
20
+ ) {
11
21
  globalThis.AsyncLocalStorage = AsyncLocalStorage;
12
22
  }
13
23
 
14
- const cwd = typeof process !== "undefined" && typeof process.cwd === "function" ? process.cwd() : ".";
24
+ const isMain = Boolean(typeof import.meta !== "undefined" && import.meta.main);
15
25
  const bundlePath = path.resolve(cwd, ".dinou/bun/server.js");
16
26
 
17
27
  let bundleModule = null;
@@ -20,17 +30,30 @@ if (fs.existsSync(bundlePath)) {
20
30
  bundleModule = await import(pathToFileURL(bundlePath).href);
21
31
  } catch (e) {
22
32
  console.error("[Dinou Bun Adapter] Failed to load .dinou/bun/server.js:", e);
33
+ if (isMain) {
34
+ process.exit(1);
35
+ }
23
36
  }
37
+ } else if (isMain) {
38
+ console.error(
39
+ "❌ [Dinou Bun Adapter] .dinou/bun/server.js not found. Please run 'npm run build:bun' first."
40
+ );
41
+ process.exit(1);
24
42
  }
25
43
 
26
44
  const PORT = Number(process.env.PORT || 3000);
45
+ const HOST = process.env.HOST || undefined;
27
46
  const IDLE_TIMEOUT = Number(process.env.IDLE_TIMEOUT || 120);
28
47
 
29
48
  export async function fetch(req) {
30
49
  if (bundleModule && typeof bundleModule.fetch === "function") {
31
50
  return bundleModule.fetch(req);
32
51
  }
33
- if (bundleModule && bundleModule.default && typeof bundleModule.default.fetch === "function") {
52
+ if (
53
+ bundleModule &&
54
+ bundleModule.default &&
55
+ typeof bundleModule.default.fetch === "function"
56
+ ) {
34
57
  return bundleModule.default.fetch(req);
35
58
  }
36
59
  return new Response(
@@ -42,8 +65,15 @@ export async function fetch(req) {
42
65
  );
43
66
  }
44
67
 
68
+ if (isMain && bundleModule) {
69
+ console.log(
70
+ `🚀 Dinou (Bun AOT Dual-Bundle) server running on http://${HOST || "localhost"}:${PORT}`
71
+ );
72
+ }
73
+
45
74
  export default {
46
75
  port: PORT,
76
+ ...(HOST ? { hostname: HOST } : {}),
47
77
  fetch,
48
78
  idleTimeout: IDLE_TIMEOUT,
49
79
  };
@@ -59,4 +89,3 @@ if (typeof process !== "undefined") {
59
89
  }
60
90
  }
61
91
  }
62
-
@@ -1,65 +1,158 @@
1
1
  // dinou/adapters/cloudflare.js
2
- // Cloudflare Workers Adapter for Dinou v7.
3
- // Universal edge entry point with KV storage, route registry, and Web Streams.
2
+ // Cloudflare Workers Adapter for Dinou (AOT Dual-Bundle & Edge Fallback).
3
+ // Delegates to the pre-bundled .dinou/cloudflare/worker.js orchestrator when present,
4
+ // and preserves custom storage adapters + registered SSR renderers in direct edge usage.
4
5
 
6
+ import * as path from "node:path";
7
+ import * as fs from "node:fs";
8
+ import { pathToFileURL } from "node:url";
5
9
  import { handleRequest } from "../core/handler.js";
6
10
  import {
7
- getStorageAdapter,
8
11
  setStorageAdapter,
12
+ hasExplicitStorageAdapter,
9
13
  CloudflareKVStorage,
10
14
  MemoryStorage,
11
15
  } from "../core/storage-adapter.js";
16
+ import {
17
+ getStaticContentType,
18
+ isPublicStaticAssetRequest,
19
+ isReservedCloudflareDist2RequestPath,
20
+ } from "../core/static-assets.js";
12
21
 
13
- // Ensure Edge runtime flag is set globally
14
22
  if (typeof globalThis !== "undefined") {
15
23
  globalThis.__DINOU_RUNTIME__ = "edge";
16
24
  }
17
25
 
26
+ const workerCacheByPath = new Map();
27
+
28
+ async function getPrebuiltCloudflareWorker() {
29
+ try {
30
+ if (
31
+ typeof process === "undefined" ||
32
+ typeof process.cwd !== "function" ||
33
+ typeof fs.existsSync !== "function"
34
+ ) {
35
+ return null;
36
+ }
37
+ const workerPath = path.resolve(process.cwd(), ".dinou/cloudflare/worker.js");
38
+ if (!fs.existsSync(workerPath)) {
39
+ return null;
40
+ }
41
+ let mtimeMs = 0;
42
+ try {
43
+ mtimeMs = fs.statSync(workerPath).mtimeMs;
44
+ } catch (e) {}
45
+ const cached = workerCacheByPath.get(workerPath);
46
+ if (cached && cached.mtimeMs === mtimeMs) {
47
+ return cached.promise;
48
+ }
49
+ const promise = import(pathToFileURL(workerPath).href).catch((err) => {
50
+ workerCacheByPath.delete(workerPath);
51
+ console.error("[Dinou Cloudflare Adapter] Failed to load .dinou/cloudflare/worker.js:", err);
52
+ return null;
53
+ });
54
+ workerCacheByPath.set(workerPath, { mtimeMs, promise });
55
+ return promise;
56
+ } catch (e) {
57
+ return null;
58
+ }
59
+ }
60
+
18
61
  let storageInitialized = false;
19
62
 
20
63
  export default {
21
64
  /**
22
65
  * Cloudflare Workers fetch handler
23
- * @param {Request} request
24
- * @param {object} env Bindings (KV, D1, Environment variables)
66
+ * @param {Request} request
67
+ * @param {object} env Bindings (KV, D1, ASSETS, Environment variables)
25
68
  * @param {object} ctx Execution context (waitUntil, passThroughOnException)
26
69
  * @returns {Promise<Response>}
27
70
  */
28
71
  async fetch(request, env, ctx) {
72
+ const prebuilt = await getPrebuiltCloudflareWorker();
73
+ const prebuiltFetch =
74
+ prebuilt?.default && typeof prebuilt.default.fetch === "function"
75
+ ? prebuilt.default.fetch
76
+ : typeof prebuilt?.fetch === "function"
77
+ ? prebuilt.fetch
78
+ : null;
79
+ if (prebuiltFetch) {
80
+ return prebuiltFetch(request, env, ctx);
81
+ }
82
+
29
83
  const url = new URL(request.url);
30
- if (url.pathname.startsWith("/cdn-cgi/")) {
84
+ if (
85
+ url.pathname.startsWith("/cdn-cgi/") ||
86
+ isReservedCloudflareDist2RequestPath(url.pathname)
87
+ ) {
31
88
  return new Response(null, { status: 404 });
32
89
  }
33
90
 
34
91
  if (!storageInitialized) {
35
- if (env && env.DINOU_CACHE) {
36
- setStorageAdapter(new CloudflareKVStorage(env.DINOU_CACHE));
37
- } else {
38
- setStorageAdapter(new MemoryStorage());
92
+ if (!hasExplicitStorageAdapter()) {
93
+ if (env && env.DINOU_CACHE) {
94
+ setStorageAdapter(new CloudflareKVStorage(env.DINOU_CACHE));
95
+ } else {
96
+ setStorageAdapter(new MemoryStorage());
97
+ }
39
98
  }
40
99
  storageInitialized = true;
41
100
  }
42
101
 
43
102
  const isRSCPayload = url.pathname.includes("____rsc_");
44
- const isServerFunction = url.pathname.includes("____server_function____") || request.headers.get("x-server-function-call") === "1";
103
+ const isServerFunction =
104
+ url.pathname.includes("____server_function____") ||
105
+ request.headers.get("x-server-function-call") === "1";
45
106
 
46
- // Static assets: files with extensions like .js, .css, .png, etc. (excluding document .html and RSC/server-functions)
47
- const staticExtRegex = /\.(js|mjs|cjs|css|png|jpg|jpeg|gif|svg|ico|webp|avif|woff|woff2|ttf|eot|otf|wasm|map|txt|webmanifest)$/i;
48
- const isStaticAsset = staticExtRegex.test(url.pathname) || url.pathname.startsWith("/assets/") || url.pathname.startsWith("/_dinou/");
107
+ const isStaticAsset = isPublicStaticAssetRequest(url.pathname);
49
108
 
50
- if (!isRSCPayload && !isServerFunction && isStaticAsset && env && env.ASSETS && (request.method === "GET" || request.method === "HEAD")) {
109
+ if (
110
+ !isRSCPayload &&
111
+ !isServerFunction &&
112
+ isStaticAsset &&
113
+ env &&
114
+ env.ASSETS &&
115
+ (request.method === "GET" || request.method === "HEAD")
116
+ ) {
51
117
  try {
52
- const assetRes = await env.ASSETS.fetch(request.clone ? request.clone() : request);
118
+ const assetRes = await env.ASSETS.fetch(
119
+ request.clone ? request.clone() : request
120
+ );
53
121
  if (assetRes && assetRes.status < 400) {
122
+ const rawCt = (assetRes.headers.get("content-type") || "").trim();
123
+ const lowerCt = rawCt.toLowerCase();
124
+ const expectedCt = getStaticContentType(url.pathname);
125
+ const needsContentTypeFix =
126
+ !rawCt ||
127
+ (lowerCt === "application/octet-stream" &&
128
+ expectedCt !== "application/octet-stream") ||
129
+ (url.pathname.toLowerCase().endsWith("/apple-app-site-association") &&
130
+ !lowerCt.includes("json"));
131
+ if (needsContentTypeFix) {
132
+ const headers = new Headers(assetRes.headers);
133
+ headers.set("content-type", expectedCt);
134
+ return new Response(assetRes.body, {
135
+ status: assetRes.status,
136
+ statusText: assetRes.statusText,
137
+ headers,
138
+ });
139
+ }
54
140
  return assetRes;
55
141
  }
56
142
  } catch (e) {}
57
143
  }
58
144
 
145
+ const registeredSsr =
146
+ typeof globalThis !== "undefined" &&
147
+ typeof globalThis.__DINOU_RENDER_HTML_STREAM__ === "function"
148
+ ? globalThis.__DINOU_RENDER_HTML_STREAM__
149
+ : undefined;
150
+
59
151
  return handleRequest(request, {
60
152
  env,
61
153
  ctx,
62
154
  runtime: "edge",
155
+ ...(registeredSsr ? { renderHtmlStream: registeredSsr } : {}),
63
156
  });
64
157
  },
65
158
  };
@@ -1,17 +1,25 @@
1
1
  // dinou/adapters/deno.js
2
- // Native Deno & Deno Deploy Adapter for Dinou v7.
2
+ // Native Deno & Deno Deploy Adapter for Dinou (Pre-bundled AOT).
3
3
  // Supports standalone containers, Deno CLI, and Deno Deploy Edge.
4
4
 
5
5
  import * as path from "node:path";
6
6
  import * as fs from "node:fs";
7
7
  import { pathToFileURL } from "node:url";
8
8
  import { AsyncLocalStorage } from "node:async_hooks";
9
+ import { loadEnvFiles } from "../core/env.js";
9
10
 
10
- if (typeof globalThis.AsyncLocalStorage === "undefined" && typeof AsyncLocalStorage !== "undefined") {
11
+ if (
12
+ typeof globalThis.AsyncLocalStorage === "undefined" &&
13
+ typeof AsyncLocalStorage !== "undefined"
14
+ ) {
11
15
  globalThis.AsyncLocalStorage = AsyncLocalStorage;
12
16
  }
13
17
 
18
+ const isMain = Boolean(typeof import.meta !== "undefined" && import.meta.main);
14
19
  const cwd = typeof Deno !== "undefined" ? Deno.cwd() : process.cwd();
20
+ try {
21
+ loadEnvFiles(cwd, { mode: "production" });
22
+ } catch (e) {}
15
23
  const mainBundlePath = path.resolve(cwd, ".dinou/deno/main.js");
16
24
 
17
25
  let mainModule = null;
@@ -20,29 +28,59 @@ if (fs.existsSync(mainBundlePath)) {
20
28
  mainModule = await import(pathToFileURL(mainBundlePath).href);
21
29
  } catch (e) {
22
30
  console.error("[Dinou Deno Adapter] Failed to load .dinou/deno/main.js:", e);
31
+ if (isMain) {
32
+ if (typeof Deno !== "undefined" && typeof Deno.exit === "function") {
33
+ Deno.exit(1);
34
+ } else if (typeof process !== "undefined") {
35
+ process.exit(1);
36
+ }
37
+ }
38
+ }
39
+ } else if (isMain) {
40
+ console.error(
41
+ "❌ [Dinou Deno Adapter] .dinou/deno/main.js not found. Please run 'npm run build:deno' first."
42
+ );
43
+ if (typeof Deno !== "undefined" && typeof Deno.exit === "function") {
44
+ Deno.exit(1);
45
+ } else if (typeof process !== "undefined") {
46
+ process.exit(1);
23
47
  }
24
48
  }
25
49
 
26
50
  const PORT = Number(
27
51
  (typeof Deno !== "undefined" ? Deno.env.get("PORT") : process.env.PORT) || 3000
28
52
  );
53
+ const HOST =
54
+ (typeof Deno !== "undefined" ? Deno.env.get("HOST") : process.env.HOST) ||
55
+ undefined;
29
56
 
30
57
  export async function fetch(req) {
31
58
  if (mainModule && typeof mainModule.fetch === "function") {
32
59
  return mainModule.fetch(req);
33
60
  }
34
- return new Response("Dinou bundle not found. Please run 'npm run build:deno' first.", {
35
- status: 500,
36
- headers: { "content-type": "text/plain; charset=utf-8" },
37
- });
61
+ if (
62
+ mainModule &&
63
+ mainModule.default &&
64
+ typeof mainModule.default.fetch === "function"
65
+ ) {
66
+ return mainModule.default.fetch(req);
67
+ }
68
+ return new Response(
69
+ "Dinou bundle not found. Please run 'npm run build:deno' first.",
70
+ {
71
+ status: 500,
72
+ headers: { "content-type": "text/plain; charset=utf-8" },
73
+ }
74
+ );
38
75
  }
39
76
 
40
77
  // Start standalone server if run directly in Deno
41
- if (typeof Deno !== "undefined" && typeof Deno.serve === "function" && import.meta.main) {
42
- Deno.serve({ port: PORT }, fetch);
78
+ if (typeof Deno !== "undefined" && typeof Deno.serve === "function" && isMain) {
79
+ Deno.serve(HOST ? { port: PORT, hostname: HOST } : { port: PORT }, fetch);
43
80
  }
44
81
 
45
82
  export default {
46
83
  port: PORT,
84
+ ...(HOST ? { hostname: HOST } : {}),
47
85
  fetch,
48
86
  };
@@ -1,74 +1,110 @@
1
1
  // dinou/adapters/netlify.js
2
- // Netlify Functions v2 Adapter for Dinou.
3
- // Automatically routes all requests to Dinou's universal Web Standards handler.
4
- Object.assign(process.env, { NODE_ENV: "production" });
2
+ // Netlify Functions v2 Adapter for Dinou (Pre-bundled AOT Dual-Bundle).
3
+ // Delegates to the standalone AOT Dual-Bundle in .dinou/netlify/functions/ssr.mjs
4
+ // (or .dinou/dist1/server/netlify.js) so dynamic SSR, TypeScript/JSX routes,
5
+ // Server Functions, and read-only AWS Lambda filesystems work with zero runtime flags.
5
6
 
6
- import path from "node:path";
7
- import Module from "node:module";
7
+ import * as path from "node:path";
8
+ import * as fs from "node:fs";
9
+ import { pathToFileURL } from "node:url";
10
+ import { AsyncLocalStorage } from "node:async_hooks";
11
+ import { loadEnvFiles } from "../core/env.js";
8
12
 
9
- const require = Module.createRequire(import.meta.url);
13
+ if (typeof process !== "undefined" && process.env && !process.env.NODE_ENV) {
14
+ process.env.NODE_ENV = "production";
15
+ }
10
16
 
11
- let reactServerPath, reactDomServerPath, reactJsxRuntimePath, reactJsxDevRuntimePath;
12
- let roggcServerNodePath, webpackServerNodePath;
17
+ if (
18
+ typeof globalThis.AsyncLocalStorage === "undefined" &&
19
+ typeof AsyncLocalStorage !== "undefined"
20
+ ) {
21
+ globalThis.AsyncLocalStorage = AsyncLocalStorage;
22
+ }
13
23
 
14
- try {
15
- const reactPkgJson = require.resolve("react/package.json");
16
- reactServerPath = path.join(path.dirname(reactPkgJson), "react.react-server.js");
17
- reactJsxRuntimePath = path.join(path.dirname(reactPkgJson), "jsx-runtime.react-server.js");
18
- reactJsxDevRuntimePath = path.join(path.dirname(reactPkgJson), "jsx-dev-runtime.react-server.js");
24
+ const bundleCacheByCwd = new Map();
19
25
 
20
- const reactDomPkgJson = require.resolve("react-dom/package.json");
21
- reactDomServerPath = path.join(path.dirname(reactDomPkgJson), "react-dom.react-server.js");
22
- } catch (e) { }
26
+ function resolveNetlifyBundlePath(cwd) {
27
+ const dedicated = path.resolve(cwd, ".dinou/netlify/functions/ssr.mjs");
28
+ if (fs.existsSync(dedicated)) {
29
+ return dedicated;
30
+ }
31
+ const dist1Fallback = path.resolve(cwd, ".dinou/dist1/server/netlify.js");
32
+ if (fs.existsSync(dist1Fallback)) {
33
+ return dist1Fallback;
34
+ }
35
+ return null;
36
+ }
23
37
 
24
- try {
25
- const roggcPkgJson = require.resolve("@roggc/react-server-dom-esm/package.json");
26
- roggcServerNodePath = path.join(path.dirname(roggcPkgJson), "server.node.js");
27
- } catch (e) { }
38
+ async function getNetlifyBundle(cwd) {
39
+ const resolvedCwd = path.resolve(cwd || ".");
40
+ const bundlePath = resolveNetlifyBundlePath(resolvedCwd);
41
+ if (!bundlePath) {
42
+ return null;
43
+ }
44
+ let mtimeMs = 0;
45
+ try {
46
+ mtimeMs = fs.statSync(bundlePath).mtimeMs;
47
+ } catch (e) {}
28
48
 
29
- try {
30
- const webpackPkgJson = require.resolve("react-server-dom-webpack/package.json");
31
- webpackServerNodePath = path.join(path.dirname(webpackPkgJson), "server.node.js");
32
- } catch (e) { }
49
+ const cached = bundleCacheByCwd.get(bundlePath);
50
+ if (cached && cached.mtimeMs === mtimeMs) {
51
+ return cached.promise;
52
+ }
33
53
 
34
- if (Module && Module._resolveFilename) {
35
- const originalResolveFilename = Module._resolveFilename;
36
- Module._resolveFilename = function (request, parent, isMain, options) {
37
- if (request === "react") {
38
- return reactServerPath;
39
- } else if (request === "react-dom") {
40
- return reactDomServerPath;
41
- } else if (request === "react/jsx-runtime") {
42
- return reactJsxRuntimePath;
43
- } else if (request === "react/jsx-dev-runtime") {
44
- return reactJsxDevRuntimePath;
45
- } else if (request === "@roggc/react-server-dom-esm/server" && roggcServerNodePath) {
46
- return roggcServerNodePath;
47
- } else if (request === "react-server-dom-webpack/server" && webpackServerNodePath) {
48
- return webpackServerNodePath;
49
- }
50
- return originalResolveFilename.call(this, request, parent, isMain, options);
51
- };
52
- }
54
+ try {
55
+ loadEnvFiles(resolvedCwd, { mode: "production" });
56
+ } catch (e) {}
53
57
 
54
- if (typeof require === "function") {
55
- globalThis.__dinou_require__ = require;
58
+ const loadPromise = import(pathToFileURL(bundlePath).href).catch((err) => {
59
+ bundleCacheByCwd.delete(bundlePath);
60
+ console.error(`[Dinou Netlify Adapter] Failed to load ${bundlePath}:`, err);
61
+ return null;
62
+ });
63
+ bundleCacheByCwd.set(bundlePath, { mtimeMs, promise: loadPromise });
64
+ return loadPromise;
56
65
  }
57
66
 
58
- import { handleRequest } from "../core/handler.js";
67
+ const initialCwd =
68
+ typeof process !== "undefined" && typeof process.cwd === "function"
69
+ ? process.cwd()
70
+ : ".";
71
+ if (resolveNetlifyBundlePath(initialCwd)) {
72
+ await getNetlifyBundle(initialCwd);
73
+ }
59
74
 
60
75
  /**
61
76
  * Netlify Function v2 handler
62
- * @param {Request} request
63
- * @param {object} context
77
+ * @param {Request} request
78
+ * @param {object} context
64
79
  * @returns {Promise<Response>}
65
80
  */
66
81
  export default async function netlifyHandler(request, context) {
67
- return handleRequest(request);
82
+ const cwd =
83
+ typeof process !== "undefined" && typeof process.cwd === "function"
84
+ ? process.cwd()
85
+ : initialCwd;
86
+ const mod = await getNetlifyBundle(cwd);
87
+ const fn =
88
+ mod && typeof mod.default === "function"
89
+ ? mod.default
90
+ : mod && typeof mod.netlifyHandler === "function"
91
+ ? mod.netlifyHandler
92
+ : null;
93
+
94
+ if (fn) {
95
+ return fn(request, context);
96
+ }
97
+
98
+ return new Response(
99
+ "Dinou Netlify bundle not found. Please run 'npm run build' or 'npx dinou build:netlify' first.",
100
+ {
101
+ status: 500,
102
+ headers: { "content-type": "text/plain; charset=utf-8" },
103
+ }
104
+ );
68
105
  }
69
106
 
70
107
  export const config = {
71
108
  path: "/*",
72
109
  preferStatic: true,
73
110
  };
74
-
@@ -6,6 +6,14 @@ import * as path from "node:path";
6
6
  import * as fs from "node:fs";
7
7
  import { pathToFileURL } from "node:url";
8
8
  import { AsyncLocalStorage } from "node:async_hooks";
9
+ import { loadEnvFiles } from "../core/env.js";
10
+
11
+ loadEnvFiles(
12
+ typeof process !== "undefined" && typeof process.cwd === "function"
13
+ ? process.cwd()
14
+ : ".",
15
+ { mode: "production" }
16
+ );
9
17
 
10
18
  import ensureVendorMode from "../core/ensure-vendor-mode.js";
11
19
  if (!ensureVendorMode()) {
package/dinou/assets.d.ts CHANGED
@@ -50,11 +50,6 @@ declare module "*.webm" {
50
50
  export default value;
51
51
  }
52
52
 
53
- declare module "*.ogg" {
54
- const value: string;
55
- export default value;
56
- }
57
-
58
53
  declare module "*.mov" {
59
54
  const value: string;
60
55
  export default value;
@@ -81,6 +76,11 @@ declare module "*.mjpg" {
81
76
  }
82
77
 
83
78
  // Audio
79
+ declare module "*.ogg" {
80
+ const value: string;
81
+ export default value;
82
+ }
83
+
84
84
  declare module "*.mp3" {
85
85
  const value: string;
86
86
  export default value;
@@ -106,3 +106,30 @@ declare module "*.aac" {
106
106
  export default value;
107
107
  }
108
108
 
109
+ // Fonts
110
+ declare module "*.woff" {
111
+ const value: string;
112
+ export default value;
113
+ }
114
+
115
+ declare module "*.woff2" {
116
+ const value: string;
117
+ export default value;
118
+ }
119
+
120
+ declare module "*.ttf" {
121
+ const value: string;
122
+ export default value;
123
+ }
124
+
125
+ declare module "*.otf" {
126
+ const value: string;
127
+ export default value;
128
+ }
129
+
130
+ declare module "*.eot" {
131
+ const value: string;
132
+ export default value;
133
+ }
134
+
135
+