Skip to content

Commit

Permalink
fix(core/tasks): tries to run package.json tasks only when task is no…
Browse files Browse the repository at this point in the history
…t found on kpo, but not for any
  • Loading branch information
rafamel committed May 3, 2019
1 parent 51d34a3 commit 20344a8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/core/tasks/from-kpo.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ITask } from '../types';
import { IScripts } from '~/types';
import purePath from './pure-path';
import { CustomError } from '~/utils/errors';

export default function getFromKpo(path: string, kpo: IScripts): ITask {
const task = trunk(purePath(path).split('.'), kpo, '');
Expand Down Expand Up @@ -41,8 +42,9 @@ export function trunk(arr: string[], obj: any, path: string): ITask {
);
}
if (!props.length) {
throw Error(
`There are no tasks matching ${purePath(path ? `${path}.${key}` : key)}`
throw new CustomError(
`There are no tasks matching ${purePath(path ? `${path}.${key}` : key)}`,
{ type: 'NotFound' }
);
}
const actualKey = props.shift() as string;
Expand Down
7 changes: 5 additions & 2 deletions src/core/tasks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import getFromKpo from './from-kpo';
import getFromPackage from './from-package';
import { ITask, ITasks } from '../types';
import recursiveFields from './recursive-fields';
import { CustomError } from '~/utils/errors';

export function getTask(
path: string,
Expand All @@ -11,9 +12,11 @@ export function getTask(
): ITask {
try {
if (kpo) return getFromKpo(path, kpo);
throw Error(`Task ${path} not found`);
throw new CustomError(`Task ${path} not found`, { type: 'NotFound' });
} catch (err) {
if (!pkg) throw err;
if (!pkg || !err.data || !err.data.type || err.data.type !== 'NotFound') {
throw err;
}

try {
return getFromPackage(path, pkg);
Expand Down

0 comments on commit 20344a8

Please sign in to comment.