Skip to content

Commit

Permalink
add some defensive programming to fix cases where babel is run withou…
Browse files Browse the repository at this point in the history
…t a filename
  • Loading branch information
mansona committed Sep 18, 2024
1 parent f7656a3 commit b2cf795
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/shared-internals/src/package-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:';

Expand Down
6 changes: 6 additions & 0 deletions packages/shared-internals/src/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '');
}
Expand Down

0 comments on commit b2cf795

Please sign in to comment.