Skip to content

Commit 32e91fe

Browse files
committed
wip
1 parent 1ce00c5 commit 32e91fe

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

packages/cli-kit/src/public/node/themes/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Theme} from './types.js'
22
import {renderTextPrompt} from '../ui.js'
33
import {getRandomName} from '../../common/string.js'
4+
import {platform} from 'os'
45

56
const GID_REGEXP = /gid:\/\/shopify\/\w*\/(\d+)/
67

@@ -33,3 +34,13 @@ export function parseGid(gid: string): number {
3334
}
3435
throw new Error(`Invalid GID: ${gid}`)
3536
}
37+
38+
export function filePathToFileUrl(filePath: string): string {
39+
let normalized = filePath.replace(/\\/g, '/')
40+
41+
if (platform() === 'win32') {
42+
normalized = `/${normalized}`
43+
}
44+
45+
return encodeURI(`file://${normalized}`)
46+
}

packages/theme/src/cli/services/profile.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {joinPath} from '@shopify/cli-kit/node/path'
88
import {AdminSession} from '@shopify/cli-kit/node/session'
99
import {writeFile, tempDirectory} from '@shopify/cli-kit/node/fs'
1010
import {outputResult, outputDebug} from '@shopify/cli-kit/node/output'
11+
import {filePathToFileUrl} from '@shopify/cli-kit/node/themes/utils'
1112

1213
export async function profile(
1314
adminSession: AdminSession,
@@ -49,8 +50,9 @@ export async function profile(
4950

5051
async 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

Comments
 (0)