Skip to content

Commit

Permalink
Better Windows support for wrapper (#958)
Browse files Browse the repository at this point in the history
Does a better job of perserving a cross-platform path, and updates the
self-reference check to skip any Windows scripts which is how the
`package.json#bin` option works on Windows rather than a symlink.
  • Loading branch information
scotttrinh authored Apr 15, 2024
1 parent 1deb943 commit 54a5822
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/driver/src/cli.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createWriteStream } from "node:fs";
import * as os from "node:os";
import * as fs from "node:fs/promises";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import * as process from "node:process";
import * as semver from "semver";
import envPaths from "env-paths";
Expand All @@ -13,6 +14,7 @@ import which from "which";
const debug = Debug("edgedb:cli");

const IS_TTY = process.stdout.isTTY;
const SCRIPT_LOCATION = await fs.realpath(fileURLToPath(import.meta.url));
const EDGEDB_PKG_ROOT = "https://packages.edgedb.com";
const CACHE_DIR = envPaths("edgedb").cache;
const TEMPORARY_CLI_PATH = path.join(CACHE_DIR, "/edgedb-cli");
Expand Down Expand Up @@ -50,7 +52,7 @@ try {
}

async function main(args: string[]) {
debug(`Running CLI wrapper from: ${new URL(import.meta.url).pathname}`);
debug(`Running CLI wrapper from: ${fileURLToPath(import.meta.url)}`);
debug("Starting main function with args:", args);
const cliLocation =
(await whichEdgeDbCli()) ??
Expand All @@ -75,11 +77,19 @@ async function whichEdgeDbCli() {
` - CLI found in PATH at: ${location} (resolved to: ${actualLocation})`
);

const scriptLocation = new URL(import.meta.url).pathname;
if (actualLocation === scriptLocation) {
if (actualLocation === SCRIPT_LOCATION) {
debug(" - CLI found in PATH is the current script. Ignoring.");
continue;
}

const lowerCaseLocation = actualLocation.toLowerCase();
if (
lowerCaseLocation.endsWith(".cmd") ||
lowerCaseLocation.endsWith(".ps1")
) {
debug(" - CLI found in PATH is a Windows script. Ignoring.");
continue;
}
return location;
}
debug(" - No CLI found in PATH.");
Expand Down

0 comments on commit 54a5822

Please sign in to comment.