-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: registry feature and change shortcuts
<!-- 👋 Hi, thanks for sending a PR to azdo-npm-auth! 💖. Please fill out all fields below and make sure each item is true and [x] checked. Otherwise we may not be able to review your PR. --> ## PR Checklist - [ ] Addresses an existing open issue: fixes #000 - [ ] That issue was marked as [`status: accepting prs`](https://github.com/johnnyreilly/azdo-npm-auth/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/johnnyreilly/azdo-npm-auth/blob/main/.github/CONTRIBUTING.md) were taken ## Overview <!-- Description of what is changed and how the code change does that. --> This PR adds the `--registry` parameter / feature and changes the short alias for some other parameters.
- Loading branch information
1 parent
8042232
commit b348db5
Showing
13 changed files
with
177 additions
and
82 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
export * from "./createPat.js"; | ||
export * from "./createUserNpmrc.js"; | ||
export * from "./makeParsedProjectNpmrc.js"; | ||
export * from "./parseProjectNpmrc.js"; | ||
export * from "./projectNpmrcMake.js"; | ||
export * from "./projectNpmrcParse.js"; | ||
export * from "./projectNpmrcRegistry.js"; | ||
export * from "./types.js"; | ||
export * from "./writeNpmrc.js"; |
This file contains 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 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 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 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 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,27 @@ | ||
import { describe, expect, it } from "vitest"; | ||
|
||
import { projectNpmrcRegistry } from "./projectNpmrcRegistry.js"; | ||
|
||
describe("projectNpmrcRegistry", () => { | ||
it("outputs the expected structure on successful parse", () => { | ||
const result = projectNpmrcRegistry({ | ||
registry: | ||
"https://pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/", | ||
}); | ||
expect(result).toEqual({ | ||
organization: "johnnyreilly", | ||
urlWithoutRegistryAtEnd: | ||
"//pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/", | ||
urlWithoutRegistryAtStart: | ||
"//pkgs.dev.azure.com/johnnyreilly/_packaging/npmrc-script-organization/npm/registry/", | ||
}); | ||
}); | ||
|
||
it("errors on invalid content", () => { | ||
expect(() => | ||
projectNpmrcRegistry({ | ||
registry: "stuff", | ||
}), | ||
).toThrowError("Unable to extract information"); | ||
}); | ||
}); |
This file contains 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,19 @@ | ||
import type { ParsedProjectNpmrc } from "./types.js"; | ||
|
||
import { makeFromRegistry } from "./projectNpmrcShared.js"; | ||
import { fallbackLogger, type Logger } from "./shared/cli/logger.js"; | ||
|
||
/** | ||
* Parse the registry parameter to acquire necessary info | ||
*/ | ||
export function projectNpmrcRegistry({ | ||
registry, | ||
logger = fallbackLogger, | ||
}: { | ||
registry: string; | ||
logger?: Logger; | ||
}): ParsedProjectNpmrc { | ||
logger.info(`Parsing from registry: ${registry}`); | ||
|
||
return makeFromRegistry({ registry, logger }); | ||
} |
This file contains 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,33 @@ | ||
import type { Logger } from "./shared/cli/logger.js"; | ||
|
||
export function makeFromRegistry({ | ||
registry, | ||
logger, | ||
}: { | ||
registry: string; | ||
logger: Logger; | ||
}) { | ||
if (!registry.startsWith("https:")) { | ||
throw new Error("Unable to extract information"); | ||
} | ||
const urlWithoutRegistryAtStart = registry.replace("https:", ""); | ||
const urlWithoutRegistryAtEnd = urlWithoutRegistryAtStart.replace( | ||
/registry\/$/, | ||
"", | ||
); | ||
// extract the organisation which we will use as the username | ||
// not sure why this is the case, but this is the behaviour | ||
// defined in ADO | ||
const organisation = urlWithoutRegistryAtEnd.split("/")[3]; | ||
|
||
logger.info(`Parsed: | ||
- organisation: ${organisation} | ||
- urlWithoutRegistryAtStart: ${urlWithoutRegistryAtStart} | ||
- urlWithoutRegistryAtEnd: ${urlWithoutRegistryAtEnd}`); | ||
|
||
return { | ||
urlWithoutRegistryAtStart, | ||
urlWithoutRegistryAtEnd, | ||
organization: organisation, | ||
}; | ||
} |
Oops, something went wrong.