dinou 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
 
8
+ ## [2.4.1]
9
+
10
+ ### Fixed
11
+
12
+ - Use hashed names for bundled files in production.
13
+
8
14
  ## [2.4.0]
9
15
 
10
16
  ### Fixed
@@ -0,0 +1,18 @@
1
+ const fs = require("fs");
2
+ const path = require("path");
3
+
4
+ let manifest = {};
5
+ let read = false;
6
+
7
+ function getAssetFromManifest(name) {
8
+ if (process.env.NODE_ENV === "production" && !read) {
9
+ const manifestPath = path.resolve(process.cwd(), "dist3/manifest.json");
10
+ if (fs.existsSync(manifestPath)) {
11
+ manifest = JSON.parse(fs.readFileSync(manifestPath, "utf-8"));
12
+ read = true;
13
+ }
14
+ }
15
+ return "/" + (manifest[name] || name);
16
+ }
17
+
18
+ module.exports = getAssetFromManifest;
@@ -23,7 +23,7 @@ addHook({
23
23
  },
24
24
  publicPath: "/assets/",
25
25
  });
26
-
26
+ const getAssetFromManifest = require("./get-asset-from-manifest.js");
27
27
  const { renderToPipeableStream } = require("react-dom/server");
28
28
  const getJSX = require("./get-jsx");
29
29
  const getSSGJSX = require("./get-ssg-jsx.js");
@@ -157,7 +157,7 @@ async function renderToStream(reqPath, query, cookies = {}) {
157
157
  writeErrorOutput(error, isProd);
158
158
  process.exit(1);
159
159
  },
160
- bootstrapModules: ["/error.js"],
160
+ bootstrapModules: [getAssetFromManifest("error.js")],
161
161
  bootstrapScriptContent: `window.__DINOU_ERROR_MESSAGE__=${JSON.stringify(
162
162
  error.message || "Unknown error"
163
163
  )};window.__DINOU_ERROR_STACK__=${JSON.stringify(
@@ -175,8 +175,8 @@ async function renderToStream(reqPath, query, cookies = {}) {
175
175
  stream.pipe(process.stdout);
176
176
  },
177
177
  bootstrapModules: isDevelopment
178
- ? ["/main.js", "/runtime.js"]
179
- : ["/main.js"],
178
+ ? [getAssetFromManifest("main.js"), getAssetFromManifest("runtime.js")]
179
+ : [getAssetFromManifest("main.js")],
180
180
  ...(isDevelopment
181
181
  ? {
182
182
  bootstrapScriptContent: `window.HMR_WEBSOCKET_URL="ws://localhost:3001";`,
@@ -0,0 +1,25 @@
1
+ let manifestData = {};
2
+
3
+ function manifestGeneratorPlugin() {
4
+ return {
5
+ name: "manifest-generator",
6
+ generateBundle(options, bundle) {
7
+ for (const [fileName, info] of Object.entries(bundle)) {
8
+ if (info.type === "chunk" && info.name) {
9
+ const cleanName = info.name + ".js";
10
+ manifestData[cleanName] = fileName;
11
+ }
12
+ }
13
+
14
+ this.emitFile({
15
+ type: "asset",
16
+ fileName: "manifest.json",
17
+ source: JSON.stringify(manifestData, null, 2),
18
+ });
19
+ },
20
+ };
21
+ }
22
+
23
+ manifestGeneratorPlugin.manifestData = manifestData;
24
+
25
+ module.exports = manifestGeneratorPlugin;
@@ -2,6 +2,7 @@
2
2
  const path = require("path");
3
3
  const parser = require("@babel/parser");
4
4
  const traverse = require("@babel/traverse").default;
5
+ const manifestGeneratorPlugin = require("./manifest-generator-plugin");
5
6
 
6
7
  function parseExports(code) {
7
8
  const ast = parser.parse(code, {
@@ -51,7 +52,7 @@ function serverFunctionsPlugin() {
51
52
 
52
53
  // Generamos un módulo que exporta proxies en lugar del código real
53
54
  let proxyCode = `
54
- import { createServerFunctionProxy } from "/serverFunctionProxy.js";
55
+ import { createServerFunctionProxy } from "/__SERVER_FUNCTION_PROXY__";
55
56
  `;
56
57
 
57
58
  for (const exp of exports) {
@@ -73,6 +74,23 @@ function serverFunctionsPlugin() {
73
74
  map: null,
74
75
  };
75
76
  },
77
+ // 🪄 After manifest exists, replace the placeholder with the final URL
78
+ generateBundle(options, bundle) {
79
+ const manifest = manifestGeneratorPlugin.manifestData;
80
+ const hashedPath =
81
+ "/" + (manifest["serverFunctionProxy.js"] || "serverFunctionProxy.js");
82
+
83
+ for (const file of Object.keys(bundle)) {
84
+ const chunk = bundle[file];
85
+ if (chunk.type === "asset" || !chunk.code) continue;
86
+ if (chunk.code.includes("/__SERVER_FUNCTION_PROXY__")) {
87
+ chunk.code = chunk.code.replace(
88
+ /\/__SERVER_FUNCTION_PROXY__/g,
89
+ hashedPath
90
+ );
91
+ }
92
+ }
93
+ },
76
94
  };
77
95
  }
78
96
 
@@ -14,6 +14,7 @@ const dinouAssetPlugin = require("./rollup-plugins/dinou-asset-plugin.js");
14
14
  const tsconfigPaths = require("rollup-plugin-tsconfig-paths");
15
15
  const serverFunctionsPlugin = require("./rollup-plugins/rollup-plugin-server-functions");
16
16
  const { regex } = require("./core/asset-extensions.js");
17
+ const manifestGeneratorPlugin = require("./rollup-plugins/manifest-generator-plugin.js");
17
18
 
18
19
  const isDevelopment = process.env.NODE_ENV !== "production";
19
20
  const outputDirectory = isDevelopment ? "public" : "dist3";
@@ -49,10 +50,14 @@ module.exports = async function () {
49
50
  output: {
50
51
  dir: outputDirectory,
51
52
  format: "esm",
52
- entryFileNames: "[name].js",
53
- chunkFileNames: "[name].js",
53
+ entryFileNames: isDevelopment ? "[name].js" : "[name]-[hash].js",
54
+ chunkFileNames: isDevelopment ? "[name].js" : "[name]-[hash].js",
54
55
  },
55
- external: ["/refresh.js", "/__hmr_client__.js", "/serverFunctionProxy.js"],
56
+ external: [
57
+ "/refresh.js",
58
+ "/__hmr_client__.js",
59
+ "/__SERVER_FUNCTION_PROXY__",
60
+ ],
56
61
  plugins: [
57
62
  del({
58
63
  targets: `${outputDirectory}/*`,
@@ -117,6 +122,7 @@ module.exports = async function () {
117
122
  }),
118
123
  isDevelopment && reactRefreshWrapModules(),
119
124
  isDevelopment && esmHmrPlugin(),
125
+ !isDevelopment && manifestGeneratorPlugin(),
120
126
  serverFunctionsPlugin(),
121
127
  ].filter(Boolean),
122
128
  watch: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dinou",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "Dinou is a modern React 19 framework with React Server Components, Server Functions, and streaming SSR. Built with Rollup for better performance and developer experience.",
5
5
  "main": "index.js",
6
6
  "bin": {