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 30 commits into
base: main
Choose a base branch
from
Open

Add theme profile command #5109

wants to merge 30 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% 8866/11800
🟡 Branches 70.31% 4310/6130
🟡 Functions 75.06% 2318/3088
🟡 Lines
75.7% (+0.01% 🔼)
8382/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 93d2018

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?

Copy link
Author

Choose a reason for hiding this comment

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

That doesn't work w/ the packaged CLI. Reported by @karreiro:

image

@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 and others added 7 commits January 8, 2025 10:39
Co-authored-by: James Meng <35415298+jamesmengo@users.noreply.github.com>
Co-authored-by: James Meng <35415298+jamesmengo@users.noreply.github.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.

package.json Outdated Show resolved Hide resolved
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.

🎩 and code LGTM!

Thanks for the changes, and for building this!
I left a couple of small comments but nothing blocking.

Copy link
Contributor

Would like to get @karreiro input in case there's anything here that would be hard to revert once it's rolled out, such as flag semantics

@karreiro
Copy link
Contributor

karreiro commented Jan 9, 2025

/snapit

Copy link
Contributor

github-actions bot commented Jan 9, 2025

🫰✨ Thanks @karreiro! Your snapshot has been published to npm.

Test the snapshot by intalling your package globally:

pnpm i -g @shopify/cli@0.0.0-snapshot-20250109124236

After installing, validate the version by running just shopify in your terminal
If the versions don't match, you might have multiple global instances installed.
Use which shopify to find out which one you are running and uninstall it.

Copy link
Contributor

@karreiro karreiro left a comment

Choose a reason for hiding this comment

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

Thanks a lot for this PR, @macournoyer! 🔥

Having a profiler in the same chain of tools is an excellent addition for theme developers. I'm sure this will raise awareness for TTFB performance on storefronts 🚀

I've left only two minor comments. Please let me know if you prefer that I handle them.

Thanks again for this PR!

packages/theme/src/cli/services/profile.ts Outdated Show resolved Hide resolved
packages/theme/src/cli/services/profile.ts Outdated Show resolved Hide resolved
@macournoyer macournoyer requested a review from karreiro January 9, 2025 15:09
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.

5 participants