Skip to content

Commit f9069b2

Browse files
committed
release: remove npm login/logut/auth checks
1 parent ad2d010 commit f9069b2

File tree

2 files changed

+2
-93
lines changed

2 files changed

+2
-93
lines changed

tools/release/npm/npm-client.ts

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,12 @@
11
import {spawnSync} from 'child_process';
22

3-
/**
4-
* Process environment that does not refer to Yarn's package registry. Since the scripts are
5-
* usually run through Yarn, we need to update the "npm_config_registry" so that NPM is able to
6-
* properly run "npm login" and "npm publish".
7-
*/
8-
const npmClientEnvironment = {
9-
...process.env,
10-
// See https://docs.npmjs.com/misc/registry for the official documentation of the NPM registry.
11-
npm_config_registry: 'https://registry.npmjs.org',
12-
};
13-
14-
/** Checks whether NPM is currently authenticated. */
15-
export function isNpmAuthenticated(): boolean {
16-
return spawnSync('npm', ['whoami'], {
17-
shell: true,
18-
env: npmClientEnvironment,
19-
}).stdout.toString() !== '';
20-
}
21-
22-
/** Runs "npm login" interactively by piping stdin/stderr/stdout to the current tty. */
23-
export function npmLoginInteractive(): boolean {
24-
return spawnSync('npm', ['login'], {
25-
stdio: 'inherit',
26-
shell: true,
27-
env: npmClientEnvironment,
28-
}).status === 0;
29-
}
30-
313
/** Runs NPM publish within a specified directory */
324
export function npmPublish(packagePath: string, distTag: string): string | null {
335
const result =
346
spawnSync('npm', ['publish', '--access', 'public', '--tag', distTag], {
357
cwd: packagePath,
368
shell: true,
37-
env: npmClientEnvironment,
9+
env: process.env,
3810
});
3911

4012
// We only want to return an error if the exit code is not zero. NPM by default prints the
@@ -44,11 +16,3 @@ export function npmPublish(packagePath: string, distTag: string): string | null
4416
}
4517
return null;
4618
}
47-
48-
/** Log out of npm. */
49-
export function npmLogout(): boolean {
50-
return spawnSync('npm', ['logout'], {
51-
shell: true,
52-
env: npmClientEnvironment,
53-
}).status === 0;
54-
}

tools/release/publish-release.ts

Lines changed: 1 addition & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@ import {checkReleaseOutput} from './check-release-output';
77
import {extractReleaseNotes} from './extract-release-notes';
88
import {GitClient} from './git/git-client';
99
import {getGithubNewReleaseUrl} from './git/github-urls';
10-
import {
11-
isNpmAuthenticated,
12-
npmLogout,
13-
npmLoginInteractive,
14-
npmPublish,
15-
} from './npm/npm-client';
10+
import {npmPublish} from './npm/npm-client';
1611
import {promptForNpmDistTag} from './prompt/npm-dist-tag-prompt';
1712
import {promptForUpstreamRemote} from './prompt/upstream-remote-prompt';
1813
import {releasePackages} from './release-output/release-packages';
1914
import {CHANGELOG_FILE_NAME} from './stage-release';
2015
import {parseVersionName, Version} from './version-name/parse-version';
2116

22-
/** Maximum allowed tries to authenticate NPM. */
23-
const MAX_NPM_LOGIN_TRIES = 2;
24-
2517
/**
2618
* Class that can be instantiated in order to create a new release. The tasks requires user
2719
* interaction/input through command line prompts.
@@ -94,10 +86,6 @@ class PublishReleaseTask extends BaseReleaseTask {
9486
await this._promptStableVersionForNextTag();
9587
}
9688

97-
// Ensure that we are authenticated, so that we can run "npm publish" for
98-
// each package once the release output is built.
99-
this._checkNpmAuthentication();
100-
10189
this._buildReleasePackages();
10290
console.info(chalk.green(` ✓ Built the release output.`));
10391

@@ -140,15 +128,6 @@ class PublishReleaseTask extends BaseReleaseTask {
140128

141129
console.log();
142130
console.info(chalk.green(chalk.bold(` ✓ Published all packages successfully`)));
143-
144-
// Always log out of npm after releasing to prevent unintentional changes to
145-
// any packages.
146-
if (npmLogout()) {
147-
console.info(chalk.green(` ✓ Logged out of npm`));
148-
} else {
149-
console.error(chalk.red(` ✘ Could not log out of NPM. Please manually log out!`));
150-
}
151-
152131
console.info(chalk.yellow(` ⚠ Please draft a new release of the version on Github.`));
153132
console.info(chalk.yellow(` ${newReleaseUrl}`));
154133
}
@@ -201,40 +180,6 @@ class PublishReleaseTask extends BaseReleaseTask {
201180
}
202181
}
203182

204-
/**
205-
* Checks whether NPM is currently authenticated. If not, the user will be prompted to enter
206-
* the NPM credentials that are necessary to publish the release. We achieve this by basically
207-
* running "npm login" as a child process and piping stdin/stdout/stderr to the current tty.
208-
*/
209-
private _checkNpmAuthentication() {
210-
if (isNpmAuthenticated()) {
211-
console.info(chalk.green(` ✓ NPM is authenticated.`));
212-
return;
213-
}
214-
215-
let failedAuthentication = false;
216-
console.log(chalk.yellow(` ⚠ NPM is currently not authenticated. Running "npm login"..`));
217-
218-
for (let i = 0; i < MAX_NPM_LOGIN_TRIES; i++) {
219-
if (npmLoginInteractive()) {
220-
// In case the user was able to login properly, we want to exit the loop as we
221-
// don't need to ask for authentication again.
222-
break;
223-
}
224-
225-
failedAuthentication = true;
226-
console.error(chalk.red(` ✘ Could not authenticate successfully. Please try again.`));
227-
}
228-
229-
if (failedAuthentication) {
230-
console.error(chalk.red(` ✘ Could not authenticate after ${MAX_NPM_LOGIN_TRIES} tries. ` +
231-
`Exiting..`));
232-
process.exit(1);
233-
}
234-
235-
console.info(chalk.green(` ✓ Successfully authenticated NPM.`));
236-
}
237-
238183
/** Publishes the specified package within the given NPM dist tag. */
239184
private _publishPackageToNpm(packageName: string, npmDistTag: string) {
240185
console.info(chalk.green(` ⭮ Publishing "${packageName}"..`));

0 commit comments

Comments
 (0)