Skip to content

Commit

Permalink
refactor(core): use picomatch and tinyglobby
Browse files Browse the repository at this point in the history
Use smaller and faster glob libraries.
Replace micromatch with picomatch and fast-glob with tinyglobby.
This change should speed up the process of file collection.
  • Loading branch information
sdorra committed Sep 2, 2024
1 parent 7a407f3 commit f8018f5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 16 deletions.
5 changes: 5 additions & 0 deletions .changeset/cuddly-flowers-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@content-collections/core": minor
---

Use smaller and faster glob libraries. Replace micromatch with picomatch and fast-glob with tinyglobby.
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"typescript": "^5.0.2"
},
"devDependencies": {
"@types/micromatch": "^4.0.9",
"@types/node": "^20.14.9",
"@types/picomatch": "^3.0.1",
"@types/pluralize": "^0.0.33",
"@types/serialize-javascript": "^5.0.4",
"@vitest/coverage-v8": "^2.0.5",
Expand All @@ -41,12 +41,12 @@
"bundle-require": "^5.0.0",
"camelcase": "^8.0.0",
"esbuild": "^0.21.4",
"fast-glob": "^3.3.2",
"gray-matter": "^4.0.3",
"micromatch": "^4.0.8",
"p-limit": "^6.1.0",
"picomatch": "^4.0.2",
"pluralize": "^8.0.0",
"serialize-javascript": "^6.0.2",
"tinyglobby": "^0.2.5",
"yaml": "^2.4.5",
"zod": "^3.23.8"
}
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/collector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fg from "fast-glob";
import { glob } from "tinyglobby";
import { readFile } from "fs/promises";
import path from "path";
import { isDefined, orderByPath } from "./utils";
Expand Down Expand Up @@ -81,7 +81,9 @@ export function createCollector(emitter: Emitter, baseDirectory: string = ".") {
async function resolveCollection<T extends FileCollection>(collection: T) {
const collectionDirectory = path.join(baseDirectory, collection.directory);

const filePaths = await fg(collection.include, {
const include = Array.isArray(collection.include) ? collection.include : [collection.include];

const filePaths = await glob(include, {
cwd: collectionDirectory,
onlyFiles: true,
absolute: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/synchronizer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import micromatch from "micromatch";
import picomatch from "picomatch";
import { CollectionFile, FileCollection, ResolvedCollection } from "./types";
import path from "node:path";
import { orderByPath } from "./utils";
Expand Down Expand Up @@ -45,7 +45,7 @@ export function createSynchronizer<T extends FileCollection>(
};
})
.filter(({ collection, relativePath }) => {
return micromatch.isMatch(relativePath, collection.include, {
return picomatch.isMatch(relativePath, collection.include, {
ignore: collection.exclude,
});
});
Expand Down
48 changes: 39 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f8018f5

Please sign in to comment.