Skip to content

feat: implement gitSubdir according to npa spec#442

Open
Kakadus wants to merge 1 commit intonpm:mainfrom
Kakadus:npa-gitSubdir
Open

feat: implement gitSubdir according to npa spec#442
Kakadus wants to merge 1 commit intonpm:mainfrom
Kakadus:npa-gitSubdir

Conversation

@Kakadus
Copy link

@Kakadus Kakadus commented Jan 31, 2026

This implements the gitSubdir parameter, which is already parsed by npa, finally allowing users of npm to specifiy subdirectories in git dependencies.

The respective parsing logic has already been agreed on and implemented nearly 4 years ago here: npm/npm-package-arg#91. In this PR, the git fetcher is changed to resolve the gitSubdir parameter from the spec if found, as suggested by the author in the original npa PR.

References

Fixes npm/cli#528
Fixes npm/npm#2974
Relates to npm/npm-package-arg#46
Relates to npm/npm-package-arg#91

Inspired from and crediting sspiff@8bd5461, which seems to have been lost after merging the PR at npa.

@Kakadus Kakadus requested a review from a team as a code owner January 31, 2026 23:06
resolved: this.resolved,
integrity: null, // it'll always be different, if we have one
}).extract(tmp).then(() => handler(tmp), er => {
}).extract(tmp).then(() => handler(`${tmp}${this.spec.gitSubdir || ''}`), er => {
Copy link
Member

Choose a reason for hiding this comment

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

This is not going to work in windows, right? I suspect this is the case especially given that you bypassed testing in windows itself. A feature like this has to work in all operating systems.

Copy link
Author

Choose a reason for hiding this comment

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

Hi, thank you very much for taking a look!
Initially, I added the test exclusion on windows, because all other git tests are also skipped with that exact expression. Earlier in the test file, there is a comment about problems with PromiseSpawn on windows.

To be on the safe side, I just tested this under windows and everything works on my device. Just for "fun", I tested in a MacOS VM - it seems to work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] Allow adding Git branch dependencies in a subdirectory Allow subdirectories within git repos in npm install

2 participants