-
Notifications
You must be signed in to change notification settings - Fork 140
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
Esbuild fixes #2100
Esbuild fixes #2100
Changes from all commits
3d9d610
cbae78c
8fdfeac
5b382c8
e87cd6f
bf7655b
8c1451c
a3098ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -971,20 +971,13 @@ export class Resolver { | |
} | ||
|
||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if (!pkg || !pkg.isV2Ember()) { | ||
return request; | ||
} | ||
|
||
// real deps take precedence over renaming rules. That is, a package like | ||
// ember-source might provide backburner via module renaming, but if you | ||
// have an explicit dependency on backburner you should still get that real | ||
// copy. | ||
|
||
// if (pkg.root === this.options.engines[0].root && request.specifier === `${pkg.name}/environment/config`) { | ||
// return logTransition('legacy config location', request, request.alias(`${pkg.name}/app/environment/config`)); | ||
// } | ||
|
||
if (!pkg.hasDependency(packageName)) { | ||
if (!pkg?.hasDependency(packageName)) { | ||
for (let [candidate, replacement] of Object.entries(this.options.renameModules)) { | ||
if (candidate === request.specifier) { | ||
return logTransition(`renameModules`, request, request.alias(replacement)); | ||
|
@@ -1008,6 +1001,10 @@ export class Resolver { | |
} | ||
} | ||
|
||
if (!pkg || !pkg.isV2Ember()) { | ||
return request; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This used to happen before renameModules, etc, now it happens after. |
||
} | ||
|
||
if (pkg.name === packageName) { | ||
// we found a self-import | ||
if (pkg.meta['auto-upgraded']) { | ||
|
@@ -1285,63 +1282,42 @@ export class Resolver { | |
} | ||
|
||
let pkg = this.packageCache.ownerOfFile(request.fromFile); | ||
if (!pkg) { | ||
return logTransition('no identifiable owningPackage', request); | ||
} | ||
|
||
// meta.originalFromFile gets set when we want to try to rehome a request | ||
// but then come back to the original location here in the fallback when the | ||
// rehomed request fails | ||
let movedPkg = this.packageCache.maybeMoved(pkg); | ||
if (movedPkg !== pkg) { | ||
let originalFromFile = request.meta?.originalFromFile; | ||
if (typeof originalFromFile !== 'string') { | ||
throw new Error(`bug: embroider resolver's meta is not propagating`); | ||
} | ||
request = request.rehome(originalFromFile); | ||
pkg = movedPkg; | ||
if (pkg) { | ||
({ pkg, request } = this.restoreRehomedRequest(pkg, request)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is just an extraction because fallbackResolve was getting so long. |
||
} | ||
|
||
if (!pkg.isV2Ember()) { | ||
return logTransition('fallbackResolve: not in an ember package', request); | ||
if (!pkg?.isV2Ember()) { | ||
// this request is coming from a file that appears to be owned by no ember | ||
// package. We offer one fallback behavior for such files. They're allowed | ||
// to resolve from the app's namespace. | ||
// | ||
// This makes it possible for integrations like vite to leave references | ||
// to the app in their pre-bundled dependencies, which will end up in an | ||
// arbitrary cache that is not inside any particular package. | ||
let description = pkg ? 'non-ember package' : 'unowned module'; | ||
|
||
let packageName = getPackageName(request.specifier); | ||
if (packageName === this.options.modulePrefix) { | ||
return logTransition( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the new support for app resolving from non-owned or non-ember packages. |
||
`fallbackResolver: ${description} resolved app namespace`, | ||
request, | ||
request.rehome(this.packageCache.maybeMoved(this.packageCache.get(this.options.appRoot)).root) | ||
); | ||
} | ||
return logTransition(`fallbackResolver: ${description}`, request); | ||
} | ||
|
||
let packageName = getPackageName(request.specifier); | ||
if (!packageName) { | ||
// this is a relative import | ||
|
||
let withinEngine = this.engineConfig(pkg.name); | ||
if (withinEngine) { | ||
// it's a relative import inside an engine (which also means app), which | ||
// means we may need to satisfy the request via app tree merging. | ||
|
||
let logicalName = engineRelativeName(pkg, resolve(dirname(request.fromFile), request.specifier)); | ||
if (!logicalName) { | ||
return logTransition( | ||
'fallbackResolve: relative failure because this file is not externally accessible', | ||
request | ||
); | ||
} | ||
let appJSMatch = await this.searchAppTree(request, withinEngine, logicalName); | ||
if (appJSMatch) { | ||
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch); | ||
} else { | ||
return logTransition('fallbackResolve: relative appJs search failure', request); | ||
} | ||
} else { | ||
// nothing else to do for relative imports | ||
return logTransition('fallbackResolve: relative failure', request); | ||
} | ||
return this.relativeFallbackResolve(pkg, request); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is another extraction to keep fallbackResolve shorter. |
||
} | ||
|
||
// auto-upgraded packages can fall back to the set of known active addons | ||
if (pkg.needsLooseResolving()) { | ||
let addon = this.locateActiveAddon(packageName); | ||
if (addon) { | ||
const rehomed = request.rehome(addon.canResolveFromFile); | ||
if (rehomed !== request) { | ||
return logTransition(`activeAddons`, request, rehomed); | ||
} | ||
let activeAddon = this.maybeFallbackToActiveAddon(request, packageName); | ||
if (activeAddon) { | ||
return activeAddon; | ||
} | ||
} | ||
|
||
|
@@ -1391,6 +1367,58 @@ export class Resolver { | |
return logTransition('fallbackResolve final exit', request); | ||
} | ||
|
||
private restoreRehomedRequest<R extends ModuleRequest>(pkg: Package, request: R): { pkg: Package; request: R } { | ||
// meta.originalFromFile gets set when we want to try to rehome a request | ||
// but then come back to the original location here in the fallback when the | ||
// rehomed request fails | ||
let movedPkg = this.packageCache.maybeMoved(pkg); | ||
if (movedPkg !== pkg) { | ||
let originalFromFile = request.meta?.originalFromFile; | ||
if (typeof originalFromFile !== 'string') { | ||
throw new Error(`bug: embroider resolver's meta is not propagating`); | ||
} | ||
request = request.rehome(originalFromFile); | ||
pkg = movedPkg; | ||
} | ||
return { pkg, request }; | ||
} | ||
|
||
private async relativeFallbackResolve<R extends ModuleRequest>(pkg: Package, request: R): Promise<R> { | ||
let withinEngine = this.engineConfig(pkg.name); | ||
if (withinEngine) { | ||
// it's a relative import inside an engine (which also means app), which | ||
// means we may need to satisfy the request via app tree merging. | ||
|
||
let logicalName = engineRelativeName(pkg, resolve(dirname(request.fromFile), request.specifier)); | ||
if (!logicalName) { | ||
return logTransition( | ||
'fallbackResolve: relative failure because this file is not externally accessible', | ||
request | ||
); | ||
} | ||
let appJSMatch = await this.searchAppTree(request, withinEngine, logicalName); | ||
if (appJSMatch) { | ||
return logTransition('fallbackResolve: relative appJsMatch', request, appJSMatch); | ||
} else { | ||
return logTransition('fallbackResolve: relative appJs search failure', request); | ||
} | ||
} else { | ||
// nothing else to do for relative imports | ||
return logTransition('fallbackResolve: relative failure', request); | ||
} | ||
} | ||
|
||
private maybeFallbackToActiveAddon<R extends ModuleRequest>(request: R, requestedPackageName: string): R | undefined { | ||
// auto-upgraded packages can fall back to the set of known active addons | ||
let addon = this.locateActiveAddon(requestedPackageName); | ||
if (addon) { | ||
const rehomed = request.rehome(addon.canResolveFromFile); | ||
if (rehomed !== request) { | ||
return logTransition(`activeAddons`, request, rehomed); | ||
} | ||
} | ||
} | ||
|
||
private getEntryFromMergeMap( | ||
inEngineSpecifier: string, | ||
root: string | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -172,14 +172,14 @@ function decodeVirtualExternalCJSModule(filename: string) { | |
} | ||
|
||
const pairComponentMarker = '-embroider-pair-component'; | ||
const pairComponentPattern = /^(?<hbsModule>.*)\/(?<jsModule>[^\/]*)-embroider-pair-component$/; | ||
const pairComponentPattern = /^(?<hbsModule>.*)__vpc__(?<jsModule>[^\/]*)-embroider-pair-component$/; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change in naming means that our virtual pair component is sitting inside a real directory, not an imaginary one. That makes esbuild resolve outbound requests from it correctly. |
||
|
||
export function virtualPairComponent(hbsModule: string, jsModule: string | undefined): string { | ||
let relativeJSModule = ''; | ||
if (jsModule) { | ||
relativeJSModule = explicitRelative(hbsModule, jsModule); | ||
relativeJSModule = explicitRelative(dirname(hbsModule), jsModule); | ||
} | ||
return `${hbsModule}/${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`; | ||
return `${hbsModule}__vpc__${encodeURIComponent(relativeJSModule)}${pairComponentMarker}`; | ||
} | ||
|
||
function decodeVirtualPairComponent( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where we're allowing a missing package to still match renamedModules.