Skip to content

Commit

Permalink
[Defect 2120][no-extraneous-dependencies] add ESM intermediate packag…
Browse files Browse the repository at this point in the history
…e.json support
  • Loading branch information
jeromeh committed Jun 10, 2021
1 parent ff2bcf0 commit f57d0b8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/core/packagePath.js
Expand Up @@ -13,6 +13,10 @@ export function getFilePackagePath(filePath) {
}

export function getFilePackageName(filePath) {
const { pkg } = readPkgUp.sync({ cwd: filePath, normalize: false });
return pkg && pkg.name;
const { pkg, path } = readPkgUp.sync({ cwd: filePath, normalize: false });
if (pkg) {
// recursion in case of intermediate esm package.json without name found
return pkg.name || getFilePackageName(dirname(dirname(path)));
}
return null;
}
Empty file.
4 changes: 4 additions & 0 deletions tests/files/node_modules/esm-package/esm-module/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file.
5 changes: 5 additions & 0 deletions tests/files/node_modules/esm-package/package.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/files/package.json
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@org/package": "^1.0.0",
"esm-package": "^1.0.0",
"jquery": "^3.1.0",
"lodash.cond": "^4.3.0",
"pkg-up": "^1.0.0",
Expand Down
4 changes: 4 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Expand Up @@ -154,6 +154,10 @@ ruleTester.run('no-extraneous-dependencies', rule, {
test({
code: 'import "rxjs/operators"',
}),

test({
code: 'import "esm-package/esm-module";',
}),
],
invalid: [
test({
Expand Down

0 comments on commit f57d0b8

Please sign in to comment.