Skip to content

Plugins priority for config and CLI args #322

Open

Description

@giuseppeg

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

Activity

  1. giuseppeg commented on Aug 20, 2020

    @giuseppeg
    ContributorAuthor

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

  2. Scrum commented on Aug 22, 2020

    @Scrum
    Member

    @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

  3. giuseppeg commented on Aug 22, 2020

    @giuseppeg
    ContributorAuthor

    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)

  4. Scrum commented on Aug 22, 2020

    @Scrum
    Member

    @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

  5. giuseppeg commented on Aug 22, 2020

    @giuseppeg
    ContributorAuthor

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

  6. Scrum commented on Aug 23, 2020

    @Scrum
    Member

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

  7. giuseppeg commented on Aug 23, 2020

    @giuseppeg
    ContributorAuthor

    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?

  8. Scrum commented on Aug 26, 2020

    @Scrum
    Member

    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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions