Skip to content

Commit 3a10c2c

Browse files
josephperrottmmalerba
authored andcommitted
build: set up all packages to publish via wombot proxy (#17679)
* build: set up all packages to publish via wombot proxy * release: remove otp prompting from release process * release: remove npm login/logut/auth checks * release: remove .npmrc file after release completes
1 parent 5822051 commit 3a10c2c

File tree

10 files changed

+37
-122
lines changed

10 files changed

+37
-122
lines changed

src/cdk-experimental/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@
2323
"@angular/cdk": "0.0.0-PLACEHOLDER",
2424
"@angular/core": "0.0.0-NG",
2525
"tslib": "^1.9.0"
26+
},
27+
"publishConfig":{
28+
"registry":"https://wombat-dressing-room.appspot.com"
2629
}
2730
}

src/cdk/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,8 @@
3838
"ng-update": {
3939
"migrations": "./schematics/migration.json"
4040
},
41-
"sideEffects": false
41+
"sideEffects": false,
42+
"publishConfig":{
43+
"registry":"https://wombat-dressing-room.appspot.com"
44+
}
4245
}

src/google-maps/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
"@angular/core": "0.0.0-NG",
3232
"@angular/common": "0.0.0-NG"
3333
},
34-
"sideEffects": false
34+
"sideEffects": false,
35+
"publishConfig":{
36+
"registry":"https://wombat-dressing-room.appspot.com"
37+
}
3538
}

src/material-experimental/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,8 @@
2424
"@angular/material": "0.0.0-PLACEHOLDER",
2525
"material-components-web": "0.0.0-MDC",
2626
"tslib": "^1.9.0"
27+
},
28+
"publishConfig":{
29+
"registry":"https://wombat-dressing-room.appspot.com"
2730
}
2831
}

src/material-moment-adapter/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
"@angular/cdk",
3232
"@angular/material-moment-adapter"
3333
]
34+
},
35+
"publishConfig":{
36+
"registry":"https://wombat-dressing-room.appspot.com"
3437
}
3538
}

src/material/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
"@angular/material-moment-adapter"
4343
]
4444
},
45-
"sideEffects": false
45+
"sideEffects": false,
46+
"publishConfig":{
47+
"registry":"https://wombat-dressing-room.appspot.com"
48+
}
4649
}
4750

src/youtube-player/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,8 @@
3131
"@angular/core": "0.0.0-NG",
3232
"@angular/common": "0.0.0-NG"
3333
},
34-
"sideEffects": false
34+
"sideEffects": false,
35+
"publishConfig":{
36+
"registry":"https://wombat-dressing-room.appspot.com"
37+
}
3538
}

tools/release/npm/npm-client.ts

Lines changed: 3 additions & 39 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 */
32-
export function npmPublish(packagePath: string, distTag: string, otp: string): string | null {
4+
export function npmPublish(packagePath: string, distTag: string): string | null {
335
const result =
34-
spawnSync('npm', ['publish', '--access', 'public', '--tag', distTag, '--otp', otp], {
6+
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, otp: string): s
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/prompt/npm-dist-tag-prompt.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,6 @@ export async function promptForNpmDistTag(version: Version): Promise<string> {
2424
return distTag;
2525
}
2626

27-
/**
28-
* Prompts the current user-input interface for a npm one-time password (OTP). This is required
29-
* to publish packages in the @angular namespace.
30-
*/
31-
export async function promptForNpmOtp(): Promise<string> {
32-
const {otp} = await prompt<{otp: string}>({
33-
type: 'text',
34-
name: 'otp',
35-
message: 'Enter the one-time password (OTP) for the angular npm account:',
36-
});
37-
38-
return otp;
39-
}
40-
4127
/**
4228
* Determines all allowed npm dist-tag choices for a specified version. For example,
4329
* a pre-release version should be never published to the "latest" tag.

tools/release/publish-release.ts

Lines changed: 9 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
import chalk from 'chalk';
22
import {spawnSync} from 'child_process';
3-
import {readFileSync} from 'fs';
3+
import {readFileSync, unlinkSync} from 'fs';
44
import {join} from 'path';
55
import {BaseReleaseTask} from './base-release-task';
66
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';
16-
import {promptForNpmDistTag, promptForNpmOtp} from './prompt/npm-dist-tag-prompt';
10+
import {npmPublish} from './npm/npm-client';
11+
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

@@ -124,12 +112,8 @@ class PublishReleaseTask extends BaseReleaseTask {
124112
// the user to interactively confirm that the script should continue.
125113
await this._promptConfirmReleasePublish();
126114

127-
// Prompt for the OTP right before publishing so that it doesn't expire while building the
128-
// packages.
129-
const npmOtp = await promptForNpmOtp();
130-
131115
for (let packageName of releasePackages) {
132-
this._publishPackageToNpm(packageName, npmDistTag, npmOtp);
116+
this._publishPackageToNpm(packageName, npmDistTag);
133117
}
134118

135119
const newReleaseUrl = getGithubNewReleaseUrl({
@@ -144,17 +128,11 @@ class PublishReleaseTask extends BaseReleaseTask {
144128

145129
console.log();
146130
console.info(chalk.green(chalk.bold(` ✓ Published all packages successfully`)));
147-
148-
// Always log out of npm after releasing to prevent unintentional changes to
149-
// any packages.
150-
if (npmLogout()) {
151-
console.info(chalk.green(` ✓ Logged out of npm`));
152-
} else {
153-
console.error(chalk.red(` ✘ Could not log out of NPM. Please manually log out!`));
154-
}
155-
156131
console.info(chalk.yellow(` ⚠ Please draft a new release of the version on Github.`));
157132
console.info(chalk.yellow(` ${newReleaseUrl}`));
133+
134+
// Remove file at ~/.npmrc after release is complete.
135+
unlinkSync('~/.npmrc');
158136
}
159137

160138
/**
@@ -205,45 +183,11 @@ class PublishReleaseTask extends BaseReleaseTask {
205183
}
206184
}
207185

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

246-
const errorOutput = npmPublish(join(this.releaseOutputPath, packageName), npmDistTag, npmOtp);
190+
const errorOutput = npmPublish(join(this.releaseOutputPath, packageName), npmDistTag);
247191

248192
if (errorOutput) {
249193
console.error(chalk.red(` ✘ An error occurred while publishing "${packageName}".`));

0 commit comments

Comments
 (0)