Add return types to npm-discards and make them consistent

This commit is contained in:
James Miller Burgess
2019-08-04 16:42:24 +09:00
parent dd30586cfa
commit e79acf2d50

View File

@@ -17,11 +17,11 @@ class NpmDiscards {
// patterns that should be discarded. See the comment in package-source.js
// about `Npm.strip` for an explanation of what should be passed for the
// `discards` parameter.
merge(discards: Discards) {
merge(discards: Discards): void {
merge(this.discards, discards);
}
shouldDiscard(candidatePath: string, isDirectory?: boolean) {
shouldDiscard(candidatePath: string, isDirectory?: boolean): boolean {
if (isDirectory === void 0) {
isDirectory = files.lstat(candidatePath).isDirectory();
}
@@ -53,7 +53,7 @@ class NpmDiscards {
}
}
function merge(into: Discards, from: Discards) {
function merge(into: Discards, from: Discards): void {
Object.keys(from).forEach((packageName: string) => {
const fromValue = from[packageName];
const intoValue = hasOwn.call(into, packageName) && into[packageName];
@@ -78,9 +78,9 @@ function merge(into: Discards, from: Discards) {
// TODO Improve this. For example we don't currently support wildcard
// string patterns (just use a RegExp if you need that flexibility).
function matches(pattern: StringOrRegExp, relPath: string) {
function matches(pattern: StringOrRegExp, relPath: string): boolean {
if (pattern instanceof RegExp) {
return relPath.match(pattern);
return pattern.test(relPath);
}
if (pattern.charAt(0) === files.pathSep) {