2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-12-21 07:39:51 +00:00
|
|
|
// Copyright the Browserify authors. MIT License.
|
|
|
|
|
2024-04-29 02:57:30 +00:00
|
|
|
import { basename } from "@std/path/basename";
|
|
|
|
import { normalize } from "@std/path/normalize";
|
2023-12-21 07:39:51 +00:00
|
|
|
import { toPathString } from "./_to_path_string.ts";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Walk entry for {@linkcode walk}, {@linkcode walkSync},
|
|
|
|
* {@linkcode expandGlob} and {@linkcode expandGlobSync}.
|
|
|
|
*/
|
|
|
|
export interface WalkEntry extends Deno.DirEntry {
|
|
|
|
/** Full path of the entry. */
|
|
|
|
path: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Create {@linkcode WalkEntry} for the `path` synchronously. */
|
|
|
|
export function createWalkEntrySync(path: string | URL): WalkEntry {
|
|
|
|
path = toPathString(path);
|
|
|
|
path = normalize(path);
|
|
|
|
const name = basename(path);
|
|
|
|
const info = Deno.statSync(path);
|
|
|
|
return {
|
|
|
|
path,
|
|
|
|
name,
|
|
|
|
isFile: info.isFile,
|
|
|
|
isDirectory: info.isDirectory,
|
|
|
|
isSymlink: info.isSymlink,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Create {@linkcode WalkEntry} for the `path` asynchronously. */
|
|
|
|
export async function createWalkEntry(path: string | URL): Promise<WalkEntry> {
|
|
|
|
path = toPathString(path);
|
|
|
|
path = normalize(path);
|
|
|
|
const name = basename(path);
|
|
|
|
const info = await Deno.stat(path);
|
|
|
|
return {
|
|
|
|
path,
|
|
|
|
name,
|
|
|
|
isFile: info.isFile,
|
|
|
|
isDirectory: info.isDirectory,
|
|
|
|
isSymlink: info.isSymlink,
|
|
|
|
};
|
|
|
|
}
|