@@ -41,6 +41,16 @@ function trimSuffix(suffix: string, value: string) {
4141 return value . substring ( 0 , value . length - suffix . length ) ;
4242}
4343
44+ const versionHashRegExp = / \? v = [ 0 - 9 a - f ] + $ / ;
45+ /**
46+ * When pre-bundling is enabled, Vite will add a hash to the end of the file path
47+ * @see https://vite.dev/guide/features.html#npm-dependency-resolving-and-pre-bundling
48+ * @see https://github.com/cloudflare/workers-sdk/pull/5673
49+ */
50+ function trimViteVersionHash ( filePath : string ) {
51+ return filePath . replace ( versionHashRegExp , "" ) ;
52+ }
53+
4454// RegExp for path suffix to force loading module as specific type.
4555// (e.g. `/path/to/module.wasm?mf_vitest_force=CompiledWasm`)
4656// This suffix will be added by the pool when fetching a module that matches a
@@ -323,21 +333,8 @@ async function viteResolve(
323333 // (Specifically, the "tinyrainbow" module imports `node:tty` as `tty`)
324334 return id ;
325335 }
326- // strip off deps optimization hash from vite
327- // @see https://github.com/cloudflare/workers-sdk/pull/5673
328- if ( resolved . id . includes ( "?v=" ) ) {
329- const [ id , hash ] = resolved . id . split ( "?v=" ) ;
330- debuglog (
331- "Trimming deps optimization hash from vite, id =" ,
332- id ,
333- "v =" ,
334- hash
335- ) ;
336336
337- return id ;
338- }
339-
340- return resolved . id ;
337+ return trimViteVersionHash ( resolved . id ) ;
341338}
342339
343340type ResolveMethod = "import" | "require" ;
@@ -490,9 +487,6 @@ async function load(
490487 filePath = trimSuffix ( disableCjsEsmShimSuffix , filePath ) ;
491488 }
492489
493- // debuglog("Trimming ");
494- // filePath = filePath.split("?v=")[0];
495-
496490 let isEsm =
497491 filePath . endsWith ( ".mjs" ) ||
498492 ( filePath . endsWith ( ".js" ) && isWithinTypeModuleContext ( filePath ) ) ;
0 commit comments