Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some more logging to the extension startup #8047

Merged
merged 1 commit into from Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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