Skip to content

Commit 5ab084b

Browse files
committed
fix: establish hermetic environment for docs-site Node.js subprocesses
Remove use_default_shell_env and set up controlled hermetic environment that includes node binary in PATH for npm subprocesses (like Sharp package post-install scripts). This eliminates system environment contamination while ensuring npm dependencies can find the hermetic node binary. Key changes: - Remove use_default_shell_env = True - Set up minimal npm_env with hermetic PATH - Include node binary directory for subprocess access - Add npm cache configuration for isolation This resolves the "sh: node: command not found" errors in docs-site builds while maintaining hermetic isolation principles.
1 parent 3db4824 commit 5ab084b

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

docs-site/docs_build.bzl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ def main():
7070
# Resolve npm binary to absolute path before changing directory
7171
npm_abs_path = os.path.abspath(npm_binary)
7272
73+
# Set up PATH to include hermetic node binary for npm subprocesses
74+
node_bin_dir = os.path.dirname(npm_abs_path)
75+
current_path = os.environ.get("PATH", "")
76+
hermetic_path = f"{node_bin_dir}:{current_path}" if current_path else node_bin_dir
77+
78+
# Set up minimal hermetic environment for npm
79+
npm_env = {
80+
"PATH": hermetic_path,
81+
"NODE_PATH": "", # Clear any existing NODE_PATH
82+
"npm_config_cache": os.path.join(work_dir, ".npm-cache"),
83+
"npm_config_progress": "false",
84+
}
85+
7386
# Change to workspace for npm operations
7487
original_cwd = os.getcwd()
7588
os.chdir(work_dir)
@@ -81,7 +94,8 @@ def main():
8194
[npm_abs_path, "install", "--no-audit", "--no-fund"],
8295
capture_output=True,
8396
text=True,
84-
timeout=300 # 5 minute timeout
97+
timeout=300, # 5 minute timeout
98+
env=npm_env
8599
)
86100
87101
if result.returncode != 0:
@@ -96,7 +110,8 @@ def main():
96110
[npm_abs_path, "run", "build"],
97111
capture_output=True,
98112
text=True,
99-
timeout=300 # 5 minute timeout
113+
timeout=300, # 5 minute timeout
114+
env=npm_env
100115
)
101116
102117
if result.returncode != 0:
@@ -158,7 +173,6 @@ if __name__ == "__main__":
158173
execution_requirements = {
159174
"local": "1", # npm install needs network
160175
},
161-
use_default_shell_env = True,
162176
)
163177

164178
return [

0 commit comments

Comments
 (0)