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
fix(config): resolve externalized specifier with internal resolver #10683
Changes from all commits
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 |
---|---|---|
|
@@ -580,12 +580,21 @@ function tryResolveFile( | |
} | ||
} | ||
|
||
export type InternalResolveOptionsWithOverrideConditions = | ||
InternalResolveOptions & { | ||
/** | ||
* @deprecated In future, `conditions` will work like this. | ||
* @internal | ||
*/ | ||
overrideConditions?: string[] | ||
} | ||
|
||
export const idToPkgMap = new Map<string, PackageData>() | ||
|
||
export function tryNodeResolve( | ||
id: string, | ||
importer: string | null | undefined, | ||
options: InternalResolveOptions, | ||
options: InternalResolveOptionsWithOverrideConditions, | ||
targetWeb: boolean, | ||
depsOptimizer?: DepsOptimizer, | ||
ssr?: boolean, | ||
|
@@ -1031,17 +1040,44 @@ function packageEntryFailure(id: string, details?: string) { | |
) | ||
} | ||
|
||
const conditionalConditions = new Set(['production', 'development', 'module']) | ||
|
||
function resolveExports( | ||
pkg: PackageData['data'], | ||
key: string, | ||
options: InternalResolveOptions, | ||
options: InternalResolveOptionsWithOverrideConditions, | ||
targetWeb: boolean | ||
) { | ||
const conditions = [options.isProduction ? 'production' : 'development'] | ||
if (!options.isRequire) { | ||
const overrideConditions = options.overrideConditions | ||
? new Set(options.overrideConditions) | ||
: undefined | ||
|
||
const conditions = [] | ||
if ( | ||
(!overrideConditions || overrideConditions.has('production')) && | ||
options.isProduction | ||
) { | ||
conditions.push('production') | ||
} | ||
if ( | ||
(!overrideConditions || overrideConditions.has('development')) && | ||
!options.isProduction | ||
) { | ||
conditions.push('development') | ||
} | ||
if ( | ||
(!overrideConditions || overrideConditions.has('module')) && | ||
!options.isRequire | ||
) { | ||
conditions.push('module') | ||
} | ||
if (options.conditions.length > 0) { | ||
if (options.overrideConditions) { | ||
conditions.push( | ||
...options.overrideConditions.filter((condition) => | ||
conditionalConditions.has(condition) | ||
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 looks like a typo. The 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. Good catch! Thanks. I'll fix it with some refactor around this. |
||
) | ||
) | ||
} else if (options.conditions.length > 0) { | ||
conditions.push(...options.conditions) | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
What does this do? Hard to know from just reading the code.
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.
Ok I think I get it.
This option decides which of the default conditions (
production
,development
,module
) are allowed. It may also add custom conditions, and it prevents theconditions
option from being used.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.
Yes, that's correct.