diff --git a/packages/theme/src/cli/services/profile.ts b/packages/theme/src/cli/services/profile.ts index 0473ed7999..d4e0f2dddc 100644 --- a/packages/theme/src/cli/services/profile.ts +++ b/packages/theme/src/cli/services/profile.ts @@ -1,6 +1,6 @@ -import * as fs from 'fs/promises' -import * as path from 'path' -import * as os from 'os' +import {writeFile} from 'fs/promises' +import {join, resolve, dirname} from 'path' +import {tmpdir} from 'os' import {fileURLToPath} from 'url' import {openURL} from '@shopify/cli-kit/node/system' @@ -22,23 +22,23 @@ export async function profile(storeUrl: string, asJson: boolean) { async function openProfile(profileJson: string) { // Adapted from https://github.com/jlfwong/speedscope/blob/146477a8508a6d2da697cb0ea0a426ba81b3e8dc/bin/cli.js#L63 const __filename = fileURLToPath(import.meta.url) - const __dirname = path.dirname(__filename) - let urlToOpen = 'file://' + path.resolve(__dirname, '../../../node_modules/speedscope/dist/release/index.html') + const __dirname = dirname(__filename) + let urlToOpen = 'file://' + resolve(__dirname, '../../../node_modules/speedscope/dist/release/index.html') const filename = 'liquid-profile' const sourceBase64 = Buffer.from(profileJson).toString('base64') const jsSource = `speedscope.loadFileFromBase64(${JSON.stringify(filename)}, ${JSON.stringify(sourceBase64)})` const filePrefix = `speedscope-${+new Date()}-${process.pid}` - const jsPath = path.join(os.tmpdir(), `${filePrefix}.js`) - await fs.writeFile(jsPath, jsSource) + const jsPath = join(tmpdir(), `${filePrefix}.js`) + await writeFile(jsPath, jsSource) urlToOpen += `#localProfilePath=${jsPath}` // 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`) - await fs.writeFile(htmlPath, ``) + const htmlPath = join(tmpdir(), `${filePrefix}.html`) + await writeFile(htmlPath, ``) urlToOpen = `file://${htmlPath}` await openURL(urlToOpen)