Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: install should use npm to check registry #283

Merged
merged 1 commit into from
Jun 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import {CLIError} from '@oclif/errors'
import cli from 'cli-ux'
import * as fs from 'fs'
import * as fse from 'fs-extra'
import HTTP from 'http-call'
import loadJSON from 'load-json-file'
import * as path from 'path'
import * as semver from 'semver'
import {exec} from 'child_process'

import {uniq, uniqWith} from './util'
import Yarn from './yarn'
Expand Down Expand Up @@ -240,20 +240,22 @@ export default class Plugins {
}

private async npmHasPackage(name: string): Promise<boolean> {
try {
const http: typeof HTTP = require('http-call').HTTP
const url = `${this.npmRegistry}/${name.replace('/', '%2f')}`
await http.get(url)
return true
} catch (error) {
this.debug(error)

if (error.statusCode === 404) {
return false
}

throw error
}
return new Promise((resolve, reject) => {
exec(`npm show ${name} dist-tags`, {
encoding: 'utf-8',
maxBuffer: 2048 * 2048,
}, error => {
if (error) {
try {
return resolve(false)
} catch {
reject(new Error(`Could not run npm show for ${name}`))
}
} else {
return resolve(true)
}
})
})
}

private async savePJSON(pjson: Config.PJSON.User) {
Expand Down
5 changes: 1 addition & 4 deletions test/commands/plugins/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,8 @@ describe('command', () => {
.it('installs and uninstalls jdxcode/oclif-debug')

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