From af6a68b224bfb97baec634d0fddcf7b09e72402f Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Fri, 12 Jul 2019 18:27:19 -0700 Subject: [PATCH 1/3] Run the prepare script of git dependencies even if NODE_ENV=production When installing a git dependency with the `NODE_ENV` environment variable set to `production`, yarn did not run the `prepare` lifecycle script, because `config.production` would default to true, and then `wrapLifecycle` would skip `prepare`: https://github.com/yarnpkg/yarn/blob/b6569538de69e0ccd201f0a33f1f5b52f2656f5b/src/cli/commands/install.js#L1202-L1207 This is contrary to npm's behavior and the intent of `GitFetcher#fetchFromInstallAndPack`, which is to install the dependency with its devDependencies and run all the relevant lifecycle scripts (excluding `prepublish`), regardless of the configuration or environment settings of the parent install command. --- __tests__/fetchers.js | 34 ++++++++++++++++++++++++++++++++++ src/fetchers/git-fetcher.js | 1 + 2 files changed, 35 insertions(+) diff --git a/__tests__/fetchers.js b/__tests__/fetchers.js index ed5f5b0cc6..55d171b3f0 100644 --- a/__tests__/fetchers.js +++ b/__tests__/fetchers.js @@ -125,6 +125,40 @@ test('GitFetcher.fetch with prepare script', async () => { expect(await fs.exists(path.join(dir, 'generated', 'prepublish'))).toBe(false); }); +test('GitFetcher.fetch with prepare script, NODE_ENV=production', async () => { + const NODE_ENV = process.env.NODE_ENV; + try { + process.env.NODE_ENV = 'production'; + const dir = await mkdir('git-fetcher-with-prepare'); + const fetcher = new GitFetcher( + dir, + { + type: 'git', + reference: 'https://github.com/Volune/test-js-git-repo', + hash: '0e56593e326069ed4bcec8126bb48a1891215c57', + registry: 'npm', + }, + await Config.create(), + ); + await fetcher.fetch(); + const name = (await fs.readJson(path.join(dir, 'package.json'))).name; + expect(name).toBe('test-js-git-repo'); + const dependencyName = (await fs.readJson(path.join(dir, 'dependency-package.json'))).name; + expect(dependencyName).toBe('beeper'); + // The file "prepare.js" is not in "files" list + expect(await fs.exists(path.join(dir, 'prepare.js'))).toBe(false); + // Check the dependency with a bin script was correctly executed + expect(await fs.exists(path.join(dir, 'testscript.output.txt'))).toBe(true); + // Check executed lifecycle scripts + expect(await fs.exists(path.join(dir, 'generated', 'preinstall'))).toBe(true); + expect(await fs.exists(path.join(dir, 'generated', 'install'))).toBe(true); + expect(await fs.exists(path.join(dir, 'generated', 'postinstall'))).toBe(true); + expect(await fs.exists(path.join(dir, 'generated', 'prepublish'))).toBe(false); + } finally { + process.env.NODE_ENV = NODE_ENV; + } +}); + test('TarballFetcher.fetch', async () => { const dir = await mkdir('tarball-fetcher'); const fetcher = new TarballFetcher( diff --git a/src/fetchers/git-fetcher.js b/src/fetchers/git-fetcher.js index 284d594384..8939d06d41 100644 --- a/src/fetchers/git-fetcher.js +++ b/src/fetchers/git-fetcher.js @@ -164,6 +164,7 @@ export default class GitFetcher extends BaseFetcher { binLinks: true, cwd: prepareDirectory, disablePrepublish: true, + production: false, }, this.reporter, ), From e9c07066433dae4fe9b700d733c4f6711394d0bf Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Mon, 15 Jul 2019 10:11:45 -0700 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32f46dfc15..eddea571a4 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 +- Run the prepare script of git dependencies even if NODE_ENV=production + + [#7398](https://github.com/yarnpkg/yarn/pull/7398) - [**John Firebaugh**](https://github.com/jfirebaugh) + - Enforces https for the Yarn and npm registries. [#7393](https://github.com/yarnpkg/yarn/pull/7393) - [**Maƫl Nison**](https://twitter.com/arcanis) From 1f67674c116ed1e57d03c4a4cf8d560a3efe6226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Nison?= Date: Wed, 24 Jul 2019 14:45:36 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eddea571a4..4babcc4778 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa ## Master -- Run the prepare script of git dependencies even if NODE_ENV=production +- Runs the `prepare` lifecycle of git dependencies even if `NODE_ENV` is set to `production`. [#7398](https://github.com/yarnpkg/yarn/pull/7398) - [**John Firebaugh**](https://github.com/jfirebaugh)