11import assert from 'node:assert' ;
22import cp from 'node:child_process' ;
33import fs from 'node:fs' ;
4- import os from 'node:os' ;
54import path from 'node:path' ;
65import url from 'node:url' ;
76
8- import { git , localRepoPath , npm } from './utils.js' ;
7+ import { git , localRepoPath , makeTmpDir , npm } from './utils.js' ;
98
109const NS_PER_SEC = 1e9 ;
1110const LOCAL = 'local' ;
@@ -35,18 +34,13 @@ interface BenchmarkProject {
3534function prepareBenchmarkProjects (
3635 revisionList : ReadonlyArray < string > ,
3736) : 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' ) ;
4438
4539 return revisionList . map ( ( revision ) => {
4640 console . log ( `🍳 Preparing ${ revision } ...` ) ;
47- const projectPath = path . join ( setupDir , revision ) ;
41+ const projectPath = tmpDirPath ( 'setup' , revision ) ;
4842 fs . rmSync ( projectPath , { recursive : true , force : true } ) ;
49- fs . mkdirSync ( projectPath ) ;
43+ fs . mkdirSync ( projectPath , { recursive : true } ) ;
5044
5145 fs . cpSync ( localRepoPath ( 'benchmark' ) , path . join ( projectPath , 'benchmark' ) , {
5246 recursive : true ,
@@ -71,20 +65,20 @@ function prepareBenchmarkProjects(
7165 function prepareNPMPackage ( revision : string ) {
7266 if ( revision === LOCAL ) {
7367 const repoDir = localRepoPath ( ) ;
74- const archivePath = path . join ( tmpDir , 'graphql-local.tgz' ) ;
68+ const archivePath = tmpDirPath ( 'graphql-local.tgz' ) ;
7569 fs . renameSync ( buildNPMArchive ( repoDir ) , archivePath ) ;
7670 return archivePath ;
7771 }
7872
7973 // Returns the complete git hash for a given git revision reference.
8074 const hash = git ( [ 'rev-parse' , revision ] ) ;
8175
82- const archivePath = path . join ( tmpDir , `graphql-${ hash } .tgz` ) ;
76+ const archivePath = tmpDirPath ( `graphql-${ hash } .tgz` ) ;
8377 if ( fs . existsSync ( archivePath ) ) {
8478 return archivePath ;
8579 }
8680
87- const repoDir = path . join ( tmpDir , hash ) ;
81+ const repoDir = tmpDirPath ( hash ) ;
8882 fs . rmSync ( repoDir , { recursive : true , force : true } ) ;
8983 fs . mkdirSync ( repoDir ) ;
9084 git ( [ 'clone' , '--quiet' , localRepoPath ( ) , repoDir ] ) ;
0 commit comments