Closed giuseppeg closed 4 years ago
If you have a config file say posthtml.config.js
{ plugins: { 'posthtml-a': { someOption: true } } }
and set another plugin via CLI and pass other options for posthtml-a
posthtml-a
posthtml *.html -u posthtml-d -u posthtml-a --posthtml-a.foo 3 -c posthtml.config.js
I'd expect the CLI plugins to be applied first but instead posthtml-cli merges the config and the CLI options in the wrong order:
{ plugins: { 'posthtml-a': { someOption: true, foo: 3 }, 'posthtml-d': {} } }
Notice that posthtml-a now comes before posthtml-d. This is because the merging target is the config file so the keys orders is mandated by the config file. The desiderable ordered would be
posthtml-d
config
{ plugins: { 'posthtml-d': {}, 'posthtml-a': { someOption: true, foo: 3 } } }
because that's the order in the CLI arguments.
Merge everything manually and in order here https://github.com/posthtml/posthtml-cli/blob/461615213ccd1bb66817582f9f42572d34946cfb/src/cfg-resolve.js#L21-L23
and then delete config.plugins so that when at the end of the function we do the final merging config doesn't have plugins.
delete config.plugins
@giuseppeg Thanks for this great request 👍
If you have a config file say posthtml.config.js
and set another plugin via CLI and pass other options for
posthtml-a
I'd expect the CLI plugins to be applied first but instead posthtml-cli merges the config and the CLI options in the wrong order:
Notice that
posthtml-a
now comes beforeposthtml-d
. This is because the merging target is theconfig
file so the keys orders is mandated by the config file. The desiderable ordered would bebecause that's the order in the CLI arguments.
possible solutions
Merge everything manually and in order here https://github.com/posthtml/posthtml-cli/blob/461615213ccd1bb66817582f9f42572d34946cfb/src/cfg-resolve.js#L21-L23
and then
delete config.plugins
so that when at the end of the function we do the final mergingconfig
doesn't have plugins.