Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ng-dev/release): ensure installed node modules do not break within Bazel #271

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ng-dev/release/publish/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ ts_library(
"@npm//@types/node",
"@npm//@types/semver",
"@npm//@types/yargs",
"@npm//del",
"@npm//ejs",
"@npm//inquirer",
"@npm//semver",
Expand Down
18 changes: 15 additions & 3 deletions ng-dev/release/publish/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import {promises as fs} from 'fs';
import {join} from 'path';
import * as semver from 'semver';
import * as del from 'del';

import {debug, error, green, info, promptConfirm, red, warn, yellow} from '../../utils/console';
import {Spinner} from '../../utils/spinner';
Expand Down Expand Up @@ -377,6 +378,17 @@ export abstract class ReleaseAction {
this.git.run(['checkout', '-q', 'FETCH_HEAD', '--detach']);
}

/** Installs all Yarn dependencies in the current branch. */
protected async installDependenciesForCurrentBranch() {
// Note: We delete all contents of the `node_modules` first. This is necessary
// because Yarn could preserve extraneous/outdated nested modules that will cause
// unexpected build failures with the NodeJS Bazel `@npm` workspace generation.
// This is a workaround for: https://github.com/yarnpkg/yarn/issues/8146. Even though
// we might be able to fix this with Yarn 2+, it is reasonable ensuring clean node modules.
await del(['node_modules/**'], {cwd: this.projectDir});
await invokeYarnInstallCommand(this.projectDir);
}

/**
* Creates a commit for the specified files with the given message.
* @param message Message for the created commit
Expand Down Expand Up @@ -585,14 +597,14 @@ export abstract class ReleaseAction {

// Checkout the publish branch and build the release packages.
await this.checkoutUpstreamBranch(publishBranch);
// Install the project dependencies for the publish branch.
await this.installDependenciesForCurrentBranch();

// Install the project dependencies for the publish branch, and then build the release
// packages. Note that we do not directly call the build packages function from the release
// Note that we do not directly call the build packages function from the release
// config. We only want to build and publish packages that have been configured in the given
// publish branch. e.g. consider we publish patch version and a new package has been
// created in the `next` branch. The new package would not be part of the patch branch,
// so we cannot build and publish it.
await invokeYarnInstallCommand(this.projectDir);
const builtPackages = await invokeReleaseBuildCommand();

// Verify the packages built are the correct version.
Expand Down
3 changes: 2 additions & 1 deletion ng-dev/release/publish/actions/cut-stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ export class CutStableAction extends ReleaseAction {
// NPM dist tag for new packages part of the released major, nor would it be acceptable
// to skip the LTS tag for packages which are no longer part of the new major.
await this.checkoutUpstreamBranch(previousPatch.branchName);
await invokeYarnInstallCommand(this.projectDir);
await this.installDependenciesForCurrentBranch();

await invokeSetNpmDistCommand(ltsTagForPatch, previousPatch.version);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class TagRecentMajorAsLatest extends ReleaseAction {
override async perform() {
await this.updateGithubReleaseEntryToStable(this.active.latest.version);
await this.checkoutUpstreamBranch(this.active.latest.branchName);
await invokeYarnInstallCommand(this.projectDir);
await this.installDependenciesForCurrentBranch();
await invokeSetNpmDistCommand('latest', this.active.latest.version);
}

Expand Down
2 changes: 1 addition & 1 deletion ng-dev/release/publish/external-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export async function invokeYarnInstallCommand(projectDir: string): Promise<void
/**
* Invokes the `yarn check --integrity` command in order to verify up to date dependencies.
*/
export async function invokeYarnIntegryCheck(projectDir: string): Promise<void> {
export async function invokeYarnIntegrityCheck(projectDir: string): Promise<void> {
try {
await spawn('yarn', ['check', '--integrity'], {cwd: projectDir, mode: 'silent'});
info(green(' ✓ Confirmed dependencies from package.json match those in yarn.lock.'));
Expand Down
4 changes: 2 additions & 2 deletions ng-dev/release/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {getNextBranchName, ReleaseRepoWithApi} from '../versioning/version-branc
import {ReleaseAction} from './actions';
import {FatalReleaseActionError, UserAbortedReleaseActionError} from './actions-error';
import {actions} from './actions/index';
import {invokeYarnIntegryCheck, invokeYarnVerifyTreeCheck} from './external-commands';
import {invokeYarnIntegrityCheck, invokeYarnVerifyTreeCheck} from './external-commands';

export enum CompletionState {
SUCCESS,
Expand Down Expand Up @@ -154,7 +154,7 @@ export class ReleaseTool {
private async _verifyInstalledDependenciesAreUpToDate(): Promise<boolean> {
try {
await invokeYarnVerifyTreeCheck(this._projectRoot);
await invokeYarnIntegryCheck(this._projectRoot);
await invokeYarnIntegrityCheck(this._projectRoot);
return true;
} catch {
return false;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"clang-format": "^1.4.0",
"cli-progress": "^3.7.0",
"conventional-commits-parser": "^3.2.1",
"del": "^6.0.0",
josephperrott marked this conversation as resolved.
Show resolved Hide resolved
"ejs": "^3.1.6",
"git-raw-commits": "^2.0.10",
"glob": "7.2.0",
Expand Down
Loading