-
-
Notifications
You must be signed in to change notification settings - Fork 376
feat: allow sort files #885
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
base: main
Are you sure you want to change the base?
Conversation
|
We need to change the local tinyglobby tgz copy with pkg-pr-new from this PR (in a few minutes I'll send an update ✔️ done): SuperchupuDev/tinyglobby#168 and once released 🤞 just update the dependency. |
@antfu any chance to add pkg-pr-new in the repo? I can send a PR to add it, I only need pkg-pr-new installed, oh wait, this is unplugin, it should be ready iirc |
src/types.ts
Outdated
* | ||
* For example, you can sort the files in descending order providing the following sort option: | ||
* ```ts | ||
* sort(_root, files): Generator<string, undefined, void> { |
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.
missing * before sort
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.
arggg the linter removing it, I need to check @antfu/eslint-config
to disable the rule.
Looks like this works, luckely the object-shorthand rule not being applied ;) (check the screenshot below):
sort: function* (_root, files): Generator<string, undefined, void> {
yield* files.sort((a, b) => b.localeCompare(a))
},

.npmrc
Outdated
@@ -0,0 +1 @@ | |||
shell-emulator=true No newline at end of file |
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.
Let's put it in the pnpm-workspace.yaml
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.
Done
* | ||
* `unplugin-vue-components` using `tinyglobby` to scan files, which is non-deterministic. | ||
*/ | ||
sortByGlob?: true |
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.
Add some warning here about performance when enabling this option, will be O(F * M)
where F
is the number of files and M
the "picomatch" search patterns logic, check the sortFilesByGlobPrecedence
function.
* @param root The root folder of the project. | ||
* @param files The scanned files (it is a new array). | ||
*/ | ||
sort?: (root: string, files: string[]) => Generator<string, undefined, void> |
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.
Maybe we can add built-in asc/desc sort support, changing sort to:
sort?: 'asc' | 'desc' | ((root: string, files: string[]) => Generator<string, undefined, void>)
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.
If asc/desc here and sortByGlob enabled just show a warning disabling sortByGlob
DO NOT MERGE YET: we need to await tinyglobby release 🤞 (SuperchupuDev/tinyglobby#168)
I need to check when
sortFilesByGlobPrecedence
should be called, I'm not sure how dirs and globs are "connected" here, this comment confuse me https://github.com/unplugin/unplugin-vue-components/blob/main/src/types.ts#L94. I guess we also need to check if globs there from raw options before callingsortFilesByGlobPrecedence
here https://github.com/unplugin/unplugin-vue-components/pull/885/files#diff-c02b4d62dc54667a8a1243f8ddc5ae0a604cc5d7218d94fd69bfda1c8514ce1fR215-R222, this should be:where
hasGlobs
should be initialized in the constructor usingthis.hasGlobs = rawOptions.globs?.lenght > 0
SuperchupuDev/tinyglobby#166
closes #831