Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e95e477

Browse files
bgotinkarcanis
andauthored
feat: add --always-auth flag to npm login (#5406)
* feat: add --always-auth flag to npm login * Fixes lint --------- Co-authored-by: Maël Nison <nison.mael@gmail.com>
1 parent e19910a commit e95e477

File tree

4 files changed

+75
-2
lines changed

4 files changed

+75
-2
lines changed

‎.yarn/versions/36a8438a.yml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
releases:
2+
"@yarnpkg/cli": minor
3+
"@yarnpkg/plugin-npm-cli": minor
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-init"
11+
- "@yarnpkg/plugin-interactive-tools"
12+
- "@yarnpkg/plugin-nm"
13+
- "@yarnpkg/plugin-pack"
14+
- "@yarnpkg/plugin-patch"
15+
- "@yarnpkg/plugin-pnp"
16+
- "@yarnpkg/plugin-pnpm"
17+
- "@yarnpkg/plugin-stage"
18+
- "@yarnpkg/plugin-typescript"
19+
- "@yarnpkg/plugin-version"
20+
- "@yarnpkg/plugin-workspace-tools"
21+
- "@yarnpkg/builder"
22+
- "@yarnpkg/core"
23+
- "@yarnpkg/doctor"

‎packages/acceptance-tests/pkg-tests-specs/sources/commands/npm/__snapshots__/login.test.ts.snap‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,14 @@ exports[`Commands npm login it should print the npm-notice when an OTP is reques
108108
",
109109
}
110110
`;
111+
112+
exports[`Commands npm login it should store npmAlwaysAuth when passed as option 1`] = `
113+
{
114+
"code": 0,
115+
"stderr": "",
116+
"stdout": "➤ YN0000: Logging in to http://registry.example.org
117+
118+
YN0000: Successfully logged in
119+
",
120+
}
121+
`;

‎packages/acceptance-tests/pkg-tests-specs/sources/commands/npm/login.test.ts‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,39 @@ describe(`Commands`, () => {
211211
expect({code, stdout, stderr}).toMatchSnapshot();
212212
}),
213213
);
214+
215+
test(
216+
`it should store npmAlwaysAuth when passed as option`,
217+
makeTemporaryEnv({}, async ({path, run, source}) => {
218+
const rcPath = ppath.join(path, PortablePath.parent, SPEC_RC_FILENAME);
219+
await xfs.writeFilePromise(rcPath, ``);
220+
221+
let code;
222+
let stdout;
223+
let stderr;
224+
225+
try {
226+
({code, stdout, stderr} = await run(`npm`, `login`, `--always-auth`, {
227+
env: {
228+
YARN_INJECT_NPM_USER: validLogins.fooUser.username,
229+
YARN_INJECT_NPM_PASSWORD: validLogins.fooUser.password,
230+
YARN_RC_FILENAME: SPEC_RC_FILENAME,
231+
},
232+
}));
233+
} catch (error) {
234+
({code, stdout, stderr} = error);
235+
}
236+
237+
expect({code, stdout, stderr}).toMatchSnapshot();
238+
239+
const {stdout: npmRegistriesConfig} = await run(`config`, `get`, `--json`, `npmRegistries`, {
240+
env: {
241+
YARN_RC_FILENAME: SPEC_RC_FILENAME,
242+
},
243+
});
244+
245+
expect(JSON.parse(npmRegistriesConfig)[`http://registry.example.org`]?.npmAlwaysAuth).toBe(true);
246+
}),
247+
);
214248
});
215249
});

‎packages/plugin-npm-cli/sources/commands/npm/login.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ export default class NpmLoginCommand extends BaseCommand {
4242
description: `Login to the publish registry`,
4343
});
4444

45+
alwaysAuth = Option.Boolean(`--always-auth`, {
46+
description: `Set the npmAlwaysAuth configuration`,
47+
});
48+
4549
async execute() {
4650
const configuration = await Configuration.find(this.context.cwd, this.context.plugins);
4751

@@ -75,7 +79,7 @@ export default class NpmLoginCommand extends BaseCommand {
7579
authType: npmHttpUtils.AuthType.NO_AUTH,
7680
}) as any;
7781

78-
await setAuthToken(registry, response.token, {configuration, scope: this.scope});
82+
await setAuthToken(registry, response.token, {alwaysAuth: this.alwaysAuth, scope: this.scope});
7983
return report.reportInfo(MessageName.UNNAMED, `Successfully logged in`);
8084
});
8185

@@ -96,7 +100,7 @@ export async function getRegistry({scope, publish, configuration, cwd}: {scope?:
96100
return npmConfigUtils.getDefaultRegistry({configuration});
97101
}
98102

99-
async function setAuthToken(registry: string, npmAuthToken: string, {configuration, scope}: {configuration: Configuration, scope?: string}) {
103+
async function setAuthToken(registry: string, npmAuthToken: string, {alwaysAuth, scope}: {alwaysAuth?: boolean, scope?: string}) {
100104
const makeUpdater = (entryName: string) => (unknownStore: unknown) => {
101105
const store = miscUtils.isIndexableObject(unknownStore)
102106
? unknownStore
@@ -111,6 +115,7 @@ async function setAuthToken(registry: string, npmAuthToken: string, {configurati
111115
...store,
112116
[entryName]: {
113117
...entry,
118+
...(alwaysAuth !== undefined ? {npmAlwaysAuth: alwaysAuth} : {}),
114119
npmAuthToken,
115120
},
116121
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /