Skip to content

Commit

Permalink
feat(state/paths): retrieves bin paths recursively for current and ro…
Browse files Browse the repository at this point in the history
…ot scopes
  • Loading branch information
rafamel committed Apr 23, 2019
1 parent ab692bc commit a92997e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/state/paths/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,20 @@ export default async function paths(opts: IPathsOpts): Promise<IPaths> {
directory: state.get('root') || path.join(base.directory, '../')
}).catch(async (err) => {
return state.get('root')
? wrap.rejects(err, { message: "@root couldn't be retrieved" })
? wrap.rejects(err, {
message: `root scope couldn't be retrieved: ${state.get('root')}`
})
: null;
});

return {
...base,
// add also root bin path
bin: base.bin
.concat(root ? root.bin : [])
.filter((x, i, arr) => arr.indexOf(x) === i),
bin: [base.bin[0]]
.concat(root ? root.bin[0] : [])
.concat(base.bin.slice(1))
.concat(root ? root.bin.slice(1) : [])
.filter((x, i, arr) => x && arr.indexOf(x) === i),
root,
children: {}
};
Expand All @@ -62,8 +66,11 @@ export async function trunk(opts: IPathsOpts): Promise<IBasePaths> {
kpo: kpo,
pkg: pkg,
directory: dir,
bin: [await up('node_modules/.bin', { cwd: dir })].filter(
Boolean
) as string[]
bin: await getBin(dir)
};
}

export async function getBin(dir: string): Promise<string[]> {
const bin = await up('node_modules/.bin', { cwd: dir });
return bin ? [bin].concat(await getBin(path.join(dir, '../'))) : [];
}

0 comments on commit a92997e

Please sign in to comment.