Make script delegation work on windows

This commit is contained in:
garronej 2024-10-25 00:01:12 +00:00
parent 2542c38c9b
commit 25d31463f4

View File

@ -8,7 +8,7 @@ import {
ApiVersion
} from "./customHandler";
import * as child_process from "child_process";
import { dirname as pathDirname } from "path";
import { sep as pathSep } from "path";
import * as fs from "fs";
assert<Equals<ApiVersion, "v1">>();
@ -19,7 +19,35 @@ export function maybeDelegateCommandToCustomHandler(params: {
}): { hasBeenHandled: boolean } {
const { commandName, buildContext } = params;
if (!fs.readdirSync(pathDirname(process.argv[1])).includes(BIN_NAME)) {
const nodeModulesBinDirPath = (() => {
const binPath = process.argv[1];
const segments: string[] = [".bin"];
let foundNodeModules = false;
for (const segment of binPath.split(pathSep).reverse()) {
skip_segment: {
if (foundNodeModules) {
break skip_segment;
}
if (segment === "node_modules") {
foundNodeModules = true;
break skip_segment;
}
continue;
}
segments.unshift(segment);
}
return segments.join(pathSep);
})();
if (!fs.readdirSync(nodeModulesBinDirPath).includes(BIN_NAME)) {
console.log(`Custom handler not found`);
return { hasBeenHandled: false };
}