Skip to content

Commit 36316ea

Browse files
committed
Merge branch 'unmatched-error'
2 parents cba9e8b + d71f61e commit 36316ea

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

src/lib/match-tasks.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default function matchTasks(taskList, patterns) {
7878
const filters = patterns.map(createFilter);
7979
const candidates = taskList.map(swapColonAndSlash);
8080
const taskSet = new TaskSet();
81+
const unknownSet = Object.create(null);
8182

8283
// Take tasks while keep the order of patterns.
8384
for (const filter of filters) {
@@ -96,8 +97,16 @@ export default function matchTasks(taskList, patterns) {
9697
// Built-in tasks should be allowed.
9798
if (!found && (filter.task === "restart" || filter.task === "env")) {
9899
taskSet.add(filter.task + filter.args, filter.task);
100+
found = true;
101+
}
102+
if (!found) {
103+
unknownSet[filter.task] = true;
99104
}
100105
}
101106

107+
const unknownTasks = Object.keys(unknownSet);
108+
if (unknownTasks.length > 0) {
109+
throw new Error(`Task not found: "${unknownTasks.join("\", ")}"`);
110+
}
102111
return taskSet.result;
103112
}

src/lib/npm-run-all.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,6 @@ export default function npmRunAll(
111111
throw new Error("Invalid options.taskList");
112112
}
113113

114-
const tasks = matchTasks(taskList || readTasks(), patterns);
115-
if (tasks.length === 0) {
116-
throw new Error(`Matched tasks not found: ${patterns.join(", ")}`);
117-
}
118-
119114
const prefixOptions = [];
120115
if (silent) {
121116
prefixOptions.push("--silent");
@@ -124,6 +119,7 @@ export default function npmRunAll(
124119
prefixOptions.push(...toOverwriteOptions(packageConfig));
125120
}
126121

122+
const tasks = matchTasks(taskList || readTasks(), patterns);
127123
const runTasks = parallel ? runTasksInParallel : runTasksInSequencial;
128124
return runTasks(tasks, stdin, stdout, stderr, prefixOptions);
129125
}

test-workspace/tasks/.eslintrc

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
"no-process-exit": 0,
1010
"node/no-missing-import": 2,
1111
"node/no-missing-require": 2,
12-
"node/no-unpublished-import": 2,
13-
"node/no-unpublished-require": 2,
1412
"node/shebang": 2
1513
}
1614
}

test/fail.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ describe("[fail] npm-run-all should fail", () => {
3737
it("command version", () => shouldFail(command(["unknown-task"])));
3838
});
3939

40+
describe("if unknown tasks are given (2):", () => {
41+
it("lib version", () => shouldFail(runAll(["test-task:append:a", "unknown-task"])));
42+
it("command version", () => shouldFail(command(["test-task:append:a", "unknown-task"])));
43+
});
44+
4045
describe("if package.json is not found:", () => {
4146
before(() => { process.chdir("no-package-json"); });
4247
after(() => { process.chdir(".."); });

0 commit comments

Comments
 (0)