Skip to content

Commit

Permalink
Fix: came to report unmatched pattern error (fixes #19)
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Jan 28, 2016
1 parent cba9e8b commit d71f61e
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/lib/match-tasks.js
Expand Up @@ -78,6 +78,7 @@ export default function matchTasks(taskList, patterns) {
const filters = patterns.map(createFilter);
const candidates = taskList.map(swapColonAndSlash);
const taskSet = new TaskSet();
const unknownSet = Object.create(null);

// Take tasks while keep the order of patterns.
for (const filter of filters) {
Expand All @@ -96,8 +97,16 @@ export default function matchTasks(taskList, patterns) {
// Built-in tasks should be allowed.
if (!found && (filter.task === "restart" || filter.task === "env")) {
taskSet.add(filter.task + filter.args, filter.task);
found = true;
}
if (!found) {
unknownSet[filter.task] = true;
}
}

const unknownTasks = Object.keys(unknownSet);
if (unknownTasks.length > 0) {
throw new Error(`Task not found: "${unknownTasks.join("\", ")}"`);
}
return taskSet.result;
}
6 changes: 1 addition & 5 deletions src/lib/npm-run-all.js
Expand Up @@ -111,11 +111,6 @@ export default function npmRunAll(
throw new Error("Invalid options.taskList");
}

const tasks = matchTasks(taskList || readTasks(), patterns);
if (tasks.length === 0) {
throw new Error(`Matched tasks not found: ${patterns.join(", ")}`);
}

const prefixOptions = [];
if (silent) {
prefixOptions.push("--silent");
Expand All @@ -124,6 +119,7 @@ export default function npmRunAll(
prefixOptions.push(...toOverwriteOptions(packageConfig));
}

const tasks = matchTasks(taskList || readTasks(), patterns);
const runTasks = parallel ? runTasksInParallel : runTasksInSequencial;
return runTasks(tasks, stdin, stdout, stderr, prefixOptions);
}
Expand Down
2 changes: 0 additions & 2 deletions test-workspace/tasks/.eslintrc
Expand Up @@ -9,8 +9,6 @@
"no-process-exit": 0,
"node/no-missing-import": 2,
"node/no-missing-require": 2,
"node/no-unpublished-import": 2,
"node/no-unpublished-require": 2,
"node/shebang": 2
}
}
5 changes: 5 additions & 0 deletions test/fail.js
Expand Up @@ -37,6 +37,11 @@ describe("[fail] npm-run-all should fail", () => {
it("command version", () => shouldFail(command(["unknown-task"])));
});

describe("if unknown tasks are given (2):", () => {
it("lib version", () => shouldFail(runAll(["test-task:append:a", "unknown-task"])));
it("command version", () => shouldFail(command(["test-task:append:a", "unknown-task"])));
});

describe("if package.json is not found:", () => {
before(() => { process.chdir("no-package-json"); });
after(() => { process.chdir(".."); });
Expand Down

0 comments on commit d71f61e

Please sign in to comment.