@pnpm/auth.commands 1100.0.14 → 1100.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/login.d.ts +1 -0
- package/lib/login.js +27 -2
- package/package.json +6 -6
package/lib/login.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const commandNames: string[];
|
|
|
6
6
|
export declare function help(): string;
|
|
7
7
|
export type LoginCommandOptions = Pick<Config, 'configDir' | 'dir' | 'fetchRetries' | 'fetchRetryFactor' | 'fetchRetryMaxtimeout' | 'fetchRetryMintimeout' | 'fetchTimeout' | 'authConfig'> & {
|
|
8
8
|
registry?: string;
|
|
9
|
+
scope?: string;
|
|
9
10
|
};
|
|
10
11
|
export declare function handler(opts: LoginCommandOptions): Promise<string>;
|
|
11
12
|
export interface LoginDate {
|
package/lib/login.js
CHANGED
|
@@ -13,7 +13,10 @@ import { renderHelp } from 'render-help';
|
|
|
13
13
|
import { writeIniFile } from 'write-ini-file';
|
|
14
14
|
import { getRegistryConfigKey, safeReadIniFile } from './shared.js';
|
|
15
15
|
export function rcOptionsTypes() {
|
|
16
|
-
return {
|
|
16
|
+
return {
|
|
17
|
+
registry: allTypes.registry,
|
|
18
|
+
scope: allTypes.scope,
|
|
19
|
+
};
|
|
17
20
|
}
|
|
18
21
|
export function cliOptionsTypes() {
|
|
19
22
|
return {
|
|
@@ -32,11 +35,15 @@ export function help() {
|
|
|
32
35
|
description: 'The registry to log in to',
|
|
33
36
|
name: '--registry <url>',
|
|
34
37
|
},
|
|
38
|
+
{
|
|
39
|
+
description: 'Associate an operation with a scope for a scoped registry. The scope-to-registry mapping is recorded so future installs in the same scope use the chosen registry.',
|
|
40
|
+
name: '--scope <scope>',
|
|
41
|
+
},
|
|
35
42
|
],
|
|
36
43
|
},
|
|
37
44
|
],
|
|
38
45
|
url: docsUrl('login'),
|
|
39
|
-
usages: ['pnpm login [--registry <url>]'],
|
|
46
|
+
usages: ['pnpm login [--registry <url>] [--scope <scope>]'],
|
|
40
47
|
});
|
|
41
48
|
}
|
|
42
49
|
export async function handler(opts) {
|
|
@@ -87,9 +94,27 @@ export async function login({ context = DEFAULT_CONTEXT, opts }) {
|
|
|
87
94
|
const settings = await safeReadIniFile(readIniFile, configPath);
|
|
88
95
|
const registryConfigKey = getRegistryConfigKey(registry);
|
|
89
96
|
settings[`${registryConfigKey}:_authToken`] = token;
|
|
97
|
+
// Persist the scope → registry mapping next to the auth token so subsequent
|
|
98
|
+
// installs for `@scope/*` packages route to this registry. `auth.ini` is
|
|
99
|
+
// already an allowed source of `@scope:registry=` (see config/reader).
|
|
100
|
+
const scopeKey = normalizeScope(opts.scope);
|
|
101
|
+
if (scopeKey != null) {
|
|
102
|
+
settings[`${scopeKey}:registry`] = registry;
|
|
103
|
+
}
|
|
90
104
|
await writeIniFile(configPath, settings);
|
|
91
105
|
return `Logged in on ${registry}`;
|
|
92
106
|
}
|
|
107
|
+
// `--scope foo` and `--scope @foo` should both produce `@foo`. Empty / blank
|
|
108
|
+
// values are treated as unset so accidental whitespace doesn't write a broken
|
|
109
|
+
// `@:registry=` entry.
|
|
110
|
+
function normalizeScope(scope) {
|
|
111
|
+
if (scope == null)
|
|
112
|
+
return undefined;
|
|
113
|
+
const trimmed = scope.trim();
|
|
114
|
+
if (trimmed === '' || trimmed === '@')
|
|
115
|
+
return undefined;
|
|
116
|
+
return trimmed.startsWith('@') ? trimmed : `@${trimmed}`;
|
|
117
|
+
}
|
|
93
118
|
async function webLogin({ context, fetchOptions, registry, }) {
|
|
94
119
|
const { fetch, globalInfo, } = context;
|
|
95
120
|
const loginUrl = new URL('-/v1/login', registry).href;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pnpm/auth.commands",
|
|
3
|
-
"version": "1100.
|
|
3
|
+
"version": "1100.1.1",
|
|
4
4
|
"description": "Commands for authentication with npm registries",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pnpm",
|
|
@@ -30,18 +30,18 @@
|
|
|
30
30
|
"read-ini-file": "5.0.0",
|
|
31
31
|
"render-help": "^2.0.0",
|
|
32
32
|
"write-ini-file": "5.0.0",
|
|
33
|
-
"@pnpm/
|
|
34
|
-
"@pnpm/network.fetch": "1100.0.5",
|
|
35
|
-
"@pnpm/network.web-auth": "1101.0.0",
|
|
33
|
+
"@pnpm/cli.utils": "1101.0.7",
|
|
36
34
|
"@pnpm/error": "1100.0.0",
|
|
37
|
-
"@pnpm/
|
|
35
|
+
"@pnpm/network.web-auth": "1101.0.0",
|
|
36
|
+
"@pnpm/network.fetch": "1100.0.6",
|
|
37
|
+
"@pnpm/config.reader": "1101.4.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"@pnpm/logger": ">=1001.0.0 <1002.0.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@jest/globals": "30.3.0",
|
|
44
|
-
"@pnpm/auth.commands": "1100.
|
|
44
|
+
"@pnpm/auth.commands": "1100.1.1",
|
|
45
45
|
"@pnpm/logger": "1100.0.0"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|