Skip to content

Commit c385e74

Browse files
josephperrottatscott
authored andcommitted
build: rely on engines to prevent using npm for dependency install (angular#41477)
Rather than relying on a preinstall script, set `engine-strict` to `true` in a project `.npmrc` file, relying on the `engines` having `npm` set to note that yarn should be used instead. --- Output from `npm install` changes from: ``` $ npm install > [email protected] preinstall /usr/local/account/js/angular > node tools/yarn/check-yarn.js /usr/local/account/js/angular/tools/yarn/check-yarn.js:12 throw new Error( ^ Error: Please use Yarn instead of NPM to install dependencies. See: https://yarnpkg.com/lang/en/docs/install/ at Object.<anonymous> (/usr/local/account/js/angular/tools/yarn/check-yarn.js:12:9) at Module._compile (internal/modules/cjs/loader.js:778:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Function.Module.runMain (internal/modules/cjs/loader.js:831:12) at startup (internal/bootstrap/node.js:283:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! [email protected] preinstall: `node tools/yarn/check-yarn.js` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the [email protected] preinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /usr/local/account/.npm/_logs/2021-04-06T22_54_02_292Z-debug.log ``` to ``` $ npm install npm ERR! code ENOTSUP npm ERR! notsup Unsupported engine for [email protected]: wanted: {"node":">=10.19.0 <13.0.0","yarn":">=1.22.4 <2","npm":"Plesae use yarn instead of NPM to install dependencies"} (current: {"node":"10.20.1","npm":"6.14.4"}) npm ERR! notsup Not compatible with your version of node/npm: [email protected] npm ERR! notsup Not compatible with your version of node/npm: [email protected] npm ERR! notsup Required: {"node":">=10.19.0 <13.0.0","yarn":">=1.22.4 <2","npm":"Plesae use yarn instead of NPM to install dependencies"} npm ERR! notsup Actual: {"npm":"6.14.4","node":"10.20.1"} npm ERR! A complete log of this run can be found in: npm ERR! /usr/local/account/.npm/_logs/2021-04-06T22_53_23_912Z-debug.log ``` PR Close angular#41477
1 parent ec27bd4 commit c385e74

File tree

7 files changed

+10
-20
lines changed

7 files changed

+10
-20
lines changed

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict = true

aio/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict = true

aio/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"author": "Angular",
77
"license": "MIT",
88
"scripts": {
9-
"preinstall": "node ../tools/yarn/check-yarn.js",
109
"postinstall": "node tools/cli-patches/patch.js",
1110
"aio-use-local": "node tools/ng-packages-installer overwrite . --debug --force --build-packages",
1211
"aio-use-npm": "node tools/ng-packages-installer restore .",
@@ -86,7 +85,8 @@
8685
"//engines-comment": "Keep this in sync with /package.json and /aio/tools/examples/shared/package.json",
8786
"engines": {
8887
"node": ">=10.19.0 <16.0.0",
89-
"yarn": ">=1.22.4 <2"
88+
"yarn": ">=1.22.4 <2",
89+
"npm": "Please use yarn instead of NPM to install dependencies"
9090
},
9191
"private": true,
9292
"dependencies": {

aio/tools/examples/shared/.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
engine-strict = true

aio/tools/examples/shared/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"http-server": "http-server",
88
"protractor": "protractor",
99
"webdriver:update": "node ../../../../scripts/webdriver-manager-update.js",
10-
"preinstall": "node ../../../../tools/yarn/check-yarn.js",
1110
"postinstall": "yarn webdriver:update",
1211
"sync-deps": "node sync-boilerplate-dependencies"
1312
},
1413
"//engines-comment": "Keep this in sync with /package.json and /aio/package.json",
1514
"engines": {
1615
"node": ">=10.19.0 <16.0.0",
17-
"yarn": ">=1.21.1 <2"
16+
"yarn": ">=1.21.1 <2",
17+
"npm": "Please use yarn instead of NPM to install dependencies"
18+
1819
},
1920
"keywords": [],
2021
"author": "",

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"//engines-comment": "Keep this in sync with /aio/package.json and /aio/tools/examples/shared/package.json",
1010
"engines": {
1111
"node": ">=10.19.0 <16.0.0",
12-
"yarn": ">=1.22.4 <2"
12+
"yarn": ">=1.22.4 <2",
13+
"npm": "Please use yarn instead of NPM to install dependencies"
1314
},
1415
"repository": {
1516
"type": "git",
@@ -31,7 +32,6 @@
3132
"// 2": "Find the usage you are looking for with:",
3233
"// 3": "yarn ng-dev --help",
3334
"/ ": "",
34-
"preinstall": "node tools/yarn/check-yarn.js",
3535
"postinstall": "node scripts/webdriver-manager-update.js && node --preserve-symlinks --preserve-symlinks-main ./tools/postinstall-patches.js",
3636
"prepare": "husky install",
3737
"test-ivy-aot": "bazelisk test --config=ivy --build_tag_filters=-no-ivy-aot,-fixme-ivy-aot --test_tag_filters=-no-ivy-aot,-fixme-ivy-aot",

tools/yarn/check-yarn.js

-14
This file was deleted.

0 commit comments

Comments
 (0)