@@ -132,16 +132,16 @@ function parsePackageJSON(packageJSONContent: CorepackPackageJSON) {
132
132
}
133
133
134
134
export async function setLocalPackageManager ( cwd : string , info : PreparedPackageManagerInfo ) {
135
- const lookup = await loadSpec ( cwd ) ;
135
+ const lookup = await loadSpec ( cwd , true ) ;
136
136
137
137
const content = lookup . type !== `NoProject`
138
138
? await fs . promises . readFile ( ( lookup as FoundSpecResult ) . envFilePath ?? lookup . target , `utf8` )
139
139
: `` ;
140
140
141
141
let previousPackageManager : string ;
142
142
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 ( ) } ` ;
145
145
const index = content . lastIndexOf ( `\n${ envKey } =` ) + 1 ;
146
146
147
147
if ( index === 0 && ! content . startsWith ( `${ envKey } =` ) )
@@ -168,13 +168,13 @@ export async function setLocalPackageManager(cwd: string, info: PreparedPackageM
168
168
} ;
169
169
}
170
170
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 > =
173
173
| { type : `NoProject`, target : string }
174
174
| { type : `NoSpec`, target : string }
175
- | FoundSpecResult ;
175
+ | FoundSpecResult < SkipSpecParsing > ;
176
176
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 > > {
178
178
let nextCwd = initialCwd ;
179
179
let currCwd = `` ;
180
180
@@ -258,10 +258,12 @@ export async function loadSpec(initialCwd: string): Promise<LoadSpecResult> {
258
258
type : `Found` ,
259
259
target : selection . manifestPath ,
260
260
envFilePath,
261
- spec : parseSpec ( rawPmSpec , path . relative ( initialCwd , selection . manifestPath ) ) ,
262
261
range : selection . data . devEngines ?. packageManager ?. version && {
263
262
name : selection . data . devEngines . packageManager . name ,
264
263
range : selection . data . devEngines . packageManager . version ,
265
264
} ,
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 > ,
266
268
} ;
267
269
}
0 commit comments