Skip to content

feat: Add defineConfig#17905

Open
liuxingbaoyu wants to merge 1 commit intobabel:mainfrom
liuxingbaoyu:defineConfig
Open

feat: Add defineConfig#17905
liuxingbaoyu wants to merge 1 commit intobabel:mainfrom
liuxingbaoyu:defineConfig

Conversation

@liuxingbaoyu
Copy link
Copy Markdown
Member

Q                       A
Fixed Issues? Fixes #1, Fixes #2
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

This allows users to more easily configure plugin and preset options.

@babel-bot
Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61260

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 26, 2026

Open in StackBlitz

commit: 600776c

? [F & (((...args: any) => any) | string | object)]
: T & (((...args: any) => any) | string | object);

export function defineConfig<
Copy link
Copy Markdown
Contributor

@JLHwung JLHwung Mar 26, 2026

Choose a reason for hiding this comment

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

Can we move the implementation to ./config/validation/declare-config.ts and re-export it here?

I suggest we rename it to declareConfig to align with declarePreset.

Aside: maybe we can also add an alias of declarePlugin in helper-plugin-utils to declare, and somehow we should have declarePreset providing the same typing hints as declareConfig.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The name defineConfig is inspired by eslint. I've also noticed that similar functions to tsup and vite are called defineConfig.

Copy link
Copy Markdown
Contributor

@JLHwung JLHwung Apr 2, 2026

Choose a reason for hiding this comment

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

Understood. However we don't have to choose the same name as other projects, as different naming could also benefit users, for example, think of a @babel/eslint-parser user using eslint.config.ts:

import { defineConfig } from "@eslint/config"
import { declareConfig } from "@babel/core"
import babelEslintParser from "@babel/eslint-parser"

export default defineConfig([{
  languageOptions: {
      parser: babelEslintParser,
      parserOptions: {
        babelOptions: declareConfig({
          plugins: [ ... ],
        }),
        requireConfigFile: false,
      },
    },
}])

A different export name reduces the possibility that people misused exports from @babel/core to eslint or vice. Since both defineConfig and declareConfig are merely typing helpers, such usage may still work if users do not run tsc on the config files.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants