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

Support subfolder when installing from Git #7483

Closed
1 task done
RexSkz opened this issue Jan 3, 2024 · 5 comments
Closed
1 task done

Support subfolder when installing from Git #7483

RexSkz opened this issue Jan 3, 2024 · 5 comments

Comments

@RexSkz
Copy link
Contributor

RexSkz commented Jan 3, 2024

Contribution

Describe the user story

PNPM now supports fetching from Git: pnpm i git+https://host/user/repo, and users can specify the branch, commit and tag using #:

git+https://host/user/repo#1a2b3c        // commit
git+https://host/user/repo#dev           // branch
git+https://host/user/repo#semver:^2.0.0 // tag

Nowadays, we use monorepo more and more. It's great to support installing from a subfolder of a git repo, not the root of it.

Currently, neither NPM nor Yarn supports this feature, and there's no RFC for it, so I'm not sure if it's okay for PNPM to support it. (In my own opinion, it's a good-to-have feature.)

Describe the solution you'd like

As a reference, UPM (Unity package manager) provides the ability to specify the subfolder using query parameter path. Maybe it's a good idea to follow this syntax, e.g.:

git+https://host/user/repo?path=/packages/util     // install from /packages/util
git+https://host/user/repo?path=/packages/util#dev // install from /packages/util at branch dev

Describe the drawbacks of your solution

It seems there are not many drawbacks to supporting queries in Git URLs. It's expected to add some logic to git-resolver and git-fetcher:

  • For the resolver, there will be no compatibility issues with the existing format.
  • For the fetcher, git fetcher uses a temp folder to perform clone/fetch actions and add "all" files (excluding .git) to store, this feature only affects the "all" word.

Describe alternatives you've considered

There is an alternative from StackOverflow that uses git sparse-checkout.

{
  "scripts": {
    "postinstall": "mkdir BotBuilder; cd BotBuilder; git init; git remote add -f origin https://github.com/Microsoft/BotBuilder.git; git config core.sparseCheckout true; echo \"Node/core\" >> .git/info/sparse-checkout; git pull --depth=1 origin master; cd ..; npm i ./BotBuilder/Node/core/"
  },
}

It can't work with the current PNPM install flow; users need to execute extra scripts when installing dependencies.

@RexSkz RexSkz changed the title Support subpath when installing from git Support subfolder when installing from Git Jan 3, 2024
RexSkz added a commit to RexSkz/pnpm that referenced this issue Jan 4, 2024
RexSkz added a commit to RexSkz/pnpm that referenced this issue Jan 4, 2024
RexSkz added a commit to RexSkz/pnpm that referenced this issue Jan 4, 2024
@zkochan
Copy link
Member

zkochan commented Jan 4, 2024

Are you sure this is not supported by Yarn? IIRC we already have an issue about this feature request and the author claimed that Yarn supports it.

@RexSkz
Copy link
Contributor Author

RexSkz commented Jan 5, 2024

It seems Yarn has a feature called workspace clone (from this issue comment), which can only work if the repo has Yarn workspace:

yarn add @name/package-name@https://github.com/user/repo#workspace=@name/package-name

There's nothing shown in the official docs: https://classic.yarnpkg.com/en/docs/cli/add

Do you mean that PNPM should implement a similar feature but with PNPM workspace rather than just adding a sub folder to the store?

@zkochan
Copy link
Member

zkochan commented Jan 6, 2024

Related issue: #4765

also mentions workspace support by Yarn.

@RexSkz
Copy link
Contributor Author

RexSkz commented Jan 6, 2024

I see. The "workspace clone" of Yarn assumed all repos use Yarn workspace to do monorepo things.

There are cases in which I need to install something (e.g. business API typings) from a repo maintained by another team which uses Lerna (or just a sub folder). Yarn's workspace clone can't handle these cases.

@zkochan
Copy link
Member

zkochan commented Jan 6, 2024

I have commented on the older issue: #4765 (comment)

marking this one as duplicate

@zkochan zkochan closed this as not planned Won't fix, can't repro, duplicate, stale Jan 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants