9
9
10
10
'use strict' ;
11
11
12
- const { Benchmark } = require ( 'benchmark' ) ;
13
- const { execSync } = require ( 'child_process' ) ;
14
12
const os = require ( 'os' ) ;
15
13
const fs = require ( 'fs' ) ;
16
14
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' ) ;
17
25
18
- // Like build:cjs, but includes __tests__ and copies other files.
19
- const BUILD_CMD = 'babel src --copy-files --out-dir dist/' ;
20
26
const LOCAL = 'local' ;
21
27
22
28
function LOCAL_DIR ( ...paths ) {
@@ -43,8 +49,7 @@ function prepareRevision(revision) {
43
49
console . log ( `🍳 Preparing ${ revision } ...` ) ;
44
50
45
51
if ( revision === LOCAL ) {
46
- execSync ( `yarn run ${ BUILD_CMD } ` ) ;
47
- return LOCAL_DIR ( 'dist' ) ;
52
+ return babelBuild ( LOCAL_DIR ( ) ) ;
48
53
} else {
49
54
if ( ! fs . existsSync ( TEMP_DIR ( ) ) ) {
50
55
fs . mkdirSync ( TEMP_DIR ( ) ) ;
@@ -66,12 +71,35 @@ function prepareRevision(revision) {
66
71
execSync (
67
72
`cp -R "${ LOCAL_DIR ( ) } /src/__fixtures__/" "${ dir } /src/__fixtures__/"`
68
73
) ;
69
- execSync ( `yarn run ${ BUILD_CMD } ` , { cwd : dir } ) ;
70
74
71
- return path . join ( dir , 'dist' ) ;
75
+ return babelBuild ( dir ) ;
72
76
}
73
77
}
74
78
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
+
75
103
function findFiles ( cwd , pattern ) {
76
104
const out = execSync ( `find . -path '${ pattern } '` , { cwd, encoding : 'utf8' } ) ;
77
105
return out . split ( '\n' ) . filter ( Boolean ) ;
0 commit comments