Skip to content

Commit

Permalink
add some more logging to the extension startup
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Apr 26, 2024
1 parent 126a00d commit b05f1e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
5 changes: 3 additions & 2 deletions packages/turbo-vsc/package.json
Expand Up @@ -49,10 +49,11 @@
"vscode": "^1.84.2"
},
"devDependencies": {
"@turbo/tsconfig": "workspace:*",
"@types/node": "^20.9.0",
"@types/vscode": "^1.84.1",
"esbuild": "^0.15.0",
"@turbo/tsconfig": "workspace:*"
"@vscode/vsce": "^2.26.0",
"esbuild": "^0.15.0"
},
"contributes": {
"commands": [
Expand Down
44 changes: 31 additions & 13 deletions packages/turbo-vsc/src/extension.ts
Expand Up @@ -42,6 +42,8 @@ const decoration = window.createTextEditorDecorationType({
color: "#04f1f9", // something like cyan
});

const logs = window.createOutputChannel("Turborepo Extension");

function rainbowRgb(i: number) {
const f = 0.5;
const r = Math.sin(f * i + (4.0 * Math.PI) / 3.0) * 127.0 + 128.0;
Expand Down Expand Up @@ -71,21 +73,27 @@ export function activate(context: ExtensionContext) {
let turboPath: string | undefined = turboSettings.get("path");
const useLocalTurbo: boolean = turboSettings.get("useLocalTurbo") ?? false;

logs.appendLine("starting the turbo extension");

if (turboPath && !fs.existsSync(turboPath)) {
window.showErrorMessage(
`turbo does not exist at path \`${turboPath}\`, attempting to locate it`
logs.appendLine(
`manually specified turbo does not exist at path \`${turboPath}\`, attempting to locate it`
);
turboPath = undefined;
}

try {
if (turboPath == null) {
turboPath = cp.execSync(
// attempt to source two well known version managers
// as well as adding the bun global bin to the path
'sh -c \'source "$HOME/.nvm/nvm.sh" > /dev/null 2>&1; source "$HOME/.asdf/asdf.sh" > /dev/null 2>&1; export PATH="$HOME/.bun/bin:$PATH"; which turbo\'',
options
);
logs.appendLine("attempting to find global turbo");
turboPath = cp
.execSync(
// attempt to source two well known version managers
// as well as adding the bun global bin to the path
'bash -c \'source "$HOME/.nvm/nvm.sh" > /dev/null 2>&1; source "$HOME/.asdf/asdf.sh" > /dev/null 2>&1; eval "$(brew shellenv)" > /dev/null 2>&1; export PATH="$HOME/.bun/bin:$PATH"; which turbo\'',
options
)
.trim();
logs.appendLine(`set turbo path to ${turboPath}`);
}
} catch (e: any) {
if (
Expand All @@ -94,21 +102,26 @@ export function activate(context: ExtensionContext) {
e.message.includes("which: no turbo in")
) {
// attempt to find local turbo instead
logs.appendLine("prompting global turbo");
promptGlobalTurbo(useLocalTurbo);
turboPath = findLocalTurbo();
} else {
window.showErrorMessage(e.message);
logs.appendLine(`unable to find turbo: ${e.message}`);
}
}

if (turboPath) {
logs.appendLine(`using turbo at path ${turboPath}`);
}

context.subscriptions.push(
commands.registerCommand("turbo.daemon.start", () => {
cp.exec(`${turboPath} daemon start`, options, (err) => {
if (err) {
if (err.message.includes("command not found")) {
promptGlobalTurbo(useLocalTurbo);
} else {
window.showErrorMessage(JSON.stringify(err));
logs.appendLine(`unable to start turbo: ${err.message}`);
}
} else {
updateStatusBarItem(true);
Expand All @@ -125,7 +138,7 @@ export function activate(context: ExtensionContext) {
if (err.message.includes("command not found")) {
promptGlobalTurbo(useLocalTurbo);
} else {
window.showErrorMessage(err.message);
logs.appendLine(`unable to stop turbo: ${err.message}`);
}
} else {
updateStatusBarItem(false);
Expand All @@ -142,7 +155,7 @@ export function activate(context: ExtensionContext) {
if (err.message.includes("command not found")) {
promptGlobalTurbo(useLocalTurbo);
} else {
window.showErrorMessage(err.message);
logs.appendLine(`unable to get turbo status: ${err.message}`);
updateStatusBarItem(false);
}
} else {
Expand Down Expand Up @@ -384,6 +397,7 @@ function findLocalTurbo(): string | undefined {

const checks = [
() => {
logs.appendLine("attempting to find local turbo using npm");
const npmList = cp.execSync("npm ls turbo --json", options);
const npmData = JSON.parse(npmList);

Expand All @@ -402,23 +416,27 @@ function findLocalTurbo(): string | undefined {
}
},
() => {
logs.appendLine("attempting to find local turbo using yarn");
const turboBin = cp.execSync("yarn bin turbo", options);
return turboBin.trim();
},
() => {
logs.appendLine("attempting to find local turbo using pnpm");
const binFolder = cp.execSync("pnpm bin", options).trim();
return path.join(binFolder, "turbo");
},
() => {
logs.appendLine("attempting to find local turbo using bun");
const binFolder = cp.execSync("bun pm bin", options).trim();
return path.join(binFolder, "turbo");
},
];

for (const potentialPath of checks) {
try {
const potential = potentialPath();
const potential = potentialPath()?.trim();
if (potential && fs.existsSync(potential)) {
logs.appendLine(`found local turbo at ${potential}`);
return potential;
}
} catch (e) {
Expand Down

0 comments on commit b05f1e1

Please sign in to comment.