@@ -260,15 +260,6 @@ def ts_project(
260260 **kwargs: passed through to underlying [`ts_project_rule`](#ts_project_rule), eg. `visibility`, `tags`
261261 """
262262
263- if srcs == None :
264- include = ["**/*.ts" , "**/*.tsx" ]
265- exclude = []
266- if allow_js == True :
267- include .extend (["**/*.js" , "**/*.jsx" ])
268- if resolve_json_module == True :
269- include .append ("**/*.json" )
270- exclude .extend (["**/package.json" , "**/package-lock.json" , "**/tsconfig*.json" ])
271- srcs = native .glob (include , exclude )
272263 tsc_deps = deps
273264
274265 common_kwargs = {
@@ -299,17 +290,20 @@ def ts_project(
299290 no_emit = compiler_options .setdefault ("noEmit" , no_emit )
300291 emit_declaration_only = compiler_options .setdefault ("emitDeclarationOnly" , emit_declaration_only )
301292 allow_js = compiler_options .setdefault ("allowJs" , allow_js )
302- if resolve_json_module != None :
303- resolve_json_module = compiler_options .setdefault ("resolveJsonModule" , resolve_json_module )
293+ resolve_json_module = compiler_options .setdefault ("resolveJsonModule" , resolve_json_module )
304294
305295 # These options are always passed on the tsc command line so don't include them
306296 # in the tsconfig. At best they're redundant, but at worst we'll have a conflict
307- if "outDir" in compiler_options .keys ():
308- out_dir = compiler_options .pop ("outDir" )
309- if "declarationDir" in compiler_options .keys ():
310- declaration_dir = compiler_options .pop ("declarationDir" )
311- if "rootDir" in compiler_options .keys ():
312- root_dir = compiler_options .pop ("rootDir" )
297+ out_dir = compiler_options .pop ("outDir" , out_dir )
298+ declaration_dir = compiler_options .pop ("declarationDir" , declaration_dir )
299+ root_dir = compiler_options .pop ("rootDir" , root_dir )
300+
301+ if srcs == None :
302+ # Default sources based on macro attributes after applying tsconfig properties
303+ srcs = _default_srcs (
304+ allow_js = allow_js ,
305+ resolve_json_module = resolve_json_module ,
306+ )
313307
314308 # FIXME: need to remove keys that have a None value?
315309 write_tsconfig (
@@ -326,6 +320,12 @@ def ts_project(
326320 # From here, tsconfig becomes a file, the same as if the
327321 # user supplied a tsconfig.json InputArtifact
328322 tsconfig = "tsconfig_%s.json" % name
323+ elif srcs == None :
324+ # Default sources based on macro attributes
325+ srcs = _default_srcs (
326+ allow_js = allow_js ,
327+ resolve_json_module = resolve_json_module ,
328+ )
329329
330330 typings_out_dir = declaration_dir if declaration_dir else out_dir
331331 tsbuildinfo_path = ts_build_info_file if ts_build_info_file else name + ".tsbuildinfo"
@@ -463,6 +463,20 @@ def ts_project(
463463 ** kwargs
464464 )
465465
466+ def _default_srcs (allow_js , resolve_json_module ):
467+ """Returns a list of srcs for ts_project when srcs is not provided."""
468+ include = ["**/*.ts" , "**/*.tsx" ]
469+ exclude = []
470+
471+ if allow_js == True :
472+ include .extend (["**/*.js" , "**/*.jsx" ])
473+
474+ if resolve_json_module == True :
475+ include .append ("**/*.json" )
476+ exclude .extend (["**/package.json" , "**/package-lock.json" , "**/tsconfig*.json" ])
477+
478+ return native .glob (include , exclude )
479+
466480def _invoke_custom_transpiler (type_str , transpiler , transpile_target_name , srcs , common_kwargs ):
467481 if type (transpiler ) == "function" or type (transpiler ) == "rule" :
468482 transpiler (
0 commit comments