From 87e80b9f6db8efcec6af3b06cbeb2c70e5161d66 Mon Sep 17 00:00:00 2001 From: Rafa Mel Date: Wed, 24 Apr 2019 10:28:43 +0200 Subject: [PATCH] feat(state): allows root scope to be set as null --- src/state/paths/index.ts | 23 +++++++++++++---------- src/types.ts | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/state/paths/index.ts b/src/state/paths/index.ts index da927c0..350b778 100644 --- a/src/state/paths/index.ts +++ b/src/state/paths/index.ts @@ -13,17 +13,20 @@ export default async function paths(opts: IPathsOpts): Promise { // has to to called after load to wait for scope options to modify state const rootDir = state.get('root'); - const root = await getRootPaths( - rootDir || path.join(self.directory, '../') - ).catch(async (err) => { - // don't fail if root directory wasn't explicitly passed via options, - // just set as null - if (!rootDir) return null; + const root = + rootDir === null + ? null + : await getRootPaths(rootDir || path.join(self.directory, '../')).catch( + async (err) => { + // don't fail if root directory wasn't explicitly passed via options, + // just set as null + if (!rootDir) return null; - return wrap.rejects(err, { - message: `root scope couldn't be retrieved: ${state.get('root')}` - }); - }); + return wrap.rejects(err, { + message: `root scope couldn't be retrieved: ${state.get('root')}` + }); + } + ); return { ...self, diff --git a/src/types.ts b/src/types.ts index 0588a74..9cdd2c9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -33,6 +33,6 @@ export interface IBaseOptions extends ICoreOptions { } export interface IScopeOptions extends ICoreOptions { - root?: string; + root?: string | null; children?: IOfType; }