diff --git a/cmd/info.js b/cmd/info.js index d425e61..3618625 100644 --- a/cmd/info.js +++ b/cmd/info.js @@ -18,10 +18,14 @@ exports.builder = (yargs) => describe: 'Format the results in a human readable format or as JSON', default: 'human', }, + api: { + describe: 'The API url', + default: 'https://api.npms.io/v2', + }, }); exports.handler = (argv) => { - got(`https://api.npms.io/package/${encodeURIComponent(argv.package)}`, { json: true }) + got(`${argv.api}/package/${encodeURIComponent(argv.package)}`, { json: true }) .then((res) => { if (argv.output === 'json') { console.log(JSON.stringify(res.body, null, 2)); diff --git a/cmd/open.js b/cmd/open.js index 2d6579b..52ff110 100644 --- a/cmd/open.js +++ b/cmd/open.js @@ -40,10 +40,14 @@ exports.builder = (yargs) => type: 'string', default: 'auto', }, + api: { + describe: 'The API url', + default: 'https://api.npms.io/v2', + }, }); exports.handler = (argv) => { - got(`https://api.npms.io/package/${encodeURIComponent(argv.package)}`, { json: true }) + got(`${argv.api}/package/${encodeURIComponent(argv.package)}`, { json: true }) .then((res) => getLink(argv, res)) .then((link) => opn(link, { wait: false })) .then(() => { process.exitCode = 0; }) diff --git a/cmd/search.js b/cmd/search.js index 4b4df3f..08461aa 100644 --- a/cmd/search.js +++ b/cmd/search.js @@ -35,10 +35,14 @@ exports.builder = (yargs) => describe: 'Format the results in a table or as JSON', default: 'table', }, + api: { + describe: 'The API url', + default: 'https://api.npms.io/v2', + }, }); exports.handler = (argv) => { - got('https://api.npms.io/search', { + got(`${argv.api}/search`, { json: true, query: JSON.parse(JSON.stringify({ q: argv.query.join(' '), diff --git a/test/util/exec.js b/test/util/exec.js index 55e0766..617965b 100644 --- a/test/util/exec.js +++ b/test/util/exec.js @@ -70,6 +70,10 @@ function waitForExit(timeout) { function exec(argv, options) { options = Object.assign({ printStderr: true, timeout: 1500 }, options); + // Force api url without version + argv.push('--api'); + argv.push('https://api.npms.io'); + // Clear the cli & yargs from the module cache delete require.cache[require.resolve('../../cli')]; delete require.cache[require.resolve('yargs')];