Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add theme profile command #5109

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open

Add theme profile command #5109

wants to merge 24 commits into from

Conversation

macournoyer
Copy link

@macournoyer macournoyer commented Dec 13, 2024

WHY are these changes introduced?

https://hackdays.shopify.io/projects/19234

We want to expose Liquid profiling via:

  1. Speedscope, in the browser
  2. In our Theme VSCode extensions

The new theme profile command will be called for both. The VSCode extensions will use the --json flag.

WHAT is this pull request doing?

Add a shopify theme profile --url command that calls SFR asking for profiling data (using the Accept header).

Left to do

How to test your changes?

Run dev shopify theme profile --store [YOUR STORE DOMAIN] --url /. Should open a browser window with Speedscope in it.

Post-release steps

Measuring impact

How do we know this change was effective? Please choose one:

  • n/a - this doesn't need measurement, e.g. a linting rule or a bug-fix
  • Existing analytics will cater for this addition
  • PR includes analytics changes to measure impact

Checklist

  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've considered possible documentation changes

Copy link
Contributor

github-actions bot commented Dec 13, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
75.14% (+0.01% 🔼)
8867/11800
🟡 Branches
70.33% (+0.02% 🔼)
4311/6130
🟡 Functions 75.06% 2318/3088
🟡 Lines
75.71% (+0.02% 🔼)
8383/11072
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / app-event-watcher.ts
93.83% (-1.23% 🔻)
86.49% (-2.7% 🔻)
90.48% 98.61%

Test suite run success

2000 tests passing in 904 suites.

Report generated by 🧪jest coverage report action from 1a56b88

Comment on lines +33 to +60
if (import.meta.resolve) {
return import.meta.resolve('speedscope/dist/release/index.html')
} else {
try {
const speedscopePath = require.resolve('speedscope/package.json')
const speedscopeDir = speedscopePath.replace('/package.json', '')
return `file://${speedscopeDir}/dist/release/index.html`
} catch (error) {
throw new Error("Can't find Speedscope package")
}
}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to work both in tests and with dev shopify. Is there some packaging magic that could make this not work?

@macournoyer macournoyer marked this pull request as ready for review January 6, 2025 14:30
@macournoyer macournoyer requested review from a team as code owners January 6, 2025 14:30

This comment has been minimized.

@macournoyer macournoyer requested a review from ianks January 6, 2025 14:31
Copy link
Contributor

@jamesmengo jamesmengo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool project! Excited about this change.

I've added a couple of suggestions around changeset management, 1 of which is blocking change.

I wasn't able to get my 🎩 working, but I'll chock it up to user error and try again tommorow

image.png

Are there any edge cases you're aware of that we may want to take note of in case we need to patch / support them in the future?

@macournoyer
Copy link
Author

I wasn't able to get my 🎩 working, but I'll chock it up to user error and try again tommorow

Hum... I'm a little worried about that error. Can you try w/ the --json option?

@EvilGenius13
Copy link
Contributor

I wasn't able to get my 🎩 working, but I'll chock it up to user error and try again tommorow

Hum... I'm a little worried about that error. Can you try w/ the --json option?

I had tried to 🎩 as well and got the same error. The json output is {"error": "unauthorized", "error_description": "The client is not authorized to perform this request"}%

@macournoyer
Copy link
Author

@EvilGenius13 what is your store?

@EvilGenius13
Copy link
Contributor

@EvilGenius13 what is your store?

teamtws.myshopify.com

@macournoyer macournoyer requested a review from jamesmengo January 8, 2025 18:12
@macournoyer
Copy link
Author

Everything should be working now!

We're set to replace https://shopify.dev/docs/storefronts/themes/tools/theme-inspector w/ this!

Copy link
Contributor

@EvilGenius13 EvilGenius13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I 🎩 again and it's working both by opening a new window with the speedscope results and also when using --json to get the output. Also checked with bad routes. Just leaving a super minor question.

env: 'SHOPIFY_FLAG_THEME_ID',
}),
url: Flags.string({
description: 'The url to be used as context',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor question, when we have the default: / does that mean if you were to pass the --url flag without inputting anything after it, that it would default to using /? I tried that out but it didn't work and was curious if it had another meaning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants