1- _node_filetype = [ ".js " , ".node" ]
1+ load ( "//node:internal/providers.bzl " , "NodeModuleInfo" )
22
3+ _node_filetype = [".js" , ".node" ]
34
45def _relname (ctx , root_file , file ):
56 """Get a path string relative to the root_file (usually the
@@ -31,7 +32,7 @@ def _get_package_dependencies(module_deps):
3132 """
3233 dependencies = {}
3334 for dep in module_deps :
34- module = dep . node_module
35+ module = dep [ NodeModuleInfo ]
3536 dependencies [module .name ] = module .version
3637 return struct (** dependencies )
3738
@@ -50,7 +51,7 @@ def _get_module_name(ctx):
5051
5152
5253def _create_package_json (ctx , name , files , executables ):
53- output_file = ctx .new_file ("%s/package.json" % name )
54+ output_file = ctx .actions . declare_file ("%s/package.json" % name )
5455
5556 json = {
5657 "name" : name ,
@@ -77,7 +78,7 @@ def _create_package_json(ctx, name, files, executables):
7778
7879 content = struct (** json )
7980
80- ctx .file_action (
81+ ctx .actions . write (
8182 output = output_file ,
8283 content = content .to_json (),
8384 )
@@ -86,12 +87,14 @@ def _create_package_json(ctx, name, files, executables):
8687
8788
8889def _get_transitive_modules (deps , key ):
89- modules = depset ()
90+ allmodules = []
9091 for dep in deps :
91- module = dep .node_module
92- modules += [module ]
93- modules += getattr (module , key , [])
94- return modules
92+ module = dep [NodeModuleInfo ]
93+ allmodules .append (module )
94+ if hasattr (module , key ):
95+ allmodules += getattr (module , key ).to_list ()
96+ # allmodules += getattr(module, key, [])
97+ return depset (allmodules )
9598
9699
97100def _get_path_for_module_file (ctx , root_file , file , sourcemap ):
@@ -114,7 +117,7 @@ def _get_path_for_module_file(ctx, root_file, file, sourcemap):
114117
115118
116119def _copy_file (ctx , src , dst ):
117- ctx .action (
120+ ctx .actions . run_shell (
118121 mnemonic = "CopyFileToNodeModule" ,
119122 inputs = [src ],
120123 outputs = [dst ],
@@ -150,40 +153,33 @@ def _node_module_impl(ctx):
150153
151154 index_file = None
152155 if ctx .file .index :
153- dst = ctx .new_file ("%s/index.%s" % (name , ctx .file .index .extension ))
156+ dst = ctx .actions . declare_file ("%s/index.%s" % (name , ctx .file .index .extension ))
154157 outputs .append (_copy_file (ctx , ctx .file .index , dst ))
155158 index_file = dst
156159
157160 sourcemap = {}
158161 for src in files :
159- dst = ctx .new_file ("%s/%s" % (name , _get_path_for_module_file (ctx , root_file , src , sourcemap )))
162+ dst = ctx .actions . declare_file ("%s/%s" % (name , _get_path_for_module_file (ctx , root_file , src , sourcemap )))
160163 outputs .append (_copy_file (ctx , src , dst ))
161164
162165 for src in ctx .files .data :
163166 filename = src .short_path
164167 dst = ctx .actions .declare_file (filename , sibling = root_file )
165168 outputs .append (_copy_file (ctx , src , dst ))
166169
167- return struct (
170+ return [ DefaultInfo (
168171 files = depset (outputs + ctx .files .data ),
169- node_module = struct (
170- identifier = name .replace (ctx .attr .separator , '_' ),
171- name = name ,
172- version = ctx .attr .version ,
173- url = ctx .attr .url ,
174- sha1 = ctx .attr .sha1 ,
175- description = ctx .attr .description ,
176- executables = executables ,
177- package_json = package_json ,
178- root = root_file ,
179- sourcemap = sourcemap ,
180- index = index_file ,
181- files = depset (outputs ),
182- sources = depset (files ),
183- transitive_deps = _get_transitive_modules (ctx .attr .deps , "transitive_deps" ),
184- transitive_dev_deps = _get_transitive_modules (ctx .attr .dev_deps , "transitive_dev_deps" ),
185- ),
186- )
172+ ), NodeModuleInfo (
173+ identifier = name .replace (ctx .attr .separator , '_' ),
174+ name = name ,
175+ version = ctx .attr .version ,
176+ url = ctx .attr .url ,
177+ sha1 = ctx .attr .sha1 ,
178+ executables = executables ,
179+ package_json = package_json ,
180+ files = depset (outputs ),
181+ transitive_deps = _get_transitive_modules (ctx .attr .deps , "transitive_deps" ),
182+ )]
187183
188184
189185node_module = rule (
@@ -231,8 +227,8 @@ node_module = rule(
231227 # the module. If not present, one will be generated UNLESS an
232228 # index file is provided.
233229 "package_json" : attr .label (
234- allow_files = ["package.json" ],
235- single_file = True ,
230+ # allow_files = ["package.json"],
231+ allow_single_file = True ,
236232 ),
237233
238234 "data" : attr .label_list (
@@ -242,12 +238,12 @@ node_module = rule(
242238
243239 # Module dependencies.
244240 "deps" : attr .label_list (
245- providers = ["node_module" ],
241+ providers = [NodeModuleInfo ],
246242 ),
247243
248244 # Development-only module dependencies.
249245 "dev_deps" : attr .label_list (
250- providers = ["node_module" ],
246+ providers = [NodeModuleInfo ],
251247 ),
252248
253249 # 'Binary' scripts, to be named in the 'package_json.bin'
@@ -279,17 +275,16 @@ node_module = rule(
279275 # File that should be named as the package.json 'main'
280276 # attribute.
281277 "main" : attr .label (
282- allow_files = True ,
283278 mandatory = False ,
284- single_file = True ,
279+ allow_single_file = True ,
285280 ),
286281
287282 # File that should be copied to the module root as 'index.js'.
288283 # If the index file is present and no 'main' is provided, a
289284 # package.json file will not be generated.
290285 "index" : attr .label (
291- allow_files = _node_filetype ,
292- single_file = True ,
286+ # allow_files = _node_filetype,
287+ allow_single_file = True ,
293288 ),
294289 },
295290)
0 commit comments