1
1
import fs from 'node:fs'
2
2
import path from 'node:path'
3
3
4
+ import { cjsRequire } from '@pkgr/core'
4
5
import type { TSESLint , TSESTree } from '@typescript-eslint/utils'
5
- import { parse as parseComment_ } from 'comment-parser'
6
- import type { Block } from 'comment-parser'
6
+ import type * as commentParser from 'comment-parser'
7
7
import debug from 'debug'
8
8
import type { AST } from 'eslint'
9
9
import { SourceCode } from 'eslint'
@@ -36,7 +36,7 @@ const tsconfigCache = new Map<string, TsConfigJsonResolved | null | undefined>()
36
36
37
37
export type DocStyleParsers = Record <
38
38
DocStyle ,
39
- ( comments : TSESTree . Comment [ ] ) => Block | undefined
39
+ ( comments : TSESTree . Comment [ ] ) => commentParser . Block | undefined
40
40
>
41
41
42
42
export interface DeclarationMetadata {
@@ -47,7 +47,7 @@ export interface DeclarationMetadata {
47
47
}
48
48
49
49
export interface ModuleNamespace {
50
- doc ?: Block
50
+ doc ?: commentParser . Block
51
51
namespace ?: ExportMap | null
52
52
}
53
53
@@ -70,7 +70,10 @@ const declTypes = new Set([
70
70
// https://github.com/syavorsky/comment-parser/issues/172
71
71
const fixup = new Set ( [ 'deprecated' , 'module' ] )
72
72
73
- const parseComment = ( comment : string ) : Block => {
73
+ let parseComment_ : typeof commentParser . parse | undefined
74
+
75
+ const parseComment = ( comment : string ) : commentParser . Block => {
76
+ parseComment_ ??= cjsRequire < typeof commentParser > ( 'comment-parser' ) . parse
74
77
const restored = `/**${ comment . split ( '\n' ) . reduce ( ( acc , line ) => {
75
78
line = line . trim ( )
76
79
return line && line !== '*' ? acc + '\n ' + line : acc
@@ -747,7 +750,7 @@ export class ExportMap {
747
750
748
751
declare private mtime : number
749
752
750
- declare doc : Block | undefined
753
+ declare doc : commentParser . Block | undefined
751
754
752
755
constructor ( public path : string ) { }
753
756
@@ -963,7 +966,7 @@ function captureDoc(
963
966
...nodes : Array < TSESTree . Node | undefined >
964
967
) {
965
968
const metadata : {
966
- doc ?: Block | undefined
969
+ doc ?: commentParser . Block | undefined
967
970
} = { }
968
971
969
972
defineLazyProperty ( metadata , 'doc' , ( ) => {
@@ -1030,7 +1033,9 @@ function captureJsDoc(comments: TSESTree.Comment[]) {
1030
1033
}
1031
1034
1032
1035
/** Parse TomDoc section from comments */
1033
- function captureTomDoc ( comments : TSESTree . Comment [ ] ) : Block | undefined {
1036
+ function captureTomDoc (
1037
+ comments : TSESTree . Comment [ ] ,
1038
+ ) : commentParser . Block | undefined {
1034
1039
// collect lines up to first paragraph break
1035
1040
const lines = [ ]
1036
1041
for ( const comment of comments ) {
@@ -1053,7 +1058,7 @@ function captureTomDoc(comments: TSESTree.Comment[]): Block | undefined {
1053
1058
description : statusMatch [ 2 ] ,
1054
1059
} ,
1055
1060
] ,
1056
- } as Block
1061
+ } as commentParser . Block
1057
1062
}
1058
1063
}
1059
1064
0 commit comments