Skip to content

Commit

Permalink
fix (buildifier): Handle relative buildifier path without warning (#387)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryanwilsonperkin authored May 2, 2024
1 parent 901006c commit 60051c5
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/buildifier/buildifier_availability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import * as fs from "fs/promises";
import * as path from "path";
import * as vscode from "vscode";
import * as which from "which";

Expand All @@ -20,6 +22,15 @@ import {
getDefaultBuildifierExecutablePath,
} from "./buildifier";

async function fileExists(filename: string) {
try {
await fs.stat(filename);
return true;
} catch {
return false;
}
}

/** The URL to load for buildifier's releases. */
const BUILDTOOLS_RELEASES_URL =
"https://github.com/bazelbuild/buildtools/releases";
Expand All @@ -33,9 +44,20 @@ const BUILDTOOLS_RELEASES_URL =
*/
export async function checkBuildifierIsAvailable() {
const buildifierExecutable = getDefaultBuildifierExecutablePath();

// Check if the program exists (in case it's an actual executable and not
// an target name starting with `@`).
if (!buildifierExecutable.startsWith("@")) {
const isTarget = buildifierExecutable.startsWith("@");

// Check if the program exists as a relative path of the workspace
const pathExists = await fileExists(
path.join(
vscode.workspace.workspaceFolders?.[0]?.uri?.fsPath,
buildifierExecutable,
),
);

if (!isTarget && !pathExists) {
try {
await which(buildifierExecutable);
} catch (e) {
Expand Down

0 comments on commit 60051c5

Please sign in to comment.