syncpack icon indicating copy to clipboard operation
syncpack copied to clipboard

Make syncpack configurable from the 'config' option in package.json

Open bombillazo opened this issue 3 years ago • 2 comments
trafficstars

Description

Currently, when configuring syncpack from package.json, it is only configurable with the syncpack option directly in the root of the package.json file. For compatibility with the config option, it would be great if syncpack also checked for the config inside the config option.

Suggested Solution

Have syncpack check for the configuration inside config:

{
  ...
  "config" : {
    "syncpack" : {
      // syncpack configuration
    }
}

bombillazo avatar Jul 10 '22 23:07 bombillazo

Hey Hector, this is all handled by https://github.com/davidtheclark/cosmiconfig – not sure yet but maybe it's some option we need to pass or it's something they might add as a new feature on request.

JamieMason avatar Jul 11 '22 08:07 JamieMason

Hey, thanks for the response, here's the prop you're looking for: packageProp : ['config', 'syncpack']

Looks like it only allows one value for package.json, it would've been nice if multiple values were could be configured.

bombillazo avatar Jul 11 '22 09:07 bombillazo

Had a quick look at this just now @bombillazo, what it would need is for syncpack to run cosmiconfig a 2nd time if result is null the first time.

https://github.com/JamieMason/syncpack/blob/2d9516f02b579ecb9ebc1c632ae4db997d796312/src/lib/disk.ts#L31

I'll lower the priority on this rather than close it, as I can see why it would be desirable. But a relative minority of users would use it, while all users which don't use the default config file location would get a performance penalty.

Thanks for raising, let's look again in a while.

JamieMason avatar Oct 28 '22 12:10 JamieMason

Sure, one recommendation I could give is to directly read the package.json file and see which keys exist before running cosmiconfig:

var pjson = require('./package.json');
const hasConfigOption = !!pjson.config.syncpack

The performance penalty for this is minimal, especially compared to rerunning cosmiconfig.

bombillazo avatar Oct 28 '22 15:10 bombillazo

Yeah, good shout 👍🏻

JamieMason avatar Oct 28 '22 15:10 JamieMason

Released in 8.3.8, thanks a lot.

JamieMason avatar Oct 28 '22 16:10 JamieMason

Thank you!

bombillazo avatar Oct 28 '22 16:10 bombillazo