codev-code 1.18.23-2 → 1.18.23-3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/codev.exe CHANGED
@@ -2,6 +2,8 @@ echo "Error: codev-code's postinstall script was not run." >&2
2
2
  echo "" >&2
3
3
  echo "This occurs when using --ignore-scripts during installation, or when using a" >&2
4
4
  echo "package manager like pnpm that does not run postinstall scripts by default." >&2
5
+ echo "npm 12 and later block install scripts on global installs unless allowed:" >&2
6
+ echo " npm install -g codev-code --allow-scripts=codev-code" >&2
5
7
  echo "" >&2
6
8
  echo "To fix this, run the postinstall script manually:" >&2
7
9
  echo " cd node_modules/codev-code && node postinstall.mjs" >&2
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "scripts": {
8
8
  "postinstall": "node ./postinstall.mjs"
9
9
  },
10
- "version": "1.18.23-2",
10
+ "version": "1.18.23-3",
11
11
  "license": "MIT",
12
12
  "os": [
13
13
  "darwin",
@@ -19,17 +19,17 @@
19
19
  "x64"
20
20
  ],
21
21
  "optionalDependencies": {
22
- "codev-code-darwin-arm64": "1.18.23-2",
23
- "codev-code-darwin-x64-baseline": "1.18.23-2",
24
- "codev-code-windows-x64": "1.18.23-2",
25
- "codev-code-linux-arm64": "1.18.23-2",
26
- "codev-code-windows-x64-baseline": "1.18.23-2",
27
- "codev-code-linux-x64-musl": "1.18.23-2",
28
- "codev-code-linux-x64-baseline": "1.18.23-2",
29
- "codev-code-linux-x64": "1.18.23-2",
30
- "codev-code-darwin-x64": "1.18.23-2",
31
- "codev-code-windows-arm64": "1.18.23-2",
32
- "codev-code-linux-x64-baseline-musl": "1.18.23-2",
33
- "codev-code-linux-arm64-musl": "1.18.23-2"
22
+ "codev-code-darwin-arm64": "1.18.23-3",
23
+ "codev-code-darwin-x64-baseline": "1.18.23-3",
24
+ "codev-code-windows-x64": "1.18.23-3",
25
+ "codev-code-linux-arm64": "1.18.23-3",
26
+ "codev-code-windows-x64-baseline": "1.18.23-3",
27
+ "codev-code-linux-x64-musl": "1.18.23-3",
28
+ "codev-code-linux-x64-baseline": "1.18.23-3",
29
+ "codev-code-linux-x64": "1.18.23-3",
30
+ "codev-code-darwin-x64": "1.18.23-3",
31
+ "codev-code-windows-arm64": "1.18.23-3",
32
+ "codev-code-linux-x64-baseline-musl": "1.18.23-3",
33
+ "codev-code-linux-arm64-musl": "1.18.23-3"
34
34
  }
35
35
  }
package/postinstall.mjs CHANGED
@@ -125,23 +125,52 @@ function resolveBinary(name) {
125
125
  return binaryPath
126
126
  }
127
127
 
128
- function installPackage(name) {
128
+ // Fork: records why each step failed in `failures` so the final error says
129
+ // what actually went wrong (the package was never installed, npm could not
130
+ // start, the binary would not run) instead of only naming packages to retry.
131
+ function installPackage(name, failures) {
129
132
  const version = packageJson.optionalDependencies?.[name]
130
- if (!version) return
133
+ if (!version) {
134
+ failures.push(`${name}: not pinned in optionalDependencies, nothing to fetch`)
135
+ return
136
+ }
131
137
 
132
138
  const temp = fs.mkdtempSync(path.join(os.tmpdir(), "codev-install-"))
133
139
  try {
134
- const result = childProcess.spawnSync(
135
- "npm",
136
- ["install", "--ignore-scripts", "--no-save", "--loglevel=error", "--prefix", temp, `${name}@${version}`],
137
- { stdio: "inherit", windowsHide: true },
138
- )
139
- if (result.status !== 0) return
140
+ const args = [
141
+ "install",
142
+ "--ignore-scripts",
143
+ "--no-save",
144
+ "--loglevel=error",
145
+ "--prefix",
146
+ temp,
147
+ `${name}@${version}`,
148
+ ]
149
+ // Fork: `npm` is `npm.cmd` on Windows, and Node refuses to spawn .cmd
150
+ // files without a shell (EINVAL since 18.20.2/20.12.2, CVE-2024-27980),
151
+ // so this fallback silently never ran there. Go through cmd.exe as the
152
+ // Node docs recommend; Node still quotes each argument, so a temp path
153
+ // with spaces survives.
154
+ const result =
155
+ platform === "windows"
156
+ ? childProcess.spawnSync("cmd.exe", ["/d", "/s", "/c", "npm", ...args], { stdio: "inherit", windowsHide: true })
157
+ : childProcess.spawnSync("npm", args, { stdio: "inherit", windowsHide: true })
158
+ if (result.error) {
159
+ failures.push(`${name}: could not start npm to fetch it (${result.error.message})`)
160
+ return
161
+ }
162
+ if (result.status !== 0) {
163
+ failures.push(`${name}: npm install ${name}@${version} exited with ${result.status ?? `signal ${result.signal}`}`)
164
+ return
165
+ }
140
166
  const packageDir = path.join(temp, "node_modules", name)
141
167
  copyBinary(path.join(packageDir, "bin", sourceBinary), targetBinary)
142
168
  // Before the finally deletes temp — the bundled rg lives in the same package.
143
169
  copyRipgrep(packageDir)
144
170
  return true
171
+ } catch (error) {
172
+ failures.push(`${name}: fetched, but ${firstLine(error.message)}`)
173
+ return
145
174
  } finally {
146
175
  fs.rmSync(temp, { recursive: true, force: true })
147
176
  }
@@ -176,33 +205,56 @@ function copyBinary(source, target) {
176
205
  fs.chmodSync(target, 0o755)
177
206
  }
178
207
 
208
+ // Fork: returns null when the binary runs, else a one-line reason. stderr is
209
+ // captured (not ignored) because a binary that a security policy or
210
+ // antivirus refuses to launch, or one missing a DLL, says so there and
211
+ // nowhere else.
179
212
  function verifyBinary() {
180
213
  const result = childProcess.spawnSync(targetBinary, ["--version"], {
181
214
  encoding: "utf8",
182
- stdio: "ignore",
215
+ stdio: ["ignore", "ignore", "pipe"],
183
216
  windowsHide: true,
184
217
  })
185
- return result.status === 0
218
+ if (result.error) return `${targetBinary} could not be started (${result.error.message})`
219
+ if (result.status === 0) return null
220
+ const stderr = (result.stderr || "").trim()
221
+ const exit = result.status === null ? `was killed by signal ${result.signal}` : `exited with code ${result.status}`
222
+ return `${targetBinary} --version ${exit}${stderr ? `: ${firstLine(stderr)}` : ""}`
223
+ }
224
+
225
+ function firstLine(text) {
226
+ return String(text).split(/\r?\n/, 1)[0].slice(0, 300)
186
227
  }
187
228
 
188
229
  function main() {
230
+ const failures = []
189
231
  for (const name of packageNames()) {
232
+ let binary
190
233
  try {
191
- const binary = resolveBinary(name)
234
+ binary = resolveBinary(name)
192
235
  copyBinary(binary, targetBinary)
193
- if (verifyBinary()) {
194
- copyRipgrep(path.dirname(path.dirname(binary)))
195
- return
236
+ } catch (error) {
237
+ failures.push(`${name}: not installed by your package manager (${firstLine(error.message)})`)
238
+ // Fetch it ourselves; the fallback verifies what it copied.
239
+ if (installPackage(name, failures)) {
240
+ const problem = verifyBinary()
241
+ if (!problem) return
242
+ failures.push(`${name}: fetched, but ${problem}`)
196
243
  }
197
- } catch {
198
- if (installPackage(name) && verifyBinary()) return
244
+ continue
245
+ }
246
+ const problem = verifyBinary()
247
+ if (!problem) {
248
+ copyRipgrep(path.dirname(path.dirname(binary)))
249
+ return
199
250
  }
251
+ failures.push(`${name}: installed, but ${problem}`)
200
252
  }
201
253
 
202
254
  throw new Error(
203
255
  `It seems your package manager failed to install the right codev CLI package. Try manually installing ${packageNames()
204
256
  .map((name) => JSON.stringify(name))
205
- .join(" or ")}.`,
257
+ .join(" or ")}.\n\nWhat was tried:\n${failures.map((line) => ` - ${line}`).join("\n")}`,
206
258
  )
207
259
  }
208
260