From db9c411611b4da87a3154dc12bd2c09e7b169b5d Mon Sep 17 00:00:00 2001 From: mathuraditya724 Date: Mon, 23 Mar 2026 00:28:31 +0530 Subject: [PATCH 1/3] fix(connector): force npmjs registry for login and npm CLI ops --- cli/src/cli.ts | 4 ++-- cli/src/npm-client.ts | 19 +++++++++++++------ test/unit/cli/npm-client.spec.ts | 14 ++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) 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..0607ab2443 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/' + +export function createNpmEnv(overrides: Record = {}): Record { + return { + ...(process.env as Record), + ...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 { @@ -184,3 +186,15 @@ describe('extractUrls', () => { expect(extractUrls(npmOutput)).toEqual(['https://www.npmjs.com/login?next=/login/cli/abc123']) }) }) + +describe('createNpmEnv', () => { + it('enforces npmjs registry for all npm commands', () => { + const env = createNpmEnv() + expect(env.npm_config_registry).toBe(NPM_REGISTRY_URL) + }) + + it('does not allow overriding enforced registry', () => { + const env = createNpmEnv({ npm_config_registry: 'https://registry.npmmirror.com/' }) + expect(env.npm_config_registry).toBe(NPM_REGISTRY_URL) + }) +}) From a42ac0f054b1898dc70c84080e1ef3e1a4ba3c92 Mon Sep 17 00:00:00 2001 From: mathuraditya724 Date: Mon, 23 Mar 2026 00:58:14 +0530 Subject: [PATCH 2/3] fix(cli): remove unused createNpmEnv export --- cli/src/npm-client.ts | 2 +- test/unit/cli/npm-client.spec.ts | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/cli/src/npm-client.ts b/cli/src/npm-client.ts index 0607ab2443..23a1c4e201 100644 --- a/cli/src/npm-client.ts +++ b/cli/src/npm-client.ts @@ -12,7 +12,7 @@ import { logCommand, logSuccess, logError, logDebug } from './logger.ts' const execFileAsync = promisify(execFile) export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/' -export function createNpmEnv(overrides: Record = {}): Record { +function createNpmEnv(overrides: Record = {}): Record { return { ...(process.env as Record), ...overrides, diff --git a/test/unit/cli/npm-client.spec.ts b/test/unit/cli/npm-client.spec.ts index 54d5eb826a..5f6b576c03 100644 --- a/test/unit/cli/npm-client.spec.ts +++ b/test/unit/cli/npm-client.spec.ts @@ -5,8 +5,6 @@ import { validateScopeTeam, validatePackageName, extractUrls, - createNpmEnv, - NPM_REGISTRY_URL, } from '../../../cli/src/npm-client' describe('validateUsername', () => { @@ -186,15 +184,3 @@ describe('extractUrls', () => { expect(extractUrls(npmOutput)).toEqual(['https://www.npmjs.com/login?next=/login/cli/abc123']) }) }) - -describe('createNpmEnv', () => { - it('enforces npmjs registry for all npm commands', () => { - const env = createNpmEnv() - expect(env.npm_config_registry).toBe(NPM_REGISTRY_URL) - }) - - it('does not allow overriding enforced registry', () => { - const env = createNpmEnv({ npm_config_registry: 'https://registry.npmmirror.com/' }) - expect(env.npm_config_registry).toBe(NPM_REGISTRY_URL) - }) -}) From 34ae5edd2f7767254f4910092d6b9564007c8f8c Mon Sep 17 00:00:00 2001 From: "Willow (GHOST)" Date: Sun, 22 Mar 2026 14:21:28 -0700 Subject: [PATCH 3/3] chore: remove type cast --- cli/src/npm-client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/npm-client.ts b/cli/src/npm-client.ts index 23a1c4e201..8448413b52 100644 --- a/cli/src/npm-client.ts +++ b/cli/src/npm-client.ts @@ -14,7 +14,7 @@ export const NPM_REGISTRY_URL = 'https://registry.npmjs.org/' function createNpmEnv(overrides: Record = {}): Record { return { - ...(process.env as Record), + ...process.env, ...overrides, FORCE_COLOR: '0', npm_config_registry: NPM_REGISTRY_URL,