Conversation
|
We also need to add a |
|
@SuperchupuDev added custom sort, PR should be ready for review |
|
We cannot use overload signature with generators, we just use modern patterns (about TS1222: An overload signature cannot be declared as a generator.
Biome: An overload signature cannot be declared as a generator. |
|
I'm going to check if we can avoid regenerating the options when using sort from options, just returning the info from the |
commit: |
commit: |
| test('sort files by precedence with no options', () => { | ||
| // we need to change the cwd to the fixture path to make sure the patterns match | ||
| // since we are not passing options to sortFilesByPatternPrecedence | ||
| const originalCwd = process.cwd(); | ||
| try { | ||
| process.chdir(cwd); | ||
| const files = ['common/Button.js', 'common/Card.js', 'overrides/Button.js']; | ||
| // sort without options | ||
| assert.deepEqual( | ||
| [...sortFilesByPatternPrecedence(files, patterns)], | ||
| ['overrides/Button.js', 'common/Button.js', 'common/Card.js'] | ||
| ); | ||
| } finally { | ||
| process.chdir(originalCwd); | ||
| } | ||
| }); |
There was a problem hiding this comment.
iirc node:test doesn't support before/after inside describe/test, and so this test should be as it is since node runs the test in the same process and we're not using workers.
Since tests in node:test (and in general in JS) run sequentially within the same file (unless there is explicit concurrency, which here does not appear to have been set up at the individual test level), this is safe.
There was a problem hiding this comment.
If there were concurrency, changing the global cwd would be dangerous. But for this use case and with the current structure, the try...finally block is a correct and localized way to handle the context switch needed to test the function without options.
There was a problem hiding this comment.
maybe we can just use relative path using import.meta.url and relativizing the path from the fixture
|
I guess it should be added in the target project, so this PR should be fine. |
|
One last optimization: if sort is |

Description
This PR adds built-in sorting support to
globandglobSyncto ensure predictable results. This is crucial for tools likeunplugin-vue-components(and maybe atunimport, andunplugin-auto-import), where declaration overwrites and.d.tsgeneration need to be deterministic.It introduces a new
sortoption with the following modes:'asc': Sorts results in ascending order (alphabetical).'desc': Sorts results in descending order.'pattern': Sorts results based on the order of the provided patterns (precedence).'pattern-asc': Sorts by pattern precedence, then ascending within matches of the same pattern.'pattern-desc': Sorts by pattern precedence, then descending within matches of the same pattern.Function: A custom comparison function(a: string, b: string) => number.Changes
getOptionsfromindex.tsto a newoptions.tsmodule (reusing it atcrawler.tsandsort.ts)crawler.tstobuildCrawlerInfofunction (reusing it atindex.tsandsort.ts)sortoption toGlobOptions.compileMatchers,sortFilesandsortFilesByPatternPrecedenceexported utilities.compileGlobstocompileMatchersand moved logic tosrc/sort.tsfrom original PR feat: add newcompileGlobshelper function #168.resolves #166
supersedes #168