@@ -138,17 +138,15 @@ sh_binary(
138138 "package" : name ,
139139 "path" : dep_path ,
140140 "link_packages" : {},
141- "link_dev_packages" : {},
142141 "deps" : transitive_deps ,
143142 }
144143
145144 # Collect first-party links in importers
146145 for link_package , import_path in package_to_importer .items ():
147146 importer = importers [import_path ]
148147 prod_deps = importer .get ("deps" , {})
149- all_deps = importer .get ("all_deps" , {})
150- for dep_package , dep_version in all_deps .items ():
151- deps_type = "link_packages" if dep_package in prod_deps else "link_dev_packages"
148+ for dep_package , dep_version in importer .get ("all_deps" , {}).items ():
149+ is_dev = dep_package not in prod_deps
152150 if dep_version .startswith ("file:" ):
153151 dep_key = "{}+{}" .format (dep_package , dep_version )
154152 if not dep_key in fp_links .keys ():
@@ -163,13 +161,13 @@ sh_binary(
163161
164162 msg = "Expected to file: referenced package {} in first-party links {}" .format (dep_key , fp_links .keys ())
165163 fail (msg )
166- fp_links [dep_key ][deps_type ][link_package ] = True
164+ fp_links [dep_key ]["link_packages" ][link_package ] = is_dev
167165 elif dep_version .startswith ("link:" ):
168166 dep_link = dep_version [len ("link:" ):]
169167 dep_path = helpers .link_package (root_package , dep_link )
170168 dep_key = "{}+{}" .format (dep_package , dep_path )
171169 if fp_links .get (dep_key , False ):
172- fp_links [dep_key ][deps_type ][link_package ] = True
170+ fp_links [dep_key ]["link_packages" ][link_package ] = is_dev
173171 else :
174172 transitive_deps = {}
175173 raw_deps = {}
@@ -193,10 +191,9 @@ sh_binary(
193191 "package" : dep_package ,
194192 "path" : dep_path ,
195193 "link_packages" : {},
196- "link_dev_packages" : {},
197194 "deps" : transitive_deps ,
198195 }
199- fp_links [dep_key ][deps_type ][link_package ] = True
196+ fp_links [dep_key ]["link_packages" ][link_package ] = is_dev
200197
201198 npm_link_packages_const = """_IMPORTER_PACKAGES = {pkgs}""" .format (
202199 pkgs = str (package_to_importer .keys ()),
@@ -382,20 +379,15 @@ def npm_link_all_packages(name = "node_modules", imported_links = [], prod = Tru
382379 # Add first-party packages to npm_link_targets before generating the function
383380 for fp_link in fp_links .values ():
384381 fp_package = fp_link .get ("package" )
385- for link_type in ["link_packages" , "link_dev_packages" ]:
386- fp_link_packages = fp_link .get (link_type , {}).keys ()
387- if len (fp_link_packages ) > 0 :
388- # Add first-party package links to npm_link_targets for each package that uses it
389- for fp_link_package in fp_link_packages :
390- if fp_link_package not in links_targets_bzl :
391- links_targets_bzl [fp_link_package ] = {"prod" : [], "dev" : []}
392-
393- fp_append_stmt = """link_targets.append(":{{}}/{pkg}".format(name))""" .format (pkg = fp_package )
394-
395- if link_type == "link_dev_packages" :
396- links_targets_bzl [fp_link_package ]["dev" ].append (" " + fp_append_stmt )
397- else :
398- links_targets_bzl [fp_link_package ]["prod" ].append (" " + fp_append_stmt )
382+
383+ # Add first-party package links to npm_link_targets for each package that uses it
384+ for fp_link_package , is_dev in fp_link .get ("link_packages" , {}).items ():
385+ if fp_link_package not in links_targets_bzl :
386+ links_targets_bzl [fp_link_package ] = {"prod" : [], "dev" : []}
387+
388+ fp_append_stmt = """link_targets.append(":{{}}/{pkg}".format(name))""" .format (pkg = fp_package )
389+
390+ links_targets_bzl [fp_link_package ]["dev" if is_dev else "prod" ].append (" " + fp_append_stmt )
399391
400392 # Generate the npm_link_targets function body
401393 first_link = True
@@ -434,18 +426,11 @@ def npm_link_all_packages(name = "node_modules", imported_links = [], prod = Tru
434426 if len (package_visibility ) == 0 :
435427 package_visibility = ["//visibility:public" ]
436428
437- # Collect all link packages from both prod and dev to avoid duplication
438- all_fp_link_packages = {}
439- for link_type in ["link_packages" , "link_dev_packages" ]:
440- fp_link_packages = fp_link .get (link_type , {}).keys ()
441- for pkg in fp_link_packages :
442- all_fp_link_packages [pkg ] = True
443-
444429 # Generate a single _FP_DIRECT_TMPL block with all link packages
445- if len (all_fp_link_packages ) > 0 :
430+ if len (fp_link [ "link_packages" ] ) > 0 :
446431 link_factories_bzl .append (_FP_DIRECT_TMPL .format (
447432 i = i ,
448- link_packages = list (all_fp_link_packages .keys ()),
433+ link_packages = list (fp_link [ "link_packages" ] .keys ()),
449434 link_visibility = package_visibility ,
450435 pkg = fp_package ,
451436 package_directory_output_group = utils .package_directory_output_group ,
@@ -454,7 +439,7 @@ def npm_link_all_packages(name = "node_modules", imported_links = [], prod = Tru
454439 package_store_root = utils .package_store_root ,
455440 ))
456441
457- for link_package in all_fp_link_packages .keys ():
442+ for link_package in fp_link [ "link_packages" ] .keys ():
458443 if link_package not in links_pkg_bzl :
459444 links_pkg_bzl [link_package ] = []
460445 links_pkg_bzl [link_package ].append (""" _fp_link_{i}(name)""" .format (i = i ))
0 commit comments