@@ -13,30 +13,35 @@ import {
1313} from 'path' ;
1414
1515/**
16- * @type {Set<string> }
16+ * @type {Set<string>|null }
1717 */
1818let deps ;
19- try {
20- const pkg = JSON . parse (
21- // @ts -expect-error It's ok
22- readFileSync ( join ( process . cwd ( ) , './package.json' ) ) ,
23- ) ;
24- deps = new Set ( [
25- ...( pkg . dependencies ?
26- Object . keys ( pkg . dependencies ) :
27- // istanbul ignore next
28- [ ] ) ,
29- ...( pkg . devDependencies ?
30- Object . keys ( pkg . devDependencies ) :
31- // istanbul ignore next
32- [ ] ) ,
33- ] ) ;
34- } catch ( error ) {
35- /* eslint-disable no-console -- Inform user */
36- // istanbul ignore next
37- console . log ( error ) ;
38- /* eslint-enable no-console -- Inform user */
39- }
19+
20+ const setDeps = function ( ) {
21+ try {
22+ const pkg = JSON . parse (
23+ // @ts -expect-error It's ok
24+ readFileSync ( join ( process . cwd ( ) , './package.json' ) ) ,
25+ ) ;
26+ deps = new Set ( [
27+ ...( pkg . dependencies ?
28+ Object . keys ( pkg . dependencies ) :
29+ // istanbul ignore next
30+ [ ] ) ,
31+ ...( pkg . devDependencies ?
32+ Object . keys ( pkg . devDependencies ) :
33+ // istanbul ignore next
34+ [ ] ) ,
35+ ] ) ;
36+ } catch ( error ) {
37+ // istanbul ignore next -- our package.json exists
38+ deps = null ;
39+ /* eslint-disable no-console -- Inform user */
40+ // istanbul ignore next -- our package.json exists
41+ console . log ( error ) ;
42+ /* eslint-enable no-console -- Inform user */
43+ }
44+ } ;
4045
4146const moduleCheck = new Map ( ) ;
4247
@@ -46,7 +51,12 @@ export default iterateJsdoc(({
4651 utils,
4752} ) => {
4853 // istanbul ignore if
49- if ( ! deps ) {
54+ if ( deps === undefined ) {
55+ setDeps ( ) ;
56+ }
57+
58+ // istanbul ignore if -- our package.json exists
59+ if ( deps === null ) {
5060 return ;
5161 }
5262
@@ -62,7 +72,13 @@ export default iterateJsdoc(({
6272 continue ;
6373 }
6474
75+ // eslint-disable-next-line no-loop-func -- Safe
6576 traverse ( typeAst , ( nde ) => {
77+ // istanbul ignore if -- TS guard
78+ if ( deps === null ) {
79+ return ;
80+ }
81+
6682 if ( nde . type === 'JsdocTypeImport' ) {
6783 let mod = nde . element . value . replace (
6884 / ^ ( @ [ ^ / ] + \/ [ ^ / ] + | [ ^ / ] + ) .* $ / u, '$1' ,
0 commit comments