Skip to content

Commit

Permalink
feat(core/scope): checks for children name conflicts when inferred fr…
Browse files Browse the repository at this point in the history
…om directory name
  • Loading branch information
rafamel committed May 4, 2019
1 parent 0073f48 commit 0cf24eb
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/core/scope/children/from-globs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,27 @@ export default async function getChildrenFromGlobs(
return acc.concat(arr);
}, []);

// TODO verify names don't conflict
// filter and make into IChild
return filter(dirs).map((dir) => ({
const children = filter(dirs).map((dir) => ({
name: path.parse(dir).name,
// absolute path
directory: path.join(directory, dir),
matcher(name: string) {
return dir.includes(name);
}
}));

// Check for name conflicts
const conflicts = children
.map((child) => child.name)
.filter((name, i, arr) => arr.indexOf(name) !== i);
if (conflicts.length)
throw Error(
`There are several children scopes with the same name: ` +
conflicts.join(', ')
);

return children;
}

export async function fromGlob(
Expand Down

0 comments on commit 0cf24eb

Please sign in to comment.