Skip to content

Commit edad15e

Browse files
crisbetoVivian Hu
authored andcommitted
build: add check when running npm install (#14021)
Even though we're using `yarn` for everything, it's still easy to fall into the old habit of running `npm i` which could mess up the `node_modules` and generate a new lock file. These changes add a script that throws an error when trying to `npm install`, similar to angular/angular.
1 parent 108ce2c commit edad15e

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"api": "gulp api-docs",
2525
"breaking-changes": "gulp breaking-changes",
2626
"gulp": "gulp",
27-
"stage-release": "bash ./tools/release/stage-release-bin.sh"
27+
"stage-release": "bash ./tools/release/stage-release-bin.sh",
28+
"preinstall": "node ./tools/npm/check-npm.js"
2829
},
2930
"version": "7.0.3",
3031
"requiredAngularVersion": ">=7.0.0",

tools/angular_material_setup_workspace.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def angular_material_setup_workspace():
1313
It creates some additional Bazel external repositories that are used internally
1414
to build Angular Material
1515
"""
16-
# Use Bazel managed node modules. See more below:
16+
# Use Bazel managed node modules. See more below:
1717
# https://github.com/bazelbuild/rules_nodejs#bazel-managed-vs-self-managed-dependencies
1818
# Note: The repository_rule name is `@matdeps` so it does not conflict with the `@npm` repository
1919
# name downstream when building Angular Material from source. In the future when Angular + Bazel
@@ -22,5 +22,7 @@ def angular_material_setup_workspace():
2222
yarn_install(
2323
name = "matdeps",
2424
package_json = "@angular_material//:package.json",
25+
# Ensure that the script is available when running `postinstall` in the Bazel sandbox.
26+
data = ["@angular_material//:tools/npm/check-npm.js"],
2527
yarn_lock = "@angular_material//:yarn.lock",
2628
)

tools/npm/check-npm.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
if (process.env.npm_execpath.indexOf('yarn') === -1) {
10+
console.error('Please use Yarn instead of NPM to install dependencies. ' +
11+
'See: https://yarnpkg.com/lang/en/docs/install/');
12+
process.exit(1);
13+
}

0 commit comments

Comments
 (0)