refactor: migrate from Bun.Glob to npm glob package (#14317)

This commit is contained in:
Dax
2026-02-19 13:40:09 -05:00
committed by GitHub
parent 7e35d0c610
commit cb8b74d3f1
17 changed files with 315 additions and 127 deletions

View File

@@ -15,6 +15,7 @@
"@actions/artifact": "5.0.1", "@actions/artifact": "5.0.1",
"@tsconfig/bun": "catalog:", "@tsconfig/bun": "catalog:",
"@types/mime-types": "3.0.1", "@types/mime-types": "3.0.1",
"glob": "13.0.5",
"husky": "9.1.7", "husky": "9.1.7",
"prettier": "3.6.2", "prettier": "3.6.2",
"semver": "^7.6.0", "semver": "^7.6.0",
@@ -321,6 +322,7 @@
"diff": "catalog:", "diff": "catalog:",
"drizzle-orm": "1.0.0-beta.12-a5629fb", "drizzle-orm": "1.0.0-beta.12-a5629fb",
"fuzzysort": "3.1.0", "fuzzysort": "3.1.0",
"glob": "13.0.5",
"google-auth-library": "10.5.0", "google-auth-library": "10.5.0",
"gray-matter": "4.0.3", "gray-matter": "4.0.3",
"hono": "catalog:", "hono": "catalog:",
@@ -2694,7 +2696,7 @@
"github-slugger": ["github-slugger@2.0.0", "", {}, "sha512-IaOQ9puYtjrkq7Y0Ygl9KDZnrf/aiUJYUpVf89y8kyaxbRG7Y1SrX/jaumrv81vc61+kiMempujsM3Yw7w5qcw=="], "github-slugger": ["github-slugger@2.0.0", "", {}, "sha512-IaOQ9puYtjrkq7Y0Ygl9KDZnrf/aiUJYUpVf89y8kyaxbRG7Y1SrX/jaumrv81vc61+kiMempujsM3Yw7w5qcw=="],
"glob": ["glob@11.1.0", "", { "dependencies": { "foreground-child": "^3.3.1", "jackspeak": "^4.1.1", "minimatch": "^10.1.1", "minipass": "^7.1.2", "package-json-from-dist": "^1.0.0", "path-scurry": "^2.0.0" }, "bin": { "glob": "dist/esm/bin.mjs" } }, "sha512-vuNwKSaKiqm7g0THUBu2x7ckSs3XJLXE+2ssL7/MfTGPLLcrJQ/4Uq1CjPTtO5cCIiRxqvN6Twy1qOwhL0Xjcw=="], "glob": ["glob@13.0.5", "", { "dependencies": { "minimatch": "^10.2.1", "minipass": "^7.1.2", "path-scurry": "^2.0.0" } }, "sha512-BzXxZg24Ibra1pbQ/zE7Kys4Ua1ks7Bn6pKLkVPZ9FZe4JQS6/Q7ef3LG1H+k7lUf5l4T3PLSyYyYJVYUvfgTw=="],
"glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="], "glob-parent": ["glob-parent@5.1.2", "", { "dependencies": { "is-glob": "^4.0.1" } }, "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow=="],
@@ -3074,7 +3076,7 @@
"lower-case": ["lower-case@2.0.2", "", { "dependencies": { "tslib": "^2.0.3" } }, "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg=="], "lower-case": ["lower-case@2.0.2", "", { "dependencies": { "tslib": "^2.0.3" } }, "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg=="],
"lru-cache": ["lru-cache@6.0.0", "", { "dependencies": { "yallist": "^4.0.0" } }, "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA=="], "lru-cache": ["lru-cache@11.2.6", "", {}, "sha512-ESL2CrkS/2wTPfuend7Zhkzo2u0daGJ/A2VucJOgQ/C48S/zB8MMeMHSGKYpXhIjbPxfuezITkaBH1wqv00DDQ=="],
"lru.min": ["lru.min@1.1.4", "", {}, "sha512-DqC6n3QQ77zdFpCMASA1a3Jlb64Hv2N2DciFGkO/4L9+q/IpIAuRlKOvCXabtRW6cQf8usbmM6BE/TOPysCdIA=="], "lru.min": ["lru.min@1.1.4", "", {}, "sha512-DqC6n3QQ77zdFpCMASA1a3Jlb64Hv2N2DciFGkO/4L9+q/IpIAuRlKOvCXabtRW6cQf8usbmM6BE/TOPysCdIA=="],
@@ -4794,14 +4796,14 @@
"openid-client/jose": ["jose@4.15.9", "", {}, "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA=="], "openid-client/jose": ["jose@4.15.9", "", {}, "sha512-1vUQX+IdDMVPj4k8kOxgUqlcK518yluMuGZwqlr44FS1ppZB/5GWh4rZG89erpOBOJjU/OBsnCVFfapsRz6nEA=="],
"openid-client/lru-cache": ["lru-cache@6.0.0", "", { "dependencies": { "yallist": "^4.0.0" } }, "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA=="],
"p-locate/p-limit": ["p-limit@2.3.0", "", { "dependencies": { "p-try": "^2.0.0" } }, "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w=="], "p-locate/p-limit": ["p-limit@2.3.0", "", { "dependencies": { "p-try": "^2.0.0" } }, "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w=="],
"parse-entities/@types/unist": ["@types/unist@2.0.11", "", {}, "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA=="], "parse-entities/@types/unist": ["@types/unist@2.0.11", "", {}, "sha512-CmBKiL6NNo/OqgmMn95Fk9Whlp2mtvIv+KNpQKN2F4SjvrEesubTRWGYSg+BnWZOnlCaSTU1sMpsBOzgbYhnsA=="],
"parse5/entities": ["entities@6.0.1", "", {}, "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g=="], "parse5/entities": ["entities@6.0.1", "", {}, "sha512-aN97NXWF6AWBTahfVOIrB/NShkzi5H7F9r1s9mD3cDj4Ko5f2qhhVoYMibXF7GlLveb/D2ioWay8lxI97Ven3g=="],
"path-scurry/lru-cache": ["lru-cache@11.2.6", "", {}, "sha512-ESL2CrkS/2wTPfuend7Zhkzo2u0daGJ/A2VucJOgQ/C48S/zB8MMeMHSGKYpXhIjbPxfuezITkaBH1wqv00DDQ=="],
"pixelmatch/pngjs": ["pngjs@6.0.0", "", {}, "sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg=="], "pixelmatch/pngjs": ["pngjs@6.0.0", "", {}, "sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg=="],
"pkg-up/find-up": ["find-up@3.0.0", "", { "dependencies": { "locate-path": "^3.0.0" } }, "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg=="], "pkg-up/find-up": ["find-up@3.0.0", "", { "dependencies": { "locate-path": "^3.0.0" } }, "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg=="],
@@ -4874,10 +4876,10 @@
"unifont/ofetch": ["ofetch@1.5.1", "", { "dependencies": { "destr": "^2.0.5", "node-fetch-native": "^1.6.7", "ufo": "^1.6.1" } }, "sha512-2W4oUZlVaqAPAil6FUg/difl6YhqhUR7x2eZY4bQCko22UXg3hptq9KLQdqFClV+Wu85UX7hNtdGTngi/1BxcA=="], "unifont/ofetch": ["ofetch@1.5.1", "", { "dependencies": { "destr": "^2.0.5", "node-fetch-native": "^1.6.7", "ufo": "^1.6.1" } }, "sha512-2W4oUZlVaqAPAil6FUg/difl6YhqhUR7x2eZY4bQCko22UXg3hptq9KLQdqFClV+Wu85UX7hNtdGTngi/1BxcA=="],
"unstorage/lru-cache": ["lru-cache@11.2.6", "", {}, "sha512-ESL2CrkS/2wTPfuend7Zhkzo2u0daGJ/A2VucJOgQ/C48S/zB8MMeMHSGKYpXhIjbPxfuezITkaBH1wqv00DDQ=="],
"utif2/pako": ["pako@1.0.11", "", {}, "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="], "utif2/pako": ["pako@1.0.11", "", {}, "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="],
"vite-plugin-icons-spritesheet/glob": ["glob@11.1.0", "", { "dependencies": { "foreground-child": "^3.3.1", "jackspeak": "^4.1.1", "minimatch": "^10.1.1", "minipass": "^7.1.2", "package-json-from-dist": "^1.0.0", "path-scurry": "^2.0.0" }, "bin": { "glob": "dist/esm/bin.mjs" } }, "sha512-vuNwKSaKiqm7g0THUBu2x7ckSs3XJLXE+2ssL7/MfTGPLLcrJQ/4Uq1CjPTtO5cCIiRxqvN6Twy1qOwhL0Xjcw=="],
"vitest/tinyexec": ["tinyexec@1.0.2", "", {}, "sha512-W/KYk+NFhkmsYpuHq5JykngiOCnxeVL8v8dFnqxSD8qEEdRfXk1SDM6JzNqcERbcGYj9tMrDQBYV9cjgnunFIg=="], "vitest/tinyexec": ["tinyexec@1.0.2", "", {}, "sha512-W/KYk+NFhkmsYpuHq5JykngiOCnxeVL8v8dFnqxSD8qEEdRfXk1SDM6JzNqcERbcGYj9tMrDQBYV9cjgnunFIg=="],
"vitest/vite": ["vite@7.1.10", "", { "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-CmuvUBzVJ/e3HGxhg6cYk88NGgTnBoOo7ogtfJJ0fefUWAxN/WDSUa50o+oVBxuIhO8FoEZW0j2eW7sfjs5EtA=="], "vitest/vite": ["vite@7.1.10", "", { "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", "picomatch": "^4.0.3", "postcss": "^8.5.6", "rollup": "^4.43.0", "tinyglobby": "^0.2.15" }, "optionalDependencies": { "fsevents": "~2.3.3" }, "peerDependencies": { "@types/node": "^20.19.0 || >=22.12.0", "jiti": ">=1.21.0", "less": "^4.0.0", "lightningcss": "^1.21.0", "sass": "^1.70.0", "sass-embedded": "^1.70.0", "stylus": ">=0.54.8", "sugarss": "^5.0.0", "terser": "^5.16.0", "tsx": "^4.8.1", "yaml": "^2.4.2" }, "optionalPeers": ["@types/node", "jiti", "less", "lightningcss", "sass", "sass-embedded", "stylus", "sugarss", "terser", "tsx", "yaml"], "bin": { "vite": "bin/vite.js" } }, "sha512-CmuvUBzVJ/e3HGxhg6cYk88NGgTnBoOo7ogtfJJ0fefUWAxN/WDSUa50o+oVBxuIhO8FoEZW0j2eW7sfjs5EtA=="],
@@ -5236,8 +5238,6 @@
"astro/unstorage/h3": ["h3@1.15.5", "", { "dependencies": { "cookie-es": "^1.2.2", "crossws": "^0.3.5", "defu": "^6.1.4", "destr": "^2.0.5", "iron-webcrypto": "^1.2.1", "node-mock-http": "^1.0.4", "radix3": "^1.1.2", "ufo": "^1.6.3", "uncrypto": "^0.1.3" } }, "sha512-xEyq3rSl+dhGX2Lm0+eFQIAzlDN6Fs0EcC4f7BNUmzaRX/PTzeuM+Tr2lHB8FoXggsQIeXLj8EDVgs5ywxyxmg=="], "astro/unstorage/h3": ["h3@1.15.5", "", { "dependencies": { "cookie-es": "^1.2.2", "crossws": "^0.3.5", "defu": "^6.1.4", "destr": "^2.0.5", "iron-webcrypto": "^1.2.1", "node-mock-http": "^1.0.4", "radix3": "^1.1.2", "ufo": "^1.6.3", "uncrypto": "^0.1.3" } }, "sha512-xEyq3rSl+dhGX2Lm0+eFQIAzlDN6Fs0EcC4f7BNUmzaRX/PTzeuM+Tr2lHB8FoXggsQIeXLj8EDVgs5ywxyxmg=="],
"astro/unstorage/lru-cache": ["lru-cache@11.2.6", "", {}, "sha512-ESL2CrkS/2wTPfuend7Zhkzo2u0daGJ/A2VucJOgQ/C48S/zB8MMeMHSGKYpXhIjbPxfuezITkaBH1wqv00DDQ=="],
"astro/unstorage/ofetch": ["ofetch@1.5.1", "", { "dependencies": { "destr": "^2.0.5", "node-fetch-native": "^1.6.7", "ufo": "^1.6.1" } }, "sha512-2W4oUZlVaqAPAil6FUg/difl6YhqhUR7x2eZY4bQCko22UXg3hptq9KLQdqFClV+Wu85UX7hNtdGTngi/1BxcA=="], "astro/unstorage/ofetch": ["ofetch@1.5.1", "", { "dependencies": { "destr": "^2.0.5", "node-fetch-native": "^1.6.7", "ufo": "^1.6.1" } }, "sha512-2W4oUZlVaqAPAil6FUg/difl6YhqhUR7x2eZY4bQCko22UXg3hptq9KLQdqFClV+Wu85UX7hNtdGTngi/1BxcA=="],
"aws-sdk/xml2js/sax": ["sax@1.4.4", "", {}, "sha512-1n3r/tGXO6b6VXMdFT54SHzT9ytu9yr7TaELowdYpMqY/Ao7EnlQGmAQ1+RatX7Tkkdm6hONI2owqNx2aZj5Sw=="], "aws-sdk/xml2js/sax": ["sax@1.4.4", "", {}, "sha512-1n3r/tGXO6b6VXMdFT54SHzT9ytu9yr7TaELowdYpMqY/Ao7EnlQGmAQ1+RatX7Tkkdm6hONI2owqNx2aZj5Sw=="],
@@ -5370,6 +5370,8 @@
"type-is/mime-types/mime-db": ["mime-db@1.52.0", "", {}, "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="], "type-is/mime-types/mime-db": ["mime-db@1.52.0", "", {}, "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="],
"vite-plugin-icons-spritesheet/glob/minimatch": ["minimatch@10.2.1", "", { "dependencies": { "brace-expansion": "^5.0.2" } }, "sha512-MClCe8IL5nRRmawL6ib/eT4oLyeKMGCghibcDWK+J0hh0Q8kqSdia6BvbRMVk6mPa6WqUa5uR2oxt6C5jd533A=="],
"wrangler/esbuild/@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.4", "", { "os": "aix", "cpu": "ppc64" }, "sha512-1VCICWypeQKhVbE9oW/sJaAmjLxhVqacdkvPLEjwlttjfwENRSClS8EjBz0KzRyFSCPDIkuXW34Je/vk7zdB7Q=="], "wrangler/esbuild/@esbuild/aix-ppc64": ["@esbuild/aix-ppc64@0.25.4", "", { "os": "aix", "cpu": "ppc64" }, "sha512-1VCICWypeQKhVbE9oW/sJaAmjLxhVqacdkvPLEjwlttjfwENRSClS8EjBz0KzRyFSCPDIkuXW34Je/vk7zdB7Q=="],
"wrangler/esbuild/@esbuild/android-arm": ["@esbuild/android-arm@0.25.4", "", { "os": "android", "cpu": "arm" }, "sha512-QNdQEps7DfFwE3hXiU4BZeOV68HHzYwGd0Nthhd3uCkkEKK7/R6MTgM0P7H7FAs5pU/DIWsviMmEGxEoxIZ+ZQ=="], "wrangler/esbuild/@esbuild/android-arm": ["@esbuild/android-arm@0.25.4", "", { "os": "android", "cpu": "arm" }, "sha512-QNdQEps7DfFwE3hXiU4BZeOV68HHzYwGd0Nthhd3uCkkEKK7/R6MTgM0P7H7FAs5pU/DIWsviMmEGxEoxIZ+ZQ=="],

View File

@@ -70,6 +70,7 @@
"@actions/artifact": "5.0.1", "@actions/artifact": "5.0.1",
"@tsconfig/bun": "catalog:", "@tsconfig/bun": "catalog:",
"@types/mime-types": "3.0.1", "@types/mime-types": "3.0.1",
"glob": "13.0.5",
"husky": "9.1.7", "husky": "9.1.7",
"prettier": "3.6.2", "prettier": "3.6.2",
"semver": "^7.6.0", "semver": "^7.6.0",

View File

@@ -107,6 +107,7 @@
"diff": "catalog:", "diff": "catalog:",
"drizzle-orm": "1.0.0-beta.12-a5629fb", "drizzle-orm": "1.0.0-beta.12-a5629fb",
"fuzzysort": "3.1.0", "fuzzysort": "3.1.0",
"glob": "13.0.5",
"google-auth-library": "10.5.0", "google-auth-library": "10.5.0",
"gray-matter": "4.0.3", "gray-matter": "4.0.3",
"hono": "catalog:", "hono": "catalog:",

View File

@@ -3,6 +3,7 @@ import path from "path"
import { createEffect, createMemo, onMount } from "solid-js" import { createEffect, createMemo, onMount } from "solid-js"
import { useSync } from "@tui/context/sync" import { useSync } from "@tui/context/sync"
import { createSimpleContext } from "./helper" import { createSimpleContext } from "./helper"
import { Glob } from "../../../../util/glob"
import aura from "./theme/aura.json" with { type: "json" } import aura from "./theme/aura.json" with { type: "json" }
import ayu from "./theme/ayu.json" with { type: "json" } import ayu from "./theme/ayu.json" with { type: "json" }
import catppuccin from "./theme/catppuccin.json" with { type: "json" } import catppuccin from "./theme/catppuccin.json" with { type: "json" }
@@ -391,7 +392,6 @@ export const { use: useTheme, provider: ThemeProvider } = createSimpleContext({
}, },
}) })
const CUSTOM_THEME_GLOB = new Bun.Glob("themes/*.json")
async function getCustomThemes() { async function getCustomThemes() {
const directories = [ const directories = [
Global.Path.config, Global.Path.config,
@@ -405,11 +405,11 @@ async function getCustomThemes() {
const result: Record<string, ThemeJson> = {} const result: Record<string, ThemeJson> = {}
for (const dir of directories) { for (const dir of directories) {
for await (const item of CUSTOM_THEME_GLOB.scan({ for (const item of await Glob.scan("themes/*.json", {
absolute: true,
followSymlinks: true,
dot: true,
cwd: dir, cwd: dir,
absolute: true,
dot: true,
symlink: true,
})) { })) {
const name = path.basename(item, ".json") const name = path.basename(item, ".json")
result[name] = await Filesystem.readJson(item) result[name] = await Filesystem.readJson(item)

View File

@@ -28,6 +28,7 @@ import { constants, existsSync } from "fs"
import { Bus } from "@/bus" import { Bus } from "@/bus"
import { GlobalBus } from "@/bus/global" import { GlobalBus } from "@/bus/global"
import { Event } from "../server/event" import { Event } from "../server/event"
import { Glob } from "../util/glob"
import { PackageRegistry } from "@/bun/registry" import { PackageRegistry } from "@/bun/registry"
import { proxied } from "@/util/proxied" import { proxied } from "@/util/proxied"
import { iife } from "@/util/iife" import { iife } from "@/util/iife"
@@ -351,14 +352,13 @@ export namespace Config {
return ext.length ? file.slice(0, -ext.length) : file return ext.length ? file.slice(0, -ext.length) : file
} }
const COMMAND_GLOB = new Bun.Glob("{command,commands}/**/*.md")
async function loadCommand(dir: string) { async function loadCommand(dir: string) {
const result: Record<string, Command> = {} const result: Record<string, Command> = {}
for await (const item of COMMAND_GLOB.scan({ for (const item of await Glob.scan("{command,commands}/**/*.md", {
absolute: true,
followSymlinks: true,
dot: true,
cwd: dir, cwd: dir,
absolute: true,
dot: true,
symlink: true,
})) { })) {
const md = await ConfigMarkdown.parse(item).catch(async (err) => { const md = await ConfigMarkdown.parse(item).catch(async (err) => {
const message = ConfigMarkdown.FrontmatterError.isInstance(err) const message = ConfigMarkdown.FrontmatterError.isInstance(err)
@@ -390,15 +390,14 @@ export namespace Config {
return result return result
} }
const AGENT_GLOB = new Bun.Glob("{agent,agents}/**/*.md")
async function loadAgent(dir: string) { async function loadAgent(dir: string) {
const result: Record<string, Agent> = {} const result: Record<string, Agent> = {}
for await (const item of AGENT_GLOB.scan({ for (const item of await Glob.scan("{agent,agents}/**/*.md", {
absolute: true,
followSymlinks: true,
dot: true,
cwd: dir, cwd: dir,
absolute: true,
dot: true,
symlink: true,
})) { })) {
const md = await ConfigMarkdown.parse(item).catch(async (err) => { const md = await ConfigMarkdown.parse(item).catch(async (err) => {
const message = ConfigMarkdown.FrontmatterError.isInstance(err) const message = ConfigMarkdown.FrontmatterError.isInstance(err)
@@ -430,14 +429,13 @@ export namespace Config {
return result return result
} }
const MODE_GLOB = new Bun.Glob("{mode,modes}/*.md")
async function loadMode(dir: string) { async function loadMode(dir: string) {
const result: Record<string, Agent> = {} const result: Record<string, Agent> = {}
for await (const item of MODE_GLOB.scan({ for (const item of await Glob.scan("{mode,modes}/*.md", {
absolute: true,
followSymlinks: true,
dot: true,
cwd: dir, cwd: dir,
absolute: true,
dot: true,
symlink: true,
})) { })) {
const md = await ConfigMarkdown.parse(item).catch(async (err) => { const md = await ConfigMarkdown.parse(item).catch(async (err) => {
const message = ConfigMarkdown.FrontmatterError.isInstance(err) const message = ConfigMarkdown.FrontmatterError.isInstance(err)
@@ -467,15 +465,14 @@ export namespace Config {
return result return result
} }
const PLUGIN_GLOB = new Bun.Glob("{plugin,plugins}/*.{ts,js}")
async function loadPlugin(dir: string) { async function loadPlugin(dir: string) {
const plugins: string[] = [] const plugins: string[] = []
for await (const item of PLUGIN_GLOB.scan({ for (const item of await Glob.scan("{plugin,plugins}/*.{ts,js}", {
absolute: true,
followSymlinks: true,
dot: true,
cwd: dir, cwd: dir,
absolute: true,
dot: true,
symlink: true,
})) { })) {
plugins.push(pathToFileURL(item).href) plugins.push(pathToFileURL(item).href)
} }

View File

@@ -1,4 +1,5 @@
import { sep } from "node:path" import { sep } from "node:path"
import { Glob } from "../util/glob"
export namespace FileIgnore { export namespace FileIgnore {
const FOLDERS = new Set([ const FOLDERS = new Set([
@@ -53,19 +54,17 @@ export namespace FileIgnore {
"**/.nyc_output/**", "**/.nyc_output/**",
] ]
const FILE_GLOBS = FILES.map((p) => new Bun.Glob(p))
export const PATTERNS = [...FILES, ...FOLDERS] export const PATTERNS = [...FILES, ...FOLDERS]
export function match( export function match(
filepath: string, filepath: string,
opts?: { opts?: {
extra?: Bun.Glob[] extra?: string[]
whitelist?: Bun.Glob[] whitelist?: string[]
}, },
) { ) {
for (const glob of opts?.whitelist || []) { for (const pattern of opts?.whitelist || []) {
if (glob.match(filepath)) return false if (Glob.match(pattern, filepath)) return false
} }
const parts = filepath.split(sep) const parts = filepath.split(sep)
@@ -74,8 +73,8 @@ export namespace FileIgnore {
} }
const extra = opts?.extra || [] const extra = opts?.extra || []
for (const glob of [...FILE_GLOBS, ...extra]) { for (const pattern of [...FILES, ...extra]) {
if (glob.match(filepath)) return true if (Glob.match(pattern, filepath)) return true
} }
return false return false

View File

@@ -13,6 +13,7 @@ import { iife } from "@/util/iife"
import { GlobalBus } from "@/bus/global" import { GlobalBus } from "@/bus/global"
import { existsSync } from "fs" import { existsSync } from "fs"
import { git } from "../util/git" import { git } from "../util/git"
import { Glob } from "../util/glob"
export namespace Project { export namespace Project {
const log = Log.create({ service: "project" }) const log = Log.create({ service: "project" })
@@ -262,16 +263,11 @@ export namespace Project {
if (input.vcs !== "git") return if (input.vcs !== "git") return
if (input.icon?.override) return if (input.icon?.override) return
if (input.icon?.url) return if (input.icon?.url) return
const glob = new Bun.Glob("**/{favicon}.{ico,png,svg,jpg,jpeg,webp}") const matches = await Glob.scan("**/favicon.{ico,png,svg,jpg,jpeg,webp}", {
const matches = await Array.fromAsync(
glob.scan({
cwd: input.worktree, cwd: input.worktree,
absolute: true, absolute: true,
onlyFiles: true, include: "file",
followSymlinks: false, })
dot: false,
}),
)
const shortest = matches.sort((a, b) => a.length - b.length)[0] const shortest = matches.sort((a, b) => a.length - b.length)[0]
if (!shortest) return if (!shortest) return
const buffer = await Filesystem.readBytes(shortest) const buffer = await Filesystem.readBytes(shortest)

View File

@@ -6,6 +6,7 @@ import { Config } from "../config/config"
import { Instance } from "../project/instance" import { Instance } from "../project/instance"
import { Flag } from "@/flag/flag" import { Flag } from "@/flag/flag"
import { Log } from "../util/log" import { Log } from "../util/log"
import { Glob } from "../util/glob"
import type { MessageV2 } from "./message-v2" import type { MessageV2 } from "./message-v2"
const log = Log.create({ service: "instruction" }) const log = Log.create({ service: "instruction" })
@@ -98,13 +99,11 @@ export namespace InstructionPrompt {
instruction = path.join(os.homedir(), instruction.slice(2)) instruction = path.join(os.homedir(), instruction.slice(2))
} }
const matches = path.isAbsolute(instruction) const matches = path.isAbsolute(instruction)
? await Array.fromAsync( ? await Glob.scan(path.basename(instruction), {
new Bun.Glob(path.basename(instruction)).scan({
cwd: path.dirname(instruction), cwd: path.dirname(instruction),
absolute: true, absolute: true,
onlyFiles: true, include: "file",
}), }).catch(() => [])
).catch(() => [])
: await resolveRelative(instruction) : await resolveRelative(instruction)
matches.forEach((p) => { matches.forEach((p) => {
paths.add(path.resolve(p)) paths.add(path.resolve(p))

View File

@@ -12,6 +12,7 @@ import { Flag } from "@/flag/flag"
import { Bus } from "@/bus" import { Bus } from "@/bus"
import { Session } from "@/session" import { Session } from "@/session"
import { Discovery } from "./discovery" import { Discovery } from "./discovery"
import { Glob } from "../util/glob"
export namespace Skill { export namespace Skill {
const log = Log.create({ service: "skill" }) const log = Log.create({ service: "skill" })
@@ -44,10 +45,9 @@ export namespace Skill {
// External skill directories to search for (project-level and global) // External skill directories to search for (project-level and global)
// These follow the directory layout used by Claude Code and other agents. // These follow the directory layout used by Claude Code and other agents.
const EXTERNAL_DIRS = [".claude", ".agents"] const EXTERNAL_DIRS = [".claude", ".agents"]
const EXTERNAL_SKILL_GLOB = new Bun.Glob("skills/**/SKILL.md") const EXTERNAL_SKILL_PATTERN = "skills/**/SKILL.md"
const OPENCODE_SKILL_PATTERN = "{skill,skills}/**/SKILL.md"
const OPENCODE_SKILL_GLOB = new Bun.Glob("{skill,skills}/**/SKILL.md") const SKILL_PATTERN = "**/SKILL.md"
const SKILL_GLOB = new Bun.Glob("**/SKILL.md")
export const state = Instance.state(async () => { export const state = Instance.state(async () => {
const skills: Record<string, Info> = {} const skills: Record<string, Info> = {}
@@ -88,15 +88,13 @@ export namespace Skill {
} }
const scanExternal = async (root: string, scope: "global" | "project") => { const scanExternal = async (root: string, scope: "global" | "project") => {
return Array.fromAsync( return Glob.scan(EXTERNAL_SKILL_PATTERN, {
EXTERNAL_SKILL_GLOB.scan({
cwd: root, cwd: root,
absolute: true, absolute: true,
onlyFiles: true, include: "file",
followSymlinks: true,
dot: true, dot: true,
}), symlink: true,
) })
.then((matches) => Promise.all(matches.map(addSkill))) .then((matches) => Promise.all(matches.map(addSkill)))
.catch((error) => { .catch((error) => {
log.error(`failed to scan ${scope} skills`, { dir: root, error }) log.error(`failed to scan ${scope} skills`, { dir: root, error })
@@ -123,12 +121,13 @@ export namespace Skill {
// Scan .opencode/skill/ directories // Scan .opencode/skill/ directories
for (const dir of await Config.directories()) { for (const dir of await Config.directories()) {
for await (const match of OPENCODE_SKILL_GLOB.scan({ const matches = await Glob.scan(OPENCODE_SKILL_PATTERN, {
cwd: dir, cwd: dir,
absolute: true, absolute: true,
onlyFiles: true, include: "file",
followSymlinks: true, symlink: true,
})) { })
for (const match of matches) {
await addSkill(match) await addSkill(match)
} }
} }
@@ -142,12 +141,13 @@ export namespace Skill {
log.warn("skill path not found", { path: resolved }) log.warn("skill path not found", { path: resolved })
continue continue
} }
for await (const match of SKILL_GLOB.scan({ const matches = await Glob.scan(SKILL_PATTERN, {
cwd: resolved, cwd: resolved,
absolute: true, absolute: true,
onlyFiles: true, include: "file",
followSymlinks: true, symlink: true,
})) { })
for (const match of matches) {
await addSkill(match) await addSkill(match)
} }
} }
@@ -157,12 +157,13 @@ export namespace Skill {
const list = await Discovery.pull(url) const list = await Discovery.pull(url)
for (const dir of list) { for (const dir of list) {
dirs.add(dir) dirs.add(dir)
for await (const match of SKILL_GLOB.scan({ const matches = await Glob.scan(SKILL_PATTERN, {
cwd: dir, cwd: dir,
absolute: true, absolute: true,
onlyFiles: true, include: "file",
followSymlinks: true, symlink: true,
})) { })
for (const match of matches) {
await addSkill(match) await addSkill(match)
} }
} }

View File

@@ -8,6 +8,7 @@ import { SessionShareTable } from "../share/share.sql"
import path from "path" import path from "path"
import { existsSync } from "fs" import { existsSync } from "fs"
import { Filesystem } from "../util/filesystem" import { Filesystem } from "../util/filesystem"
import { Glob } from "../util/glob"
export namespace JsonMigration { export namespace JsonMigration {
const log = Log.create({ service: "json-migration" }) const log = Log.create({ service: "json-migration" })
@@ -71,12 +72,7 @@ export namespace JsonMigration {
const now = Date.now() const now = Date.now()
async function list(pattern: string) { async function list(pattern: string) {
const items: string[] = [] return Glob.scan(pattern, { cwd: storageDir, absolute: true })
const scan = new Bun.Glob(pattern)
for await (const file of scan.scan({ cwd: storageDir, absolute: true })) {
items.push(file)
}
return items
} }
async function read(files: string[], start: number, end: number) { async function read(files: string[], start: number, end: number) {

View File

@@ -8,6 +8,7 @@ import { Lock } from "../util/lock"
import { $ } from "bun" import { $ } from "bun"
import { NamedError } from "@opencode-ai/util/error" import { NamedError } from "@opencode-ai/util/error"
import z from "zod" import z from "zod"
import { Glob } from "../util/glob"
export namespace Storage { export namespace Storage {
const log = Log.create({ service: "storage" }) const log = Log.create({ service: "storage" })
@@ -25,17 +26,20 @@ export namespace Storage {
async (dir) => { async (dir) => {
const project = path.resolve(dir, "../project") const project = path.resolve(dir, "../project")
if (!(await Filesystem.isDir(project))) return if (!(await Filesystem.isDir(project))) return
for await (const projectDir of new Bun.Glob("*").scan({ const projectDirs = await Glob.scan("*", {
cwd: project, cwd: project,
onlyFiles: false, include: "all",
})) { })
for (const projectDir of projectDirs) {
const fullPath = path.join(project, projectDir)
if (!(await Filesystem.isDir(fullPath))) continue
log.info(`migrating project ${projectDir}`) log.info(`migrating project ${projectDir}`)
let projectID = projectDir let projectID = projectDir
const fullProjectDir = path.join(project, projectDir) const fullProjectDir = path.join(project, projectDir)
let worktree = "/" let worktree = "/"
if (projectID !== "global") { if (projectID !== "global") {
for await (const msgFile of new Bun.Glob("storage/session/message/*/*.json").scan({ for (const msgFile of await Glob.scan("storage/session/message/*/*.json", {
cwd: path.join(project, projectDir), cwd: path.join(project, projectDir),
absolute: true, absolute: true,
})) { })) {
@@ -71,7 +75,7 @@ export namespace Storage {
}) })
log.info(`migrating sessions for project ${projectID}`) log.info(`migrating sessions for project ${projectID}`)
for await (const sessionFile of new Bun.Glob("storage/session/info/*.json").scan({ for (const sessionFile of await Glob.scan("storage/session/info/*.json", {
cwd: fullProjectDir, cwd: fullProjectDir,
absolute: true, absolute: true,
})) { })) {
@@ -83,7 +87,7 @@ export namespace Storage {
const session = await Filesystem.readJson<any>(sessionFile) const session = await Filesystem.readJson<any>(sessionFile)
await Filesystem.writeJson(dest, session) await Filesystem.writeJson(dest, session)
log.info(`migrating messages for session ${session.id}`) log.info(`migrating messages for session ${session.id}`)
for await (const msgFile of new Bun.Glob(`storage/session/message/${session.id}/*.json`).scan({ for (const msgFile of await Glob.scan(`storage/session/message/${session.id}/*.json`, {
cwd: fullProjectDir, cwd: fullProjectDir,
absolute: true, absolute: true,
})) { })) {
@@ -96,12 +100,10 @@ export namespace Storage {
await Filesystem.writeJson(dest, message) await Filesystem.writeJson(dest, message)
log.info(`migrating parts for message ${message.id}`) log.info(`migrating parts for message ${message.id}`)
for await (const partFile of new Bun.Glob(`storage/session/part/${session.id}/${message.id}/*.json`).scan( for (const partFile of await Glob.scan(`storage/session/part/${session.id}/${message.id}/*.json`, {
{
cwd: fullProjectDir, cwd: fullProjectDir,
absolute: true, absolute: true,
}, })) {
)) {
const dest = path.join(dir, "part", message.id, path.basename(partFile)) const dest = path.join(dir, "part", message.id, path.basename(partFile))
const part = await Filesystem.readJson(partFile) const part = await Filesystem.readJson(partFile)
log.info("copying", { log.info("copying", {
@@ -116,7 +118,7 @@ export namespace Storage {
} }
}, },
async (dir) => { async (dir) => {
for await (const item of new Bun.Glob("session/*/*.json").scan({ for (const item of await Glob.scan("session/*/*.json", {
cwd: dir, cwd: dir,
absolute: true, absolute: true,
})) { })) {
@@ -202,16 +204,13 @@ export namespace Storage {
}) })
} }
const glob = new Bun.Glob("**/*")
export async function list(prefix: string[]) { export async function list(prefix: string[]) {
const dir = await state().then((x) => x.dir) const dir = await state().then((x) => x.dir)
try { try {
const result = await Array.fromAsync( const result = await Glob.scan("**/*", {
glob.scan({
cwd: path.join(dir, ...prefix), cwd: path.join(dir, ...prefix),
onlyFiles: true, include: "file",
}), }).then((results) => results.map((x) => [...prefix, ...x.slice(0, -5).split(path.sep)]))
).then((results) => results.map((x) => [...prefix, ...x.slice(0, -5).split(path.sep)]))
result.sort() result.sort()
return result return result
} catch { } catch {

View File

@@ -27,16 +27,18 @@ import { LspTool } from "./lsp"
import { Truncate } from "./truncation" import { Truncate } from "./truncation"
import { PlanExitTool, PlanEnterTool } from "./plan" import { PlanExitTool, PlanEnterTool } from "./plan"
import { ApplyPatchTool } from "./apply_patch" import { ApplyPatchTool } from "./apply_patch"
import { Glob } from "../util/glob"
export namespace ToolRegistry { export namespace ToolRegistry {
const log = Log.create({ service: "tool.registry" }) const log = Log.create({ service: "tool.registry" })
export const state = Instance.state(async () => { export const state = Instance.state(async () => {
const custom = [] as Tool.Info[] const custom = [] as Tool.Info[]
const glob = new Bun.Glob("{tool,tools}/*.{js,ts}")
const matches = await Config.directories().then((dirs) => const matches = await Config.directories().then((dirs) =>
dirs.flatMap((dir) => [...glob.scanSync({ cwd: dir, absolute: true, followSymlinks: true, dot: true })]), dirs.flatMap((dir) =>
Glob.scanSync("{tool,tools}/*.{js,ts}", { cwd: dir, absolute: true, dot: true, symlink: true }),
),
) )
if (matches.length) await Config.waitForDependencies() if (matches.length) await Config.waitForDependencies()
for (const match of matches) { for (const match of matches) {

View File

@@ -6,6 +6,7 @@ import { PermissionNext } from "../permission/next"
import type { Agent } from "../agent/agent" import type { Agent } from "../agent/agent"
import { Scheduler } from "../scheduler" import { Scheduler } from "../scheduler"
import { Filesystem } from "../util/filesystem" import { Filesystem } from "../util/filesystem"
import { Glob } from "../util/glob"
export namespace Truncate { export namespace Truncate {
export const MAX_LINES = 2000 export const MAX_LINES = 2000
@@ -34,8 +35,7 @@ export namespace Truncate {
export async function cleanup() { export async function cleanup() {
const cutoff = Identifier.timestamp(Identifier.create("tool", false, Date.now() - RETENTION_MS)) const cutoff = Identifier.timestamp(Identifier.create("tool", false, Date.now() - RETENTION_MS))
const glob = new Bun.Glob("tool_*") const entries = await Glob.scan("tool_*", { cwd: DIR, include: "file" }).catch(() => [] as string[])
const entries = await Array.fromAsync(glob.scan({ cwd: DIR, onlyFiles: true })).catch(() => [] as string[])
for (const entry of entries) { for (const entry of entries) {
if (Identifier.timestamp(entry) >= cutoff) continue if (Identifier.timestamp(entry) >= cutoff) continue
await fs.unlink(path.join(DIR, entry)).catch(() => {}) await fs.unlink(path.join(DIR, entry)).catch(() => {})

View File

@@ -5,6 +5,7 @@ import { realpathSync } from "fs"
import { dirname, join, relative } from "path" import { dirname, join, relative } from "path"
import { Readable } from "stream" import { Readable } from "stream"
import { pipeline } from "stream/promises" import { pipeline } from "stream/promises"
import { Glob } from "./glob"
export namespace Filesystem { export namespace Filesystem {
// Fast sync version for metadata checks // Fast sync version for metadata checks
@@ -156,16 +157,13 @@ export namespace Filesystem {
const result = [] const result = []
while (true) { while (true) {
try { try {
const glob = new Bun.Glob(pattern) const matches = await Glob.scan(pattern, {
for await (const match of glob.scan({
cwd: current, cwd: current,
absolute: true, absolute: true,
onlyFiles: true, include: "file",
followSymlinks: true,
dot: true, dot: true,
})) { })
result.push(match) result.push(...matches)
}
} catch { } catch {
// Skip invalid glob patterns // Skip invalid glob patterns
} }

View File

@@ -0,0 +1,34 @@
import { glob, globSync, type GlobOptions } from "glob"
import { minimatch } from "minimatch"
export namespace Glob {
export interface Options {
cwd?: string
absolute?: boolean
include?: "file" | "all"
dot?: boolean
symlink?: boolean
}
function toGlobOptions(options: Options): GlobOptions {
return {
cwd: options.cwd,
absolute: options.absolute,
dot: options.dot,
follow: options.symlink ?? false,
nodir: options.include !== "all",
}
}
export async function scan(pattern: string, options: Options = {}): Promise<string[]> {
return glob(pattern, toGlobOptions(options)) as Promise<string[]>
}
export function scanSync(pattern: string, options: Options = {}): string[] {
return globSync(pattern, toGlobOptions(options)) as string[]
}
export function match(pattern: string, filepath: string): boolean {
return minimatch(filepath, pattern, { dot: true })
}
}

View File

@@ -3,6 +3,7 @@ import fs from "fs/promises"
import { createWriteStream } from "fs" import { createWriteStream } from "fs"
import { Global } from "../global" import { Global } from "../global"
import z from "zod" import z from "zod"
import { Glob } from "./glob"
export namespace Log { export namespace Log {
export const Level = z.enum(["DEBUG", "INFO", "WARN", "ERROR"]).meta({ ref: "LogLevel", description: "Log level" }) export const Level = z.enum(["DEBUG", "INFO", "WARN", "ERROR"]).meta({ ref: "LogLevel", description: "Log level" })
@@ -77,13 +78,11 @@ export namespace Log {
} }
async function cleanup(dir: string) { async function cleanup(dir: string) {
const glob = new Bun.Glob("????-??-??T??????.log") const files = await Glob.scan("????-??-??T??????.log", {
const files = await Array.fromAsync(
glob.scan({
cwd: dir, cwd: dir,
absolute: true, absolute: true,
}), include: "file",
) })
if (files.length <= 5) return if (files.length <= 5) return
const filesToDelete = files.slice(0, -10) const filesToDelete = files.slice(0, -10)

View File

@@ -0,0 +1,164 @@
import { describe, test, expect } from "bun:test"
import path from "path"
import fs from "fs/promises"
import { Glob } from "../../src/util/glob"
import { tmpdir } from "../fixture/fixture"
describe("Glob", () => {
describe("scan()", () => {
test("finds files matching pattern", async () => {
await using tmp = await tmpdir()
await fs.writeFile(path.join(tmp.path, "a.txt"), "", "utf-8")
await fs.writeFile(path.join(tmp.path, "b.txt"), "", "utf-8")
await fs.writeFile(path.join(tmp.path, "c.md"), "", "utf-8")
const results = await Glob.scan("*.txt", { cwd: tmp.path })
expect(results.sort()).toEqual(["a.txt", "b.txt"])
})
test("returns absolute paths when absolute option is true", async () => {
await using tmp = await tmpdir()
await fs.writeFile(path.join(tmp.path, "file.txt"), "", "utf-8")
const results = await Glob.scan("*.txt", { cwd: tmp.path, absolute: true })
expect(results[0]).toBe(path.join(tmp.path, "file.txt"))
})
test("excludes directories by default", async () => {
await using tmp = await tmpdir()
await fs.mkdir(path.join(tmp.path, "subdir"))
await fs.writeFile(path.join(tmp.path, "file.txt"), "", "utf-8")
const results = await Glob.scan("*", { cwd: tmp.path })
expect(results).toEqual(["file.txt"])
})
test("excludes directories when include is 'file'", async () => {
await using tmp = await tmpdir()
await fs.mkdir(path.join(tmp.path, "subdir"))
await fs.writeFile(path.join(tmp.path, "file.txt"), "", "utf-8")
const results = await Glob.scan("*", { cwd: tmp.path, include: "file" })
expect(results).toEqual(["file.txt"])
})
test("includes directories when include is 'all'", async () => {
await using tmp = await tmpdir()
await fs.mkdir(path.join(tmp.path, "subdir"))
await fs.writeFile(path.join(tmp.path, "file.txt"), "", "utf-8")
const results = await Glob.scan("*", { cwd: tmp.path, include: "all" })
expect(results.sort()).toEqual(["file.txt", "subdir"])
})
test("handles nested patterns", async () => {
await using tmp = await tmpdir()
await fs.mkdir(path.join(tmp.path, "nested"), { recursive: true })
await fs.writeFile(path.join(tmp.path, "nested", "deep.txt"), "", "utf-8")
const results = await Glob.scan("**/*.txt", { cwd: tmp.path })
expect(results).toEqual(["nested/deep.txt"])
})
test("returns empty array for no matches", async () => {
await using tmp = await tmpdir()
const results = await Glob.scan("*.nonexistent", { cwd: tmp.path })
expect(results).toEqual([])
})
test("does not follow symlinks by default", async () => {
await using tmp = await tmpdir()
await fs.mkdir(path.join(tmp.path, "realdir"))
await fs.writeFile(path.join(tmp.path, "realdir", "file.txt"), "", "utf-8")
await fs.symlink(path.join(tmp.path, "realdir"), path.join(tmp.path, "linkdir"))
const results = await Glob.scan("**/*.txt", { cwd: tmp.path })
expect(results).toEqual(["realdir/file.txt"])
})
test("follows symlinks when symlink option is true", async () => {
await using tmp = await tmpdir()
await fs.mkdir(path.join(tmp.path, "realdir"))
await fs.writeFile(path.join(tmp.path, "realdir", "file.txt"), "", "utf-8")
await fs.symlink(path.join(tmp.path, "realdir"), path.join(tmp.path, "linkdir"))
const results = await Glob.scan("**/*.txt", { cwd: tmp.path, symlink: true })
expect(results.sort()).toEqual(["linkdir/file.txt", "realdir/file.txt"])
})
test("includes dotfiles when dot option is true", async () => {
await using tmp = await tmpdir()
await fs.writeFile(path.join(tmp.path, ".hidden"), "", "utf-8")
await fs.writeFile(path.join(tmp.path, "visible"), "", "utf-8")
const results = await Glob.scan("*", { cwd: tmp.path, dot: true })
expect(results.sort()).toEqual([".hidden", "visible"])
})
test("excludes dotfiles when dot option is false", async () => {
await using tmp = await tmpdir()
await fs.writeFile(path.join(tmp.path, ".hidden"), "", "utf-8")
await fs.writeFile(path.join(tmp.path, "visible"), "", "utf-8")
const results = await Glob.scan("*", { cwd: tmp.path, dot: false })
expect(results).toEqual(["visible"])
})
})
describe("scanSync()", () => {
test("finds files matching pattern synchronously", async () => {
await using tmp = await tmpdir()
await fs.writeFile(path.join(tmp.path, "a.txt"), "", "utf-8")
await fs.writeFile(path.join(tmp.path, "b.txt"), "", "utf-8")
const results = Glob.scanSync("*.txt", { cwd: tmp.path })
expect(results.sort()).toEqual(["a.txt", "b.txt"])
})
test("respects options", async () => {
await using tmp = await tmpdir()
await fs.mkdir(path.join(tmp.path, "subdir"))
await fs.writeFile(path.join(tmp.path, "file.txt"), "", "utf-8")
const results = Glob.scanSync("*", { cwd: tmp.path, include: "all" })
expect(results.sort()).toEqual(["file.txt", "subdir"])
})
})
describe("match()", () => {
test("matches simple patterns", () => {
expect(Glob.match("*.txt", "file.txt")).toBe(true)
expect(Glob.match("*.txt", "file.js")).toBe(false)
})
test("matches directory patterns", () => {
expect(Glob.match("**/*.js", "src/index.js")).toBe(true)
expect(Glob.match("**/*.js", "src/index.ts")).toBe(false)
})
test("matches dot files", () => {
expect(Glob.match(".*", ".gitignore")).toBe(true)
expect(Glob.match("**/*.md", ".github/README.md")).toBe(true)
})
test("matches brace expansion", () => {
expect(Glob.match("*.{js,ts}", "file.js")).toBe(true)
expect(Glob.match("*.{js,ts}", "file.ts")).toBe(true)
expect(Glob.match("*.{js,ts}", "file.py")).toBe(false)
})
})
})