@@ -8,6 +8,7 @@ import {joinPath} from '@shopify/cli-kit/node/path'
88import { AdminSession } from '@shopify/cli-kit/node/session'
99import { writeFile , tempDirectory } from '@shopify/cli-kit/node/fs'
1010import { outputResult , outputDebug } from '@shopify/cli-kit/node/output'
11+ import { filePathToFileUrl } from '@shopify/cli-kit/node/themes/utils'
1112
1213export async function profile (
1314 adminSession : AdminSession ,
@@ -49,8 +50,9 @@ export async function profile(
4950
5051async function openProfile ( profileJson : string ) {
5152 // Adapted from https://github.com/jlfwong/speedscope/blob/146477a8508a6d2da697cb0ea0a426ba81b3e8dc/bin/cli.js#L63
52- let urlToOpen = await resolveAssetPath ( 'speedscope' , 'index.html' )
53- outputDebug ( `[Theme Profile] Resolved URL to open: ${ urlToOpen } ` )
53+ const speedscopeIndexPath = await resolveAssetPath ( 'speedscope' , 'index.html' )
54+ const speedscopeIndexUrl = filePathToFileUrl ( speedscopeIndexPath )
55+ outputDebug ( `[Theme Profile] Resolved URL to open: ${ speedscopeIndexUrl } ` )
5456
5557 const filename = 'liquid-profile'
5658 const sourceBase64 = Buffer . from ( profileJson ) . toString ( 'base64' )
@@ -61,18 +63,18 @@ async function openProfile(profileJson: string) {
6163 outputDebug ( `[Theme Profile] writing JS file to: ${ jsPath } ` )
6264 await writeFile ( jsPath , jsSource )
6365 outputDebug ( `[Theme Profile] JS file created successfully: ${ jsPath } ` )
64- urlToOpen + = `#localProfilePath=${ jsPath } `
66+ const redirectUrl = `${ speedscopeIndexUrl } #localProfilePath=${ jsPath } `
6567
6668 // For some silly reason, the OS X open command ignores any query parameters or hash parameters
6769 // passed as part of the URL. To get around this weird issue, we'll create a local HTML file
6870 // that just redirects.
6971 const htmlPath = joinPath ( tempDirectory ( ) , `${ filePrefix } .html` )
7072 outputDebug ( `[Theme Profile] writing HTML file to: ${ htmlPath } ` )
71- await writeFile ( htmlPath , `<script>window.location=${ JSON . stringify ( urlToOpen ) } </script>` )
73+ await writeFile ( htmlPath , `<script>window.location=${ JSON . stringify ( redirectUrl ) } </script>` )
7274 outputDebug ( `[Theme Profile] HTML file created successfully: ${ htmlPath } ` )
7375
74- urlToOpen = `file:// ${ htmlPath } `
75- outputDebug ( `[Theme Profile] Opening URL: ${ urlToOpen } ` )
76- const opened = await openURL ( urlToOpen )
76+ const htmlUrl = filePathToFileUrl ( htmlPath )
77+ outputDebug ( `[Theme Profile] Opening URL: ${ htmlUrl } ` )
78+ const opened = await openURL ( htmlUrl )
7779 outputDebug ( `[Theme Profile] URL opened successfully: ${ opened } ` )
7880}
0 commit comments