diff --git a/packages/compat/src/resolver-transform.ts b/packages/compat/src/resolver-transform.ts index 7db9c5293..395c804a3 100644 --- a/packages/compat/src/resolver-transform.ts +++ b/packages/compat/src/resolver-transform.ts @@ -385,7 +385,7 @@ class TemplateResolver implements ASTPlugin { private findRules(absPath: string): PreprocessedComponentRule | undefined { // when babel is invoked by vite our filenames can have query params still // hanging off them. That would break rule matching. - absPath = cleanUrl(absPath, true); + absPath = cleanUrl(absPath); let fileRules = this.rules.files.get(absPath); let componentRules: PreprocessedComponentRule | undefined; diff --git a/packages/shared-internals/src/colocation.ts b/packages/shared-internals/src/colocation.ts index 7a8be185b..e22101555 100644 --- a/packages/shared-internals/src/colocation.ts +++ b/packages/shared-internals/src/colocation.ts @@ -7,7 +7,7 @@ export function syntheticJStoHBS(source: string): string | null { // explicit js is the only case we care about here. Synthetic template JS is // only ever JS (never TS or anything else). And extensionless imports are // handled by the default resolving system doing extension search. - if (cleanUrl(source, true).endsWith('.js')) { + if (cleanUrl(source).endsWith('.js')) { return source.replace(/.js(\?.*)?/, '.hbs$1'); } @@ -19,7 +19,7 @@ export function needsSyntheticComponentJS( foundFile: string, packageCache: Pick ): string | null { - requestedSpecifier = cleanUrl(requestedSpecifier, true); + requestedSpecifier = cleanUrl(requestedSpecifier); foundFile = cleanUrl(foundFile); if ( discoveredImplicitHBS(requestedSpecifier, foundFile) && diff --git a/packages/shared-internals/src/paths.ts b/packages/shared-internals/src/paths.ts index 002f26344..f6cea73b0 100644 --- a/packages/shared-internals/src/paths.ts +++ b/packages/shared-internals/src/paths.ts @@ -44,23 +44,17 @@ export function unrelativize(pkg: Package, specifier: string, fromFile: string) const postfixRE = /[?#].*$/s; -// this pattern includes URL query params (ex: ?direct) -// but excludes specifiers starting with # (ex: @embroider/virtuals/components/fancy) -// so when using this pattern, @embroider/virtual/fancy would be consider a pathname -// without any params. -const postfixREQueryParams = /[?].*$/s; - // this is the same implementation Vite uses internally to keep its // cache-busting query params from leaking where they shouldn't. // includeHashSign true means #my-specifier is considered part of the pathname -export function cleanUrl(url: string, includeHashSign = false): string { - const regexp = includeHashSign ? postfixREQueryParams : postfixRE; +export function cleanUrl(url: string): string { + const regexp = postfixRE; return url.replace(regexp, ''); } // includeHashSign true means #my-specifier is considered part of the pathname -export function getUrlQueryParams(url: string, includeHashSign = false): string { - const regexp = includeHashSign ? postfixREQueryParams : postfixRE; +export function getUrlQueryParams(url: string): string { + const regexp = postfixRE; return url.match(regexp)?.[0] ?? ''; } diff --git a/packages/vite/src/request.ts b/packages/vite/src/request.ts index 0c69175fe..677c217e3 100644 --- a/packages/vite/src/request.ts +++ b/packages/vite/src/request.ts @@ -29,8 +29,8 @@ export class RollupModuleRequest implements ModuleRequest { // strip query params off the source but keep track of them // we use regexp-based methods over a URL object because the // source can be a relative path. - let cleanSource = cleanUrl(source, true); - let queryParams = getUrlQueryParams(source, true); + let cleanSource = cleanUrl(source); + let queryParams = getUrlQueryParams(source); return new RollupModuleRequest( context,