Skip to content

Commit 73051ae

Browse files
committed
refactor(ng-dev): remove pnpm version checking
Since pnpm now automatically uses the version defined in the package.json file we don't need to extract it and run the specific version manually anymore
1 parent 181bb28 commit 73051ae

File tree

7 files changed

+14
-69
lines changed

7 files changed

+14
-69
lines changed

ng-dev/release/publish/actions.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ export abstract class ReleaseAction {
101101
*/
102102
abstract perform(): Promise<void>;
103103

104-
protected pnpmVersioning = new PnpmVersioning();
105-
106104
constructor(
107105
protected active: ActiveReleaseTrains,
108106
protected git: AuthenticatedGitClient,
@@ -388,7 +386,7 @@ export abstract class ReleaseAction {
388386

389387
/** Installs all Yarn dependencies in the current branch. */
390388
protected async installDependenciesForCurrentBranch() {
391-
if (await this.pnpmVersioning.isUsingPnpm(this.projectDir)) {
389+
if (PnpmVersioning.isUsingPnpm(this.projectDir)) {
392390
// Note: We delate all contents of `node_modules` before installing dependencies. We do
393391
// this because if a pnpm workspace package exists at one ref and not another, it can
394392
// cause the pnpm install from within Bazel to errantly attempt to install a package that
@@ -439,14 +437,8 @@ export abstract class ReleaseAction {
439437
// publish branch. e.g. consider we publish patch version and a new package has been
440438
// created in the `next` branch. The new package would not be part of the patch branch,
441439
// so we cannot build and publish it.
442-
const builtPackages = await ExternalCommands.invokeReleaseBuild(
443-
this.projectDir,
444-
this.pnpmVersioning,
445-
);
446-
const releaseInfo = await ExternalCommands.invokeReleaseInfo(
447-
this.projectDir,
448-
this.pnpmVersioning,
449-
);
440+
const builtPackages = await ExternalCommands.invokeReleaseBuild(this.projectDir);
441+
const releaseInfo = await ExternalCommands.invokeReleaseInfo(this.projectDir);
450442

451443
// Extend the built packages with their disk hash and NPM package information. This is
452444
// helpful later for verifying integrity and filtering out e.g. experimental packages.
@@ -511,7 +503,6 @@ export abstract class ReleaseAction {
511503
this.projectDir,
512504
newVersion,
513505
builtPackagesWithInfo,
514-
this.pnpmVersioning,
515506
);
516507

517508
// Verify the packages built are the correct version.

ng-dev/release/publish/actions/cut-stable.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export class CutStableAction extends ReleaseAction {
8686
await ExternalCommands.invokeDeleteNpmDistTag(
8787
this.projectDir,
8888
'do-not-use-exceptional-minor',
89-
this.pnpmVersioning,
9089
);
9190
}
9291

@@ -109,7 +108,6 @@ export class CutStableAction extends ReleaseAction {
109108
this.projectDir,
110109
ltsTagForPatch,
111110
previousPatch.version,
112-
this.pnpmVersioning,
113111
{
114112
// We do not intend to tag experimental NPM packages as LTS.
115113
skipExperimentalPackages: true,

ng-dev/release/publish/actions/tag-recent-major-as-latest.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,7 @@ export class TagRecentMajorAsLatest extends ReleaseAction {
3434
await this.updateGithubReleaseEntryToStable(this.active.latest.version);
3535
await this.checkoutUpstreamBranch(this.active.latest.branchName);
3636
await this.installDependenciesForCurrentBranch();
37-
await ExternalCommands.invokeSetNpmDist(
38-
this.projectDir,
39-
'latest',
40-
this.active.latest.version,
41-
this.pnpmVersioning,
42-
);
37+
await ExternalCommands.invokeSetNpmDist(this.projectDir, 'latest', this.active.latest.version);
4338
}
4439

4540
/**

ng-dev/release/publish/external-commands.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import {ReleaseInfoJsonStdout} from '../info/cli.js';
1818
import {ReleasePrecheckJsonStdin} from '../precheck/cli.js';
1919
import {BuiltPackageWithInfo} from '../config/index.js';
2020
import {green, Log} from '../../utils/logging.js';
21-
import {PnpmVersioning} from './pnpm-versioning.js';
2221
import {getBazelBin} from '../../utils/bazel-bin.js';
22+
import {PnpmVersioning} from './pnpm-versioning.js';
2323

2424
/*
2525
* ###############################################################
@@ -51,7 +51,6 @@ export abstract class ExternalCommands {
5151
projectDir: string,
5252
npmDistTag: NpmDistTag,
5353
version: semver.SemVer,
54-
pnpmVersioning: PnpmVersioning,
5554
options: {skipExperimentalPackages: boolean} = {skipExperimentalPackages: false},
5655
) {
5756
try {
@@ -66,7 +65,6 @@ export abstract class ExternalCommands {
6665
`--skip-experimental-packages=${options.skipExperimentalPackages}`,
6766
],
6867
projectDir,
69-
pnpmVersioning,
7068
);
7169

7270
Log.info(green(` ✓ Set "${npmDistTag}" NPM dist tag for all packages to v${version}.`));
@@ -81,17 +79,12 @@ export abstract class ExternalCommands {
8179
* Invokes the `ng-dev release npm-dist-tag delete` command in order to delete the
8280
* NPM dist tag for all packages in the checked-out version branch.
8381
*/
84-
static async invokeDeleteNpmDistTag(
85-
projectDir: string,
86-
npmDistTag: NpmDistTag,
87-
pnpmVersioning: PnpmVersioning,
88-
) {
82+
static async invokeDeleteNpmDistTag(projectDir: string, npmDistTag: NpmDistTag) {
8983
try {
9084
// Note: No progress indicator needed as that is the responsibility of the command.
9185
await this._spawnNpmScript(
9286
['ng-dev', 'release', 'npm-dist-tag', 'delete', npmDistTag],
9387
projectDir,
94-
pnpmVersioning,
9588
);
9689

9790
Log.info(green(` ✓ Deleted "${npmDistTag}" NPM dist tag for all packages.`));
@@ -106,10 +99,7 @@ export abstract class ExternalCommands {
10699
* Invokes the `ng-dev release build` command in order to build the release
107100
* packages for the currently checked out branch.
108101
*/
109-
static async invokeReleaseBuild(
110-
projectDir: string,
111-
pnpmVersioning: PnpmVersioning,
112-
): Promise<ReleaseBuildJsonStdout> {
102+
static async invokeReleaseBuild(projectDir: string): Promise<ReleaseBuildJsonStdout> {
113103
// Note: We explicitly mention that this can take a few minutes, so that it's obvious
114104
// to caretakers that it can take longer than just a few seconds.
115105
const spinner = new Spinner('Building release output. This can take a few minutes.');
@@ -118,7 +108,6 @@ export abstract class ExternalCommands {
118108
const {stdout} = await this._spawnNpmScript(
119109
['ng-dev', 'release', 'build', '--json'],
120110
projectDir,
121-
pnpmVersioning,
122111
{
123112
mode: 'silent',
124113
},
@@ -144,15 +133,11 @@ export abstract class ExternalCommands {
144133
* This is useful to e.g. determine whether a built package is currently
145134
* denoted as experimental or not.
146135
*/
147-
static async invokeReleaseInfo(
148-
projectDir: string,
149-
pnpmVersioning: PnpmVersioning,
150-
): Promise<ReleaseInfoJsonStdout> {
136+
static async invokeReleaseInfo(projectDir: string): Promise<ReleaseInfoJsonStdout> {
151137
try {
152138
const {stdout} = await this._spawnNpmScript(
153139
['ng-dev', 'release', 'info', '--json'],
154140
projectDir,
155-
pnpmVersioning,
156141
{mode: 'silent'},
157142
);
158143

@@ -180,15 +165,14 @@ export abstract class ExternalCommands {
180165
projectDir: string,
181166
newVersion: semver.SemVer,
182167
builtPackagesWithInfo: BuiltPackageWithInfo[],
183-
pnpmVersioning: PnpmVersioning,
184168
): Promise<void> {
185169
const precheckStdin: ReleasePrecheckJsonStdin = {
186170
builtPackagesWithInfo,
187171
newVersion: newVersion.format(),
188172
};
189173

190174
try {
191-
await this._spawnNpmScript(['ng-dev', 'release', 'precheck'], projectDir, pnpmVersioning, {
175+
await this._spawnNpmScript(['ng-dev', 'release', 'precheck'], projectDir, {
192176
// Note: We pass the precheck information to the command through `stdin`
193177
// because command line arguments are less reliable and have length limits.
194178
input: JSON.stringify(precheckStdin),
@@ -269,12 +253,10 @@ export abstract class ExternalCommands {
269253
private static async _spawnNpmScript(
270254
args: string[],
271255
projectDir: string,
272-
pnpmVersioning: PnpmVersioning,
273256
spawnOptions: SpawnOptions = {},
274257
): Promise<SpawnResult> {
275-
if (await pnpmVersioning.isUsingPnpm(projectDir)) {
276-
const pnpmSpec = await pnpmVersioning.getPackageSpec(projectDir);
277-
return ChildProcess.spawn('npx', ['--yes', pnpmSpec, '-s', 'run', ...args], {
258+
if (PnpmVersioning.isUsingPnpm(projectDir)) {
259+
return ChildProcess.spawn('npx', ['--yes', 'pnpm', '-s', 'run', ...args], {
278260
...spawnOptions,
279261
cwd: projectDir,
280262
});

ng-dev/release/publish/pnpm-versioning.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,15 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import {readFile} from 'node:fs/promises';
109
import {join} from 'node:path';
1110
import {existsSync} from 'node:fs';
1211

13-
/**
14-
* Class that exposes helpers for fetching and using pnpm
15-
* based on a currently-checked out revision.
16-
*
17-
* This is useful as there is no vendoring/checking-in of specific
18-
* pnpm versions, so we need to automatically fetch the proper pnpm
19-
* version when executing commands in version branches. Keep in mind that
20-
* version branches may have different pnpm version ranges, and the release
21-
* tool should automatically be able to satisfy those.
22-
*/
12+
// TODO(josephperrott): Remove this version check once we no longer support v19
13+
2314
export class PnpmVersioning {
24-
async isUsingPnpm(repoPath: string) {
15+
static isUsingPnpm(repoPath: string) {
2516
// If there is only a pnpm lock file at the workspace root, we assume pnpm
2617
// is the primary package manager. We can remove such checks in the future.
2718
return existsSync(join(repoPath, 'pnpm-lock.yaml')) && !existsSync(join(repoPath, 'yarn.lock'));
2819
}
29-
30-
async getPackageSpec(repoPath: string) {
31-
const packageJsonRaw = await readFile(join(repoPath, 'package.json'), 'utf8');
32-
const packageJson = JSON.parse(packageJsonRaw) as {engines?: Record<string, string>};
33-
34-
const pnpmAllowedRange = packageJson?.engines?.['pnpm'] ?? 'latest';
35-
return `pnpm@${pnpmAllowedRange}`;
36-
}
3720
}

ng-dev/release/publish/test/cut-stable.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
} from '../../versioning/index.js';
2727
import {ReleaseNotes} from '../../notes/release-notes.js';
2828
import {workspaceRelativePackageJsonPath} from '../../../utils/constants.js';
29-
import {PnpmVersioning} from '../pnpm-versioning.js';
3029

3130
describe('cut stable action', () => {
3231
it('should not activate if a feature-freeze release-train is active', async () => {
@@ -163,7 +162,6 @@ describe('cut stable action', () => {
163162
action.projectDir,
164163
'v10-lts',
165164
matchesVersion('10.0.3'),
166-
new PnpmVersioning(),
167165
// Experimental packages are expected to be not tagged as LTS.
168166
{skipExperimentalPackages: true},
169167
);

ng-dev/release/publish/test/tag-recent-major-as-latest.spec.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {ActiveReleaseTrains} from '../../versioning/index.js';
1111
import {ReleaseTrain} from '../../versioning/release-trains.js';
1212
import {TagRecentMajorAsLatest} from '../actions/tag-recent-major-as-latest.js';
1313
import {ExternalCommands} from '../external-commands.js';
14-
import {PnpmVersioning} from '../pnpm-versioning.js';
1514
import {getTestConfigurationsForAction} from './test-utils/action-mocks.js';
1615
import {
1716
fakeNpmPackageQueryRequest,
@@ -149,7 +148,6 @@ describe('tag recent major as latest action', () => {
149148
projectDir,
150149
'latest',
151150
matchesVersion('10.0.0'),
152-
new PnpmVersioning(),
153151
);
154152
});
155153
});

0 commit comments

Comments
 (0)