@@ -167,6 +167,11 @@ interface ResolvePluginOptions {
167167 * @internal
168168 */
169169 idOnly ?: boolean
170+
171+ /**
172+ * Enable when `legacy.inconsistentCjsInterop` is true. See that option for more details.
173+ */
174+ legacyInconsistentCjsInterop ?: boolean
170175}
171176
172177export interface InternalResolveOptions
@@ -283,6 +288,7 @@ export function oxcResolvePlugin(
283288 external : options . external ,
284289 noExternal : noExternal ,
285290 dedupe : options . dedupe ,
291+ legacyInconsistentCjsInterop : options . legacyInconsistentCjsInterop ,
286292 finalizeBareSpecifier : ! depsOptimizerEnabled
287293 ? undefined
288294 : ( resolvedId , rawId , importer ) => {
@@ -553,6 +559,7 @@ export function resolvePlugin(
553559 id : ensureVersionQuery ( res , id , options , depsOptimizer ) ,
554560 packageJsonPath : findNearestPackagePath (
555561 res ,
562+ options . legacyInconsistentCjsInterop ,
556563 options . packageCache ,
557564 isBuild ,
558565 ) ,
@@ -573,6 +580,7 @@ export function resolvePlugin(
573580 id : ensureVersionQuery ( res , id , options , depsOptimizer ) ,
574581 packageJsonPath : findNearestPackagePath (
575582 res ,
583+ options . legacyInconsistentCjsInterop ,
576584 options . packageCache ,
577585 isBuild ,
578586 ) ,
@@ -629,7 +637,9 @@ export function resolvePlugin(
629637 return {
630638 id : res ,
631639 moduleSideEffects : resPkg . hasSideEffects ( res ) ,
632- packageJsonPath : path . join ( resPkg . dir , 'package.json' ) ,
640+ packageJsonPath : options . legacyInconsistentCjsInterop
641+ ? undefined
642+ : path . join ( resPkg . dir , 'package.json' ) ,
633643 }
634644 }
635645 }
@@ -653,6 +663,7 @@ export function resolvePlugin(
653663 id : ensureVersionQuery ( res , id , options , depsOptimizer ) ,
654664 packageJsonPath : findNearestPackagePath (
655665 res ,
666+ options . legacyInconsistentCjsInterop ,
656667 options . packageCache ,
657668 isBuild ,
658669 ) ,
@@ -670,6 +681,7 @@ export function resolvePlugin(
670681 id : ensureVersionQuery ( res , id , options , depsOptimizer ) ,
671682 packageJsonPath : findNearestPackagePath (
672683 res ,
684+ options . legacyInconsistentCjsInterop ,
673685 options . packageCache ,
674686 isBuild ,
675687 ) ,
@@ -1169,6 +1181,7 @@ export function tryNodeResolve(
11691181 moduleSideEffects : pkg . hasSideEffects ( resolved ) ,
11701182 packageJsonPath : findNearestPackagePath (
11711183 resolved ,
1184+ options . legacyInconsistentCjsInterop ,
11721185 options . packageCache ,
11731186 isBuild ,
11741187 ) ,
@@ -1518,7 +1531,9 @@ function tryResolveBrowserMapping(
15181531 result = {
15191532 id : res ,
15201533 moduleSideEffects : resPkg . hasSideEffects ( res ) ,
1521- packageJsonPath : path . join ( resPkg . dir , 'package.json' ) ,
1534+ packageJsonPath : options . legacyInconsistentCjsInterop
1535+ ? undefined
1536+ : path . join ( resPkg . dir , 'package.json' ) ,
15221537 }
15231538 }
15241539 }
@@ -1654,10 +1669,11 @@ function isDirectory(path: string): boolean {
16541669
16551670function findNearestPackagePath (
16561671 file : string ,
1672+ legacyInconsistentCjsInterop : boolean | undefined ,
16571673 packageCache : PackageCache | undefined ,
16581674 isBuild : boolean ,
16591675) {
1660- if ( ! isBuild ) return
1676+ if ( ! isBuild || legacyInconsistentCjsInterop ) return
16611677 const pkgData = findNearestPackageData ( file , packageCache )
16621678 return pkgData ? path . join ( pkgData . dir , 'package.json' ) : null
16631679}
0 commit comments