豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 7b66fb5

Browse files
devversionjosephperrott
authored andcommitted
fix(ng-dev/release): ensure installed node modules do not break within Bazel (#271)
This commit fixes an issue where old modules from other version branches are preserved in the `node_modules` of a newly checked-out version branch. Old/extraneous modules can cause the Bazel NodeJS rules to throw with an error when preparing the `@npm//` workspace. Yarn v1 has a bug where nested node modules are not cleaned properly. Yarn v2+ supposedly fixes that, but for now we are still on v1.x and in general it seems more safe to clean the node modules. Here is the related Yarn bug: yarnpkg/yarn#8146. Here is an example Bazel NodeJS error: ``` ✓ Created pull request #23758 in angular/components. ✓ Release staging pull request has been created. Please ask team members to review: angular/components#23758. ⠋ Waiting for pull request #23758 to be merged. ✓ Pull request #23758 has been merged. [1/5] Validating package.json... [2/5] Resolving packages... warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^2.2.1" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^2.2.1" warning Resolution field "typescript@4.3.2" is incompatible with requested version "typescript@^3.2.2" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^2.2.1" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^4.0.0" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^4.0.0" [3/5] Fetching packages... [4/5] Linking dependencies... warning "@angular/bazel > tsickle@0.38.1" has incorrect peer dependency "typescript@~3.8.2". warning " > @bazel/concatjs@4.0.0-beta.0" has unmet peer dependency "karma-junit-reporter@>=2.0.0". warning " > tsickle@0.39.1" has incorrect peer dependency "typescript@~3.9.5". [5/5] Building fresh packages... $ node tools/postinstall/apply-patches.js && ngcc --properties module main --create-ivy-entry-points && node tools/postinstall/update-ngcc-main-fields.js patching file node_modules/@angular/compiler/bundles/compiler.umd.js Hunk #1 succeeded at 26295 (offset 5289 lines). Hunk #2 succeeded at 26319 (offset 5289 lines). Hunk #3 succeeded at 26330 (offset 5289 lines). patching file node_modules/@bazel/typescript/internal/build_defs.bzl Hunk #1 succeeded at 123 with fuzz 1 (offset 21 lines). Hunk #2 succeeded at 141 with fuzz 1 (offset 21 lines). Hunk #3 succeeded at 178 (offset 20 lines). Hunk #4 succeeded at 201 (offset 20 lines). Hunk #5 succeeded at 217 (offset 21 lines). patching file node_modules/@bazel/typescript/internal/tsc_wrapped/tsc_wrapped.js Hunk #1 succeeded at 396 (offset 15 lines). Patching file /Users/andrewjs/git/components/node_modules/@angular/bazel/src/ng_package/packager.js with 2 edits.. Patching file /Users/andrewjs/git/components/node_modules/@angular/compiler-cli/src/metadata/bundle_index_host.js with 1 edits.. Patching file /Users/andrewjs/git/components/node_modules/@angular/compiler-cli/src/ngtsc/entry_point/src/logic.js with 1 edits.. Patching file /Users/andrewjs/git/components/node_modules/@angular/compiler-cli/src/transformers/compiler_host.js with 1 edits.. Patching file /Users/andrewjs/git/components/node_modules/@angular/bazel/src/ngc-wrapped/index.js with 1 edits.. Patching file /Users/andrewjs/git/components/node_modules/@angular/bazel/src/ng_module.bzl with 4 edits.. Compiling @angular/core : module as esm2015 Compiling @angular/animations : module as esm2015 Compiling @angular/compiler/testing : module as esm2015 Compiling @angular/animations : main as umd Compiling @angular/compiler/testing : main as umd Compiling @angular/core/testing : module as esm2015 Compiling @angular/animations/browser : module as esm2015 Compiling @angular/common : module as esm2015 Compiling @angular/core : main as umd Compiling @angular/platform-browser : module as esm2015 Compiling @angular/common/http : module as esm2015 Compiling @angular/common/testing : module as esm2015 Compiling @angular/platform-browser-dynamic : module as esm2015 Compiling @angular/platform-browser/testing : module as esm2015 Compiling @angular/platform-browser/animations : module as esm2015 Compiling @angular/router : module as esm2015 Compiling @angular/platform-browser-dynamic/testing : module as esm2015 Compiling @angular/platform-server : module as esm2015 Compiling @angular/animations/browser/testing : module as esm2015 Compiling @angular/common/http/testing : module as esm2015 Compiling @angular/forms : module as esm2015 Compiling @angular/platform-server/init : module as esm2015 Compiling @angular/platform-server/testing : module as esm2015 Compiling @angular/router/testing : module as esm2015 Compiling @angular/animations/browser/testing : main as umd Compiling @angular/animations/browser : main as umd Compiling @angular/common/http : main as umd Compiling @angular/common : main as umd Compiling @angular/common/http/testing : main as umd Compiling @angular/forms : main as umd Compiling @angular/platform-browser : main as umd Compiling @angular/platform-server/init : main as umd Compiling @angular/core/testing : main as umd Compiling @angular/platform-browser-dynamic : main as umd Compiling @angular/platform-browser/testing : main as umd Compiling @angular/platform-browser-dynamic/testing : main as umd Compiling @angular/platform-browser/animations : main as umd Compiling @angular/platform-server : main as umd Compiling @angular/platform-server/testing : main as umd Compiling @angular/common/testing : main as umd Compiling @angular/router/testing : main as umd Compiling @angular/router : main as umd $ husky install husky - Git hooks installed ✓ Installed project dependencies. ⠋ Building release output. Building release packages... Compiling with Ivy: false Starting local Bazel server and connecting to it... Loading: 0 packages loaded Loading: 0 packages loaded Loading: 0 packages loaded Loading: 0 packages loaded Loading: 0 packages loaded Loading: 0 packages loaded Loading: 0 packages loaded Loading: 0 packages loaded Loading: 0 packages loaded [1/5] Validating package.json... [2/5] Resolving packages... warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^2.2.1" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^2.2.1" warning Resolution field "typescript@4.3.2" is incompatible with requested version "typescript@^3.2.2" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^2.2.1" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^4.0.0" warning Resolution field "https-proxy-agent@5.0.0" is incompatible with requested version "https-proxy-agent@^4.0.0" Loading: 0 packages loaded success Already up-to-date. $ node tools/postinstall/apply-patches.js && ngcc --properties module main --create-ivy-entry-points && node tools/postinstall/update-ngcc-main-fields.js Patch: /Users/andrewjs/git/components/tools/postinstall/flat_module_factory_resolution.patch has been applied already. Skipping.. Patch: /Users/andrewjs/git/components/tools/postinstall/manifest_externs_hermeticity.patch has been applied already. Skipping.. File /Users/andrewjs/git/components/node_modules/@angular/bazel/src/ng_package/packager.js is already patched. Skipping.. File /Users/andrewjs/git/components/node_modules/@angular/compiler-cli/src/metadata/bundle_index_host.js is already patched. Skipping.. File /Users/andrewjs/git/components/node_modules/@angular/compiler-cli/src/ngtsc/entry_point/src/logic.js is already patched. Skipping.. File /Users/andrewjs/git/components/node_modules/@angular/compiler-cli/src/transformers/compiler_host.js is already patched. Skipping.. File /Users/andrewjs/git/components/node_modules/@angular/bazel/src/ngc-wrapped/index.js is already patched. Skipping.. File /Users/andrewjs/git/components/node_modules/@angular/bazel/src/ng_module.bzl is already patched. Skipping.. $ husky install husky - Git hooks installed Loading: 0 packages loaded could not find dependency 'google-protobuf' of '@angular/dev-infra-private/node_modules/@bazel/worker' INFO: Repository npm instantiated at: /Users/andrewjs/git/components/WORKSPACE:51:13: in <toplevel> /private/var/tmp/_bazel_andrewjs/784c5492abc453cc085a1c5145e774ee/external/build_bazel_rules_nodejs/index.bzl:83:18: in yarn_install Repository rule yarn_install defined at: /private/var/tmp/_bazel_andrewjs/784c5492abc453cc085a1c5145e774ee/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl:795:31: in <toplevel> Loading: 0 packages loaded ERROR: An error occurred during the fetch of repository 'npm': Traceback (most recent call last): File "/private/var/tmp/_bazel_andrewjs/784c5492abc453cc085a1c5145e774ee/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 793, column 24, in _yarn_install_impl _create_build_files(repository_ctx, "yarn_install", node, repository_ctx.attr.yarn_lock, repository_ctx.attr.generate_local_modules_build_files) File "/private/var/tmp/_bazel_andrewjs/784c5492abc453cc085a1c5145e774ee/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 425, column 13, in _create_build_files fail("generate_build_file.ts failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr)) Error in fail: generate_build_file.ts failed: STDOUT: STDERR: could not find dependency 'google-protobuf' of '@angular/dev-infra-private/node_modules/@bazel/worker' ERROR: Error fetching repository: Traceback (most recent call last): File "/private/var/tmp/_bazel_andrewjs/784c5492abc453cc085a1c5145e774ee/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 793, column 24, in _yarn_install_impl _create_build_files(repository_ctx, "yarn_install", node, repository_ctx.attr.yarn_lock, repository_ctx.attr.generate_local_modules_build_files) File "/private/var/tmp/_bazel_andrewjs/784c5492abc453cc085a1c5145e774ee/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 425, column 13, in _create_build_files fail("generate_build_file.ts failed: \nSTDOUT:\n%s\nSTDERR:\n%s" % (result.stdout, result.stderr)) Error in fail: generate_build_file.ts failed: STDOUT: STDERR: could not find dependency 'google-protobuf' of '@angular/dev-infra-private/node_modules/@bazel/worker' ERROR: no such package '@npm//@bazel/protractor': generate_build_file.ts failed: STDOUT: STDERR: could not find dependency 'google-protobuf' of '@angular/dev-infra-private/node_modules/@bazel/worker' Loading: 0 packages loaded Loading: 0 packages loaded (node:14775) UnhandledPromiseRejectionWarning: Error: Command failed: bazel query --output=label "attr('tags', '\[.*release-package.*\]', //src/...) intersect kind('.*_package', //src/...)" at checkExecSyncError (child_process.js:760:11) at Object.execSync (child_process.js:833:15) at exec (/Users/andrewjs/git/components/scripts/build-packages-dist.ts:139:18) at buildReleasePackages (/Users/andrewjs/git/components/scripts/build-packages-dist.ts:72:19) at performNpmReleaseBuild (/Users/andrewjs/git/components/scripts/build-packages-dist.ts:48:10) at /Users/andrewjs/git/components/.ng-dev/release.ts:96:12 at Generator.next (<anonymous>) at fulfilled (/Users/andrewjs/git/components/.ng-dev/release.ts:5:58) (Use `node --trace-warnings ...` to show where the warning was created) (node:14775) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:14775) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ✘ Could not build release output. Please check output above. ``` PR Close #271
1 parent 630159e commit 7b66fb5

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

ng-dev/release/publish/actions.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,18 @@ export abstract class ReleaseAction {
377377
this.git.run(['checkout', '-q', 'FETCH_HEAD', '--detach']);
378378
}
379379

380+
/** Installs all Yarn dependencies in the current branch. */
381+
protected async installDependenciesForCurrentBranch() {
382+
const nodeModulesDir = join(this.projectDir, 'node_modules');
383+
// Note: We delete all contents of the `node_modules` first. This is necessary
384+
// because Yarn could preserve extraneous/outdated nested modules that will cause
385+
// unexpected build failures with the NodeJS Bazel `@npm` workspace generation.
386+
// This is a workaround for: https://github.com/yarnpkg/yarn/issues/8146. Even though
387+
// we might be able to fix this with Yarn 2+, it is reasonable ensuring clean node modules.
388+
await fs.rm(nodeModulesDir, {force: true, recursive: true, maxRetries: 3});
389+
await invokeYarnInstallCommand(this.projectDir);
390+
}
391+
380392
/**
381393
* Creates a commit for the specified files with the given message.
382394
* @param message Message for the created commit
@@ -585,14 +597,14 @@ export abstract class ReleaseAction {
585597

586598
// Checkout the publish branch and build the release packages.
587599
await this.checkoutUpstreamBranch(publishBranch);
600+
// Install the project dependencies for the publish branch.
601+
await this.installDependenciesForCurrentBranch();
588602

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

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ export class CutStableAction extends ReleaseAction {
6767
// NPM dist tag for new packages part of the released major, nor would it be acceptable
6868
// to skip the LTS tag for packages which are no longer part of the new major.
6969
await this.checkoutUpstreamBranch(previousPatch.branchName);
70-
await invokeYarnInstallCommand(this.projectDir);
70+
await this.installDependenciesForCurrentBranch();
71+
7172
await invokeSetNpmDistCommand(ltsTagForPatch, previousPatch.version);
7273
}
7374

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class TagRecentMajorAsLatest extends ReleaseAction {
3434
override async perform() {
3535
await this.updateGithubReleaseEntryToStable(this.active.latest.version);
3636
await this.checkoutUpstreamBranch(this.active.latest.branchName);
37-
await invokeYarnInstallCommand(this.projectDir);
37+
await this.installDependenciesForCurrentBranch();
3838
await invokeSetNpmDistCommand('latest', this.active.latest.version);
3939
}
4040

0 commit comments

Comments
 (0)