Skip to content

Commit f57d0b8

Browse files
author
jeromeh
committed
[Defect 2120][no-extraneous-dependencies] add ESM intermediate package.json support
1 parent ff2bcf0 commit f57d0b8

File tree

7 files changed

+20
-2
lines changed

7 files changed

+20
-2
lines changed

src/core/packagePath.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export function getFilePackagePath(filePath) {
1313
}
1414

1515
export function getFilePackageName(filePath) {
16-
const { pkg } = readPkgUp.sync({ cwd: filePath, normalize: false });
17-
return pkg && pkg.name;
16+
const { pkg, path } = readPkgUp.sync({ cwd: filePath, normalize: false });
17+
if (pkg) {
18+
// recursion in case of intermediate esm package.json without name found
19+
return pkg.name || getFilePackageName(dirname(dirname(path)));
20+
}
21+
return null;
1822
}

tests/files/node_modules/esm-package/esm-module/index.js

Whitespace-only changes.

tests/files/node_modules/esm-package/esm-module/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/files/node_modules/esm-package/index.js

Whitespace-only changes.

tests/files/node_modules/esm-package/package.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/files/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"dependencies": {
1111
"@org/package": "^1.0.0",
12+
"esm-package": "^1.0.0",
1213
"jquery": "^3.1.0",
1314
"lodash.cond": "^4.3.0",
1415
"pkg-up": "^1.0.0",

tests/src/rules/no-extraneous-dependencies.js

+4
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ ruleTester.run('no-extraneous-dependencies', rule, {
154154
test({
155155
code: 'import "rxjs/operators"',
156156
}),
157+
158+
test({
159+
code: 'import "esm-package/esm-module";',
160+
}),
157161
],
158162
invalid: [
159163
test({

0 commit comments

Comments
 (0)