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

Add theme profile command #5109

wants to merge 41 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.25% (+0.01% 🔼)
8881/11802
🟡 Branches
70.44% (+0.03% 🔼)
4329/6146
🟡 Functions 75.06% 2326/3099
🟡 Lines
75.81% (+0.02% 🔼)
8395/11074
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / app-event-watcher.ts
93.83% (-1.23% 🔻)
86.49% 90.48% 98.61%

Test suite run success

2002 tests passing in 904 suites.

Report generated by 🧪jest coverage report action from 88d83f7

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe I found the fix for this issue. Here's the the PR:
#5178

@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

* Fix speedscope error on `shopify theme profile`

* Add 'speedscope' to 'packages/cli' ignored dependencies
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.

Thank you, @macournoyer! Really amazing stuff 🔥🚀

@karreiro
Copy link
Contributor

👋 @Shopify/app-inner-loop, could you please take a look at this? :)

@karreiro
Copy link
Contributor

@Shopify/app-inner-loop, could you please take a look at this?

@@ -102,6 +102,7 @@
},
"dependencies": {
"@ast-grep/napi": "0.33.0",
"speedscope": "1.21.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this dependency in both cli and theme package.json's? It should be enough with the theme one

Copy link
Author

Choose a reason for hiding this comment

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

Good question... not sure @karreiro if you had to add this to fix the packaging?

Copy link
Contributor

Choose a reason for hiding this comment

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

I did a short exploration into this when I had some free time.

I am relatively green to TS / JS so I won't purport to be an expert on the module system ( or have much knowledge here at all yet) - info here

Would definitely prefer not to have to udpate the cli package.json

Copy link
Author

Choose a reason for hiding this comment

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

@jamesmengo thanks for the exploration! I'm unclear what solution you're suggesting, out of those:

Only supported Node 20+ (could use import.meta.resolve)
Made @shopify/theme public (dependencies would be visible)
Didn't need to access speedscope's files directly

Copy link
Contributor

@isaacroldan isaacroldan Jan 16, 2025

Choose a reason for hiding this comment

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

That's actually not the reason why you need it there for require.resolve to work.

We bundle dependencies, once bundled, you can't access specific files with require.resolve. By adding it as a dependency of CLI, you are basically telling the CLI not to bundle this package, which will affect the total size and speed of the CLI installation.

You need to solve this issue in the bundle script, manually copying the files you want to access with require.resolve. (cli/bin/bundle.js).

Sorry but adding dependencies to CLI directly is not allowed as it affects all users performance.

Copy link
Contributor

Choose a reason for hiding this comment

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

@isaacroldan thanks for the context!

Copy link
Contributor

Choose a reason for hiding this comment

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

I should add some lint rule so that teams are warned about this earlier in the dev process and not in the final review, sorry I didn't see it earlier 🙏

Copy link
Contributor

@gonzaloriestra gonzaloriestra left a comment

Choose a reason for hiding this comment

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

This is so cool! Have you tested it in Windows/Linux?

packages/theme/src/cli/commands/theme/profile.ts Outdated Show resolved Hide resolved
macournoyer and others added 2 commits January 15, 2025 17:00
Co-authored-by: Gonzalo Riestra <gonzalo.riestra@shopify.com>
Copy link
Contributor

@isaacroldan isaacroldan left a comment

Choose a reason for hiding this comment

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

Adding this here to make it clear that changes are requested, can't add new dependencies to cli :)

@frandiox
Copy link
Contributor

Hi 👋
I had some context about bundling in the CLI thanks to some stuff we did in Hydrogen. I'm attempting to fix Isaac's feedback in this PR: #5214

With that, we """bundle""" speedscope assets and can access them in prod.

@macournoyer
Copy link
Author

@isaacroldan dependency got removed by @frandiox in latest commits. All good?

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.

8 participants