Skip to content

Commit 0c5974f

Browse files
colincaseymerceyz
andauthored
fix(core): ensure proper install for git dependency using Yarn classic and npm (#4403)
* fix(core): ensure proper install for git dependency with npm prepack * refactor: don't use variables outside of the test * test: expect on the part that rejects * chore: versions * fix(core): ensure proper install for git dependency with prepack * fix(core): ensure proper install for git dependency with prepack * fix(core): ensure proper install for git dependency with prepack * fix(core): ensure proper install for git dependency with prepack * fix(core): ensure proper install for git dependency with prepack * fix(core): ensure proper install for git dependency with prepack * fix(core): ensure proper install for git dependency with prepack * chore: style Co-authored-by: merceyz <[email protected]>
1 parent bced068 commit 0c5974f

34 files changed

+129
-1
lines changed

.yarn/versions/df71c502.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/core": patch
4+
5+
declined:
6+
- "@yarnpkg/plugin-compat"
7+
- "@yarnpkg/plugin-constraints"
8+
- "@yarnpkg/plugin-dlx"
9+
- "@yarnpkg/plugin-essentials"
10+
- "@yarnpkg/plugin-exec"
11+
- "@yarnpkg/plugin-file"
12+
- "@yarnpkg/plugin-git"
13+
- "@yarnpkg/plugin-github"
14+
- "@yarnpkg/plugin-http"
15+
- "@yarnpkg/plugin-init"
16+
- "@yarnpkg/plugin-interactive-tools"
17+
- "@yarnpkg/plugin-link"
18+
- "@yarnpkg/plugin-nm"
19+
- "@yarnpkg/plugin-npm"
20+
- "@yarnpkg/plugin-npm-cli"
21+
- "@yarnpkg/plugin-pack"
22+
- "@yarnpkg/plugin-patch"
23+
- "@yarnpkg/plugin-pnp"
24+
- "@yarnpkg/plugin-pnpm"
25+
- "@yarnpkg/plugin-stage"
26+
- "@yarnpkg/plugin-typescript"
27+
- "@yarnpkg/plugin-version"
28+
- "@yarnpkg/plugin-workspace-tools"
29+
- "@yarnpkg/builder"
30+
- "@yarnpkg/doctor"
31+
- "@yarnpkg/nm"
32+
- "@yarnpkg/pnpify"
33+
- "@yarnpkg/sdks"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = true
5+
ignorecase = true
6+
precomposeunicode = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Unnamed repository; edit this file 'description' to name the repository.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
#
3+
# An example hook script to prepare a packed repository for use over
4+
# dumb transports.
5+
#
6+
# To enable this hook, rename this file to "post-update".
7+
8+
exec git update-server-info
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# git ls-files --others --exclude-from=.git/info/exclude
2+
# Lines that start with '#' are comments.
3+
# For a project mostly in C, the following would be a good set of
4+
# exclude patterns (uncomment them if you want to use them):
5+
# *.[oa]
6+
# *~
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8d338e539dda97c94b22ceb7dacba3753189b548 refs/heads/master
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��Q
2+
�0��S�,I4I�<ɚ�5Ԩ���7^�_�xLXsN �� " m��VF���AJ�q�b�����I���Z�_�@�;}�N\é���i�;?@Y��2�V��VJQm�2�y˖� �f+�ax��0����A�
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x]��� �=��K/Bh��|��H� �mcb��B��Mfg��
2+
�w�|�0^F�@\ʎ�|�,c�h�S��)��ա�V��g�|�\������b�(�QR�ys�~�a�8��7��?o1=L7��=�+�_��v�����lf_c�9�

packages/acceptance-tests/pkg-tests-fixtures/repositories/npm-has-prepack.git/objects/8d/338e539dda97c94b22ceb7dacba3753189b548

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��A
2+
�0E��)�-�$�J)x�I2�R��颷�^���y��ť��i��$n���-
3+
�w&u�u���3.�Ψ�7�+x�9��)4��Ɉ�D�)�.�I��d�l�/�8Cϻ|�O�⩞���t�򀦵9g5�5�:�Y�ϻ���n�r|C���[2L�

packages/acceptance-tests/pkg-tests-fixtures/repositories/npm-has-prepack.git/objects/95/fad9bf2b1ca94f0054c4adb68f8bc23b0eb024

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��Q� D��{(lb�IOˢ�Ғ?���
2+
~��%o2��27�=��2bУ�)F�sF��Lhe����F�E/�%�>ڬS��q�&E��F+�Ev�o(>��n0��y�)���+q��%�����h��,g���������R ԍk�4ޛ�3�KL

packages/acceptance-tests/pkg-tests-fixtures/repositories/npm-has-prepack.git/objects/ad/3d74b1406d3978c109b8be28a0be96b45ea2bc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
xU̱
2+
�0�qg�ⶤP��EW���(isb$�����M�R\�~߿��C�ۮr���>�����|x$P�k�~�sw2���ߊ�����>�Y��Le�i��A3kxbQ��H:Ylp�8�W!�ɱ\�5��l?h�A

packages/acceptance-tests/pkg-tests-fixtures/repositories/npm-has-prepack.git/objects/b0/f4580fd4a6c9b1b63458dbec2c6dd6dae4429d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x-˽@0`u�¤��Px}�"�_��w䚝�vo6~��~���q',��3�v�� ���_/�� &PT��e_�q)B�t҅���>Mw�n���8��> '0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
xU��
2+
�0E]��K
3+
���J)�W.����#F�$&���nZ|���9��Z��e>k��p(ڝTx���P���C�N�%�������V�y ���C h���|��j�Ӣ����zb�w�&T�X�x��##';��ت`q�3mP�ao�#�V8�{M|4��/��+�P�

packages/acceptance-tests/pkg-tests-fixtures/repositories/npm-has-prepack.git/objects/be/f26554f462b4ab8ed76f5ccdda2af79fadefe2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x]���0 ���V�.4J*&�x���D��Q\�J���7�K��w�t���ԇO<��řwtţ�"&�u��U0�~v(�����&{���YX�/�gTc}��O r̻C�c �'�©��P��G�$��M[���Y�-������nw����Ȧ� ��?
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
P pack-deb3ab14c86f9987f651a205edb2adf1fee1f0bc.pack
2+
P pack-4832094f546294dfed5d785d57d7c87052827240.pack
3+
P pack-46f82cca8c5d7f3facc0cde372bbca42b3128a7f.pack
4+
P pack-bd0d366d37ae3fd802844fff1b8e5328bc2294c5.pack
5+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# pack-refs with: peeled fully-peeled sorted
2+
8d338e539dda97c94b22ceb7dacba3753189b548 refs/heads/master
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8d338e539dda97c94b22ceb7dacba3753189b548

packages/acceptance-tests/pkg-tests-specs/sources/protocols/git.test.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,15 @@ describe(`Protocols`, () => {
124124
},
125125
},
126126
async ({path, run, source}) => {
127-
await run(`install`);
127+
await expect(run(`install`, {
128+
env: {
129+
// if this is set then yarn 1 will be executed as if `--production` was passed during the install
130+
// but `yarn-1-project` requires dev dependencies to be present so this is a good way to
131+
// verify that yarn isn't throw off by this when handling the clone, install, and pack process
132+
// for git dependencies (see: https://classic.yarnpkg.com/lang/en/docs/cli/install/#toc-yarn-install-production-true-false)
133+
NODE_ENV: `production`,
134+
},
135+
})).resolves.toBeTruthy();
128136

129137
await expect(source(`require('yarn-1-project')`)).resolves.toMatch(/\byarn\/1\.[0-9]+/);
130138
},
@@ -149,6 +157,38 @@ describe(`Protocols`, () => {
149157
45000,
150158
);
151159

160+
test(
161+
`it should guarantee that all dependencies will be installed when using npm to setup npm repositories`,
162+
makeTemporaryEnv(
163+
{
164+
dependencies: {
165+
[`npm-has-prepack`]: startPackageServer().then(url => `${url}/repositories/npm-has-prepack.git`),
166+
},
167+
},
168+
async ({path, run, source}) => {
169+
await expect(run(`install`, {
170+
env: {
171+
// if this is set then npm will be executed as if `--omit=dev` was passed during the install
172+
// but `has-prepack-npm` requires dev dependencies to be present so this is a good way to
173+
// verify that yarn isn't throw off by this when handling the clone, install, and pack process
174+
// for git dependencies (see: https://docs.npmjs.com/cli/v8/using-npm/config#omit)
175+
NODE_ENV: `production`,
176+
177+
// same for NPM_CONFIG_PRODUCTION which acts just like the `--production` flat during install step
178+
// (see: https://docs.npmjs.com/cli/v8/using-npm/config#environment-variables, https://docs.npmjs.com/cli/v8/using-npm/config#production)
179+
NPM_CONFIG_PRODUCTION: `true`,
180+
npm_config_production: `true`,
181+
182+
// also force npm to use the package server as the registry so that the `has-bin-entry` dependency can be resolved
183+
NPM_CONFIG_REGISTRY: await startPackageServer(),
184+
},
185+
})).resolves.toBeTruthy();
186+
await expect(source(`require('npm-has-prepack')`)).resolves.toEqual(42);
187+
},
188+
),
189+
45000,
190+
);
191+
152192
test(
153193
`it should support installing specific workspaces from npm repositories`,
154194
makeTemporaryEnv(

packages/yarnpkg-core/sources/scriptUtils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ export async function prepareExternalProject(cwd: PortablePath, outputPath: Port
240240

241241
stdout.write(`\n`);
242242

243+
// Remove environment variables that limit the install to just production dependencies
244+
delete env.NODE_ENV;
245+
243246
// Run an install; we can't avoid it unless we inspect the
244247
// package.json, which I don't want to do to keep the codebase
245248
// clean (even if it has a slight perf cost when cloning v1 repos)
@@ -323,6 +326,11 @@ export async function prepareExternalProject(cwd: PortablePath, outputPath: Port
323326
// one instead
324327
delete env.npm_config_user_agent;
325328

329+
// Remove environment variables that limit the install to just production dependencies
330+
delete env.npm_config_production;
331+
delete env.NPM_CONFIG_PRODUCTION;
332+
delete env.NODE_ENV;
333+
326334
// We can't use `npm ci` because some projects don't have npm
327335
// lockfiles that are up-to-date. Hopefully npm won't decide
328336
// to change the versions randomly.

0 commit comments

Comments
 (0)