Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

[BUG] handle subdirectories when building relative link URLs #449

Open
johnemau opened this issue Aug 7, 2020 · 1 comment
Open

[BUG] handle subdirectories when building relative link URLs #449

johnemau opened this issue Aug 7, 2020 · 1 comment

Comments

@johnemau
Copy link

johnemau commented Aug 7, 2020

What / Why

The problem is described well in the following NPM community post and PR

The package.respository.directory is not honored when generating URLs for relative paths in README.mds of NPM packages displayed on npmjs.org.

How

  • n/a

When

  • n/a

Where

npmjs.org package pages for example, any link on https://www.npmjs.com/package/hint/v/6.0.1#further-reading

Current Behavior

Links 404 because link does not include subproject directory path provided in repository.directory of package.json

Steps to Reproduce

Add a relative link to README.md of a package in a subdirectory of a monorepo and publish that package.

Expected Behavior

Relative links become fully qualified URLs to github subproject resource in monrepo.

Who

  • n/a

The Fix

First the consumer of marky-markdown must be passed a package.json meta-data including the repository.directory, I could not find the source code for npmjs.org but I assume this is not the case today because lib/plugin/github.js treats package.repository as a string type, which does not match the example in the README.md.

- var repo = gh(opts.package.repository)
+ // Handling both `string` and `{ url: string }` types
+ var repo = gh(opts.package.repository.url | opt.package.repository)

https://github.com/npm/marky-markdown/blob/master/lib/plugin/github.js#L52

Next buildLinkUrl should use opt.package.repository.directory when building the fully qualified path:

- return prefix + path.join(repository.user, repository.repo, DEFAULT_REF, url.href)
+ // Just an example, `opt` is not in scope, refactor to pass in the repository directory,
+ return prefix + path.join(repository.user, repository.repo, DEFAULT_REF, opt.package.repository.directory, url.href)

https://github.com/npm/marky-markdown/blob/master/lib/plugin/github.js#L12

References

Related to #435
Related to #446

@johnemau
Copy link
Author

johnemau commented Aug 7, 2020

Current workaround is to provide a fully-qualified URL to gihub in the README.md instead of using a relative path.

antross pushed a commit to webhintio/hint that referenced this issue Aug 24, 2020
nhirrle added a commit to valtech-ch/saas-aem-module that referenced this issue Feb 28, 2022
There is an open bug npm/marky-markdown#449 which suggests this workaround.
On top of that I changed the package.json to represent that we are here in a monorepo
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant