Skip to content

fix(hosted-git-resolver): ensure prepare script is executed for hosted git repo #6131

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

Closed
wants to merge 1 commit into from
Closed

fix(hosted-git-resolver): ensure prepare script is executed for hosted git repo #6131

wants to merge 1 commit into from

Conversation

3cp
Copy link

@3cp 3cp commented Jul 20, 2018

Summary

Use git-fetcher, not tarball-fetcher to deal with hosted git repo. tarball-fetcher has no knowledge about the difference between normal npm package tarball, and tarball provided by hosted git (which is NOT a proper npm package).

Obviously this fix has performance penalty, but it's necessary to support prepare script.

Another possible solution is to add git-tarball-resolver (extending tarball-resolver), but I don't understand the code base enough to be able to extract hasPrepareScript and fetchFromInstallAndPack out from git-resolver.

closes #5235

Test plan

Tested my apps with github public repo, bitbucket public and private repos, all can now trigger prepare scripts.
Tested yarn import on my apps.
Tested all above with no yarn cache (yarn cache clean) and full yarn cache.

…d git repo

Use git-fetcher, not tarball-fetcher to deal with hosted git repo. tarball-fetcher has no knowledge about the difference between normal npm package tarball, and tarball provided by hosted git (which is NOT a proper npm package).

Obviously this fix has performance penalty, but it's necessary to support prepare script.

Another possible solution is to add git-tarball-resolver (extending tarball-resolver), but I don't understand the code base enough to be able to extract hasPrepareScript and fetchFromInstallAndPack out from git-resolver.

closes #5235
@buildsize
Copy link

buildsize bot commented Jul 20, 2018

File name Previous Size New Size Change
yarn-[version].noarch.rpm 910.47 KB 909.55 KB -945 bytes (0%)
yarn-[version].js 3.98 MB 3.98 MB -3.78 KB (0%)
yarn-legacy-[version].js 4.14 MB 4.14 MB -4.03 KB (0%)
yarn-v[version].tar.gz 915.29 KB 914.28 KB -1.02 KB (0%)
yarn_[version]all.deb 667.68 KB 667.18 KB -512 bytes (0%)


// If the url is accessible over git archive then we should immediately delegate to
// the git resolver.
//
// NOTE: Here we use a different url than when we delegate to the git resolver later on.
// This is because `git archive` requires access over ssh and github only allows that
// if you have write permissions
const sshGitUrl = Git.npmUrlToGitUrl(sshUrl);
if (await Git.hasArchiveCapability(sshGitUrl)) {
Copy link
Author

@3cp 3cp Jul 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note I removed the Git check archive and new Git(...).
GitResolver creates client = new Git(...), and client.init() does the same thing (check archive and resolve committish).
This just removes duplicated effort.

@3cp
Copy link
Author

3cp commented Jul 20, 2018

I guess I have to wait for someone cleanup test-macos-node10 and appveyor test on current master.
My branch passed my local test on nodejs v8.

@ghost
Copy link

ghost commented Aug 15, 2018

Any updates on where this PR is at? This is functionality we really need as we migrate some old apps to a modern build process with webpack and yarn.

@3cp
Copy link
Author

3cp commented Aug 15, 2018

It seems yarn team has not cleaned up CI/test setup on the master yet. I don't think any PR is in their consideration now.

If you want a temporary solution, install my branch as your global yarn which I did. Because the repo setup, you cannot install directly from my github repo (it would not build).

Do

git clone [email protected]:huochunpeng/yarn.git
cd yarn
git checkout fix-prepare-script-on-hosted-git
npm i
npm run build
npm uninstall -g yarn
npm i -g .

@rtsao
Copy link

rtsao commented Aug 16, 2018

Should prepare scripts be called for all dependencies (including tarballs)?

If so, then perhaps this PR should instead move the logic into src/base-fetcher.js so that this logic is consistent regardless of the kind of dependency.

@3cp
Copy link
Author

3cp commented Aug 16, 2018

Nope, a tarball can be a valid npm package (like prepared by npm pack). If you look my initial PR message, a proper way to support this is to add git-tarball-resolver, so we don't have to pay the performance penalty on not using github tarball.

gcampax added a commit to stanford-oval/genie-cloud that referenced this pull request Oct 5, 2018
yarn has a bug where it treats github: deps differently from
git:// deps (<yarnpkg/yarn#6131>), but
it also a separate bug where it just dies if a git:// depenency uses
prepare and also depends on the same package as the original
package (<yarnpkg/yarn#6312>).

Maybe we should just switch to npm...
gcampax added a commit to stanford-oval/genie-cloud that referenced this pull request Oct 5, 2018
yarn has a bug where it treats github: deps differently from
git:// deps (<yarnpkg/yarn#6131>), but
it also a separate bug where it just dies if a git:// depenency uses
prepare and also depends on the same package as the original
package (<yarnpkg/yarn#6312>).

Work around by cloning the ThingTalk repository separately and
using yarn link.

Maybe we should just switch to npm...
@ypresto
Copy link

ypresto commented Nov 21, 2019

@arcanis Could you review this PR which fixes previously-PR-welcomed issue? Sorry if bothering you!
(PR-welcomed comment is here 😉: #5235 (comment))

@karlhorky
Copy link

@arcanis is it safe to assume that this PR will never land? (because Yarn 1 is no longer receiving features?)

@merceyz
Copy link
Member

merceyz commented Jan 6, 2021

Closing as fixed in v2 where the prepack script is executed for git repos

https://yarnpkg.com/getting-started/migration

@merceyz merceyz closed this Jan 6, 2021
@merceyz merceyz added the fixed-in-modern This issue has been fixed / implemented in Yarn 2+. label Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lifecycle scripts for hosted git and local dependencies not run on install
5 participants