Skip to content

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
macournoyer committed Dec 16, 2024
1 parent 6e14e50 commit 68b0047
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@shopify/theme-language-server-node": "2.3.2",
"chokidar": "3.5.3",
"h3": "1.12.0",
"speedscope": "^1.21.0",
"speedscope": "1.21.0",
"yaml": "2.3.2"
},
"devDependencies": {
Expand Down
6 changes: 2 additions & 4 deletions packages/theme/src/cli/commands/theme/profile.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {themeFlags} from '../../flags.js'
import ThemeCommand from '../../utilities/theme-command.js'
import {profile} from '../../services/profile.js'
import {ensureThemeStore} from '../../utilities/theme-store.js'
import {Flags} from '@oclif/core'
import {globalFlags} from '@shopify/cli-kit/node/cli'
import {ensureThemeStore} from '../../utilities/theme-store.js'
import {ensureAuthenticatedThemes} from '@shopify/cli-kit/node/session'

export default class Profile extends ThemeCommand {
static summary = 'Profile the Liquid rendering of a theme page.'
Expand Down Expand Up @@ -35,8 +34,7 @@ export default class Profile extends ThemeCommand {
async run(): Promise<void> {
const {flags} = await this.parse(Profile)
const store = ensureThemeStore(flags)
const adminSession = await ensureAuthenticatedThemes(store, flags.password, [], true)

await profile(adminSession, flags.password, store, flags.url, flags.json)
await profile(flags.password, store, flags.url, flags.json)
}
}
22 changes: 8 additions & 14 deletions packages/theme/src/cli/services/profile.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
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 {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'
import {AdminSession, ensureAuthenticatedStorefront} from '@shopify/cli-kit/node/session'

export async function profile(
adminSession: AdminSession,
password: string | undefined,
storeDomain: string,
urlPath: string,
asJson: boolean,
) {
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')
Expand All @@ -35,21 +29,21 @@ 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://' + resolve(__dirname, '../../../node_modules/speedscope/dist/release/index.html')
let urlToOpen = `file://${resolvePath(__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 = join(tmpdir(), `${filePrefix}.js`)
const filePrefix = `speedscope-${Number(new Date())}-${process.pid}`
const jsPath = joinPath(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 = join(tmpdir(), `${filePrefix}.html`)
const htmlPath = joinPath(tmpdir(), `${filePrefix}.html`)
await writeFile(htmlPath, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`)

urlToOpen = `file://${htmlPath}`
Expand Down

0 comments on commit 68b0047

Please sign in to comment.