From 25d31463f46190284c8d5b280f0c8eb411554e2d Mon Sep 17 00:00:00 2001 From: garronej Date: Fri, 25 Oct 2024 00:01:12 +0000 Subject: [PATCH] Make script delegation work on windows --- src/bin/shared/customHandler_delegate.ts | 32 ++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/bin/shared/customHandler_delegate.ts b/src/bin/shared/customHandler_delegate.ts index 691989df..11f8b0c6 100644 --- a/src/bin/shared/customHandler_delegate.ts +++ b/src/bin/shared/customHandler_delegate.ts @@ -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>(); @@ -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 }; }