Skip to content

Commit d42174e

Browse files
authored
Enable Node compile cache for @babel/cli (#17285)
* add babel-cli benchmark * perf: enable V8 compile cache for cli * disable node protocol import for bin/babel * revert babel-cli package type change
1 parent 7e8e2fa commit d42174e

File tree

5 files changed

+96
-5
lines changed

5 files changed

+96
-5
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import Benchmark from "benchmark";
2+
import { report } from "../../util.mjs";
3+
import { execFileSync } from "node:child_process";
4+
import { fileURLToPath } from "node:url";
5+
import { readFileSync, writeFileSync } from "node:fs";
6+
7+
const suite = new Benchmark.Suite();
8+
9+
// Modify `@babel/cli`'s package.json such that we can run ./bin/babel.js directly from the monorepo
10+
function changeBabelCliModuleType() {
11+
const packageJSONPath = fileURLToPath(
12+
import.meta.resolve("@babel/cli/package.json")
13+
);
14+
const content = readFileSync(packageJSONPath, "utf-8");
15+
const patchedContent = content.replace(
16+
`"type": "module"`,
17+
`"type": "commonjs"`
18+
);
19+
writeFileSync(packageJSONPath, patchedContent);
20+
return () => writeFileSync(packageJSONPath, content);
21+
}
22+
23+
const revert = changeBabelCliModuleType();
24+
function benchCases(
25+
name,
26+
implementationPackageJSONSpecifier,
27+
binaryRelativePath
28+
) {
29+
const binaryPath = fileURLToPath(
30+
new URL(
31+
binaryRelativePath,
32+
import.meta.resolve(implementationPackageJSONSpecifier)
33+
)
34+
);
35+
suite.add(
36+
`${name}`,
37+
() => {
38+
execFileSync(binaryPath, ["--help"]);
39+
},
40+
{
41+
minSamples: 1,
42+
}
43+
);
44+
}
45+
46+
benchCases("baseline", "@babel-baseline/cli/package.json", "./bin/babel.js");
47+
benchCases("current", "@babel/cli/package.json", "./bin/babel.js");
48+
benchCases("current-esm", "@babel/cli/package.json", "./bin/babel.mjs");
49+
50+
suite.on("cycle", report).run();
51+
52+
revert();

benchmark/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
"private": true,
44
"type": "module",
55
"devDependencies": {
6+
"@babel-baseline/cli": "npm:@babel/cli@7.27.1",
67
"@babel-baseline/core": "npm:@babel/core@7.24.4",
78
"@babel-baseline/generator": "npm:@babel/generator@7.24.4",
89
"@babel-baseline/helper-compilation-targets": "npm:@babel/helper-compilation-targets@7.23.6",
910
"@babel-baseline/helper-validator-identifier": "npm:@babel/helper-validator-identifier@7.22.20",
1011
"@babel-baseline/parser": "npm:@babel/parser@7.24.4",
1112
"@babel-baseline/traverse": "npm:@babel/traverse@7.24.1",
1213
"@babel-baseline/types": "npm:@babel/types@7.24.0",
14+
"@babel/cli": "workspace:^",
1315
"@babel/core": "workspace:^",
1416
"@babel/generator": "workspace:^",
1517
"@babel/helper-compilation-targets": "workspace:^",

packages/babel-cli/bin/babel.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/usr/bin/env node
2+
/* eslint-disable unicorn/prefer-node-protocol */
3+
4+
// Enable Node compile cache to speed up initialization
5+
const mod = require("module");
6+
if (mod.enableCompileCache != null) mod.enableCompileCache();
27

38
require("../lib/babel");

packages/babel-cli/bin/babel.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#!/usr/bin/env node
22

3+
import mod from "node:module";
34
import "../lib/babel/index.js";
5+
6+
mod.enableCompileCache?.();

yarn.lock

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,33 @@ __metadata:
2828
languageName: node
2929
linkType: hard
3030

31+
"@babel-baseline/cli@npm:@babel/cli@7.27.1":
32+
version: 7.27.1
33+
resolution: "@babel/cli@npm:7.27.1"
34+
dependencies:
35+
"@jridgewell/trace-mapping": "npm:^0.3.25"
36+
"@nicolo-ribaudo/chokidar-2": "npm:2.1.8-no-fsevents.3"
37+
chokidar: "npm:^3.6.0"
38+
commander: "npm:^6.2.0"
39+
convert-source-map: "npm:^2.0.0"
40+
fs-readdir-recursive: "npm:^1.1.0"
41+
glob: "npm:^7.2.0"
42+
make-dir: "npm:^2.1.0"
43+
slash: "npm:^2.0.0"
44+
peerDependencies:
45+
"@babel/core": ^7.0.0-0
46+
dependenciesMeta:
47+
"@nicolo-ribaudo/chokidar-2":
48+
optional: true
49+
chokidar:
50+
optional: true
51+
bin:
52+
babel: ./bin/babel.js
53+
babel-external-helpers: ./bin/babel-external-helpers.js
54+
checksum: 10/b16dc3c4242da3e23ef98e68af89b86740bef9cc2a47678e344a6b84a6f40b29d0ee0915bb89067d610c7db2efec1c5d6973f4303f3c762a44dfc87f393c3634
55+
languageName: node
56+
linkType: hard
57+
3158
"@babel-baseline/core@npm:@babel/core@7.24.4, @babel/core@npm:^7.11.6, @babel/core@npm:^7.12.3":
3259
version: 7.24.4
3360
resolution: "@babel/core@npm:7.24.4"
@@ -174,13 +201,15 @@ __metadata:
174201
version: 0.0.0-use.local
175202
resolution: "@babel/benchmark@workspace:benchmark"
176203
dependencies:
204+
"@babel-baseline/cli": "npm:@babel/cli@7.27.1"
177205
"@babel-baseline/core": "npm:@babel/core@7.24.4"
178206
"@babel-baseline/generator": "npm:@babel/generator@7.24.4"
179207
"@babel-baseline/helper-compilation-targets": "npm:@babel/helper-compilation-targets@7.23.6"
180208
"@babel-baseline/helper-validator-identifier": "npm:@babel/helper-validator-identifier@7.22.20"
181209
"@babel-baseline/parser": "npm:@babel/parser@7.24.4"
182210
"@babel-baseline/traverse": "npm:@babel/traverse@7.24.1"
183211
"@babel-baseline/types": "npm:@babel/types@7.24.0"
212+
"@babel/cli": "workspace:^"
184213
"@babel/core": "workspace:^"
185214
"@babel/generator": "workspace:^"
186215
"@babel/helper-compilation-targets": "workspace:^"
@@ -219,7 +248,7 @@ __metadata:
219248
languageName: node
220249
linkType: hard
221250

222-
"@babel/cli@workspace:packages/babel-cli":
251+
"@babel/cli@workspace:^, @babel/cli@workspace:packages/babel-cli":
223252
version: 0.0.0-use.local
224253
resolution: "@babel/cli@workspace:packages/babel-cli"
225254
dependencies:
@@ -4786,7 +4815,7 @@ __metadata:
47864815
languageName: node
47874816
linkType: hard
47884817

4789-
"@nicolo-ribaudo/chokidar-2-BABEL_8_BREAKING-false@npm:@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3":
4818+
"@nicolo-ribaudo/chokidar-2-BABEL_8_BREAKING-false@npm:@nicolo-ribaudo/chokidar-2@2.1.8-no-fsevents.3, @nicolo-ribaudo/chokidar-2@npm:2.1.8-no-fsevents.3":
47904819
version: 2.1.8-no-fsevents.3
47914820
resolution: "@nicolo-ribaudo/chokidar-2@npm:2.1.8-no-fsevents.3"
47924821
checksum: 10/c6e83af3b5051a3f6562649ff8fe37de9934a4cc02138678ed1badbd13ed3334f7ae5f63f2bbc3432210f6b245f082ac97e9b2afe0c13730c9838b295658c185
@@ -7830,7 +7859,7 @@ __metadata:
78307859
languageName: node
78317860
linkType: hard
78327861

7833-
"commander-BABEL_8_BREAKING-false@npm:commander@^6.2.0":
7862+
"commander-BABEL_8_BREAKING-false@npm:commander@^6.2.0, commander@npm:^6.2.0":
78347863
version: 6.2.1
78357864
resolution: "commander@npm:6.2.1"
78367865
checksum: 10/25b88c2efd0380c84f7844b39cf18510da7bfc5013692d68cdc65f764a1c34e6c8a36ea6d72b6620e3710a930cf8fab2695bdec2bf7107a0f4fa30a3ef3b7d0e
@@ -12690,7 +12719,7 @@ __metadata:
1269012719
languageName: node
1269112720
linkType: hard
1269212721

12693-
"make-dir-BABEL_8_BREAKING-false@npm:make-dir@^2.1.0, make-dir@npm:^2.0.0":
12722+
"make-dir-BABEL_8_BREAKING-false@npm:make-dir@^2.1.0, make-dir@npm:^2.0.0, make-dir@npm:^2.1.0":
1269412723
version: 2.1.0
1269512724
resolution: "make-dir@npm:2.1.0"
1269612725
dependencies:
@@ -15264,7 +15293,7 @@ __metadata:
1526415293
languageName: node
1526515294
linkType: hard
1526615295

15267-
"slash-BABEL_8_BREAKING-false@npm:slash@^2.0.0":
15296+
"slash-BABEL_8_BREAKING-false@npm:slash@^2.0.0, slash@npm:^2.0.0":
1526815297
version: 2.0.0
1526915298
resolution: "slash@npm:2.0.0"
1527015299
checksum: 10/512d4350735375bd11647233cb0e2f93beca6f53441015eea241fe784d8068281c3987fbaa93e7ef1c38df68d9c60013045c92837423c69115297d6169aa85e6

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy