@@ -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,13 +34,24 @@ 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 . sourcemap = rawOptions . sourcemap ?? true
43
44
this . generateDeclaration = throttle ( 500 , this . _generateDeclaration . bind ( this ) , { noLeading : false } )
45
+
46
+ if ( this . options . dumpUnimportComponents ) {
47
+ const dumpUnimportComponents = this . options . dumpUnimportComponents === true
48
+ ? './.unimport-components.json'
49
+ : this . options . dumpUnimportComponents ?? false
50
+
51
+ this . dumpUnimportComponentsPath = dumpUnimportComponents
52
+ this . generateComponentsJson = throttle ( 500 , this . _generateComponentsJson . bind ( this ) , { noLeading : false } )
53
+ }
54
+
44
55
this . setTransformer ( this . options . transformer )
45
56
}
46
57
@@ -288,14 +299,26 @@ export class Context {
288
299
if ( ! this . options . dts )
289
300
return
290
301
291
- debug . declaration ( 'generating' )
302
+ debug . declaration ( 'generating dts ' )
292
303
return writeDeclaration ( this , this . options . dts , removeUnused )
293
304
}
294
305
295
306
generateDeclaration ( removeUnused = ! this . _server ) : void {
296
307
this . _generateDeclaration ( removeUnused )
297
308
}
298
309
310
+ _generateComponentsJson ( removeUnused = ! this . _server ) {
311
+ if ( ! Object . keys ( this . _componentNameMap ) . length )
312
+ return
313
+
314
+ debug . components ( 'generating components.json' )
315
+ return writeComponentsJson ( this , removeUnused )
316
+ }
317
+
318
+ generateComponentsJson ( removeUnused = ! this . _server ) : void {
319
+ this . _generateComponentsJson ( removeUnused )
320
+ }
321
+
299
322
get componentNameMap ( ) {
300
323
return this . _componentNameMap
301
324
}
0 commit comments