7

Suppose I want to create a colletion of packages, say related to cooking. I'll have a core package called cooking and then I want multiple cooking packages:

  • cooking-mexican
  • cooking-indian
  • cooking-tai

Each of those will use cooking. And maybe more common packages will be created in the future. What is the way to set up this structure in github such that you are not forced to create a separate repo for each, but still allow for client projects to pull just the packages they need.

Can a package reference a path within a github package?

From the pub dependencies page they show how you can reference git:

dependencies:
  cooking:
    git:
      url: git://github.com/munificent/cooking.git
      ref: some-branch

But ideally I want:

dependencies:
  cooking-indian:
    git:
      url: git://github.com/munificent/cooking.git
      ref: some-branch
      # path relative to cooking.git that has pubspec.yaml
      path: cooking-indian

Is there a way to have one github repo with N packages where only some subset can be selected via pub?

user1338952
  • 3,233
  • 2
  • 27
  • 41

1 Answers1

2

You can always have a single top level git repository, containing all the packages in sub folders which are published individually. Pub does not mandate that each package be a repo - as long as the individual packages adhere to the pub package layout format.

If you are using private repos you may want to setup a private pub host rather than relying on github for fetching.

However pub currently does not support fetching directly from sub-trees of git repos. If you want to invest effort into implementing this feature you can do so by taking advantage of git's sparse checkout feature.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
lorefnon
  • 12,875
  • 6
  • 61
  • 93
  • Proliferation still results if you want code available from pub but still want development to get specific versions via git. Putting more than one package in git means you can't use the pubspec git selector feature since pub requires the package to be the root of the repo. – user1338952 Oct 24 '15 at 15:03
  • There is an [open issue](https://github.com/dart-lang/pub/issues/1305) for this request but no one is working on it today. We use this pattern in the [build repo](https://github.com/dart-lang/build) and it has been working well, though there are some tricky parts around testing on travis before versions are published to pub. It's always possible to use specific versions published to pub, a git dependency is not the only way to lock down to a specific version. – Nate Bosch Feb 02 '17 at 08:23