Unverified Commit 1e16969f authored by Hong Minhee's avatar Hong Minhee
Browse files

Fix CLI package manager execution on Windows

parent 73785fe5
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -8,6 +8,15 @@ Version 1.8.14

To be released.

### @fedify/cli

 -  Fixed `fedify` command failing on Windows with `PermissionDenied` error
    when trying to locate or execute package managers during initialization.
    The CLI now properly handles _\*.cmd_ and _\*.bat_ files on Windows by
    invoking them through `cmd /c`.  [[#463]]

[#463]: https://github.com/fedify-dev/fedify/issues/463


Version 1.8.13
--------------
+42 −18
Original line number Diff line number Diff line
@@ -1437,7 +1437,12 @@ async function isCommandAvailable(
      "The command {command} failed with the error: {error}",
      { command: checkCommand, error },
    );
    if (error instanceof Deno.errors.NotFound) return false;
    if (
      error instanceof Deno.errors.NotFound ||
      error instanceof Deno.errors.PermissionDenied
    ) {
      return false;
    }
    throw error;
  }
}
@@ -1454,11 +1459,13 @@ async function locatePackageManager(
  }
  if (Deno.build.os !== "windows") return undefined;
  const cmd: [string, ...string[]] = [
    "cmd",
    "/c",
    packageManagers[pm].checkCommand[0] + ".cmd",
    ...packageManagers[pm].checkCommand.slice(1),
  ];
  if (await isCommandAvailable({ ...packageManagers[pm], checkCommand: cmd })) {
    return cmd[0];
    return cmd[2];
  }
  return undefined;
}
@@ -1485,7 +1492,24 @@ async function addDependencies(
      }`
    );
  if (deps.length < 1) return;
  const cmd = new Deno.Command(
  const cmd =
    runtime === "node" && packageManagerLocations[pm]?.match(/\.cmd$/i)
      ? new Deno.Command(
        "cmd",
        {
          args: [
            "/c",
            `${packageManagerLocations[pm]} add ${
              dev ? (pm === "yarn" ? "--dev" : "--save-dev") : ""
            } ${uniqueArray(deps).join(" ")}`,
          ],
          cwd: dir,
          stdin: "inherit",
          stdout: "inherit",
          stderr: "inherit",
        },
      )
      : new Deno.Command(
        runtime === "node" ? (packageManagerLocations[pm] ?? pm) : runtime,
        {
          args: [