Skip to content

Fix TYPESPEC_NPM_REGISTRY forwarding during install - #11694

Open
Vivek JM (vivekjm) wants to merge 1 commit into
microsoft:mainfrom
vivekjm:fix/forward-typespec-registry
Open

Fix TYPESPEC_NPM_REGISTRY forwarding during install#11694
Vivek JM (vivekjm) wants to merge 1 commit into
microsoft:mainfrom
vivekjm:fix/forward-typespec-registry

Conversation

@vivekjm

Copy link
Copy Markdown

Summary

  • forward TYPESPEC_NPM_REGISTRY to the npm process launched by tsp install
  • preserve an existing npm registry configuration when no TypeSpec override is provided
  • normalize case-insensitive npm registry environment keys before applying the override

Fixes #11688.

Root cause

TypeSpec already used TYPESPEC_NPM_REGISTRY when it fetched package-manager metadata and archives. The later npm install subprocess inherited that TypeSpec-specific variable, but npm reads npm_config_registry instead, so project dependencies still came from npm's default configuration.

Testing

  • pnpm setup:min
  • pnpm --filter @typespec/compiler exec vitest run test/package-manager/npm-registry.test.ts — 4 tests passed
  • pnpm --filter @typespec/compiler run build
  • pnpm exec prettier --check packages/compiler/src/install/install.ts packages/compiler/src/package-manger/npm-registry.ts packages/compiler/test/package-manager/npm-registry.test.ts .chronus/changes/forward-typespec-npm-registry-2026-08-15.md
  • pnpm --filter @typespec/compiler run lint
  • git diff --check

Local setup note: I initially invoked the compiler tests before building the generated manifest and internal workspace packages, which produced bootstrap-related missing-module errors. After running the documented pnpm setup:min step, the focused tests and all checks above passed.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Aug 15, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR forwards the TYPESPEC_NPM_REGISTRY override to the npm process spawned by tsp install, ensuring installs use the same registry as manifest resolution.

Changes:

  • Add getNpmRegistryEnvironment() to produce a child-process env with npm_config_registry set from TYPESPEC_NPM_REGISTRY.
  • Update installer to use the new environment builder when invoking the package manager.
  • Add unit tests covering forwarding behavior and preservation of existing npm registry env vars.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
packages/compiler/test/package-manager/npm-registry.test.ts Adds tests validating registry env forwarding and non-interference when no override is set.
packages/compiler/src/package-manger/npm-registry.ts Introduces getNpmRegistryEnvironment() to map TypeSpec registry override to npm’s env convention.
packages/compiler/src/install/install.ts Uses getNpmRegistryEnvironment() when spawning the package manager to apply the override.
.chronus/changes/forward-typespec-npm-registry-2026-08-15.md Adds changelog entry documenting the fix.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +97 to +112
export function getNpmRegistryEnvironment(): Record<string, string | undefined> {
const environment = { ...process.env };
if (process.env["TYPESPEC_NPM_REGISTRY"] === undefined) {
return environment;
}

// Environment variable names are case-insensitive on Windows. Remove any
// existing spelling so Node does not choose between duplicate keys.
for (const name of Object.keys(environment)) {
if (name.toLowerCase() === "npm_config_registry") {
delete environment[name];
}
}
environment["npm_config_registry"] = getNpmRegistry();
return environment;
}
Comment on lines +97 to +98
export function getNpmRegistryEnvironment(): Record<string, string | undefined> {
const environment = { ...process.env };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsp install doesn't respect TYPESPEC_NPM_REGISTRY variable

2 participants