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

feat: npm repo support repository.directory field #163

Closed
wants to merge 2 commits into from
Closed

feat: npm repo support repository.directory field #163

wants to merge 2 commits into from

Conversation

ybiquitous
Copy link
Contributor

Summary

This PR makes npm repo possible to open a given repository's full URL instead of its root URL with the new repository.directory field.

For example, npm repo react-dom opens https://github.com/facebook/react/tree/master/packages/react-dom.

Background

npm@6.8.0 shipped the new feature to support repository.field in package.json.

For example:

{
  "repository": {
    "type": "git",
    "url": "https://github.com/facebook/react.git",
    "directory": "packages/react-dom"
  }
}

See also #140

@ybiquitous
Copy link
Contributor Author

I think this change should test the following cases:

  • npm repo <github_hosted_package>
  • npm repo <gitlab_hosted_package>
  • npm repo <bitbucket_hosted_package>
  • (and so on...?)

But sadly I didn't know how to test these cases. 😢
To test the cases, should I change npm-registry-mock package, or is there some better way?

var mr = require('npm-registry-mock')

I hope someone would help me about testing... 🙏

Copy link

@toyokazu03102478 toyokazu03102478 left a comment

Choose a reason for hiding this comment

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

お願いいたします

@ybiquitous ybiquitous marked this pull request as ready for review February 19, 2019 00:19
@ybiquitous ybiquitous requested a review from a team as a code owner February 19, 2019 00:19
@zkat
Copy link
Contributor

zkat commented Feb 19, 2019

Here's an example of how to mock a packument request: https://github.com/npm/cli/blob/release-next/test/tap/aliases.js#L29-L54

You don't need to bother with mocking the tarball.

@zkat zkat added semver:minor new backwards-compatible feature in-progress labels Feb 19, 2019
@ybiquitous
Copy link
Contributor Author

@zkat Thanks for your advice! I'll rebase after #167 is merged.

t.comment(stderr)

const res = fs.readFileSync(outFile, 'ascii')
t.equal(res, 'https://github.com/foo/test-repo-with-directory/tree/master/some%2Fdirectory\n')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I expected .../some/directory, not .../some%2Fdirectory. 🤔
But I find this is a problem of hosted-git-info package.
So, I will open a new PR on npm/hosted-git-info. 💪

The relevant code is here:
https://github.com/npm/hosted-git-info/blob/067fd7f3559fc051fd56528f6231a70ec4e634d0/git-host.js#L38-L40

Copy link
Contributor

Choose a reason for hiding this comment

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

This has been fixed! So this test will actually fail now. We'll fix this up when landing this PR! :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mikemimik Thanks for your response. I have not touched this PR for a long time, but can I start again?

If you have any advice, I would be glad to accept!

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not necessary to start again. The @npm/cli-team triaged this pull-request today and we're accepting it into 6.14.0. We can fix up the test when we pull it into the release, it's no worries :)

You noted that hosted-git-info does some weird url-encoding, and you had to use "%2f". Since then hosted-git-info has had some changes and it's fixed. It now returns properly. The change to the test is just changing %2f back to / :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I understand it. I'm looking forward to a new release 😊

@ybiquitous
Copy link
Contributor Author

I added a test case and CI passed!

Notes

I thought test cases for possible Git hostings were necessary (not only GitHub).
But hosted-git-info package already tests possible hostings, so I added just the GitHub case and I think it enough to verify this PR feature.

@ybiquitous
Copy link
Contributor Author

@zkat I added the tests, so is there something I should do to review this PR?

@isaacs isaacs mentioned this pull request Jul 1, 2019
@mikemimik mikemimik added the Release 6.x work is associated with a specific npm 6 release label Nov 26, 2019
@mikemimik mikemimik added this to the Release 6.14.0 milestone Nov 26, 2019
mikemimik pushed a commit that referenced this pull request Dec 2, 2019
@mikemimik mikemimik added Priority Backlog a "backlogged" item that will be tracked in a Project Board pr: needs tests requires tests before merging labels Dec 3, 2019
@mikemimik mikemimik removed this from the Release 6.14.0 milestone Dec 3, 2019
jasonkarns added a commit to github/optimizely-javascript-sdk that referenced this pull request May 6, 2020
This is the standard configuration value for deep-linking into a
package's directory within a monorepo.

npm RFC: https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md

This will ensure the packages' pages on npmjs.org will link to the
correct directory.

Also, _eventually_, it will ensure the `npm repo` command opens to the
correct location: npm/cli#163

Lastly, this is _required_ for monorepo packages to be successfully
published to the GitHub Package Registry (if that is ever considered in
the future).
https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#publishing-multiple-packages-to-the-same-repository
mjc1283 pushed a commit to optimizely/javascript-sdk that referenced this pull request May 8, 2020
Summary:

Configure each package's package.json#repository.directory 
property to properly reflect the location of the package within 
the repository.

This is the standard configuration value for deep-linking into a
package's directory within a monorepo.

npm RFC: https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md

This will ensure the packages' pages on npmjs.org will link to the
correct directory.

Also, _eventually_, it will ensure the npm repo command opens to the
correct location: npm/cli#163

Lastly, this is _required_ for monorepo packages to be successfully
published to the GitHub Package Registry (if that is ever considered in
the future).
https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages#publishing-multiple-packages-to-the-same-repository
@darcyclarke darcyclarke added this to the OSS - Sprint 8 milestone Jun 11, 2020
@darcyclarke darcyclarke changed the base branch from latest to release/v7.0.0-beta July 31, 2020 19:01
@darcyclarke darcyclarke added Release 7.x work is associated with a specific npm 7 release Needs Review and removed Priority Backlog a "backlogged" item that will be tracked in a Project Board Release 6.x work is associated with a specific npm 6 release pr: needs tests requires tests before merging labels Jul 31, 2020
isaacs pushed a commit that referenced this pull request Aug 4, 2020
@isaacs
Copy link
Contributor

isaacs commented Aug 4, 2020

This will be in the v7 beta. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release 7.x work is associated with a specific npm 7 release semver:minor new backwards-compatible feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants