@@ -315,6 +315,13 @@ data attribute.
315315 First argument must be an exectuable, CWD will be that of package directory.
316316 """ ,
317317 ),
318+ "postinstall_cmd" : attr .string_list (
319+ doc = """
320+ Command to run after installing `node_modules`.
321+
322+ First argument must be an exectuable, CWD will be that of package directory.
323+ """ ,
324+ ),
318325 "_inputs" : attr .label_list (
319326 default = [
320327 "//internal/npm_install:pre_process_package_json.js" ,
@@ -353,6 +360,19 @@ def _run_preinstall_cmd(repository_ctx, env):
353360 if result .return_code :
354361 fail ("preinstall command failed: %s (%s)" % (result .stdout , result .stderr ))
355362
363+ def _run_postinstall_cmd (repository_ctx , env ):
364+ if len (repository_ctx .attr .preinstall_cmd ) > 0 :
365+ repository_ctx .report_progress ("Running postinstall command" )
366+ result = repository_ctx .execute (
367+ repository_ctx .attr .postinstall_cmd ,
368+ timeout = repository_ctx .attr .timeout ,
369+ quiet = repository_ctx .attr .quiet ,
370+ environment = env ,
371+ working_directory = str (repository_ctx .path (_rerooted_workspace_package_json_dir (repository_ctx ))),
372+ )
373+ if result .return_code :
374+ fail ("postinstall command failed: %s (%s)" % (result .stdout , result .stderr ))
375+
356376def _apply_pre_install_patches (repository_ctx ):
357377 if len (repository_ctx .attr .pre_install_patches ) == 0 :
358378 return
@@ -721,6 +741,8 @@ cd /D "{root}" && "{npm}" {npm_args}
721741 if result .return_code :
722742 fail ("npm_install failed: %s (%s)" % (result .stdout , result .stderr ))
723743
744+ _run_postinstall_cmd (repository_ctx , env )
745+
724746 # removeNPMAbsolutePaths is run on node_modules after npm install as the package.json files
725747 # generated by npm are non-deterministic. They contain absolute install paths and other private
726748 # information fields starting with "_". removeNPMAbsolutePaths removes all fields starting with "_".
@@ -886,6 +908,8 @@ cd /D "{root}" && "{yarn}" {yarn_args}
886908 if result .return_code :
887909 fail ("yarn_install failed: %s (%s)" % (result .stdout , result .stderr ))
888910
911+ _run_postinstall_cmd (repository_ctx , env )
912+
889913 _symlink_node_modules (repository_ctx )
890914 _apply_post_install_patches (repository_ctx )
891915
0 commit comments