diff --git a/src/reporters/lang/en.js b/src/reporters/lang/en.js index a5228c1fd8..5fc739662b 100644 --- a/src/reporters/lang/en.js +++ b/src/reporters/lang/en.js @@ -31,6 +31,7 @@ const messages = { manifestStringExpected: '$0 is not a string', manifestDependencyBuiltin: 'Dependency $0 listed in $1 is the name of a built-in module', manifestDependencyCollision: '$0 has dependency $1 with range $2 that collides with a dependency in $3 of the same name with version $4', + manifestDirectoryNotFound: 'Unable to read $0 directory of module $1', configSet: 'Set $0 to $1.', configDelete: 'Deleted $0.', diff --git a/src/util/normalize-manifest/fix.js b/src/util/normalize-manifest/fix.js index 9758b1c161..4d959b6b4f 100644 --- a/src/util/normalize-manifest/fix.js +++ b/src/util/normalize-manifest/fix.js @@ -20,10 +20,13 @@ type Dict = { [key: string]: T; }; +type WarnFunction = (msg: string) => void; + export default async function ( info: Dict, moduleLoc: string, reporter: Reporter, + warn: WarnFunction, looseSemver: boolean, ): Promise { const files = await fs.readdir(moduleLoc); @@ -184,12 +187,17 @@ export default async function ( if (!info.bin && binDir && typeof binDir === 'string') { const bin = info.bin = {}; + const fullBinDir = path.join(moduleLoc, binDir); - for (const scriptName of await fs.readdir(path.join(moduleLoc, binDir))) { - if (scriptName[0] === '.') { - continue; + if (await fs.exists(fullBinDir)) { + for (const scriptName of await fs.readdir(fullBinDir)) { + if (scriptName[0] === '.') { + continue; + } + bin[scriptName] = path.join('.', binDir, scriptName); } - bin[scriptName] = path.join('.', binDir, scriptName); + } else { + warn(reporter.lang('manifestDirectoryNotFound', binDir, info.name)); } } @@ -197,11 +205,16 @@ export default async function ( if (!info.man && typeof manDir === 'string') { const man = info.man = []; + const fullManDir = path.join(moduleLoc, manDir); - for (const filename of await fs.readdir(path.join(moduleLoc, manDir))) { - if (/^(.*?)\.[0-9]$/.test(filename)) { - man.push(path.join('.', manDir, filename)); + if (await fs.exists(fullManDir)) { + for (const filename of await fs.readdir(fullManDir)) { + if (/^(.*?)\.[0-9]$/.test(filename)) { + man.push(path.join('.', manDir, filename)); + } } + } else { + warn(reporter.lang('manifestDirectoryNotFound', manDir, info.name)); } } } diff --git a/src/util/normalize-manifest/index.js b/src/util/normalize-manifest/index.js index a207d9230d..868dfa21a9 100644 --- a/src/util/normalize-manifest/index.js +++ b/src/util/normalize-manifest/index.js @@ -13,8 +13,6 @@ export default async function ( config: Config, isRoot: boolean, ): Promise { - await fix(info, moduleLoc, config.reporter, config.looseSemver); - // create human readable name const {name, version} = info; let human: ?string; @@ -35,6 +33,7 @@ export default async function ( config.reporter.warn(msg); } + await fix(info, moduleLoc, config.reporter, warn, config.looseSemver); try { validate(info, isRoot, config.reporter, warn); } catch (err) {