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

[Themes] Improve Glob Pattern subdirectory mismatch error handling #3669

Merged
merged 2 commits into from Apr 9, 2024

Conversation

jamesmengo
Copy link
Contributor

@jamesmengo jamesmengo commented Apr 5, 2024

WHY are these changes introduced?

This warning was added to surface some work that we were always doing on the Ruby side to include subdirectories when pattern matching theme files (.shopifyignore, --ignore, --only)

Technically, the pattern templates/*.json should not match subdirectories, but this would be a largely breaking change, so we apply this change on the platform side when needed.

  • Instead of doing this work silently in the background, the warning informs devs of the modification we were making to their patterns.

WHAT is this pull request doing?

  • Fixes an issue where the warning was rendering on all pattern mismatches ( we now only render the message if the modified pattern leads to a match a hit while the original pattern does not )
    • The # of files output should only match the number of files you have in subdirectories
  • Improves the clarity of the error message
  • I'm Open to input on the error message + frequency of when to report it

How to test your changes?

  1. Start with a clean theme that has subdirectories (e.g. dawn with templates/customers)
  2. pnpm shopify theme push --path <PATH_TO_THEME> -u --ignore "templates/*.json"
  • You can also try this with --only or .shopifyignore
image
  1. Modify the pattern now to templates/**/*.json and observe that the messages disappear
  2. In either case (warning or no warning), this pattern should apply to subdirectories

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

@jamesmengo jamesmengo requested a review from a team April 5, 2024 18:11
@jamesmengo jamesmengo self-assigned this Apr 5, 2024

This comment has been minimized.

@jamesmengo jamesmengo linked an issue Apr 5, 2024 that may be closed by this pull request
2 tasks
@jamesmengo jamesmengo added Type: Bug Something isn't working Area: @shopify/theme @shopify/theme package issues labels Apr 5, 2024
Copy link
Contributor

github-actions bot commented Apr 5, 2024

Coverage report

St.
Category Percentage Covered / Total
🟡 Statements
72.01% (-0.12% 🔻)
6752/9376
🟡 Branches
69.21% (+0.03% 🔼)
3297/4764
🟡 Functions
70.74% (-0.22% 🔻)
1799/2543
🟡 Lines
73.16% (-0.12% 🔻)
6367/8703
Show files with reduced coverage 🔻
St.
File Statements Branches Functions Lines
🟢
... / app.ts
84.4% (-0.55% 🔻)
70.69% (-1.44% 🔻)
86.84%
86.02% (-0.44% 🔻)
🟢
... / loader.ts
93.13% (+0.14% 🔼)
86.81% (-0.02% 🔻)
95.12% (+0.39% 🔼)
94.1% (+0.35% 🔼)
🟡
... / select-app.ts
65.38% (-2.47% 🔻)
50% (-16.67% 🔻)
87.5%
68.18% (-1.38% 🔻)
🟡
... / monorail.ts
69.23% (-4.1% 🔻)
40% (-10% 🔻)
100%
69.23% (-4.1% 🔻)

Test suite run success

1617 tests passing in 754 suites.

Report generated by 🧪jest coverage report action from e1f01b0

@jamesmengo jamesmengo force-pushed the jmeng/improve_glob_pattern_warning branch from 88a7d2d to 72a46ba Compare April 5, 2024 18:32
Copy link
Contributor

@charlespwd charlespwd left a comment

Choose a reason for hiding this comment

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

LGTM

@jamesmengo jamesmengo requested a review from karreiro April 5, 2024 21:58
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 for this PR, @jamesmengo! I've left only one minor question, please let me know what you think about it :)

Comment on lines 60 to 61
const newPatternMatch = originalMatchGlob(key, pattern.replace('/*.', '/**/*.'))
if (newPatternMatch) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally, I don't think we should adopt pattern matching or not matching as our criteria for showing the warning, as the pattern is still used when it's not being matched.

What do you think about moving this warning to the applyIgnoreFilters level? Then, we'd display this warning once per pattern (instead of per pattern usage), and we'd still inform users about this :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jamesmengo jamesmengo force-pushed the jmeng/improve_glob_pattern_warning branch from 302fee0 to 8ca5366 Compare April 9, 2024 01:15
@jamesmengo jamesmengo force-pushed the jmeng/improve_glob_pattern_warning branch from 8ca5366 to e1f01b0 Compare April 9, 2024 01:44
})
}

function shouldReplaceGlobPattern(pattern: string): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Decision: I chose to limit this to the templates folder because that's the only folder where subdirectories are supported.

Some questions that could influence this

  • Do you consider something like assets/*.liquid to be unsafe / something we need to substitute?

    • If we recommend assets/**/*.liquid, that could be confusing since there are no subdirectories there
  • Will we remove the automatic conversion of the glob pattern one day so that templates/*.json and templates/**/*.json mean different things in the future?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for restricting this warning to templates, as it's the only directory that may have a sub-directory :)

Regarding the removal of this warning in the future, because it would be a destructive breaking change (as in some contexts it may imply file deletion), I'd suggest making this change in the next major release

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, @jamesmengo!

})
}

function shouldReplaceGlobPattern(pattern: string): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for restricting this warning to templates, as it's the only directory that may have a sub-directory :)

Regarding the removal of this warning in the future, because it would be a destructive breaking change (as in some contexts it may imply file deletion), I'd suggest making this change in the next major release

@jamesmengo jamesmengo added this pull request to the merge queue Apr 9, 2024
Merged via the queue into main with commit e8bd3fe Apr 9, 2024
29 checks passed
@jamesmengo jamesmengo deleted the jmeng/improve_glob_pattern_warning branch April 9, 2024 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: @shopify/theme @shopify/theme package issues Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Warning message since 3.58.2
3 participants