Skip to content

Conversation

userquin
Copy link
Member

@userquin userquin commented Sep 25, 2025

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 calling sortFilesByGlobPrecedence here https://github.com/unplugin/unplugin-vue-components/pull/885/files#diff-c02b4d62dc54667a8a1243f8ddc5ae0a604cc5d7218d94fd69bfda1c8514ce1fR215-R222, this should be:

  private* preparePaths(): Generator<string, undefined, void> {
    if (this.options.sortByGlob && this.hasGlobs) {
      yield* sortFilesByGlobPrecedence(this, this._componentPaths)
    }
    else {
      yield* this._componentPaths
    }
  }

where hasGlobs should be initialized in the constructor using this.hasGlobs = rawOptions.globs?.lenght > 0

SuperchupuDev/tinyglobby#166

closes #831

@userquin userquin requested a review from antfu as a code owner September 25, 2025 19:07
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@userquin userquin marked this pull request as draft September 25, 2025 19:25
@userquin userquin marked this pull request as ready for review September 26, 2025 19:49
@userquin
Copy link
Member Author

userquin commented Sep 26, 2025

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.

@userquin
Copy link
Member Author

@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

@userquin userquin requested a review from ilyaliao September 26, 2025 20:23
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> {
Copy link
Member Author

Choose a reason for hiding this comment

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

missing * before sort

Copy link
Member Author

@userquin userquin Sep 26, 2025

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))
},
image

.npmrc Outdated
@@ -0,0 +1 @@
shell-emulator=true No newline at end of file
Copy link
Member

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

Copy link
Member Author

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
Copy link
Member Author

@userquin userquin Sep 27, 2025

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>
Copy link
Member Author

@userquin userquin Sep 27, 2025

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>)

Copy link
Member Author

@userquin userquin Sep 27, 2025

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

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.

When using tinyglobby get wrong components files order
2 participants