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 c77e4b0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 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
27 changes: 21 additions & 6 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("Turbo");

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,25 @@ 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) {
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
'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(`set turbo path to ${turboPath}`);
}
} catch (e: any) {
if (
Expand All @@ -97,18 +103,22 @@ export function activate(context: ExtensionContext) {
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 +135,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 +152,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 +394,7 @@ function findLocalTurbo(): string | undefined {

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

Expand All @@ -402,14 +413,17 @@ 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");
},
Expand All @@ -419,6 +433,7 @@ function findLocalTurbo(): string | undefined {
try {
const potential = potentialPath();
if (potential && fs.existsSync(potential)) {
logs.appendLine(`found local turbo at ${potential}`);
return potential;
}
} catch (e) {
Expand Down

0 comments on commit c77e4b0

Please sign in to comment.