@@ -6,7 +6,7 @@ import process from 'node:process'
66import { slash , throttle , toArray } from '@antfu/utils'
77import Debug from 'debug'
88import { DIRECTIVE_IMPORT_PREFIX } from './constants'
9- import { writeDeclaration } from './declaration'
9+ import { writeComponentsJson , writeDeclaration } from './declaration'
1010import { searchComponents } from './fs/glob'
1111import { resolveOptions } from './options'
1212import transformer from './transformer'
@@ -34,12 +34,23 @@ export class Context {
3434 root = process . cwd ( )
3535 sourcemap : string | boolean = true
3636 alias : Record < string , string > = { }
37+ dumpUnimportComponentsPath : string | undefined
3738
3839 constructor (
3940 private rawOptions : Options ,
4041 ) {
4142 this . options = resolveOptions ( rawOptions , this . root )
4243 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+
4354 this . setTransformer ( this . options . transformer )
4455 }
4556
@@ -287,14 +298,26 @@ export class Context {
287298 if ( ! this . options . dts )
288299 return
289300
290- debug . declaration ( 'generating' )
301+ debug . declaration ( 'generating dts ' )
291302 return writeDeclaration ( this , this . options . dts , removeUnused )
292303 }
293304
294305 generateDeclaration ( removeUnused = ! this . _server ) : void {
295306 this . _generateDeclaration ( removeUnused )
296307 }
297308
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+
298321 get componentNameMap ( ) {
299322 return this . _componentNameMap
300323 }
0 commit comments