Skip to content

Commit 7350e73

Browse files
committed
fix: remove missing setup_js_workspace_action reference in npm_install
Fixes CI build failure by implementing a simplified npm_install rule that doesn't depend on the removed setup_js_workspace_action function. The npm_install rule now uses a direct shell script approach consistent with the simplified js_component implementation.
1 parent ff38ac7 commit 7350e73

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

js/defs.bzl

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -344,32 +344,46 @@ def _npm_install_impl(ctx):
344344
# Output node_modules directory
345345
node_modules = ctx.actions.declare_directory("node_modules")
346346

347-
# Prepare JavaScript workspace using File Operations Component
348-
work_dir = setup_js_workspace_action(
349-
ctx,
350-
sources = [], # No source files needed for npm install
351-
package_json = package_json,
352-
npm_deps = None, # Will be generated
347+
# Create a simple workspace for npm install
348+
build_script = ctx.actions.declare_file(ctx.attr.name + "_npm_install.sh")
349+
350+
script_lines = [
351+
"#!/bin/bash",
352+
"set -euo pipefail",
353+
"",
354+
"# Create temporary workspace",
355+
"WORK_DIR=$(mktemp -d)",
356+
"echo \"NPM install workspace: $WORK_DIR\"",
357+
"",
358+
"# Copy package.json to workspace",
359+
"cp \"{}\" \"$WORK_DIR/package.json\"".format(package_json.path),
360+
"",
361+
"# Change to workspace and run npm install",
362+
"cd \"$WORK_DIR\"",
363+
"\"$PWD/{}\" install".format(npm.path),
364+
"",
365+
"# Copy node_modules to output",
366+
"cp -r node_modules \"{}\"".format(node_modules.path),
367+
"",
368+
"echo \"NPM install complete\"",
369+
]
370+
371+
ctx.actions.write(
372+
output = build_script,
373+
content = "\n".join(script_lines),
374+
is_executable = True,
353375
)
354376

355-
# Run npm install in the prepared workspace
356-
npm_args = ctx.actions.args()
357-
npm_args.add("install")
358-
359377
ctx.actions.run(
360-
executable = npm,
361-
arguments = [npm_args],
362-
inputs = [work_dir],
378+
executable = build_script,
379+
inputs = [package_json],
363380
outputs = [node_modules],
381+
tools = [npm],
364382
mnemonic = "NPMInstall",
365383
progress_message = "Installing NPM dependencies for %s" % ctx.label,
366-
env = {
367-
"npm_config_cache": "/tmp/npm-cache-" + ctx.attr.name,
368-
},
369384
execution_requirements = {
370385
"local": "1", # NPM install requires network access
371386
},
372-
use_default_shell_env = True,
373387
)
374388

375389
return [
@@ -390,7 +404,6 @@ npm_install = rule(
390404
},
391405
toolchains = [
392406
"@rules_wasm_component//toolchains:jco_toolchain_type",
393-
"@rules_wasm_component//toolchains:file_ops_toolchain_type",
394407
],
395408
doc = """
396409
Installs NPM dependencies for JavaScript components.

0 commit comments

Comments
 (0)