Skip to content

Commit

Permalink
src/goEnvironmentStatus: get rid of fs-extra dependency
Browse files Browse the repository at this point in the history
Change-Id: I072cba03519b11d8e88777c32452aa31d23a06c8
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/240692
Run-TryBot: Hyang-Ah Hana Kim <[email protected]>
Reviewed-by: Rebecca Stambler <[email protected]>
  • Loading branch information
hyangah committed Jul 2, 2020
1 parent 0359d70 commit 2fc928c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/goEnvironmentStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
'use strict';

import cp = require('child_process');
import fs = require('fs-extra');
import fs = require('fs');
import os = require('os');
import path = require('path');
import { promisify } from 'util';
import vscode = require('vscode');
import WebRequest = require('web-request');

import { toolInstallationEnvironment } from './goEnv';
import { getCurrentGoRoot } from './goPath';
import { getCurrentGoRoot, pathExists } from './goPath';
import { outputChannel } from './goStatus';
import { getBinPath, getGoConfig, getGoVersion } from './util';

Expand Down Expand Up @@ -190,11 +190,13 @@ export async function setSelectedGo(selectedGo: GoEnvironmentOption, scope: vsco

outputChannel.appendLine('Finding newly downloaded Go');
const sdkPath = path.join(process.env.HOME, 'sdk');
if (!await fs.pathExists(sdkPath)) {
if (!await pathExists(sdkPath)) {
outputChannel.appendLine(`SDK path does not exist: ${sdkPath}`);
throw new Error(`SDK path does not exist: ${sdkPath}`);
}
const subdirs = await fs.readdir(sdkPath);

const readdir = promisify(fs.readdir);
const subdirs = await readdir(sdkPath);
const dir = subdirs.find((subdir) => subdir === newExecutableName);
if (!dir) {
outputChannel.appendLine('Could not find newly downloaded Go');
Expand Down Expand Up @@ -268,10 +270,12 @@ export function formatGoVersion(version: string): string {
async function getSDKGoOptions(): Promise<GoEnvironmentOption[]> {
// get list of Go versions
const sdkPath = path.join(os.homedir(), 'sdk');
if (!await fs.pathExists(sdkPath)) {

if (!await pathExists(sdkPath)) {
return [];
}
const subdirs = await fs.readdir(sdkPath);
const readdir = promisify(fs.readdir);
const subdirs = await readdir(sdkPath);
// the dir happens to be the version, which will be used as the label
// the path is assembled and used as the description
return subdirs.map((dir: string) =>
Expand Down
10 changes: 10 additions & 0 deletions src/goPath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import fs = require('fs');
import os = require('os');
import path = require('path');
import { promisify } from 'util';

let binPathCache: { [bin: string]: string } = {};

Expand Down Expand Up @@ -134,6 +135,15 @@ export function fileExists(filePath: string): boolean {
}
}

export async function pathExists(p: string): Promise<boolean> {
try {
const stat = promisify(fs.stat);
return (await stat(p)).isDirectory();
} catch (e) {
return false;
}
}

export function clearCacheForTools() {
binPathCache = {};
}
Expand Down

0 comments on commit 2fc928c

Please sign in to comment.