Skip to content
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

Allow subdirectories within git repos in yarn install #4725

Closed
akshetpandey opened this issue Oct 17, 2017 · 42 comments
Closed

Allow subdirectories within git repos in yarn install #4725

akshetpandey opened this issue Oct 17, 2017 · 42 comments
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.

Comments

@akshetpandey
Copy link

Do you want to request a feature or report a bug?
Feature

What is the current behavior?
Unable to install packages that are inside subdirectories in git repos. This is a very common case for monorepos and just repositories that can't have the node package in the root repo.

If the current behavior is a bug, please provide the steps to reproduce.
Not a but

What is the expected behavior?
There should be an availably syntax for yarn add and yarn global add that allows to add packages that are inside subdirectories in a git repo.

It make it much easier to use unreleased code when testing unreleased versions for issues/regressions or fixes that aren't live yet like this ticket microsoft/code-push#428

ex. packages affected by this issue
https://github.com/Microsoft/code-push/tree/master/cli
https://github.com/Microsoft/BotBuilder/tree/master/Node
https://github.com/facebook/react-native/tree/master/react-native-cli
https://github.com/babel/babel/tree/master/packages/babel-cli

Related npm issue: npm/npm#2974

Please mention your node.js, yarn and operating system version.
yarn versions v1.2.1
node version v8.7.0
macOS Sierra 10.12.6

@akshetpandey
Copy link
Author

There are a couple of good ideas for syntax to use to specify subdirectories in the linked issue (npm/npm#2974)

Use pip's way of using a query parameter
git+https://git.repo/some_repo.git?subdirectory=subdir_path#branch
or
git+https://git.repo/some_repo.git#branch?path=subdir_path
Although I would assume most url parsers won't parse this one.

Use :: as it is not a valid token for a branch name
git+https://git.repo/some_repo.git#branch::subdir_path
git+https://git.repo/some_repo.git#::subdir_path

@lukescott
Copy link

lukescott commented Oct 24, 2017

Another idea: git+https://git.repo/some_repo.git/subdir_path#branch. If I were to assume this feature existed, that's what I would try first. The other options would require someone to look up the syntax.

@akshetpandey
Copy link
Author

That might be ambiguous depending on how the git server urls are setup.

The url might be something like

git+https://github.com/yarnpkg/yarn/<subdir_path>#branch

Then it become hard to say what is part of the repo path and what is the subdir_path

@lukescott
Copy link

lukescott commented Oct 24, 2017

Not sure if this applies to every repo, but with Github both git+https://github.com/yarnpkg/yarn and git+https://github.com/yarnpkg/yarn.git work. You could assume anything after .git/ is a sub-directory.

Regardless of syntax it would be nice to have this feature either way. It would be cool to make the syntax intuitive though :).

@akshetpandey
Copy link
Author

Oh yea, I was mostly talking about other website, not really github. Sorry my example wasn't the best one to explain it.

@stealthybox
Copy link

Long discussion about supporting this in npm:
npm/npm#2974

There are some suggested separators in the thread.

@joshcartme
Copy link

joshcartme commented Nov 22, 2017

I would also like to be able to do this to facilitate working with a monorepo that contains a lot of sub modules. I also found #1570 which discusses this. That was closed in favor of https://github.com/yarnpkg/rfcs/issues/15 but https://github.com/yarnpkg/rfcs/issues/15 doesn't exist anymore so it's hard to tell what if anything was done or decided there.

@matheo
Copy link

matheo commented Nov 23, 2017

so yarn doesn't support this yet?
all right, no simpler option than publish and use npm packages :(

@erykpiast
Copy link

Yeah, rising popularity of monorepo architectures makes it a crucial feature. Is there any workaround for this, for now? Discussion about public API tend to be years long...

@lukescott
Copy link

lukescott commented Jan 11, 2018

My # 1 use-case for this is pulling in bug-fixes from monorepo's that haven't been merged or released yet. I often want to keep most of the original packages, but pull in one of the sub-repos with a bug-fix. Currently I am unable to do this, and the workarounds are complex. Being able to reference a Github branch would greatly lower the resistance.

I know there are some people at npm that are highly resistant to the idea of this, and monorepos in general. However, many of the contributors here work on projects that use monorepos. I would suspect that if yarn were to implement this feature and it became popular enough npm would follow suit. A lot of yarn ideas have been implemented in npm later on. yarn to me is the babel of npm.

@sdhull
Copy link

sdhull commented Feb 8, 2018

@erykpiast couple workarounds that I can think of:

  1. clone the target repo somewhere and then use yarn add /path/to/repo/subdirectory
  2. or possibly (if it's in your own monorepo) use yarn workspaces?

Or -- this is maybe even crazier -- add the remote in question as a submodule and (optionally move your project files into a subdirectory) then use yarn workspaces?

Disclaimer: I haven't tried either of these approaches and they both add overhead for new developers & your CI builds...

@jwdunne
Copy link

jwdunne commented Apr 20, 2018

Or -- this is maybe even crazier -- add the remote in question as a submodule and (optionally move your project files into a subdirectory) then use yarn workspaces?

I can confirm this works.

Upgraded to webpack 4. Create React App doesn't have support yet but there's a PR that's waiting to be merged - unfortunately webpack 4 has changed it's plugin API. Doubly unfortunate: create-react-app is repo containing multiple packages. Adding the forked PR as a submodule and adding the package using 'file:' syntax worked a charm.

Literally saved an entire day or more of work with this work around.

@micimize
Copy link

It's alarming that this isn't on the roadmap for either npm or yarn due to the rise in popularity of monorepos. The git+... syntax makes contributing to single-package projects a breeze, and by contrast not having it for subdirectories makes contributing to monorepo projects a total headache.

@jwdunne
Copy link

jwdunne commented Jun 29, 2018

I agree. After a few months down the git submodule, file: route, it's not ideal. Onboarding other developers is more difficult. My colleagues have to worry about initialising and updating the submodules. In their defence, it used to be as simple as running yarn to get themselves going.

Monorepo support would be a dream come true.

@Frikki
Copy link

Frikki commented Jul 1, 2018

yarn + lerna (using yarn’s workspaces) works to manage monorepos.

@jwdunne
Copy link

jwdunne commented Jul 2, 2018 via email

@micimize
Copy link

micimize commented Jul 2, 2018

@Frikki I don't believe lerna has much submodule support, and isn't a "consumption tool" anyways.

@jwdunne For now I just npm publish a namespaced version of the fork and depend on it

@ramasilveyra
Copy link
Contributor

Hello! I built https://github.com/ramasilveyra/gitpkg to "publish" packages from monorepos as git tags, it may help.

@stealthybox
Copy link

@ramasilveyra that looks super useful -- thanks for the addition 👍

@robermorales
Copy link

Some news in supporting git subdirs as install sources?

Thanks,

jquense pushed a commit to jquense/react-widgets that referenced this issue Jan 3, 2019
I missed these while cleaning up my last PR. Sorry about that. :-(

Unrelated question:  Do you have a predefined release schedule? I am working to get these changes integrated into our downstream project, and yarn makes it [a little tricky](yarnpkg/yarn#4725) until the package is published to npm. (I don't mean this to rush you; rather, I want to avoid feeling silly doing an extra workaround if you are about to publish it anyways.)
@t-benze
Copy link

t-benze commented Sep 26, 2019

Hello! I built https://github.com/ramasilveyra/gitpkg to "publish" packages from monorepos as git tags, it may help.

This may look a bit hacky at the beginning, but after some reasoning it seems to be a legitimate solution to the problem 👍

@yanickrochon
Copy link

Seriously, gitpkg works! It creates tags inside the project repository, and can be used with repositories containing multiple packages.

And this prompted me to ditch npm because only yarn can fetch nicely from Git.

@Preen
Copy link

Preen commented Oct 28, 2019

+1

@micimize
Copy link

Hello! I built https://github.com/ramasilveyra/gitpkg to "publish" packages from monorepos as git tags, it may help.

Just used gitpkg and I think it's such a good solution that it should be added as a note in the docs for this use case

@EqualMa
Copy link

EqualMa commented Feb 24, 2020

I built a service https://gitpkg.now.sh/ to download the sub folder of a git repo as a .tgz file, so that it can be installed by yarn and npm. With this service, package users can use the subdir directly and there is no need for package developers to publish the subdirs.

For example, if you want to add babel-core in branch next-8-dev as dependency,
just use:

yarn add https://gitpkg.now.sh/babel/babel/packages/babel-core?next-8-dev

also works for npm install.

Note that I must say sorry to @ramasilveyra because my service's name conflicts with the tool he develops but I didn't know that before.

@dword-design
Copy link

@EqualMa This looks pretty amazing. I'll have a look at this soo.

@erykpiast
Copy link

@EqualMa It'd be even more amazing if it works for projects with a build step. But anyway, great job, thank you so much!

@uriel-sf
Copy link

Do we still need gitpkg? Running latest lerna and when run in independent-mode it will publish git tags of each component.

@EqualMa
Copy link

EqualMa commented Apr 6, 2020

@erykpiast Finally GitPkg service supports custom scripts, allowing you to run a build step in postinstall or other scripts! You can checkout the docs or just try adding custom scripts at https://gitpkg.now.sh

@erykpiast
Copy link

@EqualMa that's even more than awesome! Thank you!

@tqwewe
Copy link

tqwewe commented Jun 1, 2020

Any updates to this? Is it planned or anything?

@artemjackson
Copy link

@EqualMa awesome! great job!

@jason-codaio
Copy link

I'm having an issue trying to fork a repo (https://github.com/ianstormtaylor/slate) that uses workspaces and has multiple packages in the same repo. I only want to modify and import one of the packages. Trying to yarn add pointing to the directory that holds the individual package.json file gives an error...

yarn add https://github.com/kr-project/slate/tree/master/packages/slate#e73db650a332fc5ded3fd72cffb1fcd7279b85d7
error https://github.com/kr-project/slate/tree/master/packages/slate: Extracting tar content of undefined failed, the file appears to be corrupt: "Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped?"

I've also tried to check in the published files, but my understanding is this is a problem with yarn looking a tar only found at the root directory of a github repo?

So is the only way to fork a project that uses workspaces to use something like gitpkg? I'm a bit surprised that there doesn't seem to be more native support for this.

@LucidDan
Copy link

Just ran into exactly the same issue as @jason-krypton ... trying to work with a fork of a repo that uses workspaces, normally I'd just yarn add the forked git repository ... that's impossible now I guess? Wasting a decent bunch of time on this in order to change a couple of lines of code. :-(

@robclancy
Copy link

I have similar issues with ckeditor5. I'm trying out GitPkg now.

@bedney
Copy link

bedney commented Aug 18, 2020

So @LucidDan and others.

I've found the following to work:

  • You must be running yarn 2.1.X for this to work.
  • See this page for the newer syntax that allows this: https://yarnpkg.com/features/protocols
  • You have to add individual entries for each package in the monorepo to your package.json under either dependencies or, in my case, devDependencies:
"package-1": "my-org-name/mono-repo-name#head=my-git-branch&workspace=package-1"

It's disappointing that there isn't a way to just have yarn install the top-level monorepo and unroll all of the attendant packages into their proper place. Maybe there is and I'm just being stupid here? If so, someone enlighten me ;-)

@paul-soporan
Copy link
Member

Implemented in v2, starting from Yarn 2.1: https://dev.to/arcanis/yarn-2-1-git-workspaces-focused-installs-loose-mode-live-playground-4kfc#workspace-cloning

You can use the following syntax to install a specific workspace (not arbitrary folder):

yarn add @yarnpkg/eslint-config@yarnpkg/berry#workspace=@yarnpkg/eslint-config

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

@paul-soporan paul-soporan added the fixed-in-modern This issue has been fixed / implemented in Yarn 2+. label Jan 2, 2021
@numandev1
Copy link

Try https://gitpkg.now.sh/

yarn add https://gitpkg.now.sh/<user>/<repo>/<subdir>[?<branch>]

OR

"@react-native-community/cli-platform-ios":"https://gitpkg.now.sh/nomi9995/cli/packages/platform-ios?fix-ios-getProductName-regex"

@yarnpkg yarnpkg locked as resolved and limited conversation to collaborators Feb 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
fixed-in-modern This issue has been fixed / implemented in Yarn 2+.
Projects
None yet
Development

No branches or pull requests