chore: use bundled dts for register and eslint-* (#17993)

* chore(dts): bundle babel-register and eslint-*

* chore: cleanup yarn constraints config

* chore: improve eslint-* typings
This commit is contained in:
Huáng Jùnliàng
2026-05-20 21:39:20 -04:00
committed by GitHub
parent 0d4e8503bd
commit 2093765b12
17 changed files with 62 additions and 144 deletions
-7
View File
@@ -943,13 +943,6 @@ const dtsBundles = Array.from(
// Not meant to be consumed manually
"babel-runtime",
"babel-runtime-corejs3",
// TODO: Add type definitions
"babel-register",
"babel-eslint-plugin",
"babel-eslint-plugin-development",
"babel-eslint-plugin-development-internal",
// Not meant to be consumed manually
"babel-eslint-shared-fixtures",
"babel-eslint-tests",
])
+1 -2
View File
@@ -21,10 +21,9 @@
},
"main": "./lib/index.js",
"type": "module",
"types": "./types.d.ts",
"exports": {
".": {
"types": "./types.d.ts",
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./package.json": "./package.json"
+10 -3
View File
@@ -1,19 +1,26 @@
import type { ESLint, Linter, AST } from "eslint";
import normalizeESLintConfig from "./configuration.ts";
import analyzeScope from "./analyze-scope.ts";
import baseParse from "./parse.ts";
import { getVisitorKeys } from "./ast-info.ts";
export const meta = {
export const meta: ESLint.ObjectMetaProperties["meta"] = {
name: PACKAGE_JSON.name,
version: PACKAGE_JSON.version,
};
export function parse(code: string, options = {}) {
export function parse(
code: string,
options: Linter.ParserOptions = {},
): AST.Program {
return baseParse(code, normalizeESLintConfig(options));
}
export function parseForESLint(code: string, options = {}) {
export function parseForESLint(
code: string,
options: Linter.ParserOptions = {},
): Linter.ESLintParseResult {
const normalizedOptions = normalizeESLintConfig(options);
const ast = baseParse(code, normalizedOptions);
const scopeManager = analyzeScope(ast, normalizedOptions);
-9
View File
@@ -1,9 +0,0 @@
import type { ESLint, Linter, AST } from "eslint";
export declare const meta: ESLint.ObjectMetaProperties["meta"];
export declare const parse: (text: string, options?: any) => AST.Program;
export declare const parseForESLint: (
text: string,
options?: any
) => Linter.ESLintParseResult;
@@ -26,7 +26,7 @@
"type": "module",
"exports": {
".": {
"types": "./types.d.ts",
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./package.json": "./package.json"
@@ -1,13 +1,15 @@
import type { ESLint } from "eslint";
import type { ESLint, Rule } from "eslint";
import noExtraneousDependencies from "./rules/no-extraneous-dependencies.ts";
import reportErrorMessageFormat from "./rules/report-error-message-format.ts";
const meta = {
const meta: ESLint.Plugin["meta"] = {
name: PACKAGE_JSON.name,
version: PACKAGE_JSON.version,
};
const rules = {
type Rules = "no-extraneous-dependencies" | "report-error-message-format";
const rules: Record<Rules, Rule.RuleModule> = {
"no-extraneous-dependencies": noExtraneousDependencies,
"report-error-message-format": reportErrorMessageFormat,
};
@@ -1,7 +0,0 @@
import type { ESLint, Rule } from "eslint";
type Rules = "report-error-message-format";
export declare const meta: ESLint.ObjectMetaProperties["meta"];
export declare const rules: Record<Rules, Rule.RuleModule>;
export declare const rulesConfig: Record<Rules, string>;
@@ -12,7 +12,7 @@
"type": "module",
"exports": {
".": {
"types": "./types.d.ts",
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./package.json": "./package.json"
@@ -1,14 +1,16 @@
import type { ESLint } from "eslint";
import type { ESLint, Rule } from "eslint";
import noDeprecatedClone from "./rules/no-deprecated-clone.ts";
import noUndefinedIdentifier from "./rules/no-undefined-identifier.ts";
import pluginName from "./rules/plugin-name.ts";
const meta = {
const meta: ESLint.Plugin["meta"] = {
name: PACKAGE_JSON.name,
version: PACKAGE_JSON.version,
};
const rules = {
type Rules = "no-deprecated-clone" | "no-undefined-identifier" | "plugin-name";
const rules: Record<Rules, Rule.RuleModule> = {
"no-deprecated-clone": noDeprecatedClone,
"no-undefined-identifier": noUndefinedIdentifier,
"plugin-name": pluginName,
-7
View File
@@ -1,7 +0,0 @@
import type { ESLint, Rule } from "eslint";
type Rules = "no-deprecated-clone" | "no-undefined-identifier" | "plugin-name";
export declare const meta: ESLint.ObjectMetaProperties["meta"];
export declare const rules: Record<Rules, Rule.RuleModule>;
export declare const rulesConfig: Record<Rules, string>;
+1 -2
View File
@@ -4,10 +4,9 @@
"description": "Companion rules for @babel/eslint-parser",
"main": "./lib/index.js",
"type": "module",
"types": "./types.d.ts",
"exports": {
".": {
"types": "./types.d.ts",
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./package.json": "./package.json"
+7 -3
View File
@@ -1,13 +1,16 @@
import type { ESLint, Rule } from "eslint";
import newCap from "./rules/new-cap.ts";
import noUndef from "./rules/no-undef.ts";
import noUnusedExpressions from "./rules/no-unused-expressions.ts";
const meta = {
const meta: ESLint.Plugin["meta"] = {
name: PACKAGE_JSON.name,
version: PACKAGE_JSON.version,
};
const rules = {
type Rules = "new-cap" | "no-undef" | "no-unused-expressions";
const rules: Record<Rules, Rule.RuleModule> = {
"new-cap": newCap,
"no-undef": noUndef,
"no-unused-expressions": noUnusedExpressions,
@@ -19,4 +22,5 @@ const rulesConfig = {
"no-unused-expressions": "off",
};
export default { meta, rules, rulesConfig };
// @ts-expect-error TODO(Babel 9): Remove rulesConfig in favor of configs
export default { meta, rules, rulesConfig } satisfies ESLint.Plugin;
-7
View File
@@ -1,7 +0,0 @@
import type { ESLint, Rule } from "eslint";
type Rules = "new-cap" | "no-undef" | "no-unused-expressions";
export declare const meta: ESLint.ObjectMetaProperties["meta"];
export declare const rules: Record<Rules, Rule.RuleModule>;
export declare const rulesConfig: Record<Rules, string>;
+2 -1
View File
@@ -16,7 +16,8 @@
"./plugins": "./data/plugins.json",
"./native-modules": "./data/native-modules.json",
"./overlapping-plugins": "./data/overlapping-plugins.json",
"./plugin-bugfixes": "./data/plugin-bugfixes.json"
"./plugin-bugfixes": "./data/plugin-bugfixes.json",
"./package.json": "./package.json"
},
"scripts": {
"build-data": "./scripts/download-compat-table.sh && node ./scripts/build-data.mjs && node ./scripts/build-modules-support.mjs && node ./scripts/build-bugfixes-targets.mjs"
+1
View File
@@ -38,6 +38,7 @@
},
"exports": {
".": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
},
"./package.json": "./package.json"
+3
View File
@@ -17,6 +17,9 @@
"@babel/compat-data/plugin-bugfixes": [
"./packages/babel-compat-data/data/plugin-bugfixes.json"
],
"@babel/compat-data/package.json": [
"./packages/babel-compat-data/package.json"
],
"@babel/core": [
"./packages/babel-core/src"
],
+25 -88
View File
@@ -1,5 +1,5 @@
// @ts-check
/// <reference lib="es2015" />
/// <reference lib="es2015" types="node" />
/**
* @typedef {import('@yarnpkg/types').Yarn.Constraints.Context} Context
@@ -11,13 +11,6 @@ const babel7plugins_babel8core = new Set(
/**
* Enforces that all workspaces depend on other workspaces using `workspace:^`
*
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, 'workspace:^', DependencyType) :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, DependencyRange, DependencyType),
% Only consider dependency ranges that start with 'workspace:'
atom_concat('workspace:', _, DependencyRange),
% Only consider 'dependencies' and 'devDependencies'
(DependencyType = 'dependencies'; DependencyType = 'devDependencies').
* @param {Context} context
*/
function enforceWorkspaceDependencies({ Yarn }) {
@@ -63,26 +56,6 @@ function enforcePackageInfo({ Yarn }) {
/**
* Enforces the engines.node field for all workspaces
gen_enforced_field(WorkspaceCwd, 'engines.node', '>=6.9.0') :-
\+ workspace_field(WorkspaceCwd, 'private', true),
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
% Exempt from the rule as it supports '>=6.0.0'. TODO: remove with the next major
WorkspaceIdent \= '@babel/parser',
% Skip '@babel/eslint*' workspaces. TODO: remove with the next major
\+ atom_concat('@babel/eslint', _, WorkspaceIdent).
% Enforces the engines.node field for '@babel/eslint*' workspaces
gen_enforced_field(WorkspaceCwd, 'engines.node', "^22.18.0 || >=24.11.0") :-
\+ workspace_field(WorkspaceCwd, 'private', true),
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
% Only target '@babel/eslint*' workspaces
atom_concat('@babel/eslint', _, WorkspaceIdent).
% Removes the 'engines.node' field from private workspaces
gen_enforced_field(WorkspaceCwd, 'engines.node', null) :-
workspace_field(WorkspaceCwd, 'private', true).
* @param {Context} context
*/
function enforceEnginesNodeForPublicUnsetForPrivate({ Yarn }) {
@@ -100,15 +73,6 @@ function enforceEnginesNodeForPublicUnsetForPrivate({ Yarn }) {
/**
* Enforces the main and types field to start with ./
gen_enforced_field(WorkspaceCwd, FieldName, ExpectedValue) :-
% Fields the rule applies to
member(FieldName, ['main', 'types']),
% Get current value
workspace_field(WorkspaceCwd, FieldName, CurrentValue),
% Must not start with ./ already
\+ atom_concat('./', _, CurrentValue),
% Store './' + CurrentValue in ExpectedValue
atom_concat('./', CurrentValue, ExpectedValue).
* @param {Context} context
*/
function enforceMainAndTypes({ Yarn }) {
@@ -125,8 +89,6 @@ function enforceMainAndTypes({ Yarn }) {
/**
* Enforces the type field to be set
gen_enforced_field(WorkspaceCwd, 'type', 'commonjs') :-
\+ workspace_field(WorkspaceCwd, 'type', 'module').
* @param {Context} context
*/
function enforceType({ Yarn }) {
@@ -139,9 +101,6 @@ function enforceType({ Yarn }) {
/**
* Enforces that a dependency doesn't appear in both `dependencies` and `devDependencies`
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'devDependencies') :-
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'devDependencies'),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies').
* @param {Context} context
*/
function enforceNoDualTypeDependencies({ Yarn }) {
@@ -162,12 +121,6 @@ function enforceNoDualTypeDependencies({ Yarn }) {
/**
* Enforces that @babel/helper-* must not depend on @babel/traverse, @babel/template, @babel/types if they peer-depend on @babel/core
gen_enforced_dependency(WorkspaceCwd, DependencyIdent, null, 'dependencies') :-
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
atom_concat('@babel/helper-', _, WorkspaceIdent),
workspace_has_dependency(WorkspaceCwd, '@babel/core', _, 'peerDependencies'),
member(DependencyIdent, ['@babel/template', '@babel/traverse', '@babel/types']).
* @param {Context} context
*/
function enforceBabelHelperBabelDeps({ Yarn }) {
@@ -185,17 +138,6 @@ function enforceBabelHelperBabelDeps({ Yarn }) {
/**
* Enforces that @babel/core must not be in dependency for most packages
gen_enforced_dependency(WorkspaceCwd, '@babel/core', null, 'dependencies') :-
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
% Exclude some packages
\+ member(WorkspaceIdent, ['@babel/eslint-shared-fixtures', '@babel/eslint-tests', '@babel/helper-transform-fixture-test-runner']).
* Enforces that @babel/core should be in devDependencies if a package peer-depends on @babel/core and it does not list @babel/core in dependencies. Doing so will ensure that they are linked to an ESM @babel/core build in the e2e ESM tests.
gen_enforced_dependency(WorkspaceCwd, '@babel/core', 'workspace:^', 'devDependencies') :-
workspace_has_dependency(WorkspaceCwd, '@babel/core', _, 'peerDependencies'),
\+ workspace_has_dependency(WorkspaceCwd, '@babel/core', _, 'dependencies').
* @param {Context} context
*/
function enforceBabelCoreNotInDeps({ Yarn }) {
@@ -221,45 +163,39 @@ function enforceBabelCoreNotInDeps({ Yarn }) {
}
/**
* Enforces `exports` to be consistent
*
gen_enforced_field(WorkspaceCwd, 'exports', '{ ".": "./lib/index.js", "./package.json": "./package.json" }') :-
\+ workspace_field(WorkspaceCwd, 'private', true),
% Exclude packages with more complex `exports`
workspace_ident(WorkspaceCwd, WorkspaceIdent),
WorkspaceIdent \= '@babel/compat-data',
WorkspaceIdent \= '@babel/helper-plugin-test-runner', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/core', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/parser',
WorkspaceIdent \= '@babel/plugin-transform-react-jsx', % TODO: Remove in Babel 8
WorkspaceIdent \= '@babel/standalone',
WorkspaceIdent \= '@babel/types', % @babel/types has types exports
\+ atom_concat('@babel/eslint-', _, WorkspaceIdent),
\+ atom_concat('@babel/runtime', _, WorkspaceIdent).
* Enforces `exports` to be consistent, and ensures that `./package.json` is always exported for public packages.
* Also enforces `types` is unset in favor of the `exports` field for type exports.
* @param {Context} context
*/
function enforceExports({ Yarn }) {
function enforceExportsAndTypes({ Yarn }) {
for (const workspace of Yarn.workspaces()) {
if (workspace.manifest.private) continue;
// Exclude packages with more complex `exports`
const packageName = workspace.pkg.ident;
if (
[
"@babel/compat-data",
"@babel/helper-globals",
"@babel/helper-plugin-test-runner", // TODO: Remove in Babel 8
"@babel/plugin-transform-react-jsx", // TODO: Remove in Babel 8
"@babel/standalone",
"@babel/types", // @babel/types has types exports
"@babel/register", // index.cjs
"@babel/code-frame", // browser.js
"@babel/node",
"@babel/build-external-helpers",
"@babel/cli",
"@babel/compat-data", // JSON library
"@babel/helper-globals", // JSON library
"@babel/standalone", // No index.js entry point
"@babel/node", // cli
"@babel/build-external-helpers", // cli
"@babel/cli", // cli
].includes(packageName) ||
packageName.startsWith("@babel/eslint-") ||
packageName.startsWith("@babel/runtime")
) {
workspace.set("exports['./package.json']", "./package.json");
continue;
} else if (
[
"@babel/helper-plugin-test-runner", // Custom exports["."].esm
"@babel/plugin-transform-react-jsx", // Extra entry points
"@babel/code-frame", // Custom exports["."].browser
].includes(packageName)
) {
workspace.set("exports['.'].default", "./lib/index.js");
workspace.set("exports['.'].types", "./lib/index.d.ts");
workspace.set("exports['./package.json']", "./package.json");
workspace.unset("types");
continue;
}
@@ -270,6 +206,7 @@ function enforceExports({ Yarn }) {
},
"./package.json": "./package.json",
});
workspace.unset("types");
}
}
@@ -305,7 +242,7 @@ module.exports = {
enforceEnginesNodeForPublicUnsetForPrivate(ctx);
enforceMainAndTypes(ctx);
enforceType(ctx);
enforceExports(ctx);
enforceExportsAndTypes(ctx);
enforceNoDualTypeDependencies(ctx);
enforceBabelHelperBabelDeps(ctx);
if (process.env.BABEL_CORE_DEV_DEP_VERSION) {