From adc1037d7027676527000e235139825afd657613 Mon Sep 17 00:00:00 2001 From: Jeff Valore Date: Wed, 30 Oct 2019 18:43:24 -0400 Subject: [PATCH] fix(run): add cwd/node_modules/.bin to run command search path (#7151) * fix(run): change run command to check cwd/node_modules/.bin for commands. Fixes run in workspaces. This fixes a bug that was introduced in #6850 where the bin path was being built only from `config.lockfileFolder`. However in workspaces, bins may not be hoisted to the workspace root, causing bins to not be found. This change adds `config.cwd` to the bin search path, so the `yarn run` command will look in a workspace package's node_modules, as well as the workspace root. fixes #7126 * modify chagelog --- CHANGELOG.md | 4 ++ __tests__/commands/run.js | 10 ++++ .../package.json.bin | 56 ++++++++++++++++++ .../GET/registry.yarnpkg.com/is-pnp.bin | 18 ++++++ .../is-pnp/-/is-pnp-1.0.2.tgz.bin | Bin 0 -> 2033 bytes .../run/nohoist-workspace/package.json | 5 ++ .../packages/pkg1/node_modules/.bin/cat-names | 0 .../packages/pkg1/package.json | 1 + src/cli/commands/run.js | 1 + 9 files changed, 95 insertions(+) create mode 100644 __tests__/fixtures/request-cache/GET/gitlab.com/leanlabsio/kanban/raw/f139bd887dea8e48c46fd7fcfe42b5ffc53d79dd/package.json.bin create mode 100644 __tests__/fixtures/request-cache/GET/registry.yarnpkg.com/is-pnp.bin create mode 100644 __tests__/fixtures/request-cache/GET/registry.yarnpkg.com/is-pnp/-/is-pnp-1.0.2.tgz.bin create mode 100644 __tests__/fixtures/run/nohoist-workspace/package.json rename __tests__/fixtures/run/{workspace => nohoist-workspace}/packages/pkg1/node_modules/.bin/cat-names (100%) create mode 100644 __tests__/fixtures/run/nohoist-workspace/packages/pkg1/package.json diff --git a/CHANGELOG.md b/CHANGELOG.md index e8abad40eb..8d4f72db86 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa ## Master +- Change run command to check cwd/node_modules/.bin for commands. Fixes run in workspaces. + + [#7151](https://github.com/yarnpkg/yarn/pull/7151) - [**Jeff Valore**](https://twitter.com/codingwithspike) + ## 1.19.1 **Important:** This release contains a cache bump. It will cause the very first install following the upgrade to take slightly more time, especially if you don't use the [Offline Mirror](https://yarnpkg.com/blog/2016/11/24/offline-mirror/) feature. After that everything will be back to normal. diff --git a/__tests__/commands/run.js b/__tests__/commands/run.js index 2bad11ef51..35a1221e56 100644 --- a/__tests__/commands/run.js +++ b/__tests__/commands/run.js @@ -207,6 +207,16 @@ test('adds workspace root node_modules/.bin to path when in a workspace', (): Pr expect(envPaths).toContain(path.join(config.cwd, 'packages', 'pkg1', 'node_modules', '.bin')); })); +test('adds cwd node_modules/.bin to path when in a workspace usig nohoist', (): Promise => + runRunInWorkspacePackage('packages/pkg1', ['env'], {}, 'nohoist-workspace', (config, reporter): ?Promise => { + const logEntry = reporter.getBuffer().find(entry => entry.type === 'log'); + const parsedLogData = JSON.parse(logEntry ? logEntry.data.toString() : '{}'); + const envPaths = (parsedLogData.PATH || parsedLogData.Path).split(path.delimiter); + + expect(envPaths).toContain(path.join(config.cwd, 'node_modules', '.bin')); + expect(envPaths).toContain(path.join(config.cwd, 'packages', 'pkg1', 'node_modules', '.bin')); + })); + test('runs script with custom script-shell', (): Promise => runRunWithCustomShell('/usr/bin/dummy', ['start'], {}, 'script-shell', async (config): ?Promise => { const pkg = await fs.readJson(path.join(config.cwd, 'package.json')); diff --git a/__tests__/fixtures/request-cache/GET/gitlab.com/leanlabsio/kanban/raw/f139bd887dea8e48c46fd7fcfe42b5ffc53d79dd/package.json.bin b/__tests__/fixtures/request-cache/GET/gitlab.com/leanlabsio/kanban/raw/f139bd887dea8e48c46fd7fcfe42b5ffc53d79dd/package.json.bin new file mode 100644 index 0000000000..e0be38d90e --- /dev/null +++ b/__tests__/fixtures/request-cache/GET/gitlab.com/leanlabsio/kanban/raw/f139bd887dea8e48c46fd7fcfe42b5ffc53d79dd/package.json.bin @@ -0,0 +1,56 @@ +HTTP/1.1 200 OK +Server: nginx +Date: Wed, 27 Mar 2019 12:51:12 GMT +Content-Type: text/plain; charset=utf-8 +Content-Length: 1181 +Cache-Control: max-age=3600, public +Content-Disposition: inline +Etag: W/"78309fbf8af4479c47eca65b0c5e3f51" +X-Content-Type-Options: nosniff +X-Frame-Options: DENY +X-Request-Id: kTsEGIR9zSa +X-Runtime: 0.099649 +X-Ua-Compatible: IE=edge +X-Xss-Protection: 1; mode=block +Strict-Transport-Security: max-age=31536000 +Content-Security-Policy: object-src 'none'; worker-src https://assets.gitlab-static.net https://gl-canary.freetls.fastly.net https://gitlab.com blob:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://assets.gitlab-static.net https://gl-canary.freetls.fastly.net https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://www.gstatic.com/recaptcha/ https://apis.google.com; style-src 'self' 'unsafe-inline' https://assets.gitlab-static.net https://gl-canary.freetls.fastly.net; img-src * data: blob:; frame-src 'self' https://www.google.com/recaptcha/ https://www.recaptcha.net/ https://content.googleapis.com https://content-compute.googleapis.com https://content-cloudbilling.googleapis.com https://content-cloudresourcemanager.googleapis.com https://*.codesandbox.io; frame-ancestors 'self'; connect-src 'self' https://assets.gitlab-static.net https://gl-canary.freetls.fastly.net wss://gitlab.com https://sentry.gitlab.net https://customers.gitlab.com https://snowplow.trx.gitlab.net + +{ + "name": "kanban", + "version": "0.0.1", + "repository": "gitlab.com/leanlabsio/kanban", + "scripts": { + "install": "npm install", + "build": "grunt build", + "watch": "grunt watch" + }, + "devDependencies": { + "grunt": "~0.4.1", + "grunt-cli": "~0.1.13", + "grunt-contrib-copy": "^0.5.0", + "grunt-contrib-concat": "~0.5.0", + "grunt-contrib-watch": "~0.5.3", + "grunt-contrib-uglify": "~0.7.0", + "grunt-sass": "1.0.0", + "grunt-contrib-connect": "~0.8.0", + "grunt-connect-proxy": "~0.1.11" + }, + "dependencies": { + "angular": "=1.5.6", + "angular-lodash": "https://github.com/EMSSConsulting/angular-lodash.git#68a726c", + "foundation-sites": "5.5.2", + "angular-foundation": "https://github.com/pineconellc/angular-foundation.git#8f3f260", + "angular-loading-bar": "=0.5.2", + "angular-storage": "=0.0.6", + "angular-ui-router": "=0.3.0", + "angularjs-datepicker": "=0.2.15", + "font-awesome": "=4.6.3", + "markdown-it": "=5.0.2", + "markdown-it-emoji": "=1.1.0", + "ng-sortable": "=1.3.6", + "sass-flex-mixin": "=1.0.3", + "lodash": "=4.13.1", + "twemoji": "=2.1.0", + "angular-file-upload": "=2.3.4" + } +} diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/is-pnp.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/is-pnp.bin new file mode 100644 index 0000000000..73976105f8 --- /dev/null +++ b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/is-pnp.bin @@ -0,0 +1,18 @@ +HTTP/1.1 200 OK +Date: Wed, 27 Mar 2019 12:49:49 GMT +Content-Type: application/vnd.npm.install-v1+json +Content-Length: 4072 +Connection: keep-alive +Set-Cookie: __cfduid=d2e7739722b1e2621b032ee7a09984edd1553690988; expires=Thu, 26-Mar-20 12:49:48 GMT; path=/; domain=.registry.yarnpkg.com; HttpOnly +CF-Cache-Status: REVALIDATED +Cache-Control: max-age=300 +CF-Ray: 4be17c86d97f56c3-IAD +Accept-Ranges: bytes +ETag: "49fffc656197ace1f624570132931c23" +Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" +Last-Modified: Thu, 01 Nov 2018 01:11:09 GMT +Vary: accept-encoding, accept +x-amz-meta-rev: 3-72d30e72712ca5e8a55f6613d7a30236 +Server: cloudflare + +{"versions":{"1.0.0":{"name":"is-pnp","version":"1.0.0","bin":{"is-pnp":"./bin.js"},"_hasShrinkwrap":false,"directories":{},"dist":{"shasum":"47d3d7151df242eb7ca4768fc2e7f6228871899a","integrity":"sha512-Lx0Sh5h20HtLz+xnlh4NRhQ6w231tGN4yuU3oBi6vn7oSbiIk2V4sqoIn00bczm9ojwkFPzzFUeSOIKEgYpszA==","tarball":"https://registry.npmjs.org/is-pnp/-/is-pnp-1.0.0.tgz","fileCount":5,"unpackedSize":2268,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb2lGmCRA9TVsSAnZWagAARHYP/1botUA//2RoqJEP3nHB\nnQ0G1qhSYL685aLgZTWJW9pS3ucPzxxeofbnByOsbSjUqycwsHBqL/DDeYsq\nz3b0dmfcfESK+CSafYECSnj8kPJH5N5VU2UXs+A+wLEM0D0nSe4wfJLVptA0\nrOpeYrkfwX8ZC1EGLGvQM4cMqpk3Ji6RBZHtD0U/ttYR3A0vP5P76oO2/tBl\n3QSK3nJSpU83OkMBPVY3hnDrGkCjJqwvcqWoWUG0/BtHS5KYD99yrxFAzT5f\nMhtqCZiediDcGtrMhP5b0VAkqdrwFPg/tZPpgqYCevR+2ipWhkxhD0Z4yyx1\n2AuJnEoQKRiBiFPIv5aiJZD9Jj00iey4tdQ1NcXnRtAA16Lo0t4MX/OnkyJW\nBfcSd795mVpe4AO9u6bqMDZfkQrBRunxa7OKKCEXUGihm0YNtTWKat5ym1ia\n9H9Bwlgm3GoFAuHQMu07ZEwidLpWoQfjrTUOufw+/rKNSIRoMNuL3Z/8i4Hj\nazYRMgdzb9rkf6+F7LLJKnyZaDY/bS/KIb61LdkfkX8JCcKUfhVAd5KIvI4e\nAwLAUfHwWM2u2smbexFzvgvXnNFmVrcCGBbMcIrQ+JfiJ+izFVJ7YyLY+Fpt\nwxbV0Vug6gyYDyDtjFCdeL2wFmgR3+nASXWFY4CZ+ZoFX+ontSZ4U5b9PTIs\n1ojq\r\n=DAoM\r\n-----END PGP SIGNATURE-----\r\n"},"engines":{"node":">=6"}},"1.0.1":{"name":"is-pnp","version":"1.0.1","bin":{"is-pnp":"./sources/cli.js"},"_hasShrinkwrap":false,"directories":{},"dist":{"shasum":"ec0e4e443287214ce90bcb6fcd112d20de51f120","integrity":"sha512-uwFQ9SabYoNJwZnDqHUs+WTPvegmoLHjVQqkX4+MiKSjhRBRk+n/zKBAex4yvWnzbN352W7FUuYX8L5yEVmiVA==","tarball":"https://registry.npmjs.org/is-pnp/-/is-pnp-1.0.1.tgz","fileCount":5,"unpackedSize":2276,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb2lJICRA9TVsSAnZWagAAX2IP/jE0+3aAdO7cu9DXNJnb\njoi3rDo8CRfARhWbJRhUj7omDxeP37U3dIIkK69AL8XZSPPUQ8o2uH1AOjZB\niI8cp0IX4bgalRXzEWPj3v8l3z6/BwJoUXy7N5ugdxron+AYj4kS4I1jI6Pa\nUo3z096sc8zAgXFE00RiKwUBGNw+4xpg0yVri/vXpezsahi8r4qZbrc9/hr3\nWzoIK6GwQnGpn5FEhdiuPbB0QiZvalYHn5v2IWtMpQG4ed6jM/vSBAqKqkFv\n95McUD13wz7iJ59BaJHwbypD/WFWz34ZBPZ8QpONk6UAJ2IZwh6J2Wj44k7a\nNtiEj3xo3A5stikfELI//H0AruTI6sSI++EJ8YvHQUj73s6kG0Z/FzPptgKp\nKYLSqXNAC/zHiId1s7uj+jsCLXIm4G2bPQUTsDMfejDS6TfjAVO2COxRF34q\ncLGzYFL1/R+/hO4ckoLl7vz6Vm/zSlMaxZPDUFDy8d0ScxHZOL+760cdIhjT\nr1XGyXAmyjGLWTHvA6sE5X0H0PgghQErsLYXi679KBdnZjN2+Xcmv0pNIqbg\nwS7SBjV+KGpc1PnwtZdfvZcegvY+252zsBvRye9/hcQ0Rdmetbod8XicA3Bw\nuTLC2N9opHeTI7a9bKrACXkSApJftjzYSfnycb27r9bgIAY6BeNhr7JFEMKV\nnxUD\r\n=8Blc\r\n-----END PGP SIGNATURE-----\r\n"},"engines":{"node":">=6"}},"1.0.2":{"name":"is-pnp","version":"1.0.2","bin":{"is-pnp":"./sources/cli.js"},"_hasShrinkwrap":false,"directories":{},"dist":{"shasum":"cbe5d6ad751897822fd92539ac5cfa37c04f3852","integrity":"sha512-BzoewUq0EZFJYKlYpObv2xRdTRJQXwMLbk2Y5l8Dhl0EQGPhdPrSdBlQaAT46gIKjAkNBNScDiUDbuBCTDNCsQ==","tarball":"https://registry.npmjs.org/is-pnp/-/is-pnp-1.0.2.tgz","fileCount":5,"unpackedSize":2282,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb2lKpCRA9TVsSAnZWagAAkFcP+QHfioEIu01ww57y/Jnw\neOtM4JPvx0hDMKxMBKSyvVHmjZKwqxvkAnqdyybHts7i6auvuuMKDO43oaRO\n5GY5i/u29arwBKnPgeVrC6TUnbVxiSP4KBtfzRs3YCXbQ0MfSPmXiH4nzzi/\ngWeNGutgCAbefJjB0eahVCUgO7DL+sM8kEt2iNSDM1gKUDSVq5yvsZD20tX+\n/60eLG4xtz/2zXDKjoqo+DZtvW9kdLJ6TlvbDU1mt1OBSzkTiakIe1XXymVT\n+gRC0QGKGMP+YJG+VothHez/JAagl/92c/JDsb54HkW/OkUKCHFyUAw0P3h1\n46p0vEr54rHa7wT6O0fKg7q+MN1mMOKR3wO258LQW20n+DQJK1hxcJOkk+xf\n6iOa2d6Ywox9yT9B/V555BEZ2fYbnNb4gw+oo3/YyJcZ1Ooadt5kvEyDb67+\ntOaOMBXZh7/FR8EghwBBqlOndWCD4OQYVXVCwIdf/PFyUtB1+Obd4/1H+Dkw\nmg01pi7jYHG8mKLIMNdjggWi966nJ3fZqBDLW0eRtFzCbe+8VSOPKGRSHHnI\n99SD9oY/dgmimcakZ3hInuGlMGf0UrSLjHwi24y0ae1O0AlnQz0bXU0qHAH2\nH/Npr3zjOcAULwvHqtu2l1mNv/PX8GtafyybiMaXBcERearcUN/48tbvcbFX\nZmBP\r\n=z5fE\r\n-----END PGP SIGNATURE-----\r\n"},"engines":{"node":">=6"}}},"name":"is-pnp","dist-tags":{"latest":"1.0.2"},"modified":"2018-11-01T01:11:07.975Z"} \ No newline at end of file diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/is-pnp/-/is-pnp-1.0.2.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/is-pnp/-/is-pnp-1.0.2.tgz.bin new file mode 100644 index 0000000000000000000000000000000000000000..980bdfcbeca11ce65cd304d5a33eb4b5fb2ea9a5 GIT binary patch literal 2033 zcmY*X2~bnl8YUp>iv|JF8Wp*yU|I-S$#NmB5M|$uC{V%6&CMc^gm6I-Y#I_W=7YL3N5b%7t3`JxpS&*y1f+2+> zT?#{}R4${)VH82hS*Q|$GCs#eATlv30RbA5%J_uJ5O_Kq1kw;hL59+$IS2v24$I`r zTAgPS!qeR3~jBu_`E~Jzx(!@Tn zJi`wNK~Y7tEIk*a8${+qummBmLm@Of3j`uV*R8|gPuR2*N_jd6WI)@2J2Cng)P6{lPkzuivl8QhuHa^V2>AEnA^@xD7P;#VPC>2Q& zAqaf(lu84l6t2X5G4qFZcD%u@NT8E zZ9bj(Pd46@-C{XDmGim=iG7!2JiIiUfKEC|A2;W;2S2{ney!T*oWZCH4LES0$aj+r zC#6&LD?C=6Z8`FI2qir##Hr7Z?YKJ{3)UvMTrB_nK{p(Bd~kdJAK&NKTfRQ79+Yi8 zx61W#>keD;@j-4bE*h-pY5XD1B~~MtI<6Zvw>fqQu^u}{R!41H+8S>f!9eZF6OyETyv~0KykU3O0JCT zqyCmxwb@mc869{Ycz!ES&Q7=jFW(tk>@&9^&+fshukaA*Ca>+=An)A6aq-vZeKAAi zANe+{z)-a;o*6kF*br7~Z%|WK$KnTI&cePC2a`nmUx#avb6SP^`T}6eWGa7c8WB;t z_ckyaXi!1>JtLvwfkPTA&p&AbZ6ldmQp~MLHstbgDhse7ZI7Bul5-B+J=T4utk9EB~@YWlsU%TB<138H*j&6v?j!1 zNp_g_Oi*R-dfT07BED?(ivg&6KDa-+zN4o{8rBt9yff^^^;7Mk?yJ^Et#^vJO)J>U z?YCQd=c}PvIqQ!&dhGuf`H{<)w+9O-Eh{d$n0gMmuZ&G|)_l3Hq(zxD7SVjVZet*_ z=DuJ-q)adAd2TBCGra5^aU|Y*p!Bbp;Y5#xPSH=rWLA#l-~&bGq+6Atv#SBsq<(D{jXJi^f4ff=1 zZFh1KPcXXXTo^RE6(Pp#q}B57?OiX|C{-WLa@TRo4l6N!7qU^?6k3*Cen;}>Yu)I{ z2-aQeJKublvWov%o52^>i|3t(?^^R`j{KzhNSr#e$gT0>;HjKPcfW2xC`IRQYb(WU!;s^7yld@&zybo3teyG3Y{jO&11q(t+IrafZ95`#VS!!eR EH-4RT=>Px# literal 0 HcmV?d00001 diff --git a/__tests__/fixtures/run/nohoist-workspace/package.json b/__tests__/fixtures/run/nohoist-workspace/package.json new file mode 100644 index 0000000000..c4ac3364a3 --- /dev/null +++ b/__tests__/fixtures/run/nohoist-workspace/package.json @@ -0,0 +1,5 @@ +{ + "workspaces": [ + "packages/*" + ] +} diff --git a/__tests__/fixtures/run/workspace/packages/pkg1/node_modules/.bin/cat-names b/__tests__/fixtures/run/nohoist-workspace/packages/pkg1/node_modules/.bin/cat-names similarity index 100% rename from __tests__/fixtures/run/workspace/packages/pkg1/node_modules/.bin/cat-names rename to __tests__/fixtures/run/nohoist-workspace/packages/pkg1/node_modules/.bin/cat-names diff --git a/__tests__/fixtures/run/nohoist-workspace/packages/pkg1/package.json b/__tests__/fixtures/run/nohoist-workspace/packages/pkg1/package.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/__tests__/fixtures/run/nohoist-workspace/packages/pkg1/package.json @@ -0,0 +1 @@ +{} diff --git a/src/cli/commands/run.js b/src/cli/commands/run.js index 8226636765..33c90d5999 100644 --- a/src/cli/commands/run.js +++ b/src/cli/commands/run.js @@ -31,6 +31,7 @@ export async function getBinEntries(config: Config): Promise // Setup the node_modules/.bin folders for analysis for (const registryFolder of config.registryFolders) { + binFolders.add(path.resolve(config.cwd, registryFolder, '.bin')); binFolders.add(path.resolve(config.lockfileFolder, registryFolder, '.bin')); }