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;
|
root?: string;
|
||||||
exclude?: string[];
|
exclude?: string[];
|
||||||
includeDirs?: boolean;
|
includeDirs?: boolean;
|
||||||
|
followSymlinks?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface SplitPath {
|
interface SplitPath {
|
||||||
@ -82,6 +83,7 @@ export async function* expandGlob(
|
|||||||
extended = true,
|
extended = true,
|
||||||
globstar = true,
|
globstar = true,
|
||||||
caseInsensitive,
|
caseInsensitive,
|
||||||
|
followSymlinks,
|
||||||
}: ExpandGlobOptions = {},
|
}: ExpandGlobOptions = {},
|
||||||
): AsyncIterableIterator<WalkEntry> {
|
): AsyncIterableIterator<WalkEntry> {
|
||||||
const globOptions: GlobOptions = { extended, globstar, caseInsensitive };
|
const globOptions: GlobOptions = { extended, globstar, caseInsensitive };
|
||||||
@ -135,6 +137,7 @@ export async function* expandGlob(
|
|||||||
return yield* walk(walkInfo.path, {
|
return yield* walk(walkInfo.path, {
|
||||||
skip: excludePatterns,
|
skip: excludePatterns,
|
||||||
maxDepth: globstar ? Infinity : 1,
|
maxDepth: globstar ? Infinity : 1,
|
||||||
|
followSymlinks,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const globPattern = globToRegExp(globSegment, globOptions);
|
const globPattern = globToRegExp(globSegment, globOptions);
|
||||||
@ -142,6 +145,7 @@ export async function* expandGlob(
|
|||||||
const walkEntry of walk(walkInfo.path, {
|
const walkEntry of walk(walkInfo.path, {
|
||||||
maxDepth: 1,
|
maxDepth: 1,
|
||||||
skip: excludePatterns,
|
skip: excludePatterns,
|
||||||
|
followSymlinks,
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
@ -201,6 +205,7 @@ export function* expandGlobSync(
|
|||||||
extended = true,
|
extended = true,
|
||||||
globstar = true,
|
globstar = true,
|
||||||
caseInsensitive,
|
caseInsensitive,
|
||||||
|
followSymlinks,
|
||||||
}: ExpandGlobOptions = {},
|
}: ExpandGlobOptions = {},
|
||||||
): IterableIterator<WalkEntry> {
|
): IterableIterator<WalkEntry> {
|
||||||
const globOptions: GlobOptions = { extended, globstar, caseInsensitive };
|
const globOptions: GlobOptions = { extended, globstar, caseInsensitive };
|
||||||
@ -254,6 +259,7 @@ export function* expandGlobSync(
|
|||||||
return yield* walkSync(walkInfo.path, {
|
return yield* walkSync(walkInfo.path, {
|
||||||
skip: excludePatterns,
|
skip: excludePatterns,
|
||||||
maxDepth: globstar ? Infinity : 1,
|
maxDepth: globstar ? Infinity : 1,
|
||||||
|
followSymlinks,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
const globPattern = globToRegExp(globSegment, globOptions);
|
const globPattern = globToRegExp(globSegment, globOptions);
|
||||||
@ -261,6 +267,7 @@ export function* expandGlobSync(
|
|||||||
const walkEntry of walkSync(walkInfo.path, {
|
const walkEntry of walkSync(walkInfo.path, {
|
||||||
maxDepth: 1,
|
maxDepth: 1,
|
||||||
skip: excludePatterns,
|
skip: excludePatterns,
|
||||||
|
followSymlinks,
|
||||||
})
|
})
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
|
@ -61,7 +61,10 @@ Deno.test("expandGlobWildcard", async function () {
|
|||||||
|
|
||||||
Deno.test("expandGlobTrailingSeparator", async function () {
|
Deno.test("expandGlobTrailingSeparator", async function () {
|
||||||
const options = EG_OPTIONS;
|
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 () {
|
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") };
|
const options = { ...EG_OPTIONS, root: join(EG_OPTIONS.root!, "a[b]c") };
|
||||||
assertEquals(await expandGlobArray("*", options), ["foo"]);
|
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