Skip to content

fix(core): ensure proper install for git dependency using Yarn classic and npm #4403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .yarn/versions/df71c502.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
precomposeunicode = true
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, rename this file to "post-update".

exec git update-server-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8d338e539dda97c94b22ceb7dacba3753189b548 refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x��Q
�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 number Diff line number Diff line change
@@ -0,0 +1,2 @@
x]��� �=��K/Bh��|��H� �mcb��B��Mfg��
�w�|�0^F�@\ʎ�|�,c�h�S��)��ա�V��g�|�\������b�(�QR�ys�~�a�8��7��?o1=L7��=�+�_��v�����lf_c�9�
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x��A
�0E��)�-�$�J)x�I2�R��颷�^���y��ť��i��$n���-
�w&u�u���3.�Ψ�7�+x�9��)4��Ɉ�D�)�.�I��d�l�/�8Cϻ|�O�⩞���t�򀦵9g5�5�:�Y�ϻ���n�r|C���[2L�
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x��Q� D��{(lb�IOˢ�Ғ?���
~��%o2��27�=��2bУ�)F�sF��Lhe����F�E/�%�>ڬS��q�&E��F+�Ev�o(>��n0��y�)���+q��%�����h��,g���������R ԍk�4ޛ�3�KL
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xU̱
�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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x-˽@0`u�¤��Px}�"�_��w䚝�vo6~��~���q',��3�v�� ���_/�� &PT��e_�q)B�t҅���>Mw�n���8��> '0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
xU��
�0E]��K
���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�
Original file line number Diff line number Diff line change
@@ -0,0 +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����Ȧ� ��?
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
P pack-deb3ab14c86f9987f651a205edb2adf1fee1f0bc.pack
P pack-4832094f546294dfed5d785d57d7c87052827240.pack
P pack-46f82cca8c5d7f3facc0cde372bbca42b3128a7f.pack
P pack-bd0d366d37ae3fd802844fff1b8e5328bc2294c5.pack

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# pack-refs with: peeled fully-peeled sorted
8d338e539dda97c94b22ceb7dacba3753189b548 refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8d338e539dda97c94b22ceb7dacba3753189b548
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,15 @@ describe(`Protocols`, () => {
},
},
async ({path, run, source}) => {
await run(`install`);
await expect(run(`install`, {
env: {
// if this is set then yarn 1 will be executed as if `--production` was passed during the install
// but `yarn-1-project` requires dev dependencies to be present so this is a good way to
// verify that yarn isn't throw off by this when handling the clone, install, and pack process
// for git dependencies (see: https://classic.yarnpkg.com/lang/en/docs/cli/install/#toc-yarn-install-production-true-false)
NODE_ENV: `production`,
},
})).resolves.toBeTruthy();

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

test(
`it should guarantee that all dependencies will be installed when using npm to setup npm repositories`,
makeTemporaryEnv(
{
dependencies: {
[`npm-has-prepack`]: startPackageServer().then(url => `${url}/repositories/npm-has-prepack.git`),
},
},
async ({path, run, source}) => {
await expect(run(`install`, {
env: {
// if this is set then npm will be executed as if `--omit=dev` was passed during the install
// but `has-prepack-npm` requires dev dependencies to be present so this is a good way to
// verify that yarn isn't throw off by this when handling the clone, install, and pack process
// for git dependencies (see: https://docs.npmjs.com/cli/v8/using-npm/config#omit)
NODE_ENV: `production`,

// same for NPM_CONFIG_PRODUCTION which acts just like the `--production` flat during install step
// (see: https://docs.npmjs.com/cli/v8/using-npm/config#environment-variables, https://docs.npmjs.com/cli/v8/using-npm/config#production)
NPM_CONFIG_PRODUCTION: `true`,
npm_config_production: `true`,

// also force npm to use the package server as the registry so that the `has-bin-entry` dependency can be resolved
NPM_CONFIG_REGISTRY: await startPackageServer(),
},
})).resolves.toBeTruthy();
await expect(source(`require('npm-has-prepack')`)).resolves.toEqual(42);
},
),
45000,
);

test(
`it should support installing specific workspaces from npm repositories`,
makeTemporaryEnv(
Expand Down
8 changes: 8 additions & 0 deletions packages/yarnpkg-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ export async function prepareExternalProject(cwd: PortablePath, outputPath: Port

stdout.write(`\n`);

// Remove environment variables that limit the install to just production dependencies
delete env.NODE_ENV;

// Run an install; we can't avoid it unless we inspect the
// package.json, which I don't want to do to keep the codebase
// clean (even if it has a slight perf cost when cloning v1 repos)
Expand Down Expand Up @@ -323,6 +326,11 @@ export async function prepareExternalProject(cwd: PortablePath, outputPath: Port
// one instead
delete env.npm_config_user_agent;

// Remove environment variables that limit the install to just production dependencies
delete env.npm_config_production;
delete env.NPM_CONFIG_PRODUCTION;
delete env.NODE_ENV;

// We can't use `npm ci` because some projects don't have npm
// lockfiles that are up-to-date. Hopefully npm won't decide
// to change the versions randomly.
Expand Down