Skip to content

Commit 9d6186f

Browse files
committed
Adjusted tmp layout
1 parent bd7b44a commit 9d6186f

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

bin/cli.js

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env node
2+
const fsPromises = require('fs/promises')
23
const path = require('path')
34
const fs = require('fs')
45
const os = require('os')
@@ -81,20 +82,43 @@ async function main() {
8182
}
8283
}
8384

84-
const filePrefix = `speedscope-${+new Date()}-${process.pid}`
85-
const jsPath = path.join(os.tmpdir(), `${filePrefix}.js`)
86-
console.log(`Creating temp file ${jsPath}`)
87-
fs.writeFileSync(jsPath, jsSource)
88-
urlToOpen += `#localProfilePath=${jsPath}`
85+
86+
const tmp_directory = path.join(os.tmpdir(),`SpeedScope`)
87+
88+
try {
89+
fs.mkdirSync(tmp_directory)
90+
} catch ( exception ){
91+
92+
if( exception.code != 'EEXIST' ){
93+
console.error(`Failed to create temporary directory 'SpeedScope'`)
94+
throw exception
95+
}
96+
}
97+
98+
console.log(`Created temporary folder ${tmp_directory}`)
99+
100+
const tmp_folder = await fsPromises
101+
.mkdtemp(`${ tmp_directory }${ path.sep }`)
102+
.catch(( exception ) => {
103+
console.error(`Failed to create /tmp/ folder`)
104+
throw exception
105+
})
106+
107+
const path_source = path.join(tmp_folder,`Source.js`)
108+
109+
console.log(`Creating temp file ${path_source}`)
110+
fs.writeFileSync(path_source, jsSource)
111+
urlToOpen += `#localProfilePath=${path_source}`
89112

90113
// For some silly reason, the OS X open command ignores any query parameters or hash parameters
91114
// passed as part of the URL. To get around this weird issue, we'll create a local HTML file
92115
// that just redirects.
93-
const htmlPath = path.join(os.tmpdir(), `${filePrefix}.html`)
94-
console.log(`Creating temp file ${htmlPath}`)
95-
fs.writeFileSync(htmlPath, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)
116+
const path_wrapper = path.join(tmp_folder,`Wrapper.html`)
117+
118+
console.log(`Creating temp file ${path_wrapper}`)
119+
fs.writeFileSync(path_wrapper, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)
96120

97-
urlToOpen = `file://${htmlPath}`
121+
urlToOpen = `file://${path_wrapper}`
98122
}
99123

100124
console.log('Opening', urlToOpen, 'in your default browser')

0 commit comments

Comments
 (0)