Skip to content

Fix TYPESPEC_NPM_REGISTRY forwarding during install - #11694

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

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

Conversation

@vivekjm

@vivekjm Vivek JM (vivekjm) commented Aug 15, 2026

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
  • treat empty and whitespace-only TypeSpec overrides as unset

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 — 6 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 thread packages/compiler/src/package-manger/npm-registry.ts Outdated
Comment thread packages/compiler/src/package-manger/npm-registry.ts Outdated
Copilot AI review requested due to automatic review settings August 16, 2026 06:50

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

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

Suppressed comments (1)

packages/compiler/src/package-manger/npm-registry.ts:112

  • This reads process.env[\"TYPESPEC_NPM_REGISTRY\"] (trimmed) in the guard, and then reads process.env again indirectly via getNpmRegistry() when setting npm_config_registry. To keep behavior consistent and easier to reason about, compute the effective registry once (e.g., a single const registry = ...) and use that value for both the guard and the assignment. This also avoids any chance of inconsistency if process.env were to change between the two reads.
export function getNpmRegistryEnvironment(): NodeJS.ProcessEnv {
  const environment = { ...process.env };
  if (!process.env["TYPESPEC_NPM_REGISTRY"]?.trim()) {
    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;

@iscai-msft

Copy link
Copy Markdown
Member

thank you so much for your contribution Vivek JM (@vivekjm), Timothee Guerin (@timotheeguerin) can you take a look at this when you're back from vacation? Thanks!

@pkg-pr-new

pkg-pr-new Bot commented Aug 18, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11694

commit: bd08169

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/compiler
Show changes

@typespec/compiler - fix ✏️

Forward TYPESPEC_NPM_REGISTRY to the npm process launched by tsp install.

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

3 participants