doczjs / docz

✍ It has never been so easy to document your things!
https://docz.site
MIT License
23.6k stars 1.46k forks source link

Build breaks with `repository` field in `package.json` #1635

Closed inlet closed 2 years ago

inlet commented 3 years ago

I'm using Docz for react-pixi, but it seems that the build breaks when having set the repository field in the app's package.json.

I get the following error:

TypeError: repo.browsetemplate.replace is not a function

  - index.js:745 getRepoUrl
    [react-pixi]/[docz-core]/dist/index.js:745:62

  - index.js:783 getInitialConfig
    [react-pixi]/[docz-core]/dist/index.js:783:19

  - index.js:817 Object.state [as config]
    [react-pixi]/[docz-core]/dist/index.js:817:19

  - sourceNodes.js:23 Object.module.exports
    [react-pixi]/[gatsby-theme-docz]/lib/sourceNodes.js:23:12

  - runMicrotasks

  - task_queues:96 processTicksAndRejections
    node:internal/process/task_queues:96:5

  - api-runner-node.js:485 runAPI
    [react-pixi]/[gatsby]/src/utils/api-runner-node.js:485:16

To Reproduce

  1. Create a project: npm init and fill in a reposity (I.e https://github.com/inlet/react-pixi.git)
  2. Install docz: npm install docz react react-dom
  3. Create a test doc: echo "# Test" > test.mdx
  4. Run build npx docz dev

Expected behavior

Pass the build

Environment

ksmithut commented 3 years ago

I am attempting to fix this issue, but have been having trouble setting up a dev environment (yarn/npm link issues), but I think I pinpointed where the issue is.

The issue is happening here. It's using a module called get-pkg-repo which turns around and uses a module called hosted-git-info which looks like it changed at some point from exposing .browsetemplate as a string to changing it to a function. It looks like you can change it to just call that function like this:

  return (
    repo &&
    repo.browse &&
    typeof repo.browse === 'function' &&
    repo.browse({
      domain: repo.domain,
      user: repo.user,
      project: repo.project,
    })
  )

But the other call further down in that file that generates the "edit" url might be a bit more complex. It would be nice if the hosted-git-info package had a function to generate an edit link. Perhaps a feature request is in order there.

pedronauck commented 3 years ago

Hi dude, I'm updating all dependencies in order to launch v2.4 with an updated and stabled version of Docz. I think next week I'll get with this, after that we can maybe go back here and see if will happen this yet.

av-k commented 3 years ago

Will be something changed for v1.x? I wouldn't like to migrate to v2 only for that fix...

adbayb commented 3 years ago

@pedronauck Any update on this one? 🙏 If needed, I'll be happy to help

silviuaavram commented 3 years ago

FYI, I did manage to work around it for now. So, just install your own version of "get-pkg-repo": "4.1.1",. On their update of 4.1.2 they switched to version 4 of "hosted-git-info": "^4.0.0",. Consequently, this is a breaking change and probably should have been labelled as such by get-pkg-repo, as the API seems to differ when using those functions (browse, browsetemplate is a function, etc).

The proper way to fix it is something similar to how @ksmithut suggests, and adapt the docz implementation to the new API of hosted-git-info. I would happily contribute with a PR to this, but I am not familiar with what exactly those 2 concatenations in repo-utils should return in order to update according to the new API.

designbyadrian commented 3 years ago

FYI, I did manage to work around it for now. So, just install your own version of "get-pkg-repo": "4.1.1",. On their update of 4.1.2 they switched to version 4 of "hosted-git-info": "^4.0.0",. Consequently, this is a breaking change and probably should have been labelled as such by get-pkg-repo, as the API seems to differ when using those functions (browse, browsetemplate is a function, etc).

I added get-pkg-repo@4.1.1 to my dependencies, I confirmed the version in node_modules, and yet I receive the same error.

e1en0r commented 3 years ago

@designbyadrian I had the same problem and was able to fix it by adding this to my package.json

"resolutions": {
  "get-pkg-repo": "4.1.1",
  "hosted-git-info": "^2.1.4",
}