Skip to content

Commit bdcb710

Browse files
committed
linting
(cherry picked from commit 66c7b16)
1 parent 9040742 commit bdcb710

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

index.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -195,25 +195,24 @@ function dedupeNonExistent(nonExistent) {
195195
}
196196
}
197197

198-
//If the file is in a node module, use the root directory of the module
199-
function getDirectory(localConfig){
198+
// If the file is in a node module, use the root directory of the module
199+
function getDirectory(localConfig) {
200200
function _getProjectPath(filename) {
201-
try{
202-
const nodeModuleParts = filename.split('node_modules')
203-
const packageSubPathPath = nodeModuleParts.pop().split(path.sep).filter(function(v){ return !!v})
204-
const packageName = packageSubPathPath[0].startsWith("@") ? `${packageSubPathPath[0]}${path.sep}${packageSubPathPath[1]}` : packageSubPathPath[0]
205-
206-
return path.join(...nodeModuleParts, 'node_modules', packageName)
207-
}
208-
catch(err){
209-
debug(`Could not determine the root directory of package file ${filename}. Using default`);
210-
return null
211-
}
201+
try {
202+
const nodeModuleParts = filename.split('node_modules');
203+
const packageSubPathPath = nodeModuleParts.pop().split(path.sep).filter(Boolean);
204+
const packageName = packageSubPathPath[0].startsWith('@') ? `${packageSubPathPath[0]}${path.sep}${packageSubPathPath[1]}` : packageSubPathPath[0];
205+
206+
return path.join(...nodeModuleParts, 'node_modules', packageName);
207+
} catch {
208+
debug(`Could not determine the root directory of package file ${filename}. Using default`);
209+
return null;
210+
}
212211
}
213212

214-
if (!localConfig.filename.includes('node_modules')){
215-
return localConfig.directory
213+
if (!localConfig.filename.includes('node_modules')) {
214+
return localConfig.directory;
216215
}
217216

218-
return _getProjectPath(path.dirname(localConfig.filename)) || localConfig.directory
219-
}
217+
return _getProjectPath(path.dirname(localConfig.filename)) || localConfig.directory;
218+
}

test/test.mjs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -472,21 +472,21 @@ describe('dependencyTree', () => {
472472
});
473473
});
474474

475-
describe("It uses package specific node_module directory when resolving package dependencies", () => {
475+
describe('It uses package specific node_module directory when resolving package dependencies', () => {
476476
testTreesForFormat('commonjs');
477477

478478
it('It can find sub package in node module package', () => {
479479
mockfs({
480480
[path.join(__dirname, '/es6')]: {
481481
'module.entry.js': 'import * as module from "parent_module_a"',
482482
node_modules: { // eslint-disable-line camelcase
483-
'parent_module_a': {
483+
parent_module_a: { // eslint-disable-line camelcase
484484
'index.main.js': 'import * as child_module from "child_node_module"; module.exports = child_module;',
485485
'package.json': '{ "main": "index.main.js"}',
486-
node_modules: {
487-
child_node_module: {
486+
node_modules: { // eslint-disable-line camelcase
487+
child_node_module: { // eslint-disable-line camelcase
488488
'index.main.js': 'module.exports = "child_node_module_of_parent_a"',
489-
'package.json': '{ "main": "index.main.js"}',
489+
'package.json': '{ "main": "index.main.js"}'
490490
}
491491
}
492492
}
@@ -506,23 +506,22 @@ describe('dependencyTree', () => {
506506
assert.ok(treeList.includes(path.normalize(`${directory}/node_modules/parent_module_a/node_modules/child_node_module/index.main.js`)));
507507
});
508508

509-
510509
it('it usues correct version of sub package in node module package', () => {
511510
mockfs({
512511
[path.join(__dirname, '/es6')]: {
513512
'module.entry.js': 'import * as module from "parent_module_a"',
514513
node_modules: { // eslint-disable-line camelcase
515-
child_node_module: {
514+
child_node_module: { // eslint-disable-line camelcase
516515
'index.main.js': 'module.exports = "child_node_module"',
517-
'package.json': '{ "main": "index.main.js", "version": "2.0.0"}',
516+
'package.json': '{ "main": "index.main.js", "version": "2.0.0"}'
518517
},
519-
parent_module_a: {
518+
parent_module_a: { // eslint-disable-line camelcase
520519
'index.main.js': 'import * as child_module from "child_node_module"; module.exports = child_module;',
521520
'package.json': '{ "main": "index.main.js"}',
522-
node_modules: {
523-
child_node_module: {
521+
node_modules: { // eslint-disable-line camelcase
522+
child_node_module: { // eslint-disable-line camelcase
524523
'index.main.js': 'module.exports = "child_node_module_of_parent_a"',
525-
'package.json': '{ "main": "index.main.js", "version": "1.0.0"}',
524+
'package.json': '{ "main": "index.main.js", "version": "1.0.0"}'
526525
}
527526
}
528527
}
@@ -541,10 +540,9 @@ describe('dependencyTree', () => {
541540

542541
assert.ok(!treeList.includes(path.normalize(`${directory}/node_modules/child_node_module/index.main.js`)));
543542
assert.ok(treeList.includes(path.normalize(`${directory}/node_modules/parent_module_a/node_modules/child_node_module/index.main.js`)));
544-
545543
});
546-
})
547-
544+
});
545+
548546
describe('module formats', () => {
549547
describe('amd', () => {
550548
testTreesForFormat('amd');

0 commit comments

Comments
 (0)