Skip to content

[CLI UI kit - Themes adoption] Extract the ownership of development themes#1169

Merged
Poitrin merged 20 commits intomainfrom
fix-509
Feb 6, 2023
Merged

[CLI UI kit - Themes adoption] Extract the ownership of development themes#1169
Poitrin merged 20 commits intomainfrom
fix-509

Conversation

@Poitrin
Copy link
Copy Markdown
Contributor

@Poitrin Poitrin commented Jan 20, 2023

WHY are these changes introduced?

Fixes https://github.com/Shopify/internal-cli-foundations/issues/509
Fixes #1084
Fixes #1263

Requires Shopify/shopify-cli#2724

WHAT is this pull request doing?

  • Generates Development Theme ID and calls Themes API in Node.js CLI.
  • Depending on the shopify theme command: passes ID of generated theme to Ruby CLI for further processing.

How to test your changes?

Make sure that your local Ruby CLI uses changes from Shopify/shopify-cli#2724

  1. Verify that (pnpm run )shopify theme info says Development Theme ID Not set
  2. Create a new development theme: shopify theme dev --path="./my-theme"
  3. Verify that shopify theme info now displays the ID for the created dev theme
  4. Verify that shopify theme open -d opens the dev theme (with the correct ID)
  5. Verify that shopify theme delete -d deletes the dev theme (after you confirm the deletion)
  6. Verify that shopify theme info says Development Theme ID Not set again
  7. Verify that shopify theme pull -d --path="./my-theme" throws the error No development theme ID has been set. Please create a development theme first.
  8. Verify that shopify theme push -d --path="./my-theme" creates a new development theme.
  9. Verify that shopify theme info now displays the ID for the created dev theme
  10. Verify that shopify theme dev --path="./my-theme" uses the correct ID
  11. Delete the theme with CLI 2.x (so that 3.x doesn't know anything about it): shopify(-dev) theme delete <your ID>
  12. Verify that shopify theme dev --path="./my-theme" still works, but has created a new ID
  13. Delete this theme also with CLI 2.x
  14. Verify that shopify theme pull -d --path="./my-theme" throws the error Development theme <old ID> could not be found. Please create a new development theme.

--theme-editor-sync

  1. shopify theme init a new theme.
  2. Make sure that no development theme ID is set in CLI.
  3. shopify theme dev --store="…" --path="./draft" --theme-editor-sync
  4. Verify that CLI does not display any "Keep the remote version" prompt.

Keep Development Theme ID when switching stores

  1. Execute shopify theme dev --path="./my-theme" --store=<store 1> and stop the server
  2. Note down the theme ID that was created
  3. Execute shopify theme dev --path="./my-theme" --store=<store 2> and stop the server
  4. Note down the theme ID that was created
  5. Execute shopify theme dev --path="./my-theme" --store=<store 1> again
  6. Verify that the ID for store 1 was reused
  7. Execute shopify theme dev --path="./my-theme" --store=<store 2> and stop the server
  8. Verify that the ID for store 2 was reused

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
  • I've made sure that any changes to dev or deploy have been reflected in the internal flowchart.

@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

Depending on what you are working on, you may want to request a review from a Shopify team:

  • Themes: @shopify/theme-developer-tools
  • UI extensions: @shopify/ui-extensions-cli
    • Checkout UI extensions: @shopify/checkout-ui-extensions-api-stewardship
  • Hydrogen: @shopify/hydrogen
  • Other: @shopify/cli-foundations

Comment thread packages/cli-kit/src/store.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 20, 2023

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
71.79% (-0.05% 🔻)
3936/5483
🟡 Branches
69.1% (-0.16% 🔻)
1771/2563
🟡 Functions
70.2% (+0.03% 🔼)
1034/1473
🟡 Lines
73.02% (-0.05% 🔻)
3754/5141
Show new covered files 🐣
St.
File Statements Branches Functions Lines
🟢
... / generate-theme-name.ts
100% 100% 100% 100%
🟢
... / replace-invalid-characters.ts
100% 100% 100% 100%
🔴
... / theme-manager.ts
0% 0% 0% 0%
🟢
... / theme-urls.ts
100% 100% 100% 100%
🟡
... / themes-api.ts
77.78% 73.68% 83.33% 79.41%
🔴
... / theme.ts
58.33% 40% 50% 44.44%
🟢
... / headers.ts
100% 90% 100% 100%
🔴
... / retry.ts
0% 100% 0% 0%
🟢
... / throttler.ts
79.31% 62.5% 84.62% 85.19%

Test suite run success

995 tests passing in 518 suites.

Report generated by 🧪jest coverage report action from 0ec8ec8

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jan 20, 2023

Benchmark report

The following table contains a summary of the startup time for all commands.

Status Command Baseline (avg) Current (avg) Diff
🟢 app build 915.33 ms 919 ms 0.4 %
🟢 app deploy 1114 ms 1118.67 ms 0.42 %
🟢 app dev 1111 ms 1117.33 ms 0.57 %
🟢 app env pull 1011.33 ms 1021.67 ms 1.02 %
🟢 app env show 1009.33 ms 1020.33 ms 1.09 %
🟢 app generate extension 1075.67 ms 1082.33 ms 0.62 %
🟢 app generate schema 1036.67 ms 1052 ms 1.48 %
🟢 app info 1016.67 ms 1015.33 ms -0.13 %
🟢 app scaffold extension 1081.33 ms 1081.67 ms 0.03 %
🟢 app update-url 984.33 ms 1000 ms 1.59 %
🟢 theme check 854 ms 865.67 ms 1.37 %
🟢 theme delete 969 ms 976.33 ms 0.76 %
🟢 theme dev 965.33 ms 972 ms 0.69 %
🟢 theme help-old 852.67 ms 862.33 ms 1.13 %
🟢 theme info 900 ms 902 ms 0.22 %
🟢 theme init 878.33 ms 879.33 ms 0.11 %
🟢 theme language-server 851 ms 856.67 ms 0.67 %
🟢 theme list 975 ms 982.33 ms 0.75 %
🟢 theme open 969.67 ms 986.33 ms 1.72 %
🟢 theme package 894.67 ms 907.67 ms 1.45 %
🟢 theme publish 969.67 ms 972 ms 0.24 %
🟢 theme pull 964 ms 976.67 ms 1.31 %
🟢 theme push 962.33 ms 973 ms 1.11 %
🟢 theme serve 965 ms 979 ms 1.45 %
🟢 theme share 962.67 ms 982 ms 2.01 %
🟢 webhook trigger 964.67 ms 966 ms 0.14 %

@Poitrin Poitrin force-pushed the fix-509 branch 10 times, most recently from 65d92fe to 752fb8a Compare January 23, 2023 14:21
Comment thread packages/theme/src/cli/utilities/theme-selector/filter.test.ts Outdated
Comment thread packages/theme/src/cli/utilities/development-theme-manager.ts Outdated
@Poitrin Poitrin marked this pull request as ready for review January 23, 2023 14:24
@github-actions

This comment has been minimized.

@Poitrin Poitrin requested a review from a team January 23, 2023 14:24
Copy link
Copy Markdown
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 for the updates, @Poitrin! 🚀

I've tried the PR and almost everything is working as expected. I've noticed a minor regression on this issue Shopify/shopify-cli#2433 / Shopify/shopify-cli#2463.

For fixing that scenario, I believe may rely on a hidden flag in the CL2 to differentiate themes created at runtime. Feel free to reach out if you need any extra context tho :)

Thanks again for this PR!

@Poitrin
Copy link
Copy Markdown
Contributor Author

Poitrin commented Jan 27, 2023

I've noticed a minor regression on this issue Shopify/shopify-cli#2433 / Shopify/shopify-cli#2463.

Phew, good to have you as a reviewer, to think of all these sneaky regressions 😥.

For fixing that scenario, I believe may rely on a hidden flag in the CL2 to differentiate themes created at runtime.

Shopify/shopify-cli#2724 + I updated this PR’s code and instructions

Poitrin pushed a commit to Shopify/shopify-cli that referenced this pull request Jan 30, 2023
### WHY are these changes introduced?

Part of https://github.com/Shopify/internal-cli-foundations/issues/509
Is required by Shopify/cli#1169

Issue #2433 was fixed with #2463.
With Shopify/cli#1169, Node CLI needs to pass Ruby CLI a hidden flag to differentiate themes created at runtime.

### WHAT is this pull request doing?

Introduces `--overwrite-json` flag that Node CLI can pass to Ruby CLI.
Copy link
Copy Markdown
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, @Poitrin! Very nice stuff with the persistent development theme IDs 🔥🚀

flags = {
...flags,
theme,
'overwrite-json': Boolean(flags['theme-editor-sync']),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

When the development theme is not new, and (at the Ruby CLI level) developers select that they want to keep the remote version, the CLI shouldn't set the overwrite-json as true.

In other words, to cover that scenario, this line should be something like:

'overwrite-json': Boolean(flags['theme-editor-sync']) && theme.isCreatedAtRuntime(),

We may solve this minor issue in a separate PR tho #1263

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was in the end such a small change that I decided to include it in this PR.
Moreover, as you suggested to make my changes "ready for host theme changes", I moved parts of them into this PR.

Comment thread .eslintrc.cjs
'**/public/node/plugins/tunnel.ts',
'**/public/node/presets.ts',
'**/public/node/result.ts',
'**/public/node/themes/**/*',
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Poitrin Poitrin requested a review from matteodepalo February 3, 2023 12:45
Copy link
Copy Markdown
Contributor

@matteodepalo matteodepalo left a comment

Choose a reason for hiding this comment

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

LGTM

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.

shopify theme dev --theme-editor-sync always overrides local JSON files [Bug]: Switching stores w/ shopify theme dev creates new theme every time

4 participants