@@ -42,7 +42,62 @@ function normalizeOverrides(overrides) {
4242 if ( ! overrides || typeof overrides !== "object" || Array . isArray ( overrides ) ) {
4343 return { } ;
4444 }
45- return normalizeOverrideValue ( overrides ) ;
45+ return normalizePnpmSelectorOverrides ( normalizeOverrideValue ( overrides ) ) ;
46+ }
47+
48+ function assignOverrideValue ( target , name , value ) {
49+ const current = target [ name ] ;
50+ if ( current === undefined ) {
51+ target [ name ] = value ;
52+ return ;
53+ }
54+ if ( isPlainObject ( current ) && isPlainObject ( value ) ) {
55+ for ( const [ nestedName , nestedValue ] of Object . entries ( value ) ) {
56+ assignOverrideValue ( current , nestedName , nestedValue ) ;
57+ }
58+ return ;
59+ }
60+ if ( isPlainObject ( current ) && ! isPlainObject ( value ) ) {
61+ current [ "." ] = value ;
62+ return ;
63+ }
64+ if ( ! isPlainObject ( current ) && isPlainObject ( value ) ) {
65+ target [ name ] = { "." : current , ...value } ;
66+ return ;
67+ }
68+ target [ name ] = value ;
69+ }
70+
71+ function assignPnpmSelectorOverride ( target , selector , value ) {
72+ const parts = selector
73+ . split ( ">" )
74+ . map ( ( part ) => part . trim ( ) )
75+ . filter ( Boolean ) ;
76+ if ( parts . length <= 1 ) {
77+ assignOverrideValue ( target , selector , value ) ;
78+ return ;
79+ }
80+
81+ let cursor = target ;
82+ for ( const part of parts . slice ( 0 , - 1 ) ) {
83+ const current = cursor [ part ] ;
84+ if ( isPlainObject ( current ) ) {
85+ cursor = current ;
86+ continue ;
87+ }
88+ const next = current === undefined ? { } : { "." : current } ;
89+ cursor [ part ] = next ;
90+ cursor = next ;
91+ }
92+ assignOverrideValue ( cursor , parts [ parts . length - 1 ] , value ) ;
93+ }
94+
95+ function normalizePnpmSelectorOverrides ( overrides ) {
96+ const normalized = { } ;
97+ for ( const [ name , value ] of Object . entries ( overrides ) ) {
98+ assignPnpmSelectorOverride ( normalized , name , value ) ;
99+ }
100+ return normalized ;
46101}
47102
48103function isPlainObject ( value ) {
@@ -304,6 +359,13 @@ function mergeOverrideEntry(merged, name, spec) {
304359 }
305360 return ;
306361 }
362+ if ( typeof current === "string" && isPlainObject ( spec ) && spec [ "." ] === undefined ) {
363+ merged [ name ] = { "." : current } ;
364+ for ( const [ nestedName , nestedSpec ] of Object . entries ( spec ) ) {
365+ mergeOverrideEntry ( merged [ name ] , nestedName , nestedSpec ) ;
366+ }
367+ return ;
368+ }
307369 if (
308370 typeof current === "string" &&
309371 isPlainObject ( spec ) &&
@@ -328,6 +390,10 @@ function mergeOverrideEntry(merged, name, spec) {
328390 current [ "." ] = preferredExactOverrideRootSpec ( current [ "." ] , spec ) ;
329391 return ;
330392 }
393+ if ( isPlainObject ( current ) && typeof spec === "string" && current [ "." ] === undefined ) {
394+ current [ "." ] = spec ;
395+ return ;
396+ }
331397 if ( JSON . stringify ( current ) !== JSON . stringify ( spec ) ) {
332398 throw new Error ( `package.json overrides.${ name } conflicts with pnpm lock policy for ${ name } ` ) ;
333399 }
0 commit comments