mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 21:01:52 +00:00
make options argument not required for fs.promises.glob (#20480)
This commit is contained in:
@@ -17,9 +17,9 @@ interface ExtendedGlobOptions extends GlobScanOptions {
|
||||
exclude(ent: string): boolean;
|
||||
}
|
||||
|
||||
async function* glob(pattern: string | string[], options: GlobOptions): AsyncGenerator<string> {
|
||||
async function* glob(pattern: string | string[], options?: GlobOptions): AsyncGenerator<string> {
|
||||
pattern = validatePattern(pattern);
|
||||
const globOptions = mapOptions(options);
|
||||
const globOptions = mapOptions(options || {});
|
||||
let it = new Bun.Glob(pattern).scan(globOptions);
|
||||
const exclude = globOptions.exclude;
|
||||
|
||||
@@ -29,9 +29,9 @@ async function* glob(pattern: string | string[], options: GlobOptions): AsyncGen
|
||||
}
|
||||
}
|
||||
|
||||
function* globSync(pattern: string | string[], options: GlobOptions): Generator<string> {
|
||||
function* globSync(pattern: string | string[], options?: GlobOptions): Generator<string> {
|
||||
pattern = validatePattern(pattern);
|
||||
const globOptions = mapOptions(options);
|
||||
const globOptions = mapOptions(options || {});
|
||||
const g = new Bun.Glob(pattern);
|
||||
const exclude = globOptions.exclude;
|
||||
for (const ent of g.scanSync(globOptions)) {
|
||||
|
||||
@@ -102,6 +102,18 @@ describe("fs.globSync", () => {
|
||||
expect(fs.globSync("a/*", { cwd: tmp, exclude })).toStrictEqual(expected);
|
||||
});
|
||||
|
||||
it("works without providing options", () => {
|
||||
const oldProcessCwd = process.cwd;
|
||||
try {
|
||||
process.cwd = () => tmp;
|
||||
|
||||
const paths = fs.globSync("*.txt");
|
||||
expect(paths).toContain("foo.txt");
|
||||
} finally {
|
||||
process.cwd = oldProcessCwd;
|
||||
}
|
||||
});
|
||||
|
||||
describe("invalid arguments", () => {
|
||||
// TODO: GlobSet
|
||||
it("does not support arrays of patterns yet", () => {
|
||||
@@ -129,4 +141,23 @@ describe("fs.promises.glob", () => {
|
||||
expect(path).toMatch(/\.txt$/);
|
||||
}
|
||||
});
|
||||
|
||||
it("works without providing options", async () => {
|
||||
const oldProcessCwd = process.cwd;
|
||||
try {
|
||||
process.cwd = () => tmp;
|
||||
|
||||
const iter = fs.promises.glob("*.txt");
|
||||
expect(iter[Symbol.asyncIterator]).toBeDefined();
|
||||
|
||||
const paths = [];
|
||||
for await (const path of iter) {
|
||||
paths.push(path);
|
||||
}
|
||||
|
||||
expect(paths).toContain("foo.txt");
|
||||
} finally {
|
||||
process.cwd = oldProcessCwd;
|
||||
}
|
||||
});
|
||||
}); // </fs.promises.glob>
|
||||
|
||||
Reference in New Issue
Block a user