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

feat: add config path option #71

Closed
tom-fletcher opened this issue Apr 20, 2022 · 3 comments
Closed

feat: add config path option #71

tom-fletcher opened this issue Apr 20, 2022 · 3 comments

Comments

@tom-fletcher
Copy link
Contributor

tom-fletcher commented Apr 20, 2022

Description

Currently, syncpack only locates the config file (if present) with cosmiconfig.

Other tools, such as ESLint and Prettier, allow the user to specific a configuration path other than the normal one auto-detected. This can be useful for i.e. moving the config files out of the package root and into a config/ folder. Allowing a custom config path would bring syncpack into parity with these tools.

Suggested Solution

Add -c / --config option to CLI:

  -i, --indent [value]    override indentation. defaults to "  "
+ -c, --config <path>     path to a syncpack config file, overriding automatic detection
  -h, --help              display help for command

When specified, use that path to locate the config file. If the file is not present, exit with an error.

When not specified, locate the config settings with cosmiconfig as normal.

PR

Happy to look at submitting a PR on this.

@tom-fletcher
Copy link
Contributor Author

I ended up with a bit of time this afternoon to look at this, and it was fairly straightforward. cosmiconfig does the heavy lifting again, all that was needed was to add a config option to the CLI and pass this through.

Of course still open for discussion if there are opinions on how to implement!

I decided to pass the config path through as a new parameter on getInput()

export function getInput(
   disk: Disk,
+  configPath: string | undefined, 
   program: Partial<SyncpackConfig>,
): ProgramInput

Initially I considered passing this through with other options on the program parameter, but this would have meant adding a config: key to the SyncpackConfig type, and it felt better to seperate this. The config option points to the config, rather than being part of the config. This did mean some tests needed to be updated, just to pass an extra option through.

@JamieMason
Copy link
Owner

Released in 7.1.0

@tom-fletcher
Copy link
Contributor Author

Very nice, thanks! 🎉

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.

2 participants