From 678e5252feebb485c59a77bd60b6bd388504fe27 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 27 May 2024 15:40:54 -0400 Subject: [PATCH 1/3] Use vscode.env.shell when launching ASDF --- vscode/src/ruby/asdf.ts | 1 + vscode/src/test/suite/ruby/asdf.test.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/vscode/src/ruby/asdf.ts b/vscode/src/ruby/asdf.ts index 8c83ed276..34d918343 100644 --- a/vscode/src/ruby/asdf.ts +++ b/vscode/src/ruby/asdf.ts @@ -23,6 +23,7 @@ export class Asdf extends VersionManager { `. ${asdfUri.fsPath} && asdf exec ruby -W0 -rjson -e '${activationScript}'`, { cwd: this.bundleUri.fsPath, + shell: vscode.env.shell, env: { ASDF_DIR: path.dirname(asdfUri.fsPath), ASDF_DATA_DIR: asdfDaraDirUri.fsPath, diff --git a/vscode/src/test/suite/ruby/asdf.test.ts b/vscode/src/test/suite/ruby/asdf.test.ts index fb07b3f15..ff62f2c53 100644 --- a/vscode/src/test/suite/ruby/asdf.test.ts +++ b/vscode/src/test/suite/ruby/asdf.test.ts @@ -44,6 +44,7 @@ suite("Asdf", () => { const findDataDirStub = sinon .stub(asdf, "findAsdfDataDir") .resolves(vscode.Uri.file(`${os.homedir()}/.asdf`)); + const shellStub = sinon.stub(vscode.env, "shell").get(() => "/bin/bash"); const { env, version, yjit } = await asdf.activate(); @@ -52,6 +53,7 @@ suite("Asdf", () => { `. ${os.homedir()}/.asdf/asdf.sh && asdf exec ruby -W0 -rjson -e '${activationScript}'`, { cwd: workspacePath, + shell: "/bin/bash", env: { ASDF_DIR: `${os.homedir()}/.asdf`, ASDF_DATA_DIR: `${os.homedir()}/.asdf`, @@ -68,5 +70,6 @@ suite("Asdf", () => { execStub.restore(); findInstallationStub.restore(); findDataDirStub.restore(); + shellStub.restore(); }); }); From 84cbedf0ecc2f32f9e950a8079c616cc8b1b1ac2 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Wed, 29 May 2024 15:28:05 -0400 Subject: [PATCH 2/3] Include current process env when launching ASDF --- vscode/src/ruby/asdf.ts | 1 + vscode/src/test/suite/ruby/asdf.test.ts | 2 ++ 2 files changed, 3 insertions(+) diff --git a/vscode/src/ruby/asdf.ts b/vscode/src/ruby/asdf.ts index 34d918343..6442f1ac4 100644 --- a/vscode/src/ruby/asdf.ts +++ b/vscode/src/ruby/asdf.ts @@ -25,6 +25,7 @@ export class Asdf extends VersionManager { cwd: this.bundleUri.fsPath, shell: vscode.env.shell, env: { + ...process.env, ASDF_DIR: path.dirname(asdfUri.fsPath), ASDF_DATA_DIR: asdfDaraDirUri.fsPath, }, diff --git a/vscode/src/test/suite/ruby/asdf.test.ts b/vscode/src/test/suite/ruby/asdf.test.ts index ff62f2c53..959861c51 100644 --- a/vscode/src/test/suite/ruby/asdf.test.ts +++ b/vscode/src/test/suite/ruby/asdf.test.ts @@ -55,6 +55,8 @@ suite("Asdf", () => { cwd: workspacePath, shell: "/bin/bash", env: { + // eslint-disable-next-line no-process-env + ...process.env, ASDF_DIR: `${os.homedir()}/.asdf`, ASDF_DATA_DIR: `${os.homedir()}/.asdf`, }, From ff7fd83a7001611d9901aaf2a7b238e902f774a4 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Wed, 29 May 2024 15:35:37 -0400 Subject: [PATCH 3/3] Pass process env when invoking ASDF --- vscode/src/ruby/asdf.ts | 57 +------------------------ vscode/src/test/suite/ruby/asdf.test.ts | 13 +----- 2 files changed, 3 insertions(+), 67 deletions(-) diff --git a/vscode/src/ruby/asdf.ts b/vscode/src/ruby/asdf.ts index 6442f1ac4..08b1cea0a 100644 --- a/vscode/src/ruby/asdf.ts +++ b/vscode/src/ruby/asdf.ts @@ -1,6 +1,5 @@ /* eslint-disable no-process-env */ -import path from "path"; import os from "os"; import * as vscode from "vscode"; @@ -15,7 +14,6 @@ import { VersionManager, ActivationResult } from "./versionManager"; export class Asdf extends VersionManager { async activate(): Promise { const asdfUri = await this.findAsdfInstallation(); - const asdfDaraDirUri = await this.findAsdfDataDir(); const activationScript = "STDERR.print({env: ENV.to_h,yjit:!!defined?(RubyVM::YJIT),version:RUBY_VERSION}.to_json)"; @@ -24,24 +22,12 @@ export class Asdf extends VersionManager { { cwd: this.bundleUri.fsPath, shell: vscode.env.shell, - env: { - ...process.env, - ASDF_DIR: path.dirname(asdfUri.fsPath), - ASDF_DATA_DIR: asdfDaraDirUri.fsPath, - }, + env: process.env, }, ); const parsedResult = this.parseWithErrorHandling(result.stderr); - // ASDF does not set GEM_HOME or GEM_PATH. It also does not add the gem bin directories to the PATH. Instead, it - // adds its shims directory to the PATH, where all gems have a shim that invokes the gem's executable with the right - // version - parsedResult.env.PATH = [ - vscode.Uri.joinPath(asdfDaraDirUri, "shims").fsPath, - parsedResult.env.PATH, - ].join(path.delimiter); - return { env: { ...process.env, ...parsedResult.env }, yjit: parsedResult.yjit, @@ -49,47 +35,6 @@ export class Asdf extends VersionManager { }; } - // Find the ASDF data directory. The default is for this to be in the same directories where we'd find the asdf.sh - // file, but that may not be the case for a Homebrew installation, in which case the we'd have - // `/opt/homebrew/opt/asdf/libexec/asdf.sh`, but the data directory might be `~/.asdf` - async findAsdfDataDir(): Promise { - const possiblePaths = [ - vscode.Uri.joinPath(vscode.Uri.file(os.homedir()), ".asdf"), - vscode.Uri.joinPath(vscode.Uri.file("/"), "opt", "asdf-vm"), - vscode.Uri.joinPath( - vscode.Uri.file("/"), - "opt", - "homebrew", - "opt", - "asdf", - "libexec", - ), - vscode.Uri.joinPath( - vscode.Uri.file("/"), - "usr", - "local", - "opt", - "asdf", - "libexec", - ), - ]; - - for (const possiblePath of possiblePaths) { - try { - await vscode.workspace.fs.stat( - vscode.Uri.joinPath(possiblePath, "shims"), - ); - return possiblePath; - } catch (error: any) { - // Continue looking - } - } - - throw new Error( - `Could not find ASDF data dir. Searched in ${possiblePaths.join(", ")}`, - ); - } - // Only public for testing. Finds the ASDF installation URI based on what's advertised in the ASDF documentation async findAsdfInstallation(): Promise { // Possible ASDF installation paths as described in https://asdf-vm.com/guide/getting-started.html#_3-install-asdf. diff --git a/vscode/src/test/suite/ruby/asdf.test.ts b/vscode/src/test/suite/ruby/asdf.test.ts index 959861c51..600dd2a94 100644 --- a/vscode/src/test/suite/ruby/asdf.test.ts +++ b/vscode/src/test/suite/ruby/asdf.test.ts @@ -41,9 +41,6 @@ suite("Asdf", () => { const findInstallationStub = sinon .stub(asdf, "findAsdfInstallation") .resolves(vscode.Uri.file(`${os.homedir()}/.asdf/asdf.sh`)); - const findDataDirStub = sinon - .stub(asdf, "findAsdfDataDir") - .resolves(vscode.Uri.file(`${os.homedir()}/.asdf`)); const shellStub = sinon.stub(vscode.env, "shell").get(() => "/bin/bash"); const { env, version, yjit } = await asdf.activate(); @@ -54,24 +51,18 @@ suite("Asdf", () => { { cwd: workspacePath, shell: "/bin/bash", - env: { - // eslint-disable-next-line no-process-env - ...process.env, - ASDF_DIR: `${os.homedir()}/.asdf`, - ASDF_DATA_DIR: `${os.homedir()}/.asdf`, - }, + // eslint-disable-next-line no-process-env + env: process.env, }, ), ); assert.strictEqual(version, "3.0.0"); assert.strictEqual(yjit, true); - assert.ok(env.PATH!.includes(`${os.homedir()}/.asdf/shims`)); assert.strictEqual(env.ANY, "true"); execStub.restore(); findInstallationStub.restore(); - findDataDirStub.restore(); shellStub.restore(); }); });