-
Notifications
You must be signed in to change notification settings - Fork 387
Set TYPESPEC_NPM_REGISTRY to devOps feed #11674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Chidozie Ononiwu (chidozieononiwu)
wants to merge
6
commits into
microsoft:main
Choose a base branch
from
chidozieononiwu:setTSPNpmConfig
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c77966b
Set TYPESPEC_NPM_REGISTRY to devOps feed
chidozieononiwu b7e10a2
Update logic to use authenticated npmrc path
chidozieononiwu 3c45dd1
Set NODE_USE_ENV_PROXY to 1
chidozieononiwu 28ad7f4
Update __snapshots__
chidozieononiwu 2a0cbf1
Re-Enable E2E tests
chidozieononiwu 17ba9cd
Use TYPESPEC_NPM_REGISTRY envar in build-packages.yml, and update tes…
chidozieononiwu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
packages/compiler/src/package-manger/npm-registry-config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| import { readFile } from "fs/promises"; | ||
| import { homedir } from "os"; | ||
| import { join } from "path"; | ||
| import type { NpmRegistryConfig } from "./npm-registry.js"; | ||
|
|
||
| interface NpmrcAuthFields { | ||
| auth?: string; | ||
| authToken?: string; | ||
| password?: string; | ||
| username?: string; | ||
| } | ||
|
|
||
| export async function loadNpmRegistryConfig(): Promise<NpmRegistryConfig> { | ||
| const npmrcPath = process.env["NPM_CONFIG_USERCONFIG"] ?? join(homedir(), ".npmrc"); | ||
| let content: string; | ||
| try { | ||
| content = await readFile(npmrcPath, "utf8"); | ||
| } catch (error) { | ||
| if ((error as NodeJS.ErrnoException).code === "ENOENT") { | ||
| return {}; | ||
| } | ||
| throw error; | ||
| } | ||
|
|
||
| const values = parseNpmrc(content); | ||
| const registry = values.get("registry"); | ||
| const authFields = new Map<string, NpmrcAuthFields>(); | ||
|
|
||
| for (const [key, value] of values) { | ||
| const separatorIndex = key.lastIndexOf(":"); | ||
| if (!key.startsWith("//") || separatorIndex === -1) { | ||
| continue; | ||
| } | ||
|
|
||
| const scope = key.slice(0, separatorIndex); | ||
| const field = key.slice(separatorIndex + 1); | ||
| const fields = authFields.get(scope) ?? {}; | ||
| switch (field) { | ||
| case "_auth": | ||
| fields.auth = value; | ||
| break; | ||
| case "_authToken": | ||
| fields.authToken = value; | ||
| break; | ||
| case "_password": | ||
| fields.password = value; | ||
| break; | ||
| case "username": | ||
| fields.username = value; | ||
| break; | ||
| default: | ||
| continue; | ||
| } | ||
| authFields.set(scope, fields); | ||
| } | ||
|
|
||
| return { | ||
| registry, | ||
| authentication: [...authFields].flatMap(([scope, fields]) => { | ||
| const authorization = createAuthorizationHeader(fields); | ||
| return authorization === undefined ? [] : [{ scope, authorization }]; | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| function parseNpmrc(content: string): Map<string, string> { | ||
| const values = new Map<string, string>(); | ||
| for (const line of content.split(/\r?\n/)) { | ||
| const trimmed = line.trim(); | ||
| if (trimmed.length === 0 || trimmed.startsWith("#") || trimmed.startsWith(";")) { | ||
| continue; | ||
| } | ||
|
|
||
| const separatorIndex = trimmed.indexOf("="); | ||
| if (separatorIndex === -1) { | ||
| continue; | ||
| } | ||
|
|
||
| const key = trimmed.slice(0, separatorIndex).trim(); | ||
| const value = trimmed | ||
| .slice(separatorIndex + 1) | ||
| .trim() | ||
| .replace(/\$\{([^}]+)\}/g, (_, name: string) => process.env[name] ?? ""); | ||
| values.set(key, value); | ||
| } | ||
| return values; | ||
| } | ||
|
|
||
| function createAuthorizationHeader(fields: NpmrcAuthFields): string | undefined { | ||
| if (fields.authToken !== undefined) { | ||
| return `Bearer ${fields.authToken}`; | ||
| } | ||
| if (fields.auth !== undefined) { | ||
| return `Basic ${fields.auth}`; | ||
| } | ||
| if (fields.username !== undefined && fields.password !== undefined) { | ||
| const password = Buffer.from(fields.password, "base64").toString("utf8"); | ||
| return `Basic ${Buffer.from(`${fields.username}:${password}`).toString("base64")}`; | ||
| } | ||
| return undefined; | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the compiler changes need to wait for some input from Timothee Guerin (@timotheeguerin)