Skip to content

Commit

Permalink
Switch to using mime type for Liquid profiling
Browse files Browse the repository at this point in the history
And use import.meta.resolve to load Speedscope
  • Loading branch information
macournoyer committed Dec 17, 2024
1 parent b0982da commit 1e5eb39
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions packages/theme/src/cli/services/profile.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import {openURL} from '@shopify/cli-kit/node/system'
import {ensureAuthenticatedStorefront} from '@shopify/cli-kit/node/session'
import {joinPath, resolvePath, dirname} from '@shopify/cli-kit/node/path'
import {joinPath} from '@shopify/cli-kit/node/path'
import {writeFile} from 'fs/promises'
import {tmpdir} from 'os'
import {fileURLToPath} from 'url'

export async function profile(password: string | undefined, storeDomain: string, urlPath: string, asJson: boolean) {
// Fetch the profiling from the Store
const url = new URL(`https://${storeDomain}/${urlPath}`)
url.searchParams.append('profile_liquid', '1')
const storefrontToken = await ensureAuthenticatedStorefront([], password)
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${storefrontToken}`,
Accept: 'application/vnd.speedscope+json',
},
})
const profileJson = await response.text()
Expand All @@ -27,11 +26,13 @@ export async function profile(password: string | undefined, storeDomain: string,

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 = dirname(__filename)
let urlToOpen = `file://${resolvePath(__dirname, '../../../node_modules/speedscope/dist/release/index.html')}`
let urlToOpen
if (import.meta.resolve) {
urlToOpen = await import.meta.resolve('speedscope/dist/release/index.html')
} else {
throw "Can't find Speedscope"

Check warning on line 33 in packages/theme/src/cli/services/profile.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

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

[@typescript-eslint/only-throw-error] Expected an error object to be thrown.
}
const filename = 'liquid-profile'

const sourceBase64 = Buffer.from(profileJson).toString('base64')
const jsSource = `speedscope.loadFileFromBase64(${JSON.stringify(filename)}, ${JSON.stringify(sourceBase64)})`

Expand Down

0 comments on commit 1e5eb39

Please sign in to comment.