Skip to content

Commit

Permalink
feat: errors out on tasks, core, and spawned processes calls if exit …
Browse files Browse the repository at this point in the history
…has already been triggered
  • Loading branch information
rafamel committed May 5, 2019
1 parent 5b5e698 commit 201dc7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { loadPackage } from 'cli-belt';
import ob from '~/utils/object-base';
import inVersionRange from '~/utils/version-range';
import { KPO_ENV_STATE, DEFAULT_LOG_LEVEL } from '~/constants';
import guardian from '~/utils/guardian';

export interface ICoreState {
version: string | null;
Expand Down Expand Up @@ -48,6 +49,7 @@ function cache<T>(fn: () => T): () => T {
const core = wrapCore(
// These will run in order before any core function call
[
async () => guardian(),
async function initialize(): Promise<void> {
if (state.version) return;

Expand Down
3 changes: 3 additions & 0 deletions src/core/run.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logger from '~/utils/logger';
import { TScript } from '~/types';
import errors from '~/utils/errors';
import guardian from '~/utils/guardian';

export default async function run(
script: TScript,
Expand All @@ -10,6 +11,8 @@ export default async function run(
| ((args: string[]) => Promise<TScript | void> | TScript | void)
) => Promise<any>
): Promise<void> {
guardian();

if (!script) {
logger.debug('Empty task');
} else if (script instanceof Error) {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import join from 'command-join';
import { IExecOptions } from '~/types';
import { spawn } from 'exits';
import errors from './errors';
import guardian from './guardian';

export default async function exec(
cmd: string,
args: string[],
fork: boolean,
options: IExecOptions = {}
): Promise<void> {
guardian();

const opts: SpawnOptions = {
shell: !fork,
cwd: options.cwd,
Expand Down

0 comments on commit 201dc7a

Please sign in to comment.