Skip to content

Commit

Permalink
Simplify helper dependencies (#15771)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jul 12, 2023
1 parent b7faa90 commit 476f633
Show file tree
Hide file tree
Showing 17 changed files with 103 additions and 68 deletions.
35 changes: 30 additions & 5 deletions constraints.pro
Expand Up @@ -111,10 +111,35 @@ gen_enforced_field(WorkspaceCwd, 'conditions', '{ "USE_ESM": [{ "type": "module"
WorkspaceIdent \= '@babel/compat-data'.

% Enforces that @babel/runtime-corejs2 must depend on core-js 2
gen_enforced_dependency(WorkspaceCwd, 'core-js', '^2.6.12', DependencyType) :-
gen_enforced_dependency(WorkspaceCwd, 'core-js', '^2.6.12', 'dependencies') :-
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
% Only consider 'dependencies'
(DependencyType = 'dependencies'),
% The rule works for @babel/runtime-corejs2 only
(WorkspaceIdent = '@babel/runtime-corejs2').
workspace_ident(WorkspaceCwd, '@babel/runtime-corejs2').

% Enforces that @babel/helper-* must peer-depend on @babel/core if they depend on @babel/traverse
gen_enforced_dependency(WorkspaceCwd, '@babel/core', '^7.0.0', 'peerDependencies') :-
% Get the workspace name
workspace_ident(WorkspaceCwd, WorkspaceIdent),
atom_concat('@babel/helper-', _, WorkspaceIdent),
workspace_has_dependency(WorkspaceCwd, DependencyIdent, _, 'dependencies'),
(DependencyIdent = '@babel/traverse').

% 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']).

% 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').
12 changes: 8 additions & 4 deletions packages/babel-helper-module-transforms/package.json
Expand Up @@ -19,10 +19,14 @@
"@babel/helper-module-imports": "workspace:^",
"@babel/helper-simple-access": "workspace:^",
"@babel/helper-split-export-declaration": "workspace:^",
"@babel/helper-validator-identifier": "workspace:^",
"@babel/template": "workspace:^",
"@babel/traverse": "workspace:^",
"@babel/types": "workspace:^"
"@babel/helper-validator-identifier": "workspace:^"
},
"devDependencies": {
"@babel/core": "workspace:^",
"@babel/traverse": "workspace:^"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
},
"engines": {
"node": ">=6.9.0"
Expand Down
@@ -1,8 +1,7 @@
// Heavily inspired by
// https://github.com/airbnb/babel-plugin-dynamic-import-node/blob/master/src/utils.js

import * as t from "@babel/types";
import template from "@babel/template";
import { types as t, template } from "@babel/core";

if (!process.env.BABEL_8_BREAKING) {
if (!USE_ESM) {
Expand Down
34 changes: 17 additions & 17 deletions packages/babel-helper-module-transforms/src/index.ts
@@ -1,21 +1,5 @@
import assert from "assert";
import {
booleanLiteral,
callExpression,
cloneNode,
directive,
directiveLiteral,
expressionStatement,
identifier,
isIdentifier,
memberExpression,
stringLiteral,
valueToNode,
variableDeclaration,
variableDeclarator,
} from "@babel/types";
import type * as t from "@babel/types";
import template from "@babel/template";
import { template, types as t } from "@babel/core";

import { isModule } from "@babel/helper-module-imports";

Expand All @@ -35,6 +19,22 @@ import type {
} from "./normalize-and-load-metadata";
import type { NodePath } from "@babel/traverse";

const {
booleanLiteral,
callExpression,
cloneNode,
directive,
directiveLiteral,
expressionStatement,
identifier,
isIdentifier,
memberExpression,
stringLiteral,
valueToNode,
variableDeclaration,
variableDeclarator,
} = t;

export { buildDynamicImport } from "./dynamic-import";

if (!process.env.BABEL_8_BREAKING) {
Expand Down
@@ -1,5 +1,11 @@
import assert from "assert";
import {
import { template, types as t } from "@babel/core";
import type { NodePath, Visitor, Scope } from "@babel/traverse";
import simplifyAccess from "@babel/helper-simple-access";

import type { ModuleMetadata } from "./normalize-and-load-metadata";

const {
assignmentExpression,
callExpression,
cloneNode,
Expand All @@ -16,13 +22,7 @@ import {
stringLiteral,
variableDeclaration,
variableDeclarator,
} from "@babel/types";
import type * as t from "@babel/types";
import template from "@babel/template";
import type { NodePath, Visitor, Scope } from "@babel/traverse";
import simplifyAccess from "@babel/helper-simple-access";

import type { ModuleMetadata } from "./normalize-and-load-metadata";
} = t;

interface RewriteReferencesVisitorState {
exported: Map<any, any>;
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-helper-module-transforms/src/rewrite-this.ts
@@ -1,6 +1,6 @@
import environmentVisitor from "@babel/helper-environment-visitor";
import traverse from "@babel/traverse";
import { numericLiteral, unaryExpression } from "@babel/types";
import { traverse, types as t } from "@babel/core";
const { numericLiteral, unaryExpression } = t;

import type { NodePath, Visitor } from "@babel/traverse";

Expand Down
3 changes: 1 addition & 2 deletions packages/babel-helper-remap-async-to-generator/package.json
Expand Up @@ -16,8 +16,7 @@
"dependencies": {
"@babel/helper-annotate-as-pure": "workspace:^",
"@babel/helper-environment-visitor": "workspace:^",
"@babel/helper-wrap-function": "workspace:^",
"@babel/types": "workspace:^"
"@babel/helper-wrap-function": "workspace:^"
},
"devDependencies": {
"@babel/core": "workspace:^",
Expand Down
7 changes: 3 additions & 4 deletions packages/babel-helper-remap-async-to-generator/src/index.ts
Expand Up @@ -4,15 +4,14 @@ import type { NodePath } from "@babel/traverse";
import wrapFunction from "@babel/helper-wrap-function";
import annotateAsPure from "@babel/helper-annotate-as-pure";
import environmentVisitor from "@babel/helper-environment-visitor";
import { traverse } from "@babel/core";
import {
import { traverse, types as t } from "@babel/core";
const {
callExpression,
cloneNode,
isIdentifier,
isThisExpression,
yieldExpression,
} from "@babel/types";
import type * as t from "@babel/types";
} = t;

const awaitVisitor = traverse.visitors.merge<{ wrapAwait: t.Expression }>([
{
Expand Down
11 changes: 7 additions & 4 deletions packages/babel-helper-replace-supers/package.json
Expand Up @@ -16,10 +16,13 @@
"dependencies": {
"@babel/helper-environment-visitor": "workspace:^",
"@babel/helper-member-expression-to-functions": "workspace:^",
"@babel/helper-optimise-call-expression": "workspace:^",
"@babel/template": "workspace:^",
"@babel/traverse": "workspace:^",
"@babel/types": "workspace:^"
"@babel/helper-optimise-call-expression": "workspace:^"
},
"devDependencies": {
"@babel/core": "workspace:^"
},
"peerDependencies": {
"@babel/core": "^7.0.0"
},
"engines": {
"node": ">=6.9.0"
Expand Down
8 changes: 3 additions & 5 deletions packages/babel-helper-replace-supers/src/index.ts
Expand Up @@ -3,10 +3,9 @@ import environmentVisitor from "@babel/helper-environment-visitor";
import memberExpressionToFunctions from "@babel/helper-member-expression-to-functions";
import type { HandlerState } from "@babel/helper-member-expression-to-functions";
import optimiseCall from "@babel/helper-optimise-call-expression";
import template from "@babel/template";
import traverse from "@babel/traverse";
import { traverse, template, types as t } from "@babel/core";
import type { NodePath, Scope } from "@babel/traverse";
import {
const {
assignmentExpression,
booleanLiteral,
callExpression,
Expand All @@ -16,8 +15,7 @@ import {
sequenceExpression,
stringLiteral,
thisExpression,
} from "@babel/types";
import type * as t from "@babel/types";
} = t;

if (!process.env.BABEL_8_BREAKING) {
if (!USE_ESM) {
Expand Down
4 changes: 3 additions & 1 deletion packages/babel-helper-wrap-function/package.json
Expand Up @@ -16,12 +16,14 @@
"dependencies": {
"@babel/helper-function-name": "workspace:^",
"@babel/template": "workspace:^",
"@babel/traverse": "workspace:^",
"@babel/types": "workspace:^"
},
"engines": {
"node": ">=6.9.0"
},
"devDependencies": {
"@babel/traverse": "workspace:^"
},
"author": "The Babel Team (https://babel.dev/team)",
"conditions": {
"BABEL_8_BREAKING": [
Expand Down
3 changes: 3 additions & 0 deletions packages/babel-plugin-syntax-decimal/package.json
Expand Up @@ -45,5 +45,8 @@
},
{}
]
},
"devDependencies": {
"@babel/core": "workspace:^"
}
}
Expand Up @@ -48,5 +48,8 @@
".": "./lib/index.js",
"./package.json": "./package.json"
},
"type": "commonjs"
"type": "commonjs",
"devDependencies": {
"@babel/core": "workspace:^"
}
}
3 changes: 3 additions & 0 deletions packages/babel-plugin-syntax-module-blocks/package.json
Expand Up @@ -45,5 +45,8 @@
},
{}
]
},
"devDependencies": {
"@babel/core": "workspace:^"
}
}
2 changes: 0 additions & 2 deletions packages/babel-plugin-transform-runtime/package.json
Expand Up @@ -37,8 +37,6 @@
"@babel/preset-env": "workspace:^",
"@babel/runtime": "workspace:^",
"@babel/runtime-corejs3": "workspace:^",
"@babel/template": "workspace:^",
"@babel/types": "workspace:^",
"make-dir": "condition:BABEL_8_BREAKING ? : ^2.1.0"
},
"homepage": "https://babel.dev/docs/en/next/babel-plugin-transform-runtime",
Expand Down
Expand Up @@ -2,9 +2,7 @@ import path from "path";
import fs from "fs";
import { createRequire } from "module";
import * as helpers from "@babel/helpers";
import { transformFromAstSync, File } from "@babel/core";
import template from "@babel/template";
import * as t from "@babel/types";
import { transformFromAstSync, File, template, types as t } from "@babel/core";
import { fileURLToPath } from "url";

import transformRuntime from "../lib/index.js";
Expand Down
17 changes: 9 additions & 8 deletions yarn.lock
Expand Up @@ -797,14 +797,15 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/helper-module-transforms@workspace:packages/babel-helper-module-transforms"
dependencies:
"@babel/core": "workspace:^"
"@babel/helper-environment-visitor": "workspace:^"
"@babel/helper-module-imports": "workspace:^"
"@babel/helper-simple-access": "workspace:^"
"@babel/helper-split-export-declaration": "workspace:^"
"@babel/helper-validator-identifier": "workspace:^"
"@babel/template": "workspace:^"
"@babel/traverse": "workspace:^"
"@babel/types": "workspace:^"
peerDependencies:
"@babel/core": ^7.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -871,7 +872,6 @@ __metadata:
"@babel/helper-environment-visitor": "workspace:^"
"@babel/helper-wrap-function": "workspace:^"
"@babel/traverse": "workspace:^"
"@babel/types": "workspace:^"
peerDependencies:
"@babel/core": ^7.0.0
languageName: unknown
Expand All @@ -895,12 +895,12 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/helper-replace-supers@workspace:packages/babel-helper-replace-supers"
dependencies:
"@babel/core": "workspace:^"
"@babel/helper-environment-visitor": "workspace:^"
"@babel/helper-member-expression-to-functions": "workspace:^"
"@babel/helper-optimise-call-expression": "workspace:^"
"@babel/template": "workspace:^"
"@babel/traverse": "workspace:^"
"@babel/types": "workspace:^"
peerDependencies:
"@babel/core": ^7.0.0
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -1541,6 +1541,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/plugin-syntax-decimal@workspace:packages/babel-plugin-syntax-decimal"
dependencies:
"@babel/core": "workspace:^"
"@babel/helper-plugin-utils": "workspace:^"
peerDependencies:
"@babel/core": ^7.0.0-0
Expand All @@ -1562,6 +1563,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/plugin-syntax-destructuring-private@workspace:packages/babel-plugin-syntax-destructuring-private"
dependencies:
"@babel/core": "workspace:^"
"@babel/helper-plugin-utils": "workspace:^"
peerDependencies:
"@babel/core": ^7.0.0-0
Expand Down Expand Up @@ -1770,6 +1772,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@babel/plugin-syntax-module-blocks@workspace:packages/babel-plugin-syntax-module-blocks"
dependencies:
"@babel/core": "workspace:^"
"@babel/helper-plugin-utils": "workspace:^"
peerDependencies:
"@babel/core": ^7.0.0-0
Expand Down Expand Up @@ -3194,8 +3197,6 @@ __metadata:
"@babel/preset-env": "workspace:^"
"@babel/runtime": "workspace:^"
"@babel/runtime-corejs3": "workspace:^"
"@babel/template": "workspace:^"
"@babel/types": "workspace:^"
babel-plugin-polyfill-corejs2: ^0.4.4
babel-plugin-polyfill-corejs3: ^0.8.2
babel-plugin-polyfill-regenerator: ^0.5.1
Expand Down

0 comments on commit 476f633

Please sign in to comment.