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

Overload defineConfig to accept a RollupOptionsFunction parameter #4728

Merged
merged 3 commits into from Dec 1, 2022

Conversation

Septh
Copy link
Contributor

@Septh Septh commented Nov 28, 2022

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This PR provides a defineConfigFunction auxiliary function, akin to defineConfig but for configs that exports a function:

// Adapted from last example at https://rollupjs.org/guide/en/#configuration-files
export default defineConfigFunction(commandLineArgs => {
  const inputBase = commandLineArgs.input || 'main.js';
  delete commandLineArgs.input;
  return {
    input: 'src/entries/' + inputBase,
    output: {...}
  }
})

@Septh
Copy link
Contributor Author

Septh commented Nov 28, 2022

I'm not really fond of the naming...

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea

I'm not really fond of the naming...

neither am I. Why not just overload defineConfig a third time to also accept a RollupConfigFunction as parameter?

@codecov
Copy link

codecov bot commented Nov 28, 2022

Codecov Report

Merging #4728 (30b17da) into master (4b1a954) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #4728   +/-   ##
=======================================
  Coverage   99.03%   99.03%           
=======================================
  Files         217      217           
  Lines        7690     7690           
  Branches     2126     2126           
=======================================
  Hits         7616     7616           
  Misses         24       24           
  Partials       50       50           
Impacted Files Coverage Δ
src/rollup/rollup.ts 100.00% <ø> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@Septh
Copy link
Contributor Author

Septh commented Nov 28, 2022

Why not just overload defineConfig a third time to also accept a RollupConfigFunction as parameter?

Why making it simple when we can make it complicated? 😃

You're absolutely right, I'm updating the PR ASAP. 🙏

@Septh Septh changed the title Add defineConfigFunction auxiliary function Overload defineConfig to accept a RollupOptionsFunction parameter Nov 28, 2022
@Septh
Copy link
Contributor Author

Septh commented Nov 28, 2022

Also renamed the type from RollupConfigFunction to RollupOptionsFunction, for consistency.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, consider if you want to improve the test descriptions, will merge this in the next days.

@@ -41,6 +41,15 @@ describe('loadConfigFile', () => {
assert.deepStrictEqual(JSON.parse(JSON.stringify(options)), defaultConfigs);
});

it('loads an ESM config file exporting a config with defineConfigFn()', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: The two test descriptions no longer fit.

Copy link
Member

@lukastaegert lukastaegert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome 🎉

@lukastaegert lukastaegert enabled auto-merge (squash) December 1, 2022 05:16
@lukastaegert lukastaegert merged commit f44c933 into rollup:master Dec 1, 2022
@rollup-bot
Copy link
Collaborator

This PR has been released as part of rollup@3.5.1. You can test it via npm install rollup.

@Septh Septh deleted the pr/defineConfigFn branch January 25, 2023 00:22
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.

None yet

3 participants