mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
feat(fs): add followSymlink to expandGlob (#3093)
This commit is contained in:
parent
da413bdac8
commit
df73bfc067
@ -22,6 +22,7 @@ export interface ExpandGlobOptions extends Omit<GlobOptions, "os"> {
|
||||
root?: string;
|
||||
exclude?: string[];
|
||||
includeDirs?: boolean;
|
||||
followSymlinks?: boolean;
|
||||
}
|
||||
|
||||
interface SplitPath {
|
||||
@ -82,6 +83,7 @@ export async function* expandGlob(
|
||||
extended = true,
|
||||
globstar = true,
|
||||
caseInsensitive,
|
||||
followSymlinks,
|
||||
}: ExpandGlobOptions = {},
|
||||
): AsyncIterableIterator<WalkEntry> {
|
||||
const globOptions: GlobOptions = { extended, globstar, caseInsensitive };
|
||||
@ -135,6 +137,7 @@ export async function* expandGlob(
|
||||
return yield* walk(walkInfo.path, {
|
||||
skip: excludePatterns,
|
||||
maxDepth: globstar ? Infinity : 1,
|
||||
followSymlinks,
|
||||
});
|
||||
}
|
||||
const globPattern = globToRegExp(globSegment, globOptions);
|
||||
@ -142,6 +145,7 @@ export async function* expandGlob(
|
||||
const walkEntry of walk(walkInfo.path, {
|
||||
maxDepth: 1,
|
||||
skip: excludePatterns,
|
||||
followSymlinks,
|
||||
})
|
||||
) {
|
||||
if (
|
||||
@ -201,6 +205,7 @@ export function* expandGlobSync(
|
||||
extended = true,
|
||||
globstar = true,
|
||||
caseInsensitive,
|
||||
followSymlinks,
|
||||
}: ExpandGlobOptions = {},
|
||||
): IterableIterator<WalkEntry> {
|
||||
const globOptions: GlobOptions = { extended, globstar, caseInsensitive };
|
||||
@ -254,6 +259,7 @@ export function* expandGlobSync(
|
||||
return yield* walkSync(walkInfo.path, {
|
||||
skip: excludePatterns,
|
||||
maxDepth: globstar ? Infinity : 1,
|
||||
followSymlinks,
|
||||
});
|
||||
}
|
||||
const globPattern = globToRegExp(globSegment, globOptions);
|
||||
@ -261,6 +267,7 @@ export function* expandGlobSync(
|
||||
const walkEntry of walkSync(walkInfo.path, {
|
||||
maxDepth: 1,
|
||||
skip: excludePatterns,
|
||||
followSymlinks,
|
||||
})
|
||||
) {
|
||||
if (
|
||||
|
@ -61,7 +61,10 @@ Deno.test("expandGlobWildcard", async function () {
|
||||
|
||||
Deno.test("expandGlobTrailingSeparator", async function () {
|
||||
const options = EG_OPTIONS;
|
||||
assertEquals(await expandGlobArray("*/", options), ["a[b]c", "subdir"]);
|
||||
assertEquals(await expandGlobArray("*/", options), [
|
||||
"a[b]c",
|
||||
"subdir",
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test("expandGlobParent", async function () {
|
||||
@ -145,3 +148,12 @@ Deno.test("expandGlobRootIsNotGlob", async function () {
|
||||
const options = { ...EG_OPTIONS, root: join(EG_OPTIONS.root!, "a[b]c") };
|
||||
assertEquals(await expandGlobArray("*", options), ["foo"]);
|
||||
});
|
||||
|
||||
Deno.test("expandGlobFollowSymlink", async function () {
|
||||
const options = {
|
||||
...EG_OPTIONS,
|
||||
root: join(EG_OPTIONS.root!, "link"),
|
||||
followSymlinks: true,
|
||||
};
|
||||
assertEquals(await expandGlobArray("*", options), ["abc"]);
|
||||
});
|
||||
|
1
fs/testdata/glob/link
vendored
Symbolic link
1
fs/testdata/glob/link
vendored
Symbolic link
@ -0,0 +1 @@
|
||||
./subdir
|
Loading…
Reference in New Issue
Block a user