syncpack doesn't respect package.json 'repository' and 'bugs' fields
See original GitHub issueDescription
- Create package.json with extended fields
repository
andbugs
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"
}
-
Run
syncpack format
-
Syncpack changes
repository
andbugs
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:
-
Add boolean flag
shortenUrl
to control such shortening behavior with default value true (to keep existing behavior as default). -
In case of
repository
and/orbugs
fields has extra sub fields besidesurl
, the shortening should not be undertook, even if shortenUrl flag is true.
OR
To avoid over complicating and adding extra flags:
- In case of
repository
and/orbugs
fields has extra sub fields besidesurl
, 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
- Clone https://github.com/muravjev/reprl_synpack_format_bug
- Run
pnpm repro
- 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:
- Created a year ago
- Comments:5 (3 by maintainers)
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.
Great report @muravjev, thanks. See also #91 which is quite similar. Will pick this up when I next work on syncpack.