From 9d6186fcb99ca07df5fa19307ebda1f11bfdc5d4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E1=B4=A9=CA=9C=E1=B4=8F=C9=B4=E1=B4=87=E1=B4=85=CA=80?=
=?UTF-8?q?=E1=B4=8F=C9=AA=E1=B4=85?=
<73050054+PhoneDroid@users.noreply.github.com>
Date: Tue, 21 Jan 2025 11:34:07 -0500
Subject: [PATCH] Adjusted tmp layout
---
bin/cli.js | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/bin/cli.js b/bin/cli.js
index 99dc66d0a..933c3cc33 100755
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -1,4 +1,5 @@
#!/usr/bin/env node
+const fsPromises = require('fs/promises')
const path = require('path')
const fs = require('fs')
const os = require('os')
@@ -81,20 +82,43 @@ async function main() {
}
}
- const filePrefix = `speedscope-${+new Date()}-${process.pid}`
- const jsPath = path.join(os.tmpdir(), `${filePrefix}.js`)
- console.log(`Creating temp file ${jsPath}`)
- fs.writeFileSync(jsPath, jsSource)
- urlToOpen += `#localProfilePath=${jsPath}`
+
+ const tmp_directory = path.join(os.tmpdir(),`SpeedScope`)
+
+ try {
+ fs.mkdirSync(tmp_directory)
+ } catch ( exception ){
+
+ if( exception.code != 'EEXIST' ){
+ console.error(`Failed to create temporary directory 'SpeedScope'`)
+ throw exception
+ }
+ }
+
+ console.log(`Created temporary folder ${tmp_directory}`)
+
+ const tmp_folder = await fsPromises
+ .mkdtemp(`${ tmp_directory }${ path.sep }`)
+ .catch(( exception ) => {
+ console.error(`Failed to create /tmp/ folder`)
+ throw exception
+ })
+
+ const path_source = path.join(tmp_folder,`Source.js`)
+
+ console.log(`Creating temp file ${path_source}`)
+ fs.writeFileSync(path_source, jsSource)
+ urlToOpen += `#localProfilePath=${path_source}`
// For some silly reason, the OS X open command ignores any query parameters or hash parameters
// passed as part of the URL. To get around this weird issue, we'll create a local HTML file
// that just redirects.
- const htmlPath = path.join(os.tmpdir(), `${filePrefix}.html`)
- console.log(`Creating temp file ${htmlPath}`)
- fs.writeFileSync(htmlPath, ``)
+ const path_wrapper = path.join(tmp_folder,`Wrapper.html`)
+
+ console.log(`Creating temp file ${path_wrapper}`)
+ fs.writeFileSync(path_wrapper, ``)
- urlToOpen = `file://${htmlPath}`
+ urlToOpen = `file://${path_wrapper}`
}
console.log('Opening', urlToOpen, 'in your default browser')