@@ -91,7 +91,7 @@ if (!PRODUCE_GITIGNORE) {
9191
9292var SLASH = "/" ;
9393
94- async function stripTypes ( filePath : string ) : Promise < string | undefined > {
94+ async function stripTypes ( filePath : string ) : Promise < { outPath : string | undefined ; config : any } | undefined > {
9595 try {
9696 const source = readFileSync ( filePath , "utf8" ) ;
9797 const startMarker = "/** @es.ts" ;
@@ -133,7 +133,7 @@ async function stripTypes(filePath: string): Promise<string | undefined> {
133133 }
134134
135135 // 3. Merge top-level config fields (excluding tool-specific ones)
136- const { mode, extension : _ext , setup, options, ...rest } = config ;
136+ const { mode, extension : _ext , setup, options, cliarguments , ...rest } = config ;
137137 const mergedOptions : any = {
138138 ...baseOptions ,
139139 ...rest ,
@@ -200,10 +200,10 @@ async function stripTypes(filePath: string): Promise<string | undefined> {
200200 }
201201 }
202202
203- if ( ! PRODUCE_GITIGNORE && firstOutPath ) {
204- console . log ( ` ${ buildMode === "bundle" ? "Bundled" : "Transpiled" } (esbuild): ${ filePath } -> ${ firstOutPath } ` ) ;
205- }
206- return firstOutPath ;
203+ return {
204+ outPath : firstOutPath ,
205+ config ,
206+ } ;
207207 } catch ( err : unknown ) {
208208 hasError = true ;
209209 const message = err instanceof Error ? err . message : String ( err ) ;
@@ -311,6 +311,9 @@ Description:
311311
312312 // Use 'undefined' to unset a default and let esbuild decide:
313313 minify: undefined,
314+
315+ // Overriding command line arguments:
316+ "cliarguments": ["--produce-gitignore"], // override global arguments for this file
314317}
315318@es.ts *${ SLASH }
316319
@@ -336,7 +339,8 @@ const rl = createInterface({
336339
337340let processedCount : number = 0 ;
338341let hasError : boolean = false ;
339- const gitignorePaths : string [ ] = [ ] ;
342+ const gitignorePaths : string [ ] = [ ] ; // paths to produce in stdout
343+ const updatePaths : string [ ] = [ ] ; // paths to actually update in .gitignore
340344const semaphore = new Semaphore ( ES_PARALLEL ) ;
341345const activeTasks = new Set < Promise < void > > ( ) ;
342346
@@ -349,10 +353,28 @@ for await (const line of rl) {
349353 // Start the task and keep track of it in the activeTasks Set
350354 const task : Promise < void > = ( async ( ) => {
351355 try {
352- let outPath = await stripTypes ( file ) ;
353- if ( PRODUCE_GITIGNORE && outPath ) {
354- outPath = relative ( gitRoot , outPath ) ;
355- gitignorePaths . push ( outPath ) ;
356+ const result = await stripTypes ( file ) ;
357+ if ( result && result . outPath ) {
358+ const { outPath, config } = result ;
359+ const buildMode = config . mode || ( CONFIG . bundle ? "bundle" : "transform" ) ;
360+ if ( ! PRODUCE_GITIGNORE ) {
361+ console . log ( `${ buildMode === "bundle" ? "Bundled" : "Transpiled" } (esbuild): ${ file } -> ${ outPath } ` ) ;
362+ }
363+
364+ const localArgs = Array . isArray ( config . cliarguments )
365+ ? config . cliarguments
366+ : args ;
367+
368+ const localProduceGitignore = localArgs . includes ( "--produce-gitignore" ) ;
369+ const localUpdateGitignore = localArgs . includes ( "--update" ) ;
370+
371+ if ( localProduceGitignore ) {
372+ const relPath = relative ( gitRoot , outPath ) ;
373+ gitignorePaths . push ( relPath ) ;
374+ if ( localUpdateGitignore ) {
375+ updatePaths . push ( relPath ) ;
376+ }
377+ }
356378 }
357379 } finally {
358380 semaphore . release ( ) ;
@@ -372,7 +394,7 @@ if (PRODUCE_GITIGNORE && gitignorePaths.length > 0) {
372394 let pathsToLog = gitignorePaths ;
373395
374396 if ( UPDATE_GITIGNORE ) {
375- pathsToLog = updateGitignoreFile ( gitRoot , startMarker , endMarker , gitignorePaths ) ;
397+ pathsToLog = updateGitignoreFile ( gitRoot , startMarker , endMarker , updatePaths ) ;
376398 }
377399
378400 const content = [ startMarker , ...pathsToLog . sort ( ) , endMarker ] . join ( "\n" ) ;
0 commit comments