MCPcopy Create free account
hub / github.com/Lisovate/fend / prepare_node_command

Function prepare_node_command

linux/src/runtime.rs:111–177  ·  view source on GitHub ↗
(
    command: &[String],
    workspace: &Path,
    tools_dir: &Path,
)

Source from the content-addressed store, hash-verified

109}
110
111fn prepare_node_command(
112 command: &[String],
113 workspace: &Path,
114 tools_dir: &Path,
115) -> Result<PreparedGuestCommand, String> {
116 let runtime = ensure_node_runtime(workspace, tools_dir)?;
117 let guest_bin = format!("{GUEST_TOOLS_ROOT}/{}/bin", runtime.dir_name);
118 let guest_root = format!("{GUEST_TOOLS_ROOT}/{}", runtime.dir_name);
119 let guest_node = format!("{guest_bin}/node");
120 let host_root = tools_dir.join(&runtime.dir_name);
121 let rewritten = match command[0].as_str() {
122 "node" => {
123 let mut args = vec![guest_node.clone()];
124 args.extend(command.iter().skip(1).cloned());
125 args
126 }
127 "npm" => {
128 ensure_host_runtime_script(
129 &host_root,
130 "lib/node_modules/npm/bin/npm-cli.js",
131 "npm",
132 &runtime.version,
133 )?;
134 let mut args = vec![
135 guest_node.clone(),
136 format!("{guest_root}/lib/node_modules/npm/bin/npm-cli.js"),
137 ];
138 args.extend(command.iter().skip(1).cloned());
139 args
140 }
141 "npx" => {
142 ensure_host_runtime_script(
143 &host_root,
144 "lib/node_modules/npm/bin/npx-cli.js",
145 "npx",
146 &runtime.version,
147 )?;
148 let mut args = vec![
149 guest_node.clone(),
150 format!("{guest_root}/lib/node_modules/npm/bin/npx-cli.js"),
151 ];
152 args.extend(command.iter().skip(1).cloned());
153 args
154 }
155 "pnpm" | "pnpx" | "yarn" => {
156 ensure_host_runtime_script(
157 &host_root,
158 "lib/node_modules/corepack/dist/corepack.js",
159 "corepack",
160 &runtime.version,
161 )?;
162 let mut args = vec![
163 guest_node,
164 format!("{guest_root}/lib/node_modules/corepack/dist/corepack.js"),
165 command[0].clone(),
166 ];
167 args.extend(command.iter().skip(1).cloned());
168 args

Callers 1

prepare_guest_commandFunction · 0.85

Calls 2

ensure_node_runtimeFunction · 0.85

Tested by

no test coverage detected