From 301499f3ce0f98d4fd44753eb1cdc6c43a585cab Mon Sep 17 00:00:00 2001 From: Elliot Goodrich Date: Tue, 24 Sep 2024 05:44:45 +0100 Subject: [PATCH] Fix backslashes when calling `del` `del` does not support forward slashes as directory separators and if we have any spaces in the path then it needs to be quoted. --- packages/esbuild/package.json | 2 +- packages/esbuild/src/esbuild.ts | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/esbuild/package.json b/packages/esbuild/package.json index d9af3fd..9b836c2 100644 --- a/packages/esbuild/package.json +++ b/packages/esbuild/package.json @@ -1,6 +1,6 @@ { "name": "@ninjutsu-build/esbuild", - "version": "0.3.0", + "version": "0.3.1", "description": "An esbuild plugin for ninjutsu-build", "author": "Elliot Goodrich", "scripts": { diff --git a/packages/esbuild/src/esbuild.ts b/packages/esbuild/src/esbuild.ts index 558803f..9ae155e 100644 --- a/packages/esbuild/src/esbuild.ts +++ b/packages/esbuild/src/esbuild.ts @@ -104,7 +104,13 @@ export function makeESBuildRule( [validations]?: (out: string) => Input | readonly Input[]; }) => O { const { name = "esbuild", ...rest } = options; - const rm = process.platform === "win32" ? "del" : "rm"; + + // Replace backslashes with forwardslashes to pass to `del` + const toDelete = + process.platform === "win32" + ? `del "$outDepsBackslash"` + : "rm $out.deps.json"; + const absOutput = resolve(process.cwd(), ninja.outputDir); const jq = relative( absOutput, @@ -126,7 +132,7 @@ export function makeESBuildRule( const prefix = process.platform === "win32" ? "cmd /c " : ""; const command = `${prefix}${esbuild} $in --outfile=$out --log-level=warning --color=true --metafile=$out.deps.json $args && ` + - `${jq} "[\\"$out:\\"] + (.inputs | keys) | map(.+\\" \\")[]" $out.deps.json --join-output > $out.deps && ${rm} $out.deps.json`; + `${jq} "[\\"$out:\\"] + (.inputs | keys) | map(.+\\" \\")[]" $out.deps.json --join-output > $out.deps && ${toDelete}`; const rule = ninja.rule(name, { command, description: "Bundling $out", @@ -149,6 +155,9 @@ export function makeESBuildRule( return rule({ ...rest, args: serializeBuildOptions(buildOptions), + ...(process.platform === "win32" + ? { outDepsBackslash: `${rest.out}.deps.json`.replaceAll("/", "\\") } + : {}), }); }; }