-
Notifications
You must be signed in to change notification settings - Fork 145
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
Render warning when using folder/ directory pattern #5251
base: main
Are you sure you want to change the base?
Conversation
Coverage report
Show files with reduced coverage 🔻
Test suite run success2001 tests passing in 904 suites. Report generated by 🧪jest coverage report action from 3c18d50 |
|
||
test(`should return all files in a directory when only option is a directory pattern`, () => { | ||
const options = { | ||
only: ['assets/'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you test this with templates/
to test a nested folder structure? I think it'll break
🤔 The issue here arises because we don't have a strong
My personal preference here is to diverge as little as possible from the JavaScript glob matching library moving forward. I think we could render a warning to get the user to fix/remediate this issue rather than adding more custom behaviour. As always, open to discussion and changing my mind! [2]
We needed to do so because the |
There was a problem hiding this 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, @EvilGenius13!
I resonate with the motivation behind this work. The --only
/--ignore
flags have an unusual behavior to maintain backward compatibility with the previous Ruby version.
When the Ruby CLI was migrated to the TypeScript CLI, many developers were affected by changes in this module, that was shape to avoid as much friction as possible.
Considering the change in behavior here, I would suggest waiting for a major CLI update to proceed with this approach, finally break backward-compatibility, and establish a more consistent ignore mechanism.
With that context in mind, I believe we could follow the approach suggested by @jamesmengo on this PR.
To avoid overwhelming users with warning messages, we could check the shape of the flag (as you are already doing) and the files being ignored (or selected by --only
). If an --ignore
flag is not effectively ignoring anything, and the shape indicates the scenario this PR addresses, we have an opportunity to warn developers.
In the warning, we could encourage users to use regexes (instead of globs) for better results, so the shape of the directory doesn't impact the pattern.
I understand this PR implements an improved behavior, but considering the potential impact, I believe this is the best path to prevent friction in a minor release.
Thanks again for this PR!
@jamesmengo @karreiro Thank you for the feedback! I will hold off for now. I am trying a few options, but I believe to properly make the nested folder pattern function properly, we will have to break backwards-compatibility. |
Differences in type declarationsWe detected differences in the type declarations generated by Typescript for this branch compared to the baseline ('main' branch). Please, review them to ensure they are backward-compatible. Here are some important things to keep in mind:
New type declarationsWe found no new type declarations in this PR Existing type declarationspackages/cli-kit/dist/public/node/fs.d.ts@@ -314,6 +314,7 @@ export declare function findPathUp(matcher: OverloadParameters<typeof internalFi
export interface MatchGlobOptions {
matchBase: boolean;
noglobstar: boolean;
+ dot?: boolean;
}
/**
* Matches a key against a glob pattern.
|
@EvilGenius13 FWIW, I believe However, since there are now users who may have started using the So, to fix forward, we should try to get the Ruby users to update their patterns by making them aware when this happens, so like Guilherme suggested, we can render a warning if:
It's definitely a tricky scenario, so we can chat about this more! :) |
It is still not possible to pull only specific folder? Example shopify theme pull -o templates/ |
6955120
to
3c18d50
Compare
We detected some changes at packages/*/src and there are no updates in the .changeset. |
Thank you for all the feedback. After doing some more digging and pairing with @jamesmengo, it's best to simply make a warning to give more information on a proper pattern. Based on TypeScript behaviour, using a pattern such as In order to grab nested folders/files, the pattern would be one the following:
If someone types in This also leaves the backwards compatible checks in place from the ruby implementation. |
@aleksandar89d you can use |
This commit fixes an issue in the matchGlob to match directories when filtering through files
WHY are these changes introduced?
References: #4855
There is some confusion on how patterns work when specifying folders with the
--only
or--ignore
flags. This is partly due to the change from Ruby to Typescript, and the way directory patterns are matched. See my comment for more information.WHAT is this pull request doing?
Added a small
renderWarning
when someone uses a folder pattern that ends with a/
such as/templates
and gives two ideas for patterns that will also grab nested folders/files.Example
Message:
When using `/templates/*:
CLI.Message.Warning.mp4
How to test your changes?
Pull down the branch
Build the branch
If in a directory with a theme:
- delete two different folders like
assets
andtemplates
- run
shopify theme pull -t <your_thene> -o templates/
- You should see the warning message
If in a blank directory:
- run
shopify theme pull -t <your_theme> -o templates/
- You should see the warning message
Post-release steps
Measuring impact
How do we know this change was effective? Please choose one:
Checklist