-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
feat(resolve)!: allow removing conditions #18395
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
Changes from 1 commit
713cee3
15f4875
5492d2f
c8ab916
7ebc958
2f833c7
c3bf6d8
33c89e2
0cb8863
ff6a3d8
edcf8f3
d7f60c8
1a4121c
41bfab4
405f65a
980ac56
4985011
0ced80a
92c2658
68ff9fb
a40eb20
c6a234a
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 |
|---|---|---|
|
|
@@ -736,18 +736,10 @@ function tryCleanFsResolve( | |
| } | ||
| } | ||
|
|
||
| export type InternalResolveOptionsWithOverrideConditions = | ||
| InternalResolveOptions & { | ||
| /** | ||
| * @internal | ||
| */ | ||
| overrideConditions?: string[] | ||
| } | ||
|
|
||
| export function tryNodeResolve( | ||
| id: string, | ||
| importer: string | null | undefined, | ||
| options: InternalResolveOptionsWithOverrideConditions, | ||
| options: InternalResolveOptions, | ||
| depsOptimizer?: DepsOptimizer, | ||
| ssr: boolean = false, | ||
| externalize?: boolean, | ||
|
|
@@ -1117,35 +1109,31 @@ function packageEntryFailure(id: string, details?: string) { | |
| function resolveExportsOrImports( | ||
| pkg: PackageData['data'], | ||
| key: string, | ||
| options: InternalResolveOptionsWithOverrideConditions, | ||
| options: InternalResolveOptions, | ||
| type: 'imports' | 'exports', | ||
| ) { | ||
| const additionalConditions = new Set( | ||
| options.overrideConditions || [ | ||
| 'production', | ||
| 'development', | ||
| 'module', | ||
| ...options.conditions, | ||
| ], | ||
| const conditions = [...options.conditions, 'require', 'import'].filter( | ||
|
||
| (condition) => { | ||
| switch (condition) { | ||
| case 'production': | ||
| return options.isProduction | ||
| case 'development': | ||
| return !options.isProduction | ||
| case 'require': | ||
| return options.isRequire | ||
| case 'import': | ||
| return !options.isRequire | ||
| case 'node': | ||
| return !options.webCompatible | ||
| case 'browser': | ||
| return options.webCompatible | ||
|
||
| } | ||
| return true | ||
| }, | ||
| ) | ||
|
|
||
| const conditions = [...additionalConditions].filter((condition) => { | ||
| switch (condition) { | ||
| case 'production': | ||
| return options.isProduction | ||
| case 'development': | ||
| return !options.isProduction | ||
| } | ||
| return true | ||
| }) | ||
|
|
||
| const fn = type === 'imports' ? imports : exports | ||
| const result = fn(pkg, key, { | ||
| browser: options.webCompatible && !additionalConditions.has('node'), | ||
| require: options.isRequire && !additionalConditions.has('import'), | ||
| conditions, | ||
| }) | ||
|
|
||
| const result = fn(pkg, key, { conditions, unsafe: true }) | ||
| return result ? result[0] : undefined | ||
| } | ||
|
|
||
|
|
@@ -1183,11 +1171,7 @@ function resolveDeepImport( | |
| `${path.join(dir, 'package.json')}.`, | ||
| ) | ||
| } | ||
| } else if ( | ||
| options.webCompatible && | ||
| options.mainFields.includes('browser') && | ||
| isObject(browserField) | ||
| ) { | ||
| } else if (options.mainFields.includes('browser') && isObject(browserField)) { | ||
| // resolve without postfix (see #7098) | ||
| const { file, postfix } = splitFileAndPostfix(relativeId) | ||
| const mapped = mapWithBrowserField(file, browserField) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.