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,6 +1,6 @@
1
1
  {
2
2
  "name": "dinou-ejected",
3
- "version": "9.3.0",
3
+ "version": "10.0.1",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -118,10 +118,6 @@
118
118
  "unvendorized": "@rollup/plugin-replace",
119
119
  "default": "./compiled/rollup-plugin-replace/index.js"
120
120
  },
121
- "#rollup-plugin-copy": {
122
- "unvendorized": "rollup-plugin-copy",
123
- "default": "./compiled/rollup-plugin-copy/index.js"
124
- },
125
121
  "#rollup-plugin-delete": {
126
122
  "unvendorized": "rollup-plugin-delete",
127
123
  "default": "./compiled/rollup-plugin-delete/index.js"
@@ -130,10 +126,6 @@
130
126
  "unvendorized": "rollup-plugin-postcss",
131
127
  "default": "./compiled/rollup-plugin-postcss/index.js"
132
128
  },
133
- "#rollup-plugin-tsconfig-paths": {
134
- "unvendorized": "rollup-plugin-tsconfig-paths",
135
- "default": "./compiled/rollup-plugin-tsconfig-paths/index.js"
136
- },
137
129
  "#babel-loader": {
138
130
  "unvendorized": "babel-loader",
139
131
  "default": "./compiled/babel-loader/index.js"
@@ -150,22 +142,10 @@
150
142
  "unvendorized": "copy-webpack-plugin",
151
143
  "default": "./compiled/copy-webpack-plugin/index.js"
152
144
  },
153
- "#tsconfig-paths-webpack-plugin": {
154
- "unvendorized": "tsconfig-paths-webpack-plugin",
155
- "default": "./compiled/tsconfig-paths-webpack-plugin/index.js"
156
- },
157
145
  "#commander": {
158
146
  "unvendorized": "commander",
159
147
  "default": "./compiled/commander/index.js"
160
148
  },
161
- "#dotenv": {
162
- "unvendorized": "dotenv",
163
- "default": "./compiled/dotenv/index.js"
164
- },
165
- "#cross-env": {
166
- "unvendorized": "cross-env",
167
- "default": "./compiled/cross-env/index.js"
168
- },
169
149
  "#ws": {
170
150
  "unvendorized": "ws",
171
151
  "default": "./compiled/ws/index.js"
@@ -174,23 +154,24 @@
174
154
  "unvendorized": "chokidar",
175
155
  "default": "./compiled/chokidar/index.js"
176
156
  },
177
- "#esbuild-copy-static-files": {
178
- "unvendorized": "esbuild-copy-static-files",
179
- "default": "./compiled/esbuild-copy-static-files/index.js"
157
+ "#fast-glob": {
158
+ "unvendorized": "fast-glob",
159
+ "default": "./compiled/fast-glob/index.js"
180
160
  },
181
- "#esbuild-plugins/tsconfig-paths": {
182
- "unvendorized": "@esbuild-plugins/tsconfig-paths",
183
- "default": "./compiled/esbuild-tsconfig-paths/index.js"
161
+ "#resolve": {
162
+ "unvendorized": "resolve",
163
+ "default": "./compiled/resolve/index.js"
184
164
  }
185
165
  },
186
166
  "dependencies": {
187
167
  "@babel/core": "7.29.7",
168
+ "@babel/generator": "7.29.8",
188
169
  "@babel/parser": "7.29.11",
189
170
  "@babel/plugin-syntax-import-meta": "7.10.4",
190
171
  "@babel/preset-react": "7.29.7",
191
172
  "@babel/preset-typescript": "7.29.7",
192
173
  "@babel/traverse": "7.29.10",
193
- "@esbuild-plugins/tsconfig-paths": "0.1.2",
174
+ "@babel/types": "7.29.11",
194
175
  "@roggc/react-server-dom-esm": "19.3.1",
195
176
  "@rollup/plugin-babel": "6.1.0",
196
177
  "@rollup/plugin-commonjs": "28.0.9",
@@ -205,11 +186,9 @@
205
186
  "chokidar": "4.0.3",
206
187
  "commander": "14.0.3",
207
188
  "copy-webpack-plugin": "14.0.0",
208
- "cross-env": "7.0.3",
209
189
  "css-loader": "7.1.5",
210
- "dotenv": "16.6.1",
211
190
  "esbuild": "0.27.7",
212
- "esbuild-copy-static-files": "0.1.0",
191
+ "fast-glob": "3.3.3",
213
192
  "generic-names": "4.0.0",
214
193
  "mini-css-extract-plugin": "2.10.2",
215
194
  "postcss": "8.5.31",
@@ -218,13 +197,11 @@
218
197
  "postcss-modules": "6.0.1",
219
198
  "react-refresh": "0.17.0",
220
199
  "react-server-dom-webpack": "19.3.1",
200
+ "resolve": "1.22.12",
221
201
  "rollup": "4.65.0",
222
- "rollup-plugin-copy": "3.5.0",
223
202
  "rollup-plugin-delete": "3.0.2",
224
203
  "rollup-plugin-postcss": "4.0.2",
225
- "rollup-plugin-tsconfig-paths": "1.5.2",
226
204
  "tailwindcss": "4.3.3",
227
- "tsconfig-paths-webpack-plugin": "4.2.0",
228
205
  "webpack": "5.112.2",
229
206
  "webpack-cli": "6.0.1",
230
207
  "webpack-dev-server": "5.2.7",
@@ -1,6 +1,5 @@
1
+ import { createBasePostCssPlugins } from "../core/postcss-pipeline.js";
2
+
1
3
  export default {
2
- plugins: {
3
- "@tailwindcss/postcss": {},
4
- autoprefixer: {},
5
- },
4
+ plugins: createBasePostCssPlugins(),
6
5
  };
@@ -161,7 +161,13 @@ socket.addEventListener("message", ({ data: _data }) => {
161
161
 
162
162
  if (data.type === "rsc-update") {
163
163
  if (typeof window !== "undefined" && typeof window.__DINOU_ROUTER_REFRESH__ === "function") {
164
- window.__DINOU_ROUTER_REFRESH__();
164
+ const refreshLayout = Boolean(
165
+ data.layout ||
166
+ (data.path &&
167
+ (/(?:^|[\\/])layout\.[jt]sx?$/i.test(data.path) ||
168
+ /\.module\.css$/i.test(data.path)))
169
+ );
170
+ window.__DINOU_ROUTER_REFRESH__({ layout: refreshLayout });
165
171
  return;
166
172
  }
167
173
  reload();
@@ -173,16 +179,31 @@ socket.addEventListener("message", ({ data: _data }) => {
173
179
  (data.type === "update" && data.url && (data.url.endsWith(".css") || data.url.includes("styles.css")))
174
180
  ) {
175
181
  const targetUrl = data.url ? data.url.split("?")[0] : "";
176
- const links = document.querySelectorAll('link[rel="stylesheet"]');
177
- for (const link of links) {
178
- const rawHref = link.getAttribute("href");
179
- if (!rawHref) continue;
180
- const cleanHref = rawHref.split("?")[0];
181
- if (!targetUrl || cleanHref.endsWith(targetUrl) || targetUrl.endsWith(cleanHref) || cleanHref.includes("styles.css")) {
182
- const nextUrl = new URL(link.href, window.location.origin);
183
- nextUrl.searchParams.set("t", String(Date.now()));
184
- link.href = nextUrl.href;
182
+ const applyStyleUpdate = () => {
183
+ const links = document.querySelectorAll('link[rel="stylesheet"]');
184
+ for (const link of links) {
185
+ const rawHref = link.getAttribute("href");
186
+ if (!rawHref) continue;
187
+ const cleanHref = rawHref.split("?")[0];
188
+ if (!targetUrl || cleanHref.endsWith(targetUrl) || targetUrl.endsWith(cleanHref) || cleanHref.includes("styles.css")) {
189
+ const nextUrl = new URL(link.href, window.location.origin);
190
+ nextUrl.searchParams.set("t", String(Date.now()));
191
+ link.href = nextUrl.href;
192
+ }
185
193
  }
194
+ };
195
+
196
+ if (typeof document !== "undefined" && document.body?.getAttribute("data-hydrated") === "true") {
197
+ applyStyleUpdate();
198
+ } else if (typeof window !== "undefined") {
199
+ let attempts = 0;
200
+ const waitHydration = setInterval(() => {
201
+ attempts++;
202
+ if (document.body?.getAttribute("data-hydrated") === "true" || attempts >= 60) {
203
+ clearInterval(waitHydration);
204
+ applyStyleUpdate();
205
+ }
206
+ }, 50);
186
207
  }
187
208
  return;
188
209
  }
@@ -25,20 +25,23 @@ function reactRefreshWrapModules() {
25
25
  return null;
26
26
  }
27
27
 
28
- // Only wrap user component chunks that contain actual app code (not third-party libraries)
28
+ // Only wrap user component chunks that contain actual JS/TS app code (not pure CSS chunks or third-party libraries)
29
29
  const modulePaths = Object.keys(chunk.modules || {});
30
- const hasUserCode = modulePaths.some(
31
- (p) =>
32
- !p.includes("node_modules") &&
33
- !p.includes("dinou[\\/]core") &&
34
- !p.includes("dinou[\\/]rollup") &&
35
- !p.includes("dinou[\\/]esbuild") &&
36
- !p.includes("dinou[\\/]webpack") &&
37
- !p.includes("dinou/core") &&
38
- !p.includes("dinou/rollup") &&
39
- !p.includes("dinou/esbuild") &&
40
- !p.includes("dinou/webpack")
41
- );
30
+ const hasUserCode = modulePaths.some((p) => {
31
+ const cleanPath = p.replace(/\?.*$/, "");
32
+ return (
33
+ /\.(jsx?|tsx?)$/i.test(cleanPath) &&
34
+ !cleanPath.includes("node_modules") &&
35
+ !cleanPath.includes("dinou/core") &&
36
+ !cleanPath.includes("dinou\\core") &&
37
+ !cleanPath.includes("dinou/rollup") &&
38
+ !cleanPath.includes("dinou\\rollup") &&
39
+ !cleanPath.includes("dinou/esbuild") &&
40
+ !cleanPath.includes("dinou\\esbuild") &&
41
+ !cleanPath.includes("dinou/webpack") &&
42
+ !cleanPath.includes("dinou\\webpack")
43
+ );
44
+ });
42
45
 
43
46
  if (!hasUserCode) {
44
47
  return null;
@@ -10,6 +10,8 @@ const changedIds = new Set();
10
10
  const pendingUpdateUrls = new Set();
11
11
  let needsFullReload = false;
12
12
  let hasPendingCssUpdate = false;
13
+ let lastStylesCssContent = null;
14
+ const lastChunkCodeByFile = new Map();
13
15
 
14
16
  function normalizePath(p) {
15
17
  return path.resolve(p).replace(/\\/g, "/").toLowerCase();
@@ -20,6 +22,8 @@ let activeHmrEngine = null;
20
22
 
21
23
  function esmHmrPlugin() {
22
24
  let hmrEngine = activeHmrEngine;
25
+ lastChunkCodeByFile.clear();
26
+ lastStylesCssContent = null;
23
27
 
24
28
  return {
25
29
  name: "esm-hmr",
@@ -68,7 +72,7 @@ function esmHmrPlugin() {
68
72
  // Inject client HMR runtime if it's the entry
69
73
  if (isClientEntry && !code.includes("/__hmr_client__.js")) {
70
74
  return {
71
- code: `import { createHotContext } from "/__hmr_client__.js";window.__hotContext = createHotContext;\n` + code,
75
+ code: `import "/runtime.js";import { createHotContext } from "/__hmr_client__.js";window.__hotContext = createHotContext;\n` + code,
72
76
  map: null,
73
77
  };
74
78
  }
@@ -97,17 +101,55 @@ function esmHmrPlugin() {
97
101
  source: clientSource,
98
102
  });
99
103
 
104
+ const stylesAsset = bundle["styles.css"];
105
+ if (stylesAsset && stylesAsset.type === "asset") {
106
+ const nextCss = Buffer.isBuffer(stylesAsset.source)
107
+ ? stylesAsset.source.toString("utf8")
108
+ : String(stylesAsset.source || "");
109
+ if (lastStylesCssContent !== null && nextCss !== lastStylesCssContent) {
110
+ hasPendingCssUpdate = true;
111
+ }
112
+ lastStylesCssContent = nextCss;
113
+ }
114
+
115
+ const isInitialBundle = lastChunkCodeByFile.size === 0;
116
+ if (isInitialBundle) {
117
+ for (const [fileName, chunkInfo] of Object.entries(bundle)) {
118
+ if (!fileName.endsWith(".css") && chunkInfo.type === "chunk") {
119
+ lastChunkCodeByFile.set(fileName, chunkInfo.code);
120
+ }
121
+ }
122
+ }
123
+
100
124
  if (changedIds.size > 0) {
101
- hasPendingCssUpdate = Array.from(changedIds).some((id) => {
102
- const lower = id.toLowerCase();
103
- return lower.endsWith(".css") || lower.endsWith(".scss") || lower.endsWith(".less");
104
- });
125
+ if (
126
+ Array.from(changedIds).some((id) => {
127
+ const lower = id.toLowerCase();
128
+ return (
129
+ lower.endsWith(".css") ||
130
+ lower.endsWith(".scss") ||
131
+ lower.endsWith(".less")
132
+ );
133
+ })
134
+ ) {
135
+ hasPendingCssUpdate = true;
136
+ }
105
137
 
106
138
  for (const [fileName, chunkInfo] of Object.entries(bundle)) {
107
139
  if (fileName.endsWith(".css") || chunkInfo.type !== "chunk") {
108
140
  continue;
109
141
  }
110
142
 
143
+ const prevChunkCode = lastChunkCodeByFile.get(fileName);
144
+ lastChunkCodeByFile.set(fileName, chunkInfo.code);
145
+ if (
146
+ !isInitialBundle &&
147
+ prevChunkCode !== undefined &&
148
+ prevChunkCode === chunkInfo.code
149
+ ) {
150
+ continue;
151
+ }
152
+
111
153
  let isChangedByJs = false;
112
154
 
113
155
  // 1. Check facadeModuleId
@@ -150,8 +192,12 @@ function esmHmrPlugin() {
150
192
  }
151
193
 
152
194
  if (isChangedByJs) {
153
- const urlId = "/" + fileName;
154
- pendingUpdateUrls.add(urlId);
195
+ if (chunkInfo.code && chunkInfo.code.includes("import.meta.hot")) {
196
+ const urlId = "/" + fileName;
197
+ pendingUpdateUrls.add(urlId);
198
+ } else {
199
+ needsFullReload = true;
200
+ }
155
201
  }
156
202
  }
157
203
  }
@@ -1,33 +1,71 @@
1
- import fs from "node:fs";
2
1
  import path from "node:path";
3
- import createScopedName from "../../core/createScopedName.js";
4
- import { regex } from "../../core/asset-extensions.js";
2
+ import {
3
+ getAssetExtensionsInfo,
4
+ getAssetInfo,
5
+ resolveAssetImport,
6
+ } from "../../core/asset-extensions.js";
7
+
8
+ function dinouAssetPlugin({
9
+ include = null,
10
+ dinouConfig = null,
11
+ projectRoot = process.cwd(),
12
+ emitFiles = true,
13
+ } = {}) {
14
+ const rootDir = path.resolve(projectRoot || process.cwd());
15
+ let cleanRegex =
16
+ include || getAssetExtensionsInfo(dinouConfig, rootDir).regex;
17
+ let emittedInCurrentBuild = new Set();
5
18
 
6
- function dinouAssetPlugin({ include = regex } = {}) {
7
19
  return {
8
20
  name: "dinou-asset-plugin",
21
+ buildStart() {
22
+ cleanRegex =
23
+ include || getAssetExtensionsInfo(dinouConfig, rootDir).regex;
24
+ emittedInCurrentBuild = new Set();
25
+ },
26
+ resolveId(source, importer) {
27
+ if (!source || source.startsWith("\0")) return null;
28
+ const cleanSpec = source.split("?")[0].split("#")[0];
29
+ if (!cleanRegex.test(cleanSpec)) return null;
30
+ const resolved = resolveAssetImport(source, {
31
+ importer: importer || "",
32
+ projectRoot: rootDir,
33
+ assetRegex: cleanRegex,
34
+ });
35
+ return resolved || null;
36
+ },
9
37
  async load(id) {
10
- if (!include.test(id)) return null;
11
-
12
- const source = await fs.promises.readFile(id);
38
+ if (!id || id.startsWith("\0")) return null;
39
+ const cleanId = id.split("?")[0].split("#")[0];
40
+ if (!cleanRegex.test(cleanId)) return null;
13
41
 
14
- const base = path.basename(id, path.extname(id));
15
- const scoped = createScopedName(base, id);
16
- const ext = path.extname(id);
42
+ this.addWatchFile(cleanId);
17
43
 
18
- const fileName = `assets/${scoped}${ext}`;
44
+ const info = getAssetInfo(cleanId, rootDir, {
45
+ includeBuffer: emitFiles,
46
+ });
19
47
 
20
- const emitted = globalThis.__DINOU_EMITTED_ASSETS__ || (globalThis.__DINOU_EMITTED_ASSETS__ = new Set());
21
- if (!emitted.has(fileName)) {
22
- emitted.add(fileName);
23
- this.emitFile({
24
- type: "asset",
25
- fileName,
26
- source,
27
- });
48
+ if (emitFiles && info.buffer) {
49
+ const sharedEmitted =
50
+ typeof globalThis !== "undefined"
51
+ ? globalThis.__DINOU_EMITTED_ASSETS__ ||
52
+ (globalThis.__DINOU_EMITTED_ASSETS__ = new Set())
53
+ : null;
54
+ if (
55
+ !emittedInCurrentBuild.has(info.fileName) &&
56
+ (!sharedEmitted || !sharedEmitted.has(info.fileName))
57
+ ) {
58
+ emittedInCurrentBuild.add(info.fileName);
59
+ sharedEmitted?.add(info.fileName);
60
+ this.emitFile({
61
+ type: "asset",
62
+ fileName: info.fileName,
63
+ source: info.buffer,
64
+ });
65
+ }
28
66
  }
29
67
 
30
- return `export default '/assets/${scoped}${ext}';`;
68
+ return `export default ${JSON.stringify(info.publicUrl)};`;
31
69
  },
32
70
  };
33
71
  }
@@ -1,9 +1,16 @@
1
- let manifestData = {};
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ const manifestData = {};
2
5
 
3
6
  function manifestGeneratorPlugin() {
4
7
  return {
5
8
  name: "manifest-generator",
6
- generateBundle(options, bundle) {
9
+ async generateBundle(options, bundle) {
10
+ for (const key of Object.keys(manifestData)) {
11
+ delete manifestData[key];
12
+ }
13
+
7
14
  for (const [fileName, info] of Object.entries(bundle)) {
8
15
  if (info.type === "chunk" && info.name) {
9
16
  const cleanName = info.name + ".js";
@@ -11,11 +18,13 @@ function manifestGeneratorPlugin() {
11
18
  }
12
19
  }
13
20
 
14
- this.emitFile({
15
- type: "asset",
16
- fileName: "manifest.json",
17
- source: JSON.stringify(manifestData, null, 2),
18
- });
21
+ const dist1Dir = path.resolve(process.cwd(), ".dinou/dist1");
22
+ await fs.mkdir(dist1Dir, { recursive: true });
23
+ await fs.writeFile(
24
+ path.join(dist1Dir, "manifest.json"),
25
+ JSON.stringify(manifestData, null, 2),
26
+ "utf8"
27
+ );
19
28
  },
20
29
  };
21
30
  }