dinou 6.1.0 → 7.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 (135) hide show
  1. package/CHANGELOG.md +99 -0
  2. package/README.md +9461 -1080
  3. package/cli.js +392 -169
  4. package/dinou/adapters/bun.js +62 -0
  5. package/dinou/adapters/cloudflare.js +65 -0
  6. package/dinou/adapters/deno.js +48 -0
  7. package/dinou/adapters/netlify.js +85 -0
  8. package/dinou/adapters/node.mjs +31 -0
  9. package/dinou/bun/build.mjs +1077 -0
  10. package/dinou/cloudflare/build.mjs +1121 -0
  11. package/dinou/cloudflare/shims/child_process.js +14 -0
  12. package/dinou/cloudflare/shims/empty.js +2 -0
  13. package/dinou/cloudflare/shims/fs.js +99 -0
  14. package/dinou/cloudflare/shims/os.js +29 -0
  15. package/dinou/config.js +1 -0
  16. package/dinou/config.mjs +2 -0
  17. package/dinou/constants.js +29 -4
  18. package/dinou/core/babel-esm-loader.js +66 -37
  19. package/dinou/core/bailout-proxy.js +61 -0
  20. package/dinou/core/build-static-pages.js +309 -157
  21. package/dinou/core/cache-revalidate.js +471 -144
  22. package/dinou/core/cache-slot.js +387 -0
  23. package/dinou/core/client-redirect.jsx +12 -7
  24. package/dinou/core/client-webpack.jsx +457 -82
  25. package/dinou/core/client.jsx +452 -82
  26. package/dinou/core/config.js +11 -0
  27. package/dinou/core/dinou-paths.js +52 -0
  28. package/dinou/core/edge-ssr.js +122 -0
  29. package/dinou/core/export-static.mjs +64 -0
  30. package/dinou/core/generate-route-types.js +252 -0
  31. package/dinou/core/generate-static-page.js +55 -94
  32. package/dinou/core/generate-static-rsc.js +47 -15
  33. package/dinou/core/generate-static.js +212 -10
  34. package/dinou/core/generating-isg.js +5 -0
  35. package/dinou/core/get-asset-from-manifest.js +9 -3
  36. package/dinou/core/get-error-jsx.js +221 -41
  37. package/dinou/core/get-file-path-and-dynamic-params.js +9 -13
  38. package/dinou/core/get-jsx.js +172 -95
  39. package/dinou/core/handler.js +2296 -0
  40. package/dinou/core/http-adapter.js +115 -0
  41. package/dinou/core/import-module.js +83 -53
  42. package/dinou/core/layout-functions.js +181 -0
  43. package/dinou/core/link.jsx +18 -6
  44. package/dinou/core/load-dinou-config.js +60 -0
  45. package/dinou/core/manifest-provider.js +261 -0
  46. package/dinou/core/navigation-utils.js +4 -0
  47. package/dinou/core/navigation.js +50 -39
  48. package/dinou/core/parse-exports.js +207 -2
  49. package/dinou/core/ppr-context.js +105 -0
  50. package/dinou/core/ppr-runtime.js +263 -0
  51. package/dinou/core/redirect.jsx +20 -19
  52. package/dinou/core/render-jsx-to-client-jsx.js +133 -15
  53. package/dinou/core/request-context.js +47 -13
  54. package/dinou/core/resolve-module-ppr.js +32 -0
  55. package/dinou/core/revalidating.js +28 -9
  56. package/dinou/core/route-generator.js +107 -0
  57. package/dinou/core/rsc-renderer.js +90 -0
  58. package/dinou/core/run-ssg.js +19 -0
  59. package/dinou/core/scan-dependency-components.js +218 -0
  60. package/dinou/core/server-function-proxy-webpack.js +3 -0
  61. package/dinou/core/server-function-proxy.js +3 -0
  62. package/dinou/core/slot.js +302 -0
  63. package/dinou/core/status-manifest.js +41 -1
  64. package/dinou/core/storage-adapter.js +522 -0
  65. package/dinou/core/url-resolver.js +16 -16
  66. package/dinou/core/vfs.js +139 -68
  67. package/dinou/deno/build.mjs +1112 -0
  68. package/dinou/deno/seed-kv.js +115 -0
  69. package/dinou/esbuild/build.mjs +51 -1
  70. package/dinou/esbuild/dev.mjs +290 -224
  71. package/dinou/esbuild/helpers-esbuild/get-config-esbuild-prod.mjs +3 -2
  72. package/dinou/esbuild/helpers-esbuild/get-config-esbuild.mjs +104 -16
  73. package/dinou/esbuild/helpers-esbuild/get-esbuild-entries.mjs +31 -19
  74. package/dinou/esbuild/helpers-esbuild/strip-namespace.mjs +9 -0
  75. package/dinou/esbuild/helpers-esbuild/swc-disk-cache.mjs +225 -0
  76. package/dinou/esbuild/helpers-esbuild/update-manifest-for-module.mjs +7 -0
  77. package/dinou/esbuild/helpers-esbuild/write.mjs +111 -2
  78. package/dinou/esbuild/plugins-esbuild/assets-plugin.mjs +236 -161
  79. package/dinou/esbuild/plugins-esbuild/css-processor-plugin.mjs +101 -5
  80. package/dinou/esbuild/plugins-esbuild/react-client-manifest-plugin.mjs +63 -24
  81. package/dinou/esbuild/plugins-esbuild/server-functions-plugin.mjs +177 -56
  82. package/dinou/esbuild/plugins-esbuild/skip-missing-entry-points-plugin.mjs +3 -0
  83. package/dinou/esbuild/plugins-esbuild/stable-chunk-names-and-maps-plugin.mjs +182 -137
  84. package/dinou/esbuild/plugins-postcss/postcss-extract-plugin.js +38 -11
  85. package/dinou/esbuild/react-refresh/esm-hmr/client.mjs +55 -8
  86. package/dinou/esbuild/react-refresh/esm-hmr/server.js +1 -1
  87. package/dinou/esbuild/react-refresh/esm-hmr-plugin.mjs +238 -101
  88. package/dinou/esbuild/react-refresh/is-react-refresh-boundary.mjs +18 -4
  89. package/dinou/index.d.ts +315 -11
  90. package/dinou/index.js +12 -6
  91. package/dinou/index.mjs +9 -0
  92. package/dinou/node/build.mjs +195 -0
  93. package/dinou/node/bundle-dual-engine.mjs +1012 -0
  94. package/dinou/node/dev.mjs +2589 -0
  95. package/dinou/node/port-selector.mjs +164 -0
  96. package/dinou/node/terminal-status.mjs +345 -0
  97. package/dinou/package.json +17 -14
  98. package/dinou/rollup/react-refresh/esm-hmr/client.js +66 -10
  99. package/dinou/rollup/react-refresh/esm-hmr/server.js +1 -1
  100. package/dinou/rollup/react-refresh/is-react-refresh-boundary.js +24 -5
  101. package/dinou/rollup/react-refresh/react-refresh-runtime.js +13 -6
  102. package/dinou/rollup/react-refresh/react-refresh-wrap-modules.js +56 -11
  103. package/dinou/rollup/react-refresh/rollup-plugin-esm-hmr.js +176 -48
  104. package/dinou/rollup/rollup-plugins/dinou-asset-plugin.js +9 -5
  105. package/dinou/rollup/rollup-plugins/rollup-plugin-memory.js +66 -0
  106. package/dinou/rollup/rollup-plugins/rollup-plugin-react-client-manifest.js +468 -123
  107. package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +44 -12
  108. package/dinou/rollup/rollup-plugins/rollup-plugin-swc.js +100 -0
  109. package/dinou/rollup/rollup.config.js +155 -43
  110. package/dinou/server.d.ts +114 -12
  111. package/dinou/server.js +35 -10
  112. package/dinou/server.mjs +30 -9
  113. package/dinou/webpack/helpers/get-webpack-entries.js +14 -19
  114. package/dinou/webpack/loaders/server-functions-loader.js +22 -1
  115. package/dinou/webpack/loaders/swc-loader.js +76 -0
  116. package/dinou/webpack/plugins/manifest-generator-plugin.js +1 -0
  117. package/dinou/webpack/plugins/server-functions-plugin.js +75 -19
  118. package/dinou/webpack/plugins/webpack-memory-plugin.js +66 -0
  119. package/dinou/webpack/webpack.config.js +227 -29
  120. package/eject.js +173 -94
  121. package/package.json +110 -107
  122. package/dinou/core/asset-require-hook.js +0 -58
  123. package/dinou/core/client-error-webpack.jsx +0 -432
  124. package/dinou/core/client-error.jsx +0 -432
  125. package/dinou/core/concurrency-manager.js +0 -48
  126. package/dinou/core/context-proxy.js +0 -68
  127. package/dinou/core/generate-static-pages.js +0 -130
  128. package/dinou/core/generate-static-rscs.js +0 -151
  129. package/dinou/core/get-ssg-metadata.js +0 -31
  130. package/dinou/core/register-loader.mjs +0 -11
  131. package/dinou/core/register-paths.js +0 -27
  132. package/dinou/core/render-app-to-html.js +0 -430
  133. package/dinou/core/render-html.js +0 -407
  134. package/dinou/core/server.js +0 -1542
  135. package/dinou/esbuild/plugins-esbuild/write-metafile-plugin.mjs +0 -16
@@ -1,407 +0,0 @@
1
- const path = require("path");
2
- global.__webpack_require__ = function (id) {
3
- if (global.__webpack_require_map__ && global.__webpack_require_map__[id]) {
4
- return require(global.__webpack_require_map__[id]);
5
- }
6
- if (typeof id === "string" && id.startsWith("./")) {
7
- id = path.resolve(process.cwd(), id);
8
- }
9
- return require(id);
10
- };
11
- global.__webpack_chunk_load__ = function (chunkId) {
12
- return Promise.resolve();
13
- };
14
-
15
- require("./register-paths");
16
- const babelRegister = require("@babel/register");
17
- babelRegister({
18
- ignore: [/node_modules[\\/](?!dinou)/],
19
- presets: [
20
- ["@babel/preset-react", { runtime: "automatic" }],
21
- "@babel/preset-typescript",
22
- ],
23
- plugins: ["@babel/transform-modules-commonjs"],
24
- extensions: [".js", ".jsx", ".ts", ".tsx"],
25
- });
26
- const addHook = require("./asset-require-hook.js");
27
- const { extensions } = require("./asset-extensions.js");
28
- const createScopedName = require("./createScopedName");
29
- require("./css-require-hook.js")();
30
- addHook({
31
- extensions,
32
- name: function (localName, filepath) {
33
- const result = createScopedName(localName, filepath);
34
- return result + ".[ext]";
35
- },
36
- publicPath: "/assets/",
37
- });
38
- const getAssetFromManifest = require("./get-asset-from-manifest.js");
39
- const { renderToPipeableStream } = require("react-dom/server");
40
- const getJSX = require("./get-jsx");
41
- const { getErrorJSX } = require("./get-error-jsx");
42
- const isDevelopment = process.env.NODE_ENV !== "production";
43
- const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
44
- const { requestStorage } = require("./request-context.js");
45
- const { createResponseProxy } = require("./context-proxy.js");
46
-
47
- function formatErrorHtml(error) {
48
- const message = error.message || "Unknown error";
49
- const stack = error.stack
50
- ? error.stack.replace(/\n/g, "<br>").replace(/\s/g, "&nbsp;")
51
- : "No stack trace available";
52
-
53
- return `
54
- <!DOCTYPE html>
55
- <html lang="en">
56
- <head>
57
- <meta charset="UTF-8">
58
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
59
- <title>Error</title>
60
- <style>
61
- body {
62
- font-family: Arial, sans-serif;
63
- margin: 0;
64
- padding: 20px;
65
- background-color: #f8f8f8;
66
- color: #333;
67
- }
68
- .error-container {
69
- max-width: 800px;
70
- margin: 0 auto;
71
- background-color: #fff;
72
- padding: 20px;
73
- border-radius: 8px;
74
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
75
- }
76
- .error-title {
77
- color: #d32f2f;
78
- font-size: 24px;
79
- margin-bottom: 10px;
80
- }
81
- .error-message {
82
- font-size: 18px;
83
- margin-bottom: 20px;
84
- }
85
- .error-stack {
86
- background-color: #f5f5f5;
87
- padding: 15px;
88
- border-radius: 4px;
89
- font-family: Consolas, monospace;
90
- font-size: 14px;
91
- overflow-x: auto;
92
- }
93
- .error-footer {
94
- margin-top: 20px;
95
- font-size: 14px;
96
- color: #666;
97
- }
98
- </style>
99
- </head>
100
- <body>
101
- <div class="error-container">
102
- <h1 class="error-title">An Error Occurred</h1>
103
- <p class="error-message">${message}</p>
104
- <div class="error-stack">${stack}</div>
105
- </div>
106
- </body>
107
- </html>
108
- `;
109
- }
110
-
111
- function formatErrorHtmlProduction(error) {
112
- const escapedMessage = JSON.stringify(`Render error: ${error.message}`);
113
- const escapedStack = JSON.stringify(error.stack || "");
114
-
115
- return `
116
- <!DOCTYPE html>
117
- <html>
118
- <head><meta charset="utf-8"></head>
119
- <body>
120
- <script>
121
- console.error(${escapedMessage} + "\\n" + ${escapedStack});
122
- </script>
123
- </body>
124
- </html>
125
- `;
126
- }
127
-
128
- function writeErrorOutput(error, isProd) {
129
- process.stdout.write(
130
- isProd ? formatErrorHtmlProduction(error) : formatErrorHtml(error),
131
- );
132
- process.stderr.write(
133
- JSON.stringify({ error: error.message, stack: error.stack }),
134
- );
135
- }
136
-
137
- function getImportMapHtml() {
138
- const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
139
- if (isWebpack) return "";
140
-
141
- const fs = require("fs");
142
- const path = require("path");
143
- const { pathToFileURL } = require("url");
144
-
145
- const manifestPath = path.resolve(
146
- process.cwd(),
147
- ".dinou/react_client_manifest/react-client-manifest.json"
148
- );
149
-
150
- if (!fs.existsSync(manifestPath)) {
151
- return "";
152
- }
153
-
154
- try {
155
- const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
156
- const imports = {};
157
- const moduleBasePath = pathToFileURL(process.cwd()).href + "/";
158
-
159
- for (const [key, val] of Object.entries(manifest)) {
160
- let specifier = key;
161
- if (specifier.startsWith(moduleBasePath)) {
162
- specifier = specifier.slice(moduleBasePath.length);
163
- }
164
- const hashIdx = specifier.indexOf("#");
165
- if (hashIdx !== -1) {
166
- specifier = specifier.slice(0, hashIdx);
167
- }
168
- imports[specifier] = val.id;
169
- }
170
-
171
- return `<script type="importmap">{"imports":${JSON.stringify(imports)}}</script><script>(function(){const map=document.querySelector('script[type="importmap"]');if(map)map.remove();if(document.currentScript)document.currentScript.remove();})();</script>`;
172
- } catch (err) {
173
- console.error("Error generating importmap:", err);
174
- return "";
175
- }
176
- }
177
-
178
- let cachedSsrManifest = null;
179
- let cachedRequireMap = null;
180
- function getSsrManifest() {
181
- if (!isDevelopment && cachedSsrManifest) return cachedSsrManifest;
182
- try {
183
- const fs = require("fs");
184
- const path = require("path");
185
- const ssrManifestPath = path.resolve(
186
- process.cwd(),
187
- isDevelopment ? ".dinou/public/react-ssr-manifest.json" : ".dinou/dist3/react-ssr-manifest.json"
188
- );
189
- const clientManifestPath = path.resolve(
190
- process.cwd(),
191
- isDevelopment ? ".dinou/public/react-client-manifest.json" : ".dinou/dist3/react-client-manifest.json"
192
- );
193
-
194
- const ssrContent = fs.readFileSync(ssrManifestPath, "utf8");
195
- const ssrManifest = JSON.parse(ssrContent);
196
-
197
- if (fs.existsSync(clientManifestPath)) {
198
- const clientContent = fs.readFileSync(clientManifestPath, "utf8");
199
- const clientManifest = JSON.parse(clientContent);
200
-
201
- const { fileURLToPath } = require("url");
202
- const requireMap = {};
203
- for (const [fileUrl, entry] of Object.entries(clientManifest)) {
204
- if (entry && entry.id !== undefined) {
205
- try {
206
- requireMap[entry.id] = fileURLToPath(fileUrl);
207
- } catch { }
208
- }
209
- }
210
- global.__webpack_require_map__ = requireMap;
211
- cachedRequireMap = requireMap;
212
-
213
- if (ssrManifest.moduleMap) {
214
- for (const [modId, exports] of Object.entries(ssrManifest.moduleMap)) {
215
- for (const [expName, expData] of Object.entries(exports)) {
216
- if (expData && expData.specifier) {
217
- const clientEntry = clientManifest[expData.specifier];
218
- if (clientEntry) {
219
- expData.id = clientEntry.id;
220
- expData.chunks = clientEntry.chunks;
221
- }
222
- }
223
- }
224
- }
225
- }
226
- }
227
-
228
- cachedSsrManifest = ssrManifest;
229
- return cachedSsrManifest;
230
- } catch (e) {
231
- if (cachedSsrManifest) {
232
- console.warn("Using cached SSR manifest due to read error:", e.message);
233
- if (cachedRequireMap) {
234
- global.__webpack_require_map__ = cachedRequireMap;
235
- }
236
- return cachedSsrManifest;
237
- }
238
- console.error("Error reading SSR manifest:", e);
239
- return {};
240
- }
241
- }
242
-
243
- const { createFromNodeStream } = isWebpack
244
- ? require("react-server-dom-webpack/client")
245
- : require("@roggc/react-server-dom-esm/client");
246
-
247
- async function renderToStream(
248
- reqPath,
249
- query,
250
- serializedBox,
251
- isDynamic,
252
- ) {
253
- const context = {
254
- req: serializedBox.req,
255
- res: createResponseProxy(),
256
- };
257
- await requestStorage.run(context, async () => {
258
- try {
259
- const { createReadStream } = require("fs");
260
- const rscStream = createReadStream(null, { fd: 4 });
261
- const { pathToFileURL } = require("url");
262
- const baseUrl = pathToFileURL(process.cwd()).href + "/";
263
-
264
- const jsx = isWebpack
265
- ? await createFromNodeStream(rscStream, getSsrManifest())
266
- : await createFromNodeStream(rscStream, baseUrl, baseUrl);
267
-
268
- const stream = renderToPipeableStream(jsx, {
269
- onError(error) {
270
- process.nextTick(async () => {
271
- if (stream && !stream.destroyed) {
272
- try {
273
- stream.unpipe(process.stdout);
274
- stream.destroy();
275
- } catch { }
276
- }
277
- const isProd = process.env.NODE_ENV === "production";
278
-
279
- try {
280
- const errorJSX = await getErrorJSX(
281
- reqPath,
282
- query,
283
- error,
284
- isDevelopment,
285
- );
286
-
287
- if (!context.res.headersSent) context.res.status(500);
288
-
289
- if (errorJSX === undefined) {
290
- writeErrorOutput(error, isProd);
291
- process.exit(1);
292
- }
293
-
294
- const errorStream = renderToPipeableStream(errorJSX, {
295
- onShellReady() {
296
- const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
297
- if (!isWebpack) {
298
- const importMapHtml = getImportMapHtml();
299
- process.stdout.write(importMapHtml);
300
- }
301
- errorStream.pipe(process.stdout);
302
- },
303
- onError(err) {
304
- console.error("Error rendering error JSX:", err);
305
- writeErrorOutput(error, isProd);
306
- process.exit(1);
307
- },
308
- bootstrapModules: isDevelopment
309
- ? [
310
- getAssetFromManifest("error.js"),
311
- isWebpack
312
- ? undefined
313
- : getAssetFromManifest("runtime.js"),
314
- ].filter(Boolean)
315
- : [getAssetFromManifest("error.js")],
316
- bootstrapScriptContent: `window.__DINOU_ERROR_MESSAGE__=${JSON.stringify(
317
- error.message || "Unknown error",
318
- )};window.__DINOU_ERROR_NAME__=${JSON.stringify(error.name)};${isDevelopment
319
- ? `window.__DINOU_ERROR_STACK__=${JSON.stringify(
320
- error.stack || "No stack trace available",
321
- )};`
322
- : ""
323
- }${isDevelopment
324
- ? `window.HMR_WEBSOCKET_URL="ws://localhost:3001";`
325
- : ""
326
- }`,
327
- });
328
- } catch (err) {
329
- console.error("Render error (no error.tsx?):", err);
330
- writeErrorOutput(error, isProd);
331
- process.exit(1);
332
- }
333
- });
334
- },
335
- onShellReady() {
336
- const isWebpack = process.env.DINOU_BUILD_TOOL === "webpack";
337
- if (!isWebpack) {
338
- const importMapHtml = getImportMapHtml();
339
- process.stdout.write(importMapHtml);
340
- }
341
- stream.pipe(process.stdout);
342
- },
343
- bootstrapModules: isDevelopment
344
- ? [
345
- getAssetFromManifest("main.js"),
346
- isWebpack ? undefined : getAssetFromManifest("runtime.js"),
347
- ].filter(Boolean)
348
- : [getAssetFromManifest("main.js")],
349
- ...(isDevelopment
350
- ? {
351
- bootstrapScriptContent: `window.HMR_WEBSOCKET_URL="ws://localhost:3001";`,
352
- }
353
- : {}),
354
- });
355
- } catch (error) {
356
- if (context && context.res && typeof context.res.status === "function") {
357
- if (!context.res.headersSent) context.res.status(500);
358
- }
359
- process.stdout.write(formatErrorHtml(error));
360
- process.stderr.write(
361
- JSON.stringify({
362
- error: error.message,
363
- stack: error.stack,
364
- }),
365
- );
366
- process.exit(1);
367
- }
368
- });
369
- }
370
-
371
- const reqPath = process.argv[2] || "/";
372
- const query = JSON.parse(process.argv[3] || "{}");
373
- const serializedBox = JSON.parse(process.argv[4] || "{}");
374
- const isDynamic = process.argv[5] === "true";
375
-
376
- process.on("uncaughtException", (error) => {
377
- process.stdout.write(formatErrorHtml(error));
378
- process.stderr.write(
379
- JSON.stringify({
380
- error: error.message,
381
- stack: error.stack,
382
- }),
383
- );
384
- process.exit(1);
385
- });
386
-
387
- process.on("unhandledRejection", (reason) => {
388
- const error = reason instanceof Error ? reason : new Error(String(reason));
389
- process.stdout.write(formatErrorHtml(error));
390
- process.stderr.write(
391
- JSON.stringify({
392
- error: error.message,
393
- stack: error.stack,
394
- }),
395
- );
396
- process.exit(1);
397
- });
398
-
399
- renderToStream(
400
- reqPath,
401
- query,
402
- serializedBox,
403
- isDynamic,
404
- ).catch((err) => {
405
- console.error("❌ Fatal error starting render stream:", err);
406
- process.exit(1);
407
- });