@rangojs/router 0.0.0-experimental.115 → 0.0.0-experimental.116

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 (37) hide show
  1. package/dist/vite/index.js +148 -97
  2. package/package.json +17 -18
  3. package/skills/api-client/SKILL.md +211 -0
  4. package/skills/mime-routes/SKILL.md +1 -1
  5. package/skills/rango/SKILL.md +1 -0
  6. package/skills/response-routes/SKILL.md +61 -43
  7. package/skills/typesafety/SKILL.md +3 -3
  8. package/src/__augment-tests__/augmented.check.ts +2 -3
  9. package/src/build/collect-fallback-refs.ts +107 -0
  10. package/src/build/generate-manifest.ts +28 -1
  11. package/src/build/index.ts +8 -1
  12. package/src/build/prefix-tree-utils.ts +123 -0
  13. package/src/build/route-trie.ts +43 -0
  14. package/src/client.tsx +4 -23
  15. package/src/errors.ts +0 -3
  16. package/src/href-client.ts +7 -8
  17. package/src/index.rsc.ts +1 -2
  18. package/src/index.ts +1 -2
  19. package/src/router/find-match.ts +54 -6
  20. package/src/router/lazy-includes.ts +33 -14
  21. package/src/router/manifest.ts +19 -6
  22. package/src/router/pattern-matching.ts +15 -2
  23. package/src/router/router-interfaces.ts +11 -0
  24. package/src/router/trie-matching.ts +22 -3
  25. package/src/router.ts +21 -7
  26. package/src/rsc/manifest-init.ts +28 -41
  27. package/src/rsc/response-error.ts +79 -12
  28. package/src/rsc/response-route-handler.ts +16 -13
  29. package/src/urls/index.ts +1 -2
  30. package/src/urls/type-extraction.ts +33 -24
  31. package/src/vite/discovery/discover-routers.ts +46 -29
  32. package/src/vite/discovery/state.ts +7 -0
  33. package/src/vite/plugins/client-ref-hashing.ts +12 -1
  34. package/src/vite/rango.ts +32 -4
  35. package/src/vite/utils/client-chunks.ts +41 -7
  36. package/src/vite/utils/manifest-utils.ts +8 -75
  37. package/src/vite/utils/shared-utils.ts +58 -0
@@ -116,6 +116,50 @@ export function createVirtualEntriesPlugin(
116
116
  };
117
117
  }
118
118
 
119
+ // Matches rollup's FILE_NAME_CONFLICT message and reports whether the colliding
120
+ // file is a content-hashed asset, e.g.
121
+ // The emitted file "assets/index-DlGNrvnU.css" overwrites a previously ...
122
+ // The emitted file "assets/inter-latin-Dx4kXJAl.woff2" overwrites a ...
123
+ // The match is UNANCHORED on purpose: by the time the warning reaches this user
124
+ // onwarn handler, Vite's logger has wrapped rollup's raw message with an ANSI
125
+ // color sequence and a "[CODE] " label, e.g.
126
+ // "[FILE_NAME_CONFLICT] The emitted file \"...\" overwrites ..."
127
+ // A "^The emitted file" anchor sits behind that prefix and never matches; and
128
+ // Vite also strips the JSON.stringify quotes rollup puts around the filename, so
129
+ // the match is UNANCHORED and quote-OPTIONAL ("?...?"?). The non-whitespace
130
+ // capture stops at the space before "overwrites" (Vite's unquoted display form)
131
+ // or the closing quote (raw rollup form); either way it carries no ANSI.
132
+ // A content-hashed name ends with a "-" separator + a Vite content hash. The
133
+ // hash is a FIXED-LENGTH base64url run ([A-Za-z0-9_-], default 8), so it can
134
+ // itself contain "-"/"_": it CANNOT be located by splitting on the last "-"
135
+ // (that lands inside the hash whenever it carries a dash, e.g. "...-Cabi7G8-" ->
136
+ // "" or "...-CkhJZR-_" -> "_", which let those conflicts leak). Instead take the
137
+ // trailing HASH_LEN chars and require the "-" separator right before them. The
138
+ // hash must hold an uppercase letter or digit (a real hash is never an
139
+ // all-lowercase word), so stable names like "assets/manifest.json" or
140
+ // "assets/loading-skeleton.css" still surface as potential genuine overwrites.
141
+ function isContentHashedAssetConflict(message: string | undefined): boolean {
142
+ if (!message) return false;
143
+ const match =
144
+ /The emitted file "?([^"\s]+)"? overwrites a previously emitted file/.exec(
145
+ message,
146
+ );
147
+ if (!match) return false;
148
+ const fileName = match[1];
149
+ const base = fileName.slice(fileName.lastIndexOf("/") + 1);
150
+ const dot = base.lastIndexOf(".");
151
+ if (dot <= 0) return false;
152
+ const stem = base.slice(0, dot);
153
+ // HASH_LEN tracks Vite's default [hash] width; bump it if an app sets a custom
154
+ // assetFileNames hash length.
155
+ const HASH_LEN = 8;
156
+ if (stem.length < HASH_LEN + 1 || stem[stem.length - HASH_LEN - 1] !== "-") {
157
+ return false;
158
+ }
159
+ const hash = stem.slice(-HASH_LEN);
160
+ return /^[A-Za-z0-9_-]+$/.test(hash) && /[A-Z0-9]/.test(hash);
161
+ }
162
+
119
163
  /**
120
164
  * Rollup onwarn handler that suppresses known harmless warnings:
121
165
  * - "use client" directives: handled by the RSC plugin, not relevant to Rollup
@@ -126,6 +170,14 @@ export function createVirtualEntriesPlugin(
126
170
  * by the bundler, rather than the vite:reporter message handled below (Rollup/Vite 7 shape).
127
171
  * - empty bundle: @vitejs/plugin-rsc scan build (step 1/5) produces an empty "index" chunk
128
172
  * because the RSC entry is fully externalized during client-reference analysis
173
+ * - file name conflicts on content-hashed assets: @vitejs/plugin-rsc copies the rsc
174
+ * environment's imported CSS/assets into the client bundle (its assets-manifest
175
+ * generateBundle re-emits each via emitFile with an explicit content-hashed
176
+ * fileName). When the client bundle already produced that identical asset,
177
+ * rollup raises FILE_NAME_CONFLICT even though the bytes are identical (a
178
+ * content hash collision IS a content match). Only these are suppressed; a
179
+ * collision on a stable name still surfaces. No upstream fix as of
180
+ * @vitejs/plugin-rsc@0.5.27; remove when it skips the redundant emit.
129
181
  */
130
182
  export function onwarn(
131
183
  warning: Vite.Rollup.RollupLog,
@@ -139,6 +191,12 @@ export function onwarn(
139
191
  ) {
140
192
  return;
141
193
  }
194
+ if (
195
+ warning.code === "FILE_NAME_CONFLICT" &&
196
+ isContentHashedAssetConflict(warning.message)
197
+ ) {
198
+ return;
199
+ }
142
200
  // @vitejs/plugin-rsc@0.5.14: rsc:virtual:vite-rsc/assets-manifest renderChunk
143
201
  // returns { code } without map, causing Rollup to warn about incorrect sourcemaps.
144
202
  // This is harmless (simple string replacement). Remove this suppression if a