Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when man or bin directory not found but don't crash #1663

Merged
merged 4 commits into from
Nov 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down
27 changes: 20 additions & 7 deletions src/util/normalize-manifest/fix.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ type Dict<T> = {
[key: string]: T;
};

type WarnFunction = (msg: string) => void;

export default async function (
info: Dict<mixed>,
moduleLoc: string,
reporter: Reporter,
warn: WarnFunction,
looseSemver: boolean,
): Promise<void> {
const files = await fs.readdir(moduleLoc);
Expand Down Expand Up @@ -184,24 +187,34 @@ 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));
}
}

const manDir = dirs.man;

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));
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/util/normalize-manifest/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export default async function (
config: Config,
isRoot: boolean,
): Promise<Manifest> {
await fix(info, moduleLoc, config.reporter, config.looseSemver);

// create human readable name
const {name, version} = info;
let human: ?string;
Expand All @@ -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) {
Expand Down