question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

syncpack doesn't respect package.json 'repository' and 'bugs' fields

See original GitHub issue

Description

  1. Create package.json with extended fields repository and bugs as in:
  "repository": {
    "type": "git",
    "url": "https://github.com/muravjev/reprl_synpack_format_bug.git",
    "directory": "packages/mydir"
  },
  "bugs": {
    "url": "https://github.com/muravjev/reprl_synpack_format_bug/issues"
  }
  1. Run syncpack format

  2. Syncpack changes repository and bugs fields to the following values:

  "repository": "muravjev/reprl_synpack_format_bug.git",
  "bugs": "https://github.com/muravjev/reprl_synpack_format_bug/issues"

Summary

Shortening of the bugs field is may be appropriate (as syntax sugar), though some people may not like it.

Shortening of the repository field, especially if it contains directory sub field, changes the final target url that someone would have liked to point to.

Note, that there cases when package is not in the root directory (for example if it is part of a monorepo) and in this case npmjs suggests use directory sub field to point to exact package location (npmjs doc)

Suggested Solution

I see that such shortening is a feature of syncpack, but in case of valid extended syntax as in example the modification of the url fields (repository and/or bugs) maybe undesirable.

I suggest:

  1. Add boolean flag shortenUrl to control such shortening behavior with default value true (to keep existing behavior as default).

  2. In case of repository and/or bugs fields has extra sub fields besides url, the shortening should not be undertook, even if shortenUrl flag is true.

OR

To avoid over complicating and adding extra flags:

  1. In case of repository and/or bugs fields has extra sub fields besides url, the shortening should not be undertook.

Note, that in either cases the changes will not affect existed package jsons that are already formatted with syncpack.

Help Needed

If you approve either approach, I would love to apply it.

BTW I have found the syncpack accidentally today, and this this is really great tool! Thank you, @JamieMason for creating it! 👍👍👍

MRE

  1. Clone https://github.com/muravjev/reprl_synpack_format_bug
  2. Run pnpm repro
  3. Check the git changes

Environment

  System:
    OS: Windows 10 10.0.17763
    CPU: (8) x64 Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
    Memory: 1.92 GB / 7.95 GB
  Binaries:
    Node: 18.5.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.19 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 8.12.1 - C:\Program Files\nodejs\npm.CMD
  Managers:
    pip3: 22.2.2 - C:\Program Files\Python310\Scripts\pip3.EXE
  Utilities:
    Git: 2.37.1.
  Virtualization:
    Docker: 20.10.12 - C:\Program Files\Docker\Docker\resources\bin\docker.EXE
  IDEs:
    VSCode: 1.72.2 - C:\Program Files\Microsoft VS Code\bin\code.CMD
    Visual Studio: 17.3.32825.248 (Visual Studio Enterprise 2022), 16.11.32106.194 (Visual Studio Enterprise�2019)
  Languages:
    Java: 1.8.0_321
    Python: 3.10.7
  Browsers:
    Internet Explorer: 11.0.17763.2989

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JamieMasoncommented, Oct 28, 2022

Thanks @muravjev.

The kinds of formatters needed haven’t changed very much since working on syncpack, so it’s not something I need to optimise for just now. If in the future I find I’m having to do a lot of manual work in this area though, I’ve got your idea in the back pocket I can refer to.

1reaction
JamieMasoncommented, Oct 27, 2022

Great report @muravjev, thanks. See also #91 which is quite similar. Will pick this up when I next work on syncpack.

Read more comments on GitHub >

github_iconTop Results From Across the Web

syncpack/package.json at master · JamieMason ... - GitHub
Consistent dependency versions in large JavaScript Monorepos. - syncpack/package.json at master · JamieMason/syncpack.
Read more >
syncpack - npm
Manage multiple package.json files, such as in Lerna Monorepos and ... are used where available, such as the "repository" and "bugs" fields.
Read more >
npm WARN package.json: No repository field - Stack Overflow
If you are getting this from your own package.json , just add the repository field to it. (use the link to your actual...
Read more >
npm packages in the Package Registry - GitLab Docs
In the GitLab project that houses your .npmrc and package.json , edit or create a ... Due to a bug in npm 6.9.0,...
Read more >
But what the hell is package-lock.json?
json will simply avoid this general behavior of installing updated minor version so when someone clones your repo and run npm install in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found