|
17 | 17 |
|
18 | 18 | const fs = require('fs'); |
19 | 19 | const path = require('path'); |
20 | | -const { execSync } = require('child_process'); |
| 20 | +const { execSync, execFileSync } = require('child_process'); |
21 | 21 | const { parseArgs } = require('util'); |
22 | 22 |
|
23 | 23 | // ANSI color codes |
@@ -219,12 +219,17 @@ function isPrivatePackage(packageJsonPath) { |
219 | 219 | * @returns {boolean} True if the package version is already published |
220 | 220 | */ |
221 | 221 | function isPublishedOnNpm(packageName, version, registry) { |
222 | | - const registryArg = registry ? ` --registry ${registry}` : ''; |
| 222 | + // Shell-free npm invocation (node + its CLI, values as argv) so a caller-controlled |
| 223 | + // registry/package/version can't inject; npm's Windows .cmd shim needs a shell otherwise. |
| 224 | + const npmCli = path.join(path.dirname(process.execPath), 'node_modules', 'npm', 'bin', 'npm-cli.js'); |
| 225 | + const args = [npmCli, 'view', `${packageName}@${version}`, 'version']; |
| 226 | + if (registry) { |
| 227 | + args.push('--registry', registry); |
| 228 | + } |
223 | 229 | try { |
224 | | - // Use npm view to check if the specific version exists |
225 | | - execSync(`npm view ${packageName}@${version} version${registryArg}`, { |
| 230 | + execFileSync(process.execPath, args, { |
226 | 231 | encoding: 'utf8', |
227 | | - stdio: ['pipe', 'pipe', 'pipe'] |
| 232 | + stdio: ['pipe', 'pipe', 'pipe'], |
228 | 233 | }); |
229 | 234 | return true; |
230 | 235 | } catch (error) { |
|
0 commit comments