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

Plugins priority for config and CLI args #322

Open
giuseppeg opened this issue Aug 20, 2020 · 8 comments
Open

Plugins priority for config and CLI args #322

giuseppeg opened this issue Aug 20, 2020 · 8 comments
Labels

Comments

@giuseppeg
Copy link
Contributor

giuseppeg commented Aug 20, 2020

@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
Copy link
Contributor Author

giuseppeg commented Aug 20, 2020

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).

@Scrum
Copy link
Member

Scrum commented Aug 22, 2020

@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

@giuseppeg
Copy link
Contributor Author

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 (#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)

@Scrum
Copy link
Member

Scrum commented Aug 22, 2020

@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

@giuseppeg
Copy link
Contributor Author

giuseppeg commented Aug 22, 2020

@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.

@Scrum
Copy link
Member

Scrum commented Aug 23, 2020

@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.

@giuseppeg
Copy link
Contributor Author

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?

@Scrum
Copy link
Member

Scrum commented Aug 26, 2020

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 Scrum added the feat label Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants