diff --git a/cli/src/cli.ts b/cli/src/cli.ts index d648bff193..e122cec9f2 100644 --- a/cli/src/cli.ts +++ b/cli/src/cli.ts @@ -6,7 +6,7 @@ import * as p from '@clack/prompts' import { defineCommand, runMain } from 'citty' import { serve } from 'srvx' import { createConnectorApp, generateToken, CONNECTOR_VERSION } from './server.ts' -import { getNpmUser } from './npm-client.ts' +import { getNpmUser, NPM_REGISTRY_URL } from './npm-client.ts' import { initLogger, showToken, logInfo, logWarning, logError } from './logger.ts' const DEFAULT_PORT = 31415 @@ -15,7 +15,7 @@ const DEV_FRONTEND_URL = 'http://127.0.0.1:3000/' async function runNpmLogin(): Promise { return new Promise(resolve => { - const child = spawn('npm', ['login'], { + const child = spawn('npm', ['login', `--registry=${NPM_REGISTRY_URL}`], { stdio: 'inherit', shell: true, }) diff --git a/cli/src/npm-client.ts b/cli/src/npm-client.ts index a3f61a5c10..8448413b52 100644 --- a/cli/src/npm-client.ts +++ b/cli/src/npm-client.ts @@ -10,6 +10,16 @@ import { PackageNameSchema, UsernameSchema, OrgNameSchema, ScopeTeamSchema } fro import { logCommand, logSuccess, logError, logDebug } from './logger.ts' const execFileAsync = promisify(execFile) +export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/' + +function createNpmEnv(overrides: Record = {}): Record { + return { + ...process.env, + ...overrides, + FORCE_COLOR: '0', + npm_config_registry: NPM_REGISTRY_URL, + } +} /** * Validates an npm package name using the official npm validation package @@ -191,10 +201,7 @@ async function execNpmInteractive( let authUrlTimeout: ReturnType | null = null let authUrlTimedOut = false - const env: Record = { - ...(process.env as Record), - FORCE_COLOR: '0', - } + const env = createNpmEnv() // When openUrls is false, tell npm not to open the browser. // npm still prints the auth URL and polls doneUrl @@ -330,7 +337,7 @@ async function execNpm(args: string[], options: ExecNpmOptions = {}): Promise