Skip to content

Commit

Permalink
Add support for custom npm registry url
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jan 31, 2022
1 parent c9e6479 commit e1dca0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion bin-src/lib/checkForUpdates.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import execa from 'execa';
import semver from 'semver';
import yon from 'yarn-or-npm';
import { Context } from '../types';
Expand All @@ -18,7 +19,10 @@ export default async function checkForUpdates(ctx: Context) {

let latestVersion: string;
try {
const pkgUrl = `https://registry.npmjs.org/${ctx.pkg.name}`;
const registryUrl = await execa('npm', ['config', 'get', 'registry'])
.then(({ stdout }) => stdout.trim())
.catch(() => 'https://registry.npmjs.org/');
const pkgUrl = `${registryUrl}${ctx.pkg.name}`;
// If not fetched within 5 seconds, nevermind.
const res = await withTimeout(ctx.http.fetch(pkgUrl), 5000);
const { 'dist-tags': distTags = {} } = (await res.json()) as any;
Expand Down
3 changes: 2 additions & 1 deletion bin-src/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,10 @@ describe('runAll', () => {
ctx.http.fetch.mockReturnValueOnce({
json: () => Promise.resolve({ 'dist-tags': { latest: '5.0.0' } }),
} as any);
execa.mockResolvedValue({ stdout: 'https://registry.example.org/' } as any);
await runAll(ctx);
expect(ctx.exitCode).toBe(1);
expect(ctx.http.fetch).toHaveBeenCalledWith('https://registry.npmjs.org/chromatic');
expect(ctx.http.fetch).toHaveBeenCalledWith('https://registry.example.org/chromatic');
expect(ctx.testLogger.warnings[0]).toMatch('Using outdated package');
});

Expand Down

0 comments on commit e1dca0e

Please sign in to comment.