Skip to content

Commit 0c4e5b6

Browse files
committed
fix(imports-as-dependencies): handle resolve.exports errors
1 parent 6c13a32 commit 0c4e5b6

File tree

5 files changed

+76
-5
lines changed

5 files changed

+76
-5
lines changed

docs/rules/imports-as-dependencies.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ The following patterns are considered problems:
4040
* @type {null|import('@sth/pkg').SomeApi}
4141
*/
4242
// Message: import points to package which is not found in dependencies
43+
44+
/**
45+
* @type {null|import('sinon').SomeApi}
46+
*/
47+
// Message: import points to package which is not found in dependencies
4348
````
4449

4550

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"replace": "^1.2.2",
7171
"rimraf": "^6.0.1",
7272
"semantic-release": "^25.0.1",
73+
"sinon": "^21.0.0",
7374
"typescript": "5.9.3",
7475
"typescript-eslint": "^8.46.2"
7576
},

pnpm-lock.yaml

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rules/importsAsDependencies.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,15 @@ export default iterateJsdoc(({
104104
// Ignore
105105
}
106106

107-
if (!pkg || (!pkg.types && !pkg.typings && !resolve.exports(pkg, '.', {
108-
conditions: [
109-
'!default', '!import', '!node', 'types',
110-
],
111-
}))) {
107+
try {
108+
if (!pkg || (!pkg.types && !pkg.typings && !resolve.exports(pkg, '.', {
109+
conditions: [
110+
'!default', '!import', '!node', 'types',
111+
],
112+
}))) {
113+
mod = `@types/${mod}`;
114+
}
115+
} catch {
112116
mod = `@types/${mod}`;
113117
}
114118

test/rules/assertions/importsAsDependencies.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@ export default /** @type {import('../index.js').TestCases} */ ({
5757
},
5858
],
5959
},
60+
{
61+
code: `
62+
/**
63+
* @type {null|import('sinon').SomeApi}
64+
*/
65+
`,
66+
errors: [
67+
{
68+
line: 3,
69+
message: 'import points to package which is not found in dependencies',
70+
},
71+
],
72+
},
6073
],
6174
valid: [
6275
{

0 commit comments

Comments
 (0)