Use lodash _.startsWith
This commit is contained in:
parent
8a42cea978
commit
c5e43f8da5
@ -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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user