1
1
import assert from 'node:assert' ;
2
2
import cp from 'node:child_process' ;
3
3
import fs from 'node:fs' ;
4
- import os from 'node:os' ;
5
4
import path from 'node:path' ;
6
5
import url from 'node:url' ;
7
6
8
- import { git , localRepoPath , npm } from './utils.js' ;
7
+ import { git , localRepoPath , makeTmpDir , npm } from './utils.js' ;
9
8
10
9
const NS_PER_SEC = 1e9 ;
11
10
const LOCAL = 'local' ;
@@ -35,18 +34,13 @@ interface BenchmarkProject {
35
34
function prepareBenchmarkProjects (
36
35
revisionList : ReadonlyArray < string > ,
37
36
) : Array < BenchmarkProject > {
38
- const tmpDir = path . join ( os . tmpdir ( ) , 'graphql-js-benchmark' ) ;
39
- fs . rmSync ( tmpDir , { recursive : true , force : true } ) ;
40
- fs . mkdirSync ( tmpDir ) ;
41
-
42
- const setupDir = path . join ( tmpDir , 'setup' ) ;
43
- fs . mkdirSync ( setupDir ) ;
37
+ const { tmpDirPath } = makeTmpDir ( 'graphql-js-benchmark' ) ;
44
38
45
39
return revisionList . map ( ( revision ) => {
46
40
console . log ( `🍳 Preparing ${ revision } ...` ) ;
47
- const projectPath = path . join ( setupDir , revision ) ;
41
+ const projectPath = tmpDirPath ( 'setup' , revision ) ;
48
42
fs . rmSync ( projectPath , { recursive : true , force : true } ) ;
49
- fs . mkdirSync ( projectPath ) ;
43
+ fs . mkdirSync ( projectPath , { recursive : true } ) ;
50
44
51
45
fs . cpSync ( localRepoPath ( 'benchmark' ) , path . join ( projectPath , 'benchmark' ) , {
52
46
recursive : true ,
@@ -71,20 +65,20 @@ function prepareBenchmarkProjects(
71
65
function prepareNPMPackage ( revision : string ) {
72
66
if ( revision === LOCAL ) {
73
67
const repoDir = localRepoPath ( ) ;
74
- const archivePath = path . join ( tmpDir , 'graphql-local.tgz' ) ;
68
+ const archivePath = tmpDirPath ( 'graphql-local.tgz' ) ;
75
69
fs . renameSync ( buildNPMArchive ( repoDir ) , archivePath ) ;
76
70
return archivePath ;
77
71
}
78
72
79
73
// Returns the complete git hash for a given git revision reference.
80
74
const hash = git ( [ 'rev-parse' , revision ] ) ;
81
75
82
- const archivePath = path . join ( tmpDir , `graphql-${ hash } .tgz` ) ;
76
+ const archivePath = tmpDirPath ( `graphql-${ hash } .tgz` ) ;
83
77
if ( fs . existsSync ( archivePath ) ) {
84
78
return archivePath ;
85
79
}
86
80
87
- const repoDir = path . join ( tmpDir , hash ) ;
81
+ const repoDir = tmpDirPath ( hash ) ;
88
82
fs . rmSync ( repoDir , { recursive : true , force : true } ) ;
89
83
fs . mkdirSync ( repoDir ) ;
90
84
git ( [ 'clone' , '--quiet' , localRepoPath ( ) , repoDir ] ) ;
0 commit comments