@@ -13,30 +13,35 @@ import {
13
13
} from 'path' ;
14
14
15
15
/**
16
- * @type {Set<string> }
16
+ * @type {Set<string>|null }
17
17
*/
18
18
let 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
+ } ;
40
45
41
46
const moduleCheck = new Map ( ) ;
42
47
@@ -46,7 +51,12 @@ export default iterateJsdoc(({
46
51
utils,
47
52
} ) => {
48
53
// 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 ) {
50
60
return ;
51
61
}
52
62
@@ -62,7 +72,13 @@ export default iterateJsdoc(({
62
72
continue ;
63
73
}
64
74
75
+ // eslint-disable-next-line no-loop-func -- Safe
65
76
traverse ( typeAst , ( nde ) => {
77
+ // istanbul ignore if -- TS guard
78
+ if ( deps === null ) {
79
+ return ;
80
+ }
81
+
66
82
if ( nde . type === 'JsdocTypeImport' ) {
67
83
let mod = nde . element . value . replace (
68
84
/ ^ ( @ [ ^ / ] + \/ [ ^ / ] + | [ ^ / ] + ) .* $ / u, '$1' ,
0 commit comments