Skip to content

Commit d6c973a

Browse files
Adapt benchmark to the new build script (#1845)
1 parent 316e24e commit d6c973a

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ package-lock.json
1111
node_modules
1212
coverage
1313
dist
14+
benchmarkDist
1415
npm

resources/benchmark.js

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99

1010
'use strict';
1111

12-
const { Benchmark } = require('benchmark');
13-
const { execSync } = require('child_process');
1412
const os = require('os');
1513
const fs = require('fs');
1614
const path = require('path');
15+
const { execSync } = require('child_process');
16+
const { Benchmark } = require('benchmark');
17+
18+
const {
19+
copyFile,
20+
writeFile,
21+
rmdirRecursive,
22+
mkdirRecursive,
23+
readdirRecursive,
24+
} = require('./fs-utils');
1725

18-
// Like build:cjs, but includes __tests__ and copies other files.
19-
const BUILD_CMD = 'babel src --copy-files --out-dir dist/';
2026
const LOCAL = 'local';
2127

2228
function LOCAL_DIR(...paths) {
@@ -43,8 +49,7 @@ function prepareRevision(revision) {
4349
console.log(`🍳 Preparing ${revision}...`);
4450

4551
if (revision === LOCAL) {
46-
execSync(`yarn run ${BUILD_CMD}`);
47-
return LOCAL_DIR('dist');
52+
return babelBuild(LOCAL_DIR());
4853
} else {
4954
if (!fs.existsSync(TEMP_DIR())) {
5055
fs.mkdirSync(TEMP_DIR());
@@ -66,12 +71,35 @@ function prepareRevision(revision) {
6671
execSync(
6772
`cp -R "${LOCAL_DIR()}/src/__fixtures__/" "${dir}/src/__fixtures__/"`
6873
);
69-
execSync(`yarn run ${BUILD_CMD}`, { cwd: dir });
7074

71-
return path.join(dir, 'dist');
75+
return babelBuild(dir);
7276
}
7377
}
7478

79+
function babelBuild(dir) {
80+
const oldCWD = process.cwd();
81+
process.chdir(dir);
82+
83+
rmdirRecursive('./benchmarkDist');
84+
mkdirRecursive('./benchmarkDist');
85+
86+
const babel = require('@babel/core');
87+
for (const filepath of readdirRecursive('./src')) {
88+
const srcPath = path.join('./src', filepath);
89+
const distPath = path.join('./benchmarkDist', filepath);
90+
91+
if (filepath.endsWith('.js')) {
92+
const cjs = babel.transformFileSync(srcPath, { envName: 'cjs' });
93+
writeFile(distPath, cjs.code);
94+
} else {
95+
copyFile(srcPath, distPath);
96+
}
97+
}
98+
99+
process.chdir(oldCWD);
100+
return path.join(dir, 'benchmarkDist');
101+
}
102+
75103
function findFiles(cwd, pattern) {
76104
const out = execSync(`find . -path '${pattern}'`, { cwd, encoding: 'utf8' });
77105
return out.split('\n').filter(Boolean);

0 commit comments

Comments
 (0)