Use lodash _.startsWith
This commit is contained in:
parent
8a42cea978
commit
c5e43f8da5
@ -17,8 +17,8 @@ export class NPMResolver extends Resolver {
|
||||
let packageName;
|
||||
let packageScopeIfExists;
|
||||
let other;
|
||||
if (importPath.startsWith('@')) {
|
||||
[packageScope, packageName, ...other] = importPath.split('/');
|
||||
if (_.startsWith(importPath, '@')) {
|
||||
[packageScopeIfExists, packageName, ...other] = importPath.split('/');
|
||||
} else {
|
||||
[packageName, ...other] = importPath.split('/');
|
||||
}
|
||||
@ -26,7 +26,9 @@ export class NPMResolver extends Resolver {
|
||||
let currentPath = this._packagePath;
|
||||
const 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);
|
||||
if (fs.existsSync(lookupPath) && fs.lstatSync(lookupPath).isFile()) {
|
||||
const fileContent = fs.readFileSync(lookupPath).toString();
|
||||
|
Loading…
x
Reference in New Issue
Block a user