Skip to content

Commit 60051c5

Browse files
fix (buildifier): Handle relative buildifier path without warning (#387)
Relative paths for buildifier are now supported as of v0.10.0, the warning should not be shown when the buildifier executable exists at the relative path specified.
1 parent 901006c commit 60051c5

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/buildifier/buildifier_availability.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
import * as fs from "fs/promises";
16+
import * as path from "path";
1517
import * as vscode from "vscode";
1618
import * as which from "which";
1719

@@ -20,6 +22,15 @@ import {
2022
getDefaultBuildifierExecutablePath,
2123
} from "./buildifier";
2224

25+
async function fileExists(filename: string) {
26+
try {
27+
await fs.stat(filename);
28+
return true;
29+
} catch {
30+
return false;
31+
}
32+
}
33+
2334
/** The URL to load for buildifier's releases. */
2435
const BUILDTOOLS_RELEASES_URL =
2536
"https://github.com/bazelbuild/buildtools/releases";
@@ -33,9 +44,20 @@ const BUILDTOOLS_RELEASES_URL =
3344
*/
3445
export async function checkBuildifierIsAvailable() {
3546
const buildifierExecutable = getDefaultBuildifierExecutablePath();
47+
3648
// Check if the program exists (in case it's an actual executable and not
3749
// an target name starting with `@`).
38-
if (!buildifierExecutable.startsWith("@")) {
50+
const isTarget = buildifierExecutable.startsWith("@");
51+
52+
// Check if the program exists as a relative path of the workspace
53+
const pathExists = await fileExists(
54+
path.join(
55+
vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath,
56+
buildifierExecutable,
57+
),
58+
);
59+
60+
if (!isTarget && !pathExists) {
3961
try {
4062
await which(buildifierExecutable);
4163
} catch (e) {

0 commit comments

Comments
 (0)