Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some defensive programming to fix cases where babel is run without a filename #2116

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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