Skip to content

Commit

Permalink
[cli] Allow DS_Store in definitions nested directories (#4217)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brianzchen committed Jan 4, 2022
1 parent 25f15b8 commit 3dd4af9
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions cli/src/lib/npm/npmLibDefs.js
Expand Up @@ -536,22 +536,24 @@ async function getSingleLibdef(
const scope = itemName;
const scopeDirItems = await fs.readdir(itemPath);
const settled = await P.all(
scopeDirItems.map(async itemName => {
const itemPath = path.join(npmDefsDirPath, scope, itemName);
const itemStat = await fs.stat(itemPath);
if (itemStat.isDirectory()) {
return await extractLibDefsFromNpmPkgDir(
itemPath,
scope,
itemName,
validating,
);
} else {
throw new ValidationError(
`Expected only sub-directories in this dir!`,
);
}
}),
scopeDirItems
.filter(item => item !== '.DS_Store')
.map(async itemName => {
const itemPath = path.join(npmDefsDirPath, scope, itemName);
const itemStat = await fs.stat(itemPath);
if (itemStat.isDirectory()) {
return await extractLibDefsFromNpmPkgDir(
itemPath,
scope,
itemName,
validating,
);
} else {
throw new ValidationError(
`Expected only sub-directories in this dir!`,
);
}
}),
);
return [].concat(...settled);
} else {
Expand Down Expand Up @@ -581,6 +583,10 @@ export async function getNpmLibDefs(
const dirItems = await fs.readdir(npmDefsDirPath);
const errors = [];
const proms = dirItems.map(async itemName => {
// If a user opens definitions dir in finder it will create `.DS_Store`
// which will need to be excluded while parsing
if (itemName === '.DS_Store') return;

try {
return await getSingleLibdef(itemName, npmDefsDirPath, validating);
} catch (e) {
Expand Down

0 comments on commit 3dd4af9

Please sign in to comment.