@@ -69,13 +69,23 @@ def _npm_extension_impl(module_ctx):
6969 # Process npm_translate_lock and npm_import tags
7070 for mod in module_ctx .modules :
7171 for attr in mod .tags .npm_translate_lock :
72- _npm_translate_lock_bzlmod (attr , exclude_package_contents_config , replace_packages )
72+ state = npm_translate_lock_state .new (attr .name , module_ctx , attr )
73+
74+ importers , packages = translate_to_transitive_closure (
75+ state .importers (),
76+ state .packages (),
77+ attr .prod ,
78+ attr .dev ,
79+ attr .no_optional ,
80+ )
81+
82+ _npm_translate_lock_bzlmod (attr , state , importers , packages , exclude_package_contents_config , replace_packages )
7383
7484 # We cannot read the pnpm_lock file before it has been bootstrapped.
7585 # See comment in e2e/update_pnpm_lock_with_import/test.sh.
7686 if attr .pnpm_lock :
7787 module_ctx .watch (attr .pnpm_lock )
78- _npm_lock_imports_bzlmod (module_ctx , attr , exclude_package_contents_config , replace_packages )
88+ _npm_lock_imports_bzlmod (module_ctx , attr , state , importers , packages , exclude_package_contents_config , replace_packages )
7989
8090 for i in mod .tags .npm_import :
8191 _npm_import_bzlmod (i )
@@ -108,7 +118,7 @@ def _build_exclude_package_contents_config(module_ctx):
108118
109119 return exclusions
110120
111- def _npm_translate_lock_bzlmod (attr , exclude_package_contents_config , replace_packages ):
121+ def _npm_translate_lock_bzlmod (attr , state , importers , packages , exclude_package_contents_config , replace_packages ):
112122 # TODO(3.0): remove this warning when replace_packages attribute is removed
113123 if attr .replace_packages :
114124 # buildifier: disable=print
@@ -132,6 +142,10 @@ The 'replace_packages' attribute will be removed in rules_js version 3.0.
132142 fail ("Package replacement conflict: {} specified in both replace_packages attribute and npm_replace_package tag" .format (package ))
133143 replace_packages [package ] = replacement
134144
145+ # TODO(zbarsky): Use these
146+ # buildifier: disable=unused-variable
147+ _ = state , importers , packages
148+
135149 npm_translate_lock_rule (
136150 name = attr .name ,
137151 bins = attr .bins ,
@@ -165,17 +179,7 @@ The 'replace_packages' attribute will be removed in rules_js version 3.0.
165179 additional_file_contents = attr .additional_file_contents ,
166180 )
167181
168- def _npm_lock_imports_bzlmod (module_ctx , attr , exclude_package_contents_config , replace_packages ):
169- state = npm_translate_lock_state .new (attr .name , module_ctx , attr )
170-
171- importers , packages = translate_to_transitive_closure (
172- state .importers (),
173- state .packages (),
174- attr .prod ,
175- attr .dev ,
176- attr .no_optional ,
177- )
178-
182+ def _npm_lock_imports_bzlmod (module_ctx , attr , state , importers , packages , exclude_package_contents_config , replace_packages ):
179183 registries = {}
180184 npm_auth = {}
181185 if attr .npmrc :
0 commit comments