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

Format command removes "directory" property when converting "repository" to shorthand #91

Closed
jodyheavener opened this issue Aug 6, 2022 · 3 comments

Comments

@jodyheavener
Copy link
Contributor

jodyheavener commented Aug 6, 2022

Description

The format command likes to convert the long-form "repository" property into the shorthand version. However in a monorepo with multiple packages, one can use the "directory" property in the repository object to denote where the package lives if it's not at the root, so when the command is run it erroneously erases that directory property.

Steps to reproduce:

Set up a project with a package.json and set the "repository" property to the long-form version, with a "directory" property. For example:

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

Run syncpack format.

Expected result

Syncpack knows to retain the "directory" key-value pair intact.

Actual result

The "repository" property is formatted into shorthand (e.g. facebook/react.git), removing the "directory" property.

Suggested Solution

Since there is no way to incorporate the "directory" into the shorthand format, I think if syncpack detects such a property it should abort converting it to shorthand.

Alternatively, a config option to not use shorthand format altogether.

@JamieMason
Copy link
Owner

Thanks Jody, should be an easy fix. I hadn't seen the directory property before.

@muravjev
Copy link

@JamieMason, what do you think if syncpack will add formatters config option, that can be used (and the default value of it now) would be like this

formatters: [
  ["bugs", "repository"]: ["simplifyUrl", "shortenUrl"]
]
  • simplifyUrl - turns object with url subfield into just url string
  • shortenUrl - shortens string by trimming 'https://github.com/' substring.

Though it would be hard coded now (formatters: simplifyUrl, shortenUrl), but it will be highly customizable and later could be easily extended with other formatters which could be assigned on any fields at will.

And if you don't want any field custom formatting you could use:

formatters: []

@JamieMason
Copy link
Owner

Fixed by @jodyheavener in 8.2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants