Skip to content

Commit

Permalink
Fix backslashes when calling del
Browse files Browse the repository at this point in the history
`del` does not support forward slashes as directory separators and
if we have any spaces in the path then it needs to be quoted.
  • Loading branch information
elliotgoodrich committed Sep 24, 2024
1 parent 4883d4b commit 301499f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/esbuild/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
13 changes: 11 additions & 2 deletions packages/esbuild/src/esbuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,13 @@ export function makeESBuildRule(
[validations]?: (out: string) => Input<string> | readonly Input<string>[];
}) => 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,
Expand All @@ -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",
Expand All @@ -149,6 +155,9 @@ export function makeESBuildRule(
return rule({
...rest,
args: serializeBuildOptions(buildOptions),
...(process.platform === "win32"
? { outDepsBackslash: `${rest.out}.deps.json`.replaceAll("/", "\\") }
: {}),
});
};
}

0 comments on commit 301499f

Please sign in to comment.