diff --git a/packages/shared-internals/src/package-cache.ts b/packages/shared-internals/src/package-cache.ts index 6e1c467a8..cd4767273 100644 --- a/packages/shared-internals/src/package-cache.ts +++ b/packages/shared-internals/src/package-cache.ts @@ -67,6 +67,12 @@ export default class PackageCache { } ownerOfFile(filename: string): Package | undefined { + // this can arise if anyone is using @embroider/macros with babel on an explicit + // string (not a file on disk). We should never even try to check owner of the + // file since there is no file that can be owned + if (!filename) { + return undefined; + } let candidate = filename; const virtualPrefix = 'embroider_virtual:'; diff --git a/packages/shared-internals/src/paths.ts b/packages/shared-internals/src/paths.ts index f6cea73b0..632b5c584 100644 --- a/packages/shared-internals/src/paths.ts +++ b/packages/shared-internals/src/paths.ts @@ -48,6 +48,12 @@ const postfixRE = /[?#].*$/s; // 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): string { + // a tiny bit of defensive programming to make sure that things won't explode + // a simple example is executing babel with @embroider/macros on a file without + // a filename (not on disk) will cause an error here + if (!url) { + return url; + } const regexp = postfixRE; return url.replace(regexp, ''); }