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

feat: Implement default configuration where possible #83

Merged
merged 5 commits into from Apr 12, 2022

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 yocontra and sttk April 7, 2022 03:58
@phated phated added this to In progress in v5 via automation Apr 7, 2022
@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
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
@phated phated moved this from In progress to Done in v5 May 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
v5
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants