Skip to content

Commit c35cb4d

Browse files
authored
Merge pull request #1385 from andresiraola/getversion-cwd
Pass cwd to getVersionText
2 parents c2f989a + f64c701 commit c35cb4d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/targets/node/nodeBinaryProvider.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ export interface INodeBinaryProvider {
192192
env: EnvironmentVars,
193193
executable?: string,
194194
explicitVersion?: number,
195+
cwd?: string,
195196
): Promise<NodeBinary>;
196197
}
197198

@@ -221,9 +222,10 @@ export class NodeBinaryProvider {
221222
env: EnvironmentVars,
222223
executable = 'node',
223224
explicitVersion?: number,
225+
cwd?: string,
224226
): Promise<NodeBinary> {
225227
try {
226-
return await this.resolveAndValidateInner(env, executable, explicitVersion);
228+
return await this.resolveAndValidateInner(env, executable, explicitVersion, cwd);
227229
} catch (e) {
228230
if (!(e instanceof NodeBinaryOutOfDateError)) {
229231
throw e;
@@ -249,6 +251,7 @@ export class NodeBinaryProvider {
249251
env: EnvironmentVars,
250252
executable: string,
251253
explicitVersion: number | undefined,
254+
cwd: string | undefined,
252255
): Promise<NodeBinary> {
253256
const location = await this.resolveBinaryLocation(executable, env);
254257
this.logger.info(LogTag.RuntimeLaunch, 'Using binary at', { location, executable });
@@ -278,7 +281,7 @@ export class NodeBinaryProvider {
278281
}
279282

280283
try {
281-
const realBinary = await this.resolveAndValidateInner(env, 'node', undefined);
284+
const realBinary = await this.resolveAndValidateInner(env, 'node', undefined, cwd);
282285
return new NodeBinary(location, realBinary.version);
283286
} catch (e) {
284287
// if we verified it's outdated, still throw the error. If it's not
@@ -303,7 +306,7 @@ export class NodeBinaryProvider {
303306
}
304307

305308
// match the "12" in "v12.34.56"
306-
const versionText = await this.getVersionText(location);
309+
const versionText = await this.getVersionText(location, cwd);
307310

308311
// Handle other cases where Node.js is installed via snap, but not in `/span/`.
309312
// We just get empty output from it in that case.
@@ -345,10 +348,11 @@ export class NodeBinaryProvider {
345348
: await findInPath(this.fs, executable, env.value);
346349
}
347350

348-
public async getVersionText(binary: string) {
351+
public async getVersionText(binary: string, cwd: string | undefined) {
349352
try {
350353
const { stdout } = await spawnAsync(binary, ['--version'], {
351354
env: EnvironmentVars.processEnv().defined(),
355+
cwd,
352356
});
353357
return stdout.trim();
354358
} catch (e) {

src/targets/node/nodeLauncherBase.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ export abstract class NodeLauncherBase<T extends AnyNodeConfiguration> implement
266266
EnvironmentVars.merge(EnvironmentVars.processEnv(), this.getConfiguredEnvironment(params)),
267267
executable,
268268
params.nodeVersionHint,
269+
params.cwd,
269270
);
270271
}
271272

0 commit comments

Comments
 (0)