From a640f490011d3a78e1349bdf49ed938af095693a Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Wed, 30 Jan 2019 18:25:35 +0000 Subject: [PATCH] Treat the ignore-scripts in yarnrc as a synonym to the cli arg (#6983) * Treat the ignore-scripts in yarnrc as a synonym to the cli arg Allow users to specify `ignore-scripts true` in the `.yarnrc` as specified by the `npm-config`. It is treated the same as if the user specifies `--ignore-scripts true` in the `.yarnrc` or passes `--ignore-scripts` as cli arg. * Update Changelog * Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ __tests__/commands/_helpers.js | 1 + __tests__/commands/check.js | 1 + __tests__/commands/install/integration.js | 8 ++++++++ __tests__/commands/install/offline-mirror.js | 5 +++++ .../install/ignore-scripts-by-yarnrc/.yarnrc | 2 ++ .../mirror-for-offline/dep-a-1.0.0.tgz | Bin 0 -> 1005 bytes .../mirror-for-offline/dep-b-1.0.0.tgz | Bin 0 -> 1001 bytes .../mirror-for-offline/dep-c-1.0.0.tgz | Bin 0 -> 947 bytes .../ignore-scripts-by-yarnrc/package.json | 5 +++++ .../ignore-scripts-by-yarnrc/yarn.lock | 18 ++++++++++++++++++ src/cli/commands/install.js | 3 +-- src/config.js | 2 ++ src/integrity-checker.js | 3 ++- 14 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 __tests__/fixtures/install/ignore-scripts-by-yarnrc/.yarnrc create mode 100644 __tests__/fixtures/install/ignore-scripts-by-yarnrc/mirror-for-offline/dep-a-1.0.0.tgz create mode 100644 __tests__/fixtures/install/ignore-scripts-by-yarnrc/mirror-for-offline/dep-b-1.0.0.tgz create mode 100644 __tests__/fixtures/install/ignore-scripts-by-yarnrc/mirror-for-offline/dep-c-1.0.0.tgz create mode 100644 __tests__/fixtures/install/ignore-scripts-by-yarnrc/package.json create mode 100644 __tests__/fixtures/install/ignore-scripts-by-yarnrc/yarn.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c1fb6a220..0b78a703e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa [#6951](https://github.com/yarnpkg/yarn/pull/6951) - [**John-David Dalton**](https://twitter.com/jdalton) +- Packages won't be auto-unplugged anymore if `ignore-scripts` is set in the yarnrc file + + [#6983](https://github.com/yarnpkg/yarn/pull/6983) - [**Micha Reiser**](https://github.com/MichaReiser) + ## 1.14.0 - Improves PnP compatibility with Node 6 diff --git a/__tests__/commands/_helpers.js b/__tests__/commands/_helpers.js index 1bd4d9f590..b7c641903b 100644 --- a/__tests__/commands/_helpers.js +++ b/__tests__/commands/_helpers.js @@ -85,6 +85,7 @@ export function makeConfigFromDirectory(cwd: string, reporter: Reporter, flags: { binLinks: !!flags.binLinks, cwd, + ignoreScripts: flags.ignoreScripts, globalFolder: flags.globalFolder || path.join(cwd, '.yarn-global'), cacheFolder: flags.cacheFolder || path.join(cwd, '.yarn-cache'), linkFolder: flags.linkFolder || path.join(cwd, '.yarn-link'), diff --git a/__tests__/commands/check.js b/__tests__/commands/check.js index f210e3a541..6a6b2d5d08 100644 --- a/__tests__/commands/check.js +++ b/__tests__/commands/check.js @@ -215,6 +215,7 @@ test.concurrent('--integrity should fail if --ignore-scripts is changed', async async (config, reporter, install, getStdout): Promise => { let thrown = false; try { + config.ignoreScripts = false; await checkCmd.run(config, reporter, {integrity: true, ignoreScripts: false}, []); } catch (e) { thrown = true; diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 116f59c4c4..e3df495d88 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -1139,3 +1139,11 @@ test('install will not warn for missing optional peer dependencies', () => const warningMessage = messageParts.every(part => stdout.includes(part)); expect(warningMessage).toBe(false); })); + +test('install skips the scripts if the yarnrc specifies skip-scripts true', () => + runInstall({}, 'ignore-scripts-by-yarnrc', (config, reporter, install, getStdout) => { + const stdout = getStdout(); + + const ignoredScriptsMessage = reporter.lang('ignoredScripts'); + expect(stdout).toMatch(ignoredScriptsMessage); + })); diff --git a/__tests__/commands/install/offline-mirror.js b/__tests__/commands/install/offline-mirror.js index 176f76d356..843a761674 100644 --- a/__tests__/commands/install/offline-mirror.js +++ b/__tests__/commands/install/offline-mirror.js @@ -35,6 +35,7 @@ test.concurrent( // enable packing of built artifacts config.packBuiltPackages = true; + config.ignoreScripts = false; // after first run we observe both package and global side effects let reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd)); @@ -64,6 +65,7 @@ test.concurrent( // enable packing of built artifacts config.packBuiltPackages = true; + config.ignoreScripts = false; // after first run we observe package side effects let reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd)); @@ -89,6 +91,8 @@ test.concurrent('install without pack-built-packages should keep running install expect(await fs.exists(path.join(config.cwd, 'node_modules', 'dep-a', 'module-a-build.log'))).toEqual(false); expect(await fs.exists(path.join(config.cwd, 'module-a-build.log'))).toEqual(false); + config.ignoreScripts = false; + // after first run we observe both package and global side effects let reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd)); await reinstall.init(); @@ -113,6 +117,7 @@ test.concurrent('removing prebuilt package .tgz file falls back to running scrip // enable packing of built artifacts config.packBuiltPackages = true; + config.ignoreScripts = false; // after first run we observe both package and global side effects let reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd)); diff --git a/__tests__/fixtures/install/ignore-scripts-by-yarnrc/.yarnrc b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/.yarnrc new file mode 100644 index 0000000000..13e317bfda --- /dev/null +++ b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/.yarnrc @@ -0,0 +1,2 @@ +yarn-offline-mirror "./mirror-for-offline" +ignore-scripts true \ No newline at end of file diff --git a/__tests__/fixtures/install/ignore-scripts-by-yarnrc/mirror-for-offline/dep-a-1.0.0.tgz b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/mirror-for-offline/dep-a-1.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000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YfQ~$|Lbu7c)?37^D zr-a?2ivR6L{T%o4zh#i6__r-;*ZjW^Xo_W;kvqobGidsl91ogDO5~&Pc#x*?=J zZT9Gr%NqXwX05g{$0qzQ%K#bwj_lX`zYjc!|552(6*sOnITAG3gCyEPQ5*p*D*9tv5f1|k*bH<8zF>3Sz8 z;o|>zkOg7dIw5A|F3(Q+2Nn>l!s` X)TmLTMvWRZc8 literal 0 HcmV?d00001 diff --git a/__tests__/fixtures/install/ignore-scripts-by-yarnrc/mirror-for-offline/dep-c-1.0.0.tgz b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/mirror-for-offline/dep-c-1.0.0.tgz new file mode 100644 index 0000000000000000000000000000000000000000..0b12d36e324b6310e1372a019bad6217ad250d96 GIT binary patch literal 947 zcmV;k15ErMiwFSKJ^@$&1MOJdZre5#_O+hkR2Ov;Br>TV%5LCcU9q77IxJX*4MPy1 zigc2wmMM*rTnDLv-tLw58hfFUvJ|_vx6Fp^Vk3bU5fu$cqYQ74Ws8z9t`M+?R~h-C?7UIaphlH>I-9Blra>8rqF z`yT=A!fhP&Y1e0z65sC{k|`C#Sg+?fl(>dXAS~h`_NnVLc`(vdTrkghJ;!jm@aF8B zmp{IGefIOWRwz(fr2JDWV%QE`NQ*bWS`m(9H}X@kZEDzVL&rSrJB(4^aa^jxsd=8n ze9-rd&pl-SE7V!v*<~M1{(qF`;qRk!)uw-*{6S_|$bX00P7AzU2G!sT&;Mrr&mVOl z<`Isqclq}EkmJEz_aEv%^*~NIaa?IfnVf&ma~)m(_km67zsuNC{b!`NMrF5q%v-AL zR9E)>qsjm6XZ;LK{(o$(uK&Kx7V_U^l(c~CBA7*d;rVZLj*bjCf;fLEL~t)pJBBd| zL_ zb6JE&$l>iMNZwAvfq+9$^(?Oyh2vnDCHSJgtWk$`aCvojI!AXp@D&uI#1*E2xGjgs zi+tJRCP?yCF75W;+baI+ED*sE9)|H4qY22js91qTDL6b_r)e^oj?*xW$^M;(tX#FB-&f;qg+Y>3Zl}iN zbd5r~tp7D5YeCAl^Nl^J|8x64>bWxinZvaH?**Iazh}EE^uPPW{!dP-FXwl?Rf4Nm z3A;s;|J%>{8J^OA`CTmJzvrs`pVt4~!%!+?@?ePO3os+hPD1loQ4!{$h%=SJ>dvb> z3Yg){ zt5F`tsLWM>lj_DapoWt~mgYswW-%o!W<_*X7kZGi9_Uh^_JhC{bU*wT}KpF z=>I1JxQ#y6(tqER`R@~IYyIB`Hqw8WuH66si~qmQTK|8ktN#-07?1kD^{k)aDg7sm zEaX2UuGas(K;Um>EbyRxleZ78_aZLvyEws%dmbLNtL4DSbr~l``xvTC@aK+KLqkJD VLqkJDLqlV8`~^``-**5g004VV>nZ>M literal 0 HcmV?d00001 diff --git a/__tests__/fixtures/install/ignore-scripts-by-yarnrc/package.json b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/package.json new file mode 100644 index 0000000000..c0d4b7cf22 --- /dev/null +++ b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "dep-a": "1.0.0" + } +} diff --git a/__tests__/fixtures/install/ignore-scripts-by-yarnrc/yarn.lock b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/yarn.lock new file mode 100644 index 0000000000..b044b0d81d --- /dev/null +++ b/__tests__/fixtures/install/ignore-scripts-by-yarnrc/yarn.lock @@ -0,0 +1,18 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 +dep-a@1.0.0: + version "1.0.0" + resolved dep-a-1.0.0.tgz#63970c7301ec8a5d37dac4e454fff354f31c31b4 + integrity sha1-Y5cMcwHsil032sTkVP/zVPMcMbQ= + dependencies: + dep-b "1.0.0" +dep-b@1.0.0: + version "1.0.0" + resolved dep-b-1.0.0.tgz#569c27a4e30b1679eaa7e2299e741f30a7f70926 + integrity sha1-VpwnpOMLFnnqp+IpnnQfMKf3CSY= + dependencies: + dep-c "1.0.0" +dep-c@1.0.0: + version "1.0.0" + resolved dep-c-1.0.0.tgz#100eef2bf00fc31b596542fb9af18186e37716cc + integrity sha1-EA7vK/APwxtZZUL7mvGBhuN3Fsw= diff --git a/src/cli/commands/install.js b/src/cli/commands/install.js index e72e2b6924..962520d48f 100644 --- a/src/cli/commands/install.js +++ b/src/cli/commands/install.js @@ -56,7 +56,6 @@ type Flags = { har: boolean, ignorePlatform: boolean, ignoreEngines: boolean, - ignoreScripts: boolean, ignoreOptional: boolean, linkDuplicates: boolean, force: boolean, @@ -685,7 +684,7 @@ export class Install { emoji.get('hammer'), ); - if (this.flags.ignoreScripts) { + if (this.config.ignoreScripts) { this.reporter.warn(this.reporter.lang('ignoredScripts')); } else { await this.scripts.init(flattenedTopLevelPatterns); diff --git a/src/config.js b/src/config.js index e09d8e5b34..77de5c4889 100644 --- a/src/config.js +++ b/src/config.js @@ -416,6 +416,8 @@ export default class Config { this.plugnplayShebang = String(this.getOption('plugnplay-shebang') || '') || '/usr/bin/env node'; this.plugnplayBlacklist = String(this.getOption('plugnplay-blacklist') || '') || null; + this.ignoreScripts = opts.ignoreScripts || Boolean(this.getOption('ignore-scripts', false)); + this.workspacesEnabled = this.getOption('workspaces-experimental') !== false; this.workspacesNohoistEnabled = this.getOption('workspaces-nohoist-experimental') !== false; diff --git a/src/integrity-checker.js b/src/integrity-checker.js index 3f4ab4dbf1..c1f7500d26 100644 --- a/src/integrity-checker.js +++ b/src/integrity-checker.js @@ -237,7 +237,8 @@ export default class InstallationIntegrityChecker { if (flags.flat) { result.flags.push('flat'); } - if (flags.ignoreScripts) { + + if (this.config.ignoreScripts) { result.flags.push('ignoreScripts'); } if (this.config.focus) {