@@ -6,7 +6,7 @@ import process from 'node:process'
6
6
import { slash , throttle , toArray } from '@antfu/utils'
7
7
import Debug from 'debug'
8
8
import { DIRECTIVE_IMPORT_PREFIX } from './constants'
9
- import { writeDeclaration } from './declaration'
9
+ import { writeComponentsJson , writeDeclaration } from './declaration'
10
10
import { searchComponents } from './fs/glob'
11
11
import { resolveOptions } from './options'
12
12
import transformer from './transformer'
@@ -34,12 +34,23 @@ export class Context {
34
34
root = process . cwd ( )
35
35
sourcemap : string | boolean = true
36
36
alias : Record < string , string > = { }
37
+ dumpUnimportComponentsPath : string | undefined
37
38
38
39
constructor (
39
40
private rawOptions : Options ,
40
41
) {
41
42
this . options = resolveOptions ( rawOptions , this . root )
42
43
this . generateDeclaration = throttle ( 500 , this . _generateDeclaration . bind ( this ) , { noLeading : false } )
44
+
45
+ if ( this . options . dumpUnimportComponents ) {
46
+ const dumpUnimportComponents = this . options . dumpUnimportComponents === true
47
+ ? './.unimport-components.json'
48
+ : this . options . dumpUnimportComponents ?? false
49
+
50
+ this . dumpUnimportComponentsPath = dumpUnimportComponents
51
+ this . generateComponentsJson = throttle ( 500 , this . _generateComponentsJson . bind ( this ) , { noLeading : false } )
52
+ }
53
+
43
54
this . setTransformer ( this . options . transformer )
44
55
}
45
56
@@ -287,14 +298,26 @@ export class Context {
287
298
if ( ! this . options . dts )
288
299
return
289
300
290
- debug . declaration ( 'generating' )
301
+ debug . declaration ( 'generating dts ' )
291
302
return writeDeclaration ( this , this . options . dts , removeUnused )
292
303
}
293
304
294
305
generateDeclaration ( removeUnused = ! this . _server ) : void {
295
306
this . _generateDeclaration ( removeUnused )
296
307
}
297
308
309
+ _generateComponentsJson ( removeUnused = ! this . _server ) {
310
+ if ( ! Object . keys ( this . _componentNameMap ) . length )
311
+ return
312
+
313
+ debug . components ( 'generating components.json' )
314
+ return writeComponentsJson ( this , removeUnused )
315
+ }
316
+
317
+ generateComponentsJson ( removeUnused = ! this . _server ) : void {
318
+ this . _generateComponentsJson ( removeUnused )
319
+ }
320
+
298
321
get componentNameMap ( ) {
299
322
return this . _componentNameMap
300
323
}
0 commit comments