-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Open theme profile in Speedscope by default
- Loading branch information
1 parent
c8e0104
commit f32eda5
Showing
6 changed files
with
75 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
export async function profile(storeUrl: string) { | ||
import * as fs from 'fs/promises' | ||
import * as path from 'path' | ||
Check failure on line 2 in packages/theme/src/cli/services/profile.ts GitHub Actions / ESLint Report Analysispackages/theme/src/cli/services/profile.ts#L2
|
||
import * as os from 'os' | ||
import {fileURLToPath} from 'url' | ||
import {openURL} from '@shopify/cli-kit/node/system' | ||
|
||
export async function profile(storeUrl: string, asJson: boolean) { | ||
// Fetch the profiling from the Store | ||
const url = new URL(storeUrl) | ||
url.searchParams.append('profile_liquid', '1') | ||
const response = await fetch(url) | ||
const profileJson = await response.text() | ||
// use process.stdout.write to print the JSON | ||
process.stdout.write(profileJson) | ||
|
||
if (asJson) { | ||
// Print the JSON | ||
process.stdout.write(profileJson) | ||
} else { | ||
await openProfile(profileJson) | ||
} | ||
} | ||
|
||
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 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) | ||
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, `<script>window.location=${JSON.stringify(urlToOpen)}</script>`) | ||
|
||
urlToOpen = `file://${htmlPath}` | ||
await openURL(urlToOpen) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.