Use lodash _.startsWith

This commit is contained in:
Leonid Logvinov 2018-12-03 13:40:06 +01:00
parent 8a42cea978
commit c5e43f8da5
No known key found for this signature in database
GPG Key ID: 0DD294BFDE8C95D4

View File

@ -17,8 +17,8 @@ export class NPMResolver extends Resolver {
let packageName; let packageName;
let packageScopeIfExists; let packageScopeIfExists;
let other; let other;
if (importPath.startsWith('@')) { if (_.startsWith(importPath, '@')) {
[packageScope, packageName, ...other] = importPath.split('/'); [packageScopeIfExists, packageName, ...other] = importPath.split('/');
} else { } else {
[packageName, ...other] = importPath.split('/'); [packageName, ...other] = importPath.split('/');
} }
@ -26,7 +26,9 @@ export class NPMResolver extends Resolver {
let currentPath = this._packagePath; let currentPath = this._packagePath;
const ROOT_PATH = '/'; const ROOT_PATH = '/';
while (currentPath !== ROOT_PATH) { while (currentPath !== ROOT_PATH) {
const packagePath = _.isUndefined(packageScopeIfExists) ? packageName : path.join(packageScopeIfExists, packageName); const packagePath = _.isUndefined(packageScopeIfExists)
? packageName
: path.join(packageScopeIfExists, packageName);
const lookupPath = path.join(currentPath, 'node_modules', packagePath, pathWithinPackage); const lookupPath = path.join(currentPath, 'node_modules', packagePath, pathWithinPackage);
if (fs.existsSync(lookupPath) && fs.lstatSync(lookupPath).isFile()) { if (fs.existsSync(lookupPath) && fs.lstatSync(lookupPath).isFile()) {
const fileContent = fs.readFileSync(lookupPath).toString(); const fileContent = fs.readFileSync(lookupPath).toString();