posthtml-cli icon indicating copy to clipboard operation
posthtml-cli copied to clipboard

Plugins priority for config and CLI args

Open giuseppeg opened this issue 5 years ago • 8 comments

@Scrum with my previous PR the declaration order of the plugin is now stable. Would you accept a new PR to add a config file option to configure whether config.plugins are registered before or after plugins enabled via CLI?

For example, given the following CLI invokation:

posthtml index.html -u posthtml-plugin-foo -c posthtml.config.js

And posthtml.config.js:

module.exports = {
  plugins: {
    priority: 'high', // default to 'normal' to preserve the current behavior
    ...
  }
}

It applies the plugins from the config file first and then the ones passed as CLI arguments.

My use case is the following: I am building a CLI that wraps posthtml-cli. When I call posthtml-cli I pass some default plugins via CLI arguments along with the rest of the original args. Since users can pass --config posthtml.config.js my plugins will always run first whereas in many cases it'd be better to run them at the end.

Happy to submit a PR if you like this idea.

giuseppeg avatar Aug 20 '20 15:08 giuseppeg

Maybe this should be a CLI option so that this change doesn't affect the configuration and posthtml the library. In that case we can do --use.priority low (default to high to preserve the current behavior).

giuseppeg avatar Aug 20 '20 15:08 giuseppeg

@giuseppeg I like the idea itself, but I think we are not fighting a problem.

What are you trying to prioritize?

In fact, there should not be any priority as such, there is an order that must be followed for a correct transformation. https://github.com/post/post-sequence

Happy to submit a PR if you like this idea.

I will gladly accept your request if another idea does not suit you

Scrum avatar Aug 22 '20 11:08 Scrum

What are you trying to prioritize?

I am writing a CLI that wraps posthtml-cli and adds two plugins via arguments. So users install and run my CLI and internally I invoke

posthtml -u posthtml-extends -u -posthtml-markdown

With our recent changes (https://github.com/posthtml/posthtml-cli/pull/319) these plugins are always first and if you also have an external configuration...

posthtml -u posthtml-extends -u -posthtml-markdown -c posthtml.config.js

...there is no way to run posthtml-extends and posthtml-markdown at the end.

I think that in this specific case it could be useful to run them at the end - imagine someone adds a plugin for loops and other expressions (https://github.com/posthtml/posthtml-expressions#loops). From your experience is it ok to run posthtml-extends as the first plugin? (again imagine you have a loop with extends)

giuseppeg avatar Aug 22 '20 14:08 giuseppeg

@giuseppeg What do you think about 👇

In fact, there should not be any priority as such, there is an order that must be followed for a correct transformation. https://github.com/post/post-sequence

Scrum avatar Aug 22 '20 14:08 Scrum

@Scrum as far as I understood that is to create a configuration object (which you write to a file) with a specific order.

Basically that's something the end user would do but I am not sure if it'll work because we always start to construct the final plugins object from flags.use (see https://github.com/posthtml/posthtml-cli/pull/319/files#diff-532c51740b320dd4ec5143dd090e5d5aR25) so the plugins set via CLI arguments will always have precedence.

giuseppeg avatar Aug 22 '20 15:08 giuseppeg

@Scrum as far as I understood that is to create a configuration object (which you write to a file) with a specific order.

this saves us from having to introduce the notion of priority as such, providing already correctly configured order of application of packages.

Basically that's something the end user would do but I am not sure if it'll work because we always start to construct the final plugins object from flags.use (see https://github.com/posthtml/posthtml-cli/pull/319/files#diff-532c51740b320dd4ec5143dd090e5d5aR25) so the plugins set via CLI arguments will always have precedence.

As I wrote earlier, if the priority system suits you more, namely, it gives the user the ability to customize the order according to the priority rules manually, then I will accept this option.

Scrum avatar Aug 23 '20 10:08 Scrum

In theory we could change how we merge the plugins (config file and flags.use) to let the config file dictate the order. Users can then use https://github.com/post/post-sequence to decide when to execute flags.use.

Probably this is how it was in the beginning before we made the changes I suggested (sorry for that) - can you confirm? If that was the case.. what do you suggest we do? Another breaking change?

giuseppeg avatar Aug 23 '20 16:08 giuseppeg

I think it's worth trying to add the package post-sequence into the general system under the flag of sequence: true|false

what do you think of it ?

Scrum avatar Aug 26 '20 06:08 Scrum