MCPcopy Create free account
hub / github.com/anomalyco/opencode / installPackage

Function installPackage

packages/opencode/script/postinstall.mjs:126–144  ·  view source on GitHub ↗
(name)

Source from the content-addressed store, hash-verified

124}
125
126function installPackage(name) {
127 const version = packageJson.optionalDependencies?.[name]
128 if (!version) return
129
130 const temp = fs.mkdtempSync(path.join(os.tmpdir(), "opencode-install-"))
131 try {
132 const result = childProcess.spawnSync(
133 "npm",
134 ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
135 { stdio: "inherit", windowsHide: true },
136 )
137 if (result.status !== 0) return
138 const packageDir = path.join(temp, "node_modules", name)
139 copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
140 return true
141 } finally {
142 fs.rmSync(temp, { recursive: true, force: true })
143 }
144}
145
146function copyBinary(source, target) {
147 if (!fs.existsSync(source)) throw new Error(`Binary not found at ${source}`)

Callers 1

mainFunction · 0.85

Calls 1

copyBinaryFunction · 0.85

Tested by

no test coverage detected