Skip to content

feat: Implement default configuration where possible#83

Merged
phated merged 5 commits intomasterfrom
phated/configless
Apr 12, 2022
Merged

feat: Implement default configuration where possible#83
phated merged 5 commits intomasterfrom
phated/configless

Conversation

@phated
Copy link
Member

@phated phated commented Apr 7, 2022

This was a random idea I had while working on this package. Why do we require people to configure their require hooks? We can (mostly) do that for them when we load the hook. Many of the hooks I researched allow you to pass any options when calling the register function.

This PR demonstrates the things we could override by default. Looking for thoughts about the overall idea.

@phated phated requested review from sttk and yocontra April 7, 2022 03:58
@phated
Copy link
Member Author

phated commented Apr 8, 2022

@sttk what do you think of this approach? Will it cause users to be confused?

@sttk
Copy link
Contributor

sttk commented Apr 9, 2022

@phated I forget the inside of interpret and rechoir, and try to remember them now. Please wait for a while.

@sttk
Copy link
Contributor

sttk commented Apr 9, 2022

@phated I think that this is good idea, but I'm worried that there are no way that user changes this default configuration because it is inside a function.
How about adding a new property to specify this options, and merging it in a function? (Though this needs to modify rechoir.)

var extensions = {
  '.babel.js': {
    module: '@babel/register',
    register: function (hook, overrides) {
      hook({
        extensions: '.js',
        rootMode: 'upward-optional',
        // MODIFY: Merge configurations with excluding necessary options.
        overrides: [defaults({ only: [endsInBabelJs] }, overrides)],
      }, options);
    },
    // ADD: Configurations which are customizable
    overrides: { presets: ['@babel/preset-env'] },
  },
  ...
};

@phated
Copy link
Member Author

phated commented Apr 10, 2022

@sttk thank you! I like your idea but I want to think of the best way to implement it.

@phated phated force-pushed the phated/configless branch from 637d2e0 to 2cd9efb Compare April 12, 2022 00:38
@phated
Copy link
Member Author

phated commented Apr 12, 2022

@sttk I adjusted your idea slightly, but I like how this turned out! Now, a consumer can pass any config they want to override the default hook config, and it will completely replace all config except the { extensions } property.

Overriding the default config is a very advanced technique, so I'm only documenting it a tiny bit.

@phated
Copy link
Member Author

phated commented Apr 12, 2022

I'm going to merge this, but will plan to cut the 3.0.0 release in the next couple of days. Please let me know if you see anything bad about this!

@phated phated merged commit 85e3193 into master Apr 12, 2022
@phated phated deleted the phated/configless branch April 12, 2022 00:49
phated added a commit that referenced this pull request Apr 12, 2022
feat: Allow register function configuration to be overridden
@github-actions github-actions bot mentioned this pull request Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants