@@ -132,16 +132,16 @@ function parsePackageJSON(packageJSONContent: CorepackPackageJSON) {
132132}
133133
134134export async function setLocalPackageManager ( cwd : string , info : PreparedPackageManagerInfo ) {
135- const lookup = await loadSpec ( cwd ) ;
135+ const lookup = await loadSpec ( cwd , true ) ;
136136
137137 const content = lookup . type !== `NoProject`
138138 ? await fs . promises . readFile ( ( lookup as FoundSpecResult ) . envFilePath ?? lookup . target , `utf8` )
139139 : `` ;
140140
141141 let previousPackageManager : string ;
142142 let newContent : string ;
143- if ( ( lookup as FoundSpecResult ) . envFilePath ) {
144- const envKey = `COREPACK_DEV_ENGINES_${ ( lookup as FoundSpecResult ) . spec . name . toUpperCase ( ) } ` ;
143+ if ( ( lookup as FoundSpecResult ) . envFilePath && ( lookup as FoundSpecResult ) . range ) {
144+ const envKey = `COREPACK_DEV_ENGINES_${ ( lookup as FoundSpecResult ) . range ! . name . toUpperCase ( ) } ` ;
145145 const index = content . lastIndexOf ( `\n${ envKey } =` ) + 1 ;
146146
147147 if ( index === 0 && ! content . startsWith ( `${ envKey } =` ) )
@@ -168,13 +168,13 @@ export async function setLocalPackageManager(cwd: string, info: PreparedPackageM
168168 } ;
169169}
170170
171- type FoundSpecResult = { type : `Found`, target : string , spec : Descriptor , range ?: Descriptor , envFilePath ?: string } ;
172- export type LoadSpecResult =
171+ type FoundSpecResult < SkipSpecParsing extends boolean = true > = { type : `Found`, target : string , spec : SkipSpecParsing extends true ? undefined : Descriptor , range ?: Descriptor , envFilePath ?: string } ;
172+ export type LoadSpecResult < SkipSpecParsing extends boolean > =
173173 | { type : `NoProject`, target : string }
174174 | { type : `NoSpec`, target : string }
175- | FoundSpecResult ;
175+ | FoundSpecResult < SkipSpecParsing > ;
176176
177- export async function loadSpec ( initialCwd : string ) : Promise < LoadSpecResult > {
177+ export async function loadSpec < SkipSpecParsing extends boolean = false > ( initialCwd : string , skipSpecParsing ?: SkipSpecParsing ) : Promise < LoadSpecResult < SkipSpecParsing > > {
178178 let nextCwd = initialCwd ;
179179 let currCwd = `` ;
180180
@@ -258,10 +258,12 @@ export async function loadSpec(initialCwd: string): Promise<LoadSpecResult> {
258258 type : `Found` ,
259259 target : selection . manifestPath ,
260260 envFilePath,
261- spec : parseSpec ( rawPmSpec , path . relative ( initialCwd , selection . manifestPath ) ) ,
262261 range : selection . data . devEngines ?. packageManager ?. version && {
263262 name : selection . data . devEngines . packageManager . name ,
264263 range : selection . data . devEngines . packageManager . version ,
265264 } ,
265+ spec : skipSpecParsing ?
266+ ( undefined as SkipSpecParsing extends true ? undefined : never ) :
267+ parseSpec ( rawPmSpec , path . relative ( initialCwd , selection . manifestPath ) ) as SkipSpecParsing extends true ? never : ReturnType < typeof parseSpec > ,
266268 } ;
267269}
0 commit comments