Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions internal/npm_install/npm_install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,13 @@ data attribute.
First argument must be an exectuable, CWD will be that of package directory.
""",
),
"postinstall_cmd": attr.string_list(
doc = """
Command to run after installing `node_modules`.

First argument must be an exectuable, CWD will be that of package directory.
""",
),
"_inputs": attr.label_list(
default = [
"//internal/npm_install:pre_process_package_json.js",
Expand Down Expand Up @@ -353,6 +360,19 @@ def _run_preinstall_cmd(repository_ctx, env):
if result.return_code:
fail("preinstall command failed: %s (%s)" % (result.stdout, result.stderr))

def _run_postinstall_cmd(repository_ctx, env):
if len(repository_ctx.attr.preinstall_cmd) > 0:
repository_ctx.report_progress("Running postinstall command")
result = repository_ctx.execute(
repository_ctx.attr.postinstall_cmd,
timeout = repository_ctx.attr.timeout,
quiet = repository_ctx.attr.quiet,
environment = env,
working_directory = str(repository_ctx.path(_rerooted_workspace_package_json_dir(repository_ctx))),
)
if result.return_code:
fail("postinstall command failed: %s (%s)" % (result.stdout, result.stderr))

def _apply_pre_install_patches(repository_ctx):
if len(repository_ctx.attr.pre_install_patches) == 0:
return
Expand Down Expand Up @@ -721,6 +741,8 @@ cd /D "{root}" && "{npm}" {npm_args}
if result.return_code:
fail("npm_install failed: %s (%s)" % (result.stdout, result.stderr))

_run_postinstall_cmd(repository_ctx, env)

# removeNPMAbsolutePaths is run on node_modules after npm install as the package.json files
# generated by npm are non-deterministic. They contain absolute install paths and other private
# information fields starting with "_". removeNPMAbsolutePaths removes all fields starting with "_".
Expand Down Expand Up @@ -886,6 +908,8 @@ cd /D "{root}" && "{yarn}" {yarn_args}
if result.return_code:
fail("yarn_install failed: %s (%s)" % (result.stdout, result.stderr))

_run_postinstall_cmd(repository_ctx, env)

_symlink_node_modules(repository_ctx)
_apply_post_install_patches(repository_ctx)

Expand Down