@@ -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,13 +34,24 @@ export class Context {
3434root = process . cwd ( )
3535sourcemap :string | boolean = true
3636alias :Record < string , string > = { }
37+ dumpComponentsInfoPath :string | undefined
3738
3839constructor (
3940private rawOptions :Options ,
4041) {
4142this . options = resolveOptions ( rawOptions , this . root )
4243this . sourcemap = rawOptions . sourcemap ?? true
4344this . generateDeclaration = throttle ( 500 , this . _generateDeclaration . bind ( this ) , { noLeading :false } )
45+
46+ if ( this . options . dumpComponentsInfo ) {
47+ const dumpComponentsInfo = this . options . dumpComponentsInfo === true
48+ ?'./.components-info.json'
49+ :this . options . dumpComponentsInfo ?? false
50+
51+ this . dumpComponentsInfoPath = dumpComponentsInfo
52+ this . generateComponentsJson = throttle ( 500 , this . _generateComponentsJson . bind ( this ) , { noLeading :false } )
53+ }
54+
4455this . setTransformer ( this . options . transformer )
4556}
4657
@@ -169,6 +180,7 @@ export class Context {
169180
170181onUpdate ( path :string ) {
171182this . generateDeclaration ( )
183+ this . generateComponentsJson ( )
172184
173185if ( ! this . _server )
174186return
@@ -288,14 +300,26 @@ export class Context {
288300if ( ! this . options . dts )
289301return
290302
291- debug . declaration ( 'generating' )
303+ debug . declaration ( 'generating dts ' )
292304return writeDeclaration ( this , this . options . dts , removeUnused )
293305}
294306
295307generateDeclaration ( removeUnused = ! this . _server ) :void {
296308this . _generateDeclaration ( removeUnused )
297309}
298310
311+ _generateComponentsJson ( removeUnused = ! this . _server ) {
312+ if ( ! Object . keys ( this . _componentNameMap ) . length )
313+ return
314+
315+ debug . components ( 'generating components-info' )
316+ return writeComponentsJson ( this , removeUnused )
317+ }
318+
319+ generateComponentsJson ( removeUnused = ! this . _server ) :void {
320+ this . _generateComponentsJson ( removeUnused )
321+ }
322+
299323get componentNameMap ( ) {
300324return this . _componentNameMap
301325}