Skip to content

Commit a2e8180

Browse files
authored
fix: install should use npm to check registry (#283)
Modify plugins.ts#hasPackage to use npm instead of https to check if a package exists on the registry. #282
1 parent 01139cd commit a2e8180

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

src/plugins.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {CLIError} from '@oclif/errors'
33
import cli from 'cli-ux'
44
import * as fs from 'fs'
55
import * as fse from 'fs-extra'
6-
import HTTP from 'http-call'
76
import loadJSON from 'load-json-file'
87
import * as path from 'path'
98
import * as semver from 'semver'
9+
import {exec} from 'child_process'
1010

1111
import {uniq, uniqWith} from './util'
1212
import Yarn from './yarn'
@@ -240,20 +240,22 @@ export default class Plugins {
240240
}
241241

242242
private async npmHasPackage(name: string): Promise<boolean> {
243-
try {
244-
const http: typeof HTTP = require('http-call').HTTP
245-
const url = `${this.npmRegistry}/${name.replace('/', '%2f')}`
246-
await http.get(url)
247-
return true
248-
} catch (error) {
249-
this.debug(error)
250-
251-
if (error.statusCode === 404) {
252-
return false
253-
}
254-
255-
throw error
256-
}
243+
return new Promise((resolve, reject) => {
244+
exec(`npm show ${name} dist-tags`, {
245+
encoding: 'utf-8',
246+
maxBuffer: 2048 * 2048,
247+
}, error => {
248+
if (error) {
249+
try {
250+
return resolve(false)
251+
} catch {
252+
reject(new Error(`Could not run npm show for ${name}`))
253+
}
254+
} else {
255+
return resolve(true)
256+
}
257+
})
258+
})
257259
}
258260

259261
private async savePJSON(pjson: Config.PJSON.User) {

test/commands/plugins/index.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,8 @@ describe('command', () => {
5555
.it('installs and uninstalls jdxcode/oclif-debug')
5656

5757
test
58-
.nock('https://registry.npmjs.org', api => api
59-
.get('/@heroku-cli%2fplugin-stubbed')
60-
.reply(503, ''))
6158
.command(['plugins:install', 'stubbed'], {reset: true})
62-
.catch(/HTTP Error 503/)
59+
.catch(/1/)
6360
.stdout()
6461
.command(['plugins'], {reset: true})
6562
.do(output => expect(output.stdout).to.equal('no plugins installed\n'))

0 commit comments

Comments
 (0)