Skip to content

Commit

Permalink
All phony to take an array of targets
Browse files Browse the repository at this point in the history
The `phony` rule can actually take multiple targets and not just one.
My initial reading of the documentation missed this.

Double bump the version as 0.8.4 had a trailing space for `phony` rules
with no inputs.  This isn't an issue for `ninja`, but does not match our
other rules.
  • Loading branch information
elliotgoodrich committed Feb 26, 2024
1 parent 4b21905 commit fa7202d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ninjutsu-build/core",
"version": "0.8.3",
"version": "0.8.5",
"description": "Easily create ninja build files with this TypeScript library (https://ninja-build.org/)",
"author": "Elliot Goodrich",
"engines": {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/core.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,18 @@ test("phony rule", () => {
const out2: "my:: alia$ !" = phony({ out: "my:: alia$ !", in: "file$ .txt" });
assert.equal(out2, "my:: alia$ !");

const out3: "all" = phony({ out: "all", in: ["in1", "in2"] });
assert.equal(out3, "all");

const out4: "none" = phony({ out: "none", in: [] });
assert.equal(out4, "none");

assert.equal(
ninja.output,
`build alias: phony file.txt
build my$:$:$ alia$$ !: phony file$$ .txt
build all: phony in1 in2
build none: phony
`,
);
});
Expand Down
14 changes: 10 additions & 4 deletions packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,13 +398,19 @@ export class NinjaBuilder {
* ninja.default(foo, mybar);
* ```
*/
get phony(): <O extends string>(args: { out: O; in: string }) => O {
return <O extends string>(args: { out: O; in: string }): O => {
get phony(): <O extends string>(args: {
out: O;
in: string | readonly string[];
}) => O {
return <O extends string>(args: {
out: O;
in: string | readonly string[];
}): O => {
this.output +=
"build " +
escapePath(args.out) +
": phony " +
escapePath(args.in) +
": phony" +
concatPaths(" ", args.in) +
"\n";
return args.out;
};
Expand Down

0 comments on commit fa7202d

Please sign in to comment.