File System
File System
The File System utilities offer a way to organize and query file-system data in renoun. It is a powerful tool that allows you to define a schema for file exports and query those exports using a simple API.
To get started with the File System API, instantiate the Directory class to target a set of files and directories from the file system. You can then use the getEntry / getDirectory / getFile methods to query a specific descendant file or directory:
import { Directory } from 'renoun'
const posts = new Directory({
path: 'posts',
loader: {
mdx: (path) => import(`./posts/${path}.mdx`),
},
})
Here we are creating a new Directory instance that targets the posts directory relative to the working directory. We are also specifying a loader for the mdx file extension that will be used to load the file contents using the bundler.
Referencing protocol paths
The Directory and File constructors accept protocol-prefixed paths that resolve using internal resolvers before the adapters interact with the file system. The only supported protocol currently is workspace:, which resolves paths relative to the workspace root instead of the current working directory.
This is helpful when using renoun from a nested package (for example apps/site) but you need to reference files located in another workspace folder (like examples):
import { Directory } from 'renoun'
const examples = new Directory({
path: 'workspace:examples',
})
If the current working directory is apps/site, the example above resolves to ../../examples internally while remaining ./examples when run from the workspace root.
Querying file system entries
import { Directory } from 'renoun'
const posts = new Directory({
path: 'posts',
loader: {
mdx: (path) => import(`./posts/${path}.mdx`),
},
})
export default async function Page({ slug }: { slug: string }) {
const post = await posts.getFile(slug, 'mdx')
const Content = await post.getExportValue('default')
return <Content />
}
You can query the entries within the directory to help with generating navigations and index pages. For example, we can filter to only mdx file extensions to generate an index page of links to all posts using the getEntries method:
import { Directory, withSchema } from 'renoun'
interface PostType {
frontmatter: {
title: string
date: Date
}
}
const posts = new Directory({
path: 'posts',
filter: '*.mdx',
loader: {
mdx: withSchema<PostType>((path) => import(`./posts/${path}.mdx`)),
},
})
export default async function Page() {
const allPosts = await posts.getEntries()
return (
<>
<h1>Blog</h1>
<ul>
{allPosts.map(async (post) => {
const pathname = post.getPathname()
const frontmatter = await post.getExportValue('frontmatter')
return (
<li key={pathname}>
<a href={pathname}>{frontmatter.title}</a>
</li>
)
})}
</ul>
</>
)
}
Type checking file exports
To improve type safety, you can utilize the withSchema helper to specify the schema for the file’s exports:
import { Directory, withSchema } from 'renoun'
interface PostType {
frontmatter: {
title: string
date: Date
}
}
const posts = new Directory({
path: 'posts',
loader: {
mdx: withSchema<PostType>((path) => import(`./posts/${path}.mdx`)),
},
})
Now when we call JavaScript#getExportValue and JavaScriptExport#getRuntimeValue we will have stronger type checking and autocomplete.
Working with globbed module maps
When using bundler utilities like import.meta.glob, you can return a loader map from the loader option to reuse the globbed modules:
import { Directory, withSchema } from 'renoun'
interface PostType {
frontmatter: {
title: string
date: Date
}
}
const posts = new Directory({
path: 'posts',
loader: () => {
const mdxModules = import.meta.glob('./posts/**/*.mdx')
Property 'glob' does not exist on type 'ImportMeta'. (2339) return {
mdx: withSchema<PostType>((path) => mdxModules[`./posts/${path}.mdx`]),
}
},
})
The loader factory executes once and returns the extension-to-loader map, so the globbed modules are reused across all files in the directory. If the glob returns loader functions themselves, they will automatically be called and awaited for you.
Schema Validation
You can also apply schema validation using libraries that follow the Standard Schema Spec like Zod, Valibot, or Arktype to ensure file exports conform to a specific schema:
import { Directory, withSchema } from 'renoun'
import { z } from 'zod'
const posts = new Directory({
path: 'posts',
loader: {
mdx: withSchema(
{
frontmatter: z.object({
title: z.string(),
date: z.date(),
}),
},
(path) => import(`./posts/${path}.mdx`)
),
},
})
Alternatively, you can define a schema yourself using both TypeScript types and custom validation functions:
import { Directory, withSchema } from 'renoun'
interface PostType {
frontmatter: {
title: string
date: Date
}
}
const posts = new Directory({
path: 'posts',
loader: {
mdx: withSchema<PostType>(
{
frontmatter: (value) => {
if (typeof value.title !== 'string') {
throw new Error('Title is required')
}
if (!(value.date instanceof Date)) {
throw new Error('Date is required')
}
return value
},
},
(path) => import(`./posts/${path}.mdx`)
),
},
})
The file system utilities are not limited to MDX files and can be used with any file type. By organizing content and source code into structured collections, you can easily generate static pages and manage complex routing and navigations.
API Reference
Constructor
(options: FileSystemOptions = {}) => FileSystem| Parameter | Type | Default Value |
|---|---|---|
| options | FileSystemOptions | {} |
Methods
| Method | Type | Modifiers | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getProjectOptions | () => ProjectOptions | abstract | |||||||||||||||
ReturnsProjectOptions | |||||||||||||||||
| getAbsolutePath | (path: string) => string | abstract | |||||||||||||||
Parameters
Returnsstring | |||||||||||||||||
| getRelativePathToWorkspace | (path: string) => string | abstract | |||||||||||||||
Parameters
Returnsstring | |||||||||||||||||
| getPathname | (path: string, options: { basePath?: string; rootPath?: string } = {}) => string | — | |||||||||||||||
Parameters
Returnsstring | |||||||||||||||||
| readDirectorySync | (path?: string) => Array<DirectoryEntry> | abstract | |||||||||||||||
Parameters
ReturnsArray<DirectoryEntry> | |||||||||||||||||
| readDirectory | (path?: string) => Promise<Array<DirectoryEntry>> | abstract | |||||||||||||||
Parameters
ReturnsPromise<Array<DirectoryEntry>>Modifiersasync | |||||||||||||||||
| readFileSync | (path: string) => string | abstract | |||||||||||||||
Parameters
Returnsstring | |||||||||||||||||
| readFile | (path: string) => Promise<string> | abstract | |||||||||||||||
Parameters
ReturnsPromise<string>Modifiersasync | |||||||||||||||||
| readFileBinarySync | (path: string) => Uint8Array<ArrayBufferLike> | abstract | |||||||||||||||
Parameters
ReturnsUint8Array<ArrayBufferLike> | |||||||||||||||||
| readFileBinary | (path: string) => Promise<Uint8Array<ArrayBufferLike>> | abstract | |||||||||||||||
Parameters
ReturnsPromise<Uint8Array<ArrayBufferLike>>Modifiersasync | |||||||||||||||||
| readFileStream | (path: string) => FileReadableStream | abstract | |||||||||||||||
Parameters
ReturnsFileReadableStream | |||||||||||||||||
| writeFileSync | (path: string, content: FileSystemWriteFileContent) => void | abstract | |||||||||||||||
Parameters
Returnsvoid | |||||||||||||||||
| writeFile | (path: string, content: FileSystemWriteFileContent) => Promise<void> | abstract | |||||||||||||||
Parameters
ReturnsPromise<void>Modifiersasync | |||||||||||||||||
| writeFileStream | (path: string) => FileWritableStream | abstract | |||||||||||||||
Parameters
ReturnsFileWritableStream | |||||||||||||||||
| fileExistsSync | (path: string) => boolean | abstract | |||||||||||||||
Check synchronously if a file exists at the given path. Parameters
Returnsboolean | |||||||||||||||||
| fileExists | (path: string) => Promise<boolean> | — | |||||||||||||||
Parameters
ReturnsPromise<boolean>Modifiersasync | |||||||||||||||||
| deleteFileSync | (path: string) => void | abstract | |||||||||||||||
Parameters
Returnsvoid | |||||||||||||||||
| deleteFile | (path: string) => Promise<void> | abstract | |||||||||||||||
Parameters
ReturnsPromise<void>Modifiersasync | |||||||||||||||||
| isFilePathExcludedFromTsConfig | (filePath: string, isDirectory = false) => boolean | — | |||||||||||||||
Parameters
Returnsboolean | |||||||||||||||||
| isFilePathGitIgnored | (filePath: string) => boolean | abstract | |||||||||||||||
Parameters
Returnsboolean | |||||||||||||||||
| getFileExports | (filePath: string) => Promise<Array<ModuleExport>> | — | |||||||||||||||
Parameters
ReturnsPromise<Array<ModuleExport>>Modifiersasync | |||||||||||||||||
| getFileExportMetadata | (name: string, filePath: string, position: number, kind: SyntaxKind) => Promise<{ name: string; environment: string; jsDocMetadata: { description?: string | undefined; tags?: Array<{ name: string; text?: string | undefined; }> | undefined; } | undefined; location: DeclarationLocation; }> | — | |||||||||||||||
Parameters
ReturnsPromise<{ name: string; environment: string; jsDocMetadata: { description?: string | undefined; tags?: Array<{ name: string; text?: string | undefined; }> | undefined; } | undefined; location: DeclarationLocation; }>Modifiersasync | |||||||||||||||||
| getFileExportText | (filePath: string, position: number, kind: SyntaxKind, includeDependencies?: boolean) => Promise<string> | — | |||||||||||||||
Parameters
ReturnsPromise<string>Modifiersasync | |||||||||||||||||
| getFileExportStaticValue | (filePath: string, position: number, kind: SyntaxKind) => Promise<unknown> | — | |||||||||||||||
Parameters
ReturnsPromise<unknown>Modifiersasync | |||||||||||||||||
| resolveTypeAtLocation | (filePath: string, position: number, kind: SyntaxKind, filter?: TypeFilter) => Promise<Kind | undefined> | — | |||||||||||||||
Parameters
ReturnsPromise<Kind | undefined>Modifiersasync | |||||||||||||||||
Constructor
(options: GitHostFileSystemOptions) => GitHostFileSystem| Parameter | Type | Default Value |
|---|---|---|
| options | options: GitHostFileSystemOptions | — |
Methods
| Method | Type | Modifiers | ||||||
|---|---|---|---|---|---|---|---|---|
| clearCache | () => void | — | ||||||
Returnsvoid | ||||||||
| readDirectory | (path: string = '.') => Promise<Array<DirectoryEntry>> | — | ||||||
Parameters
ReturnsPromise<Array<DirectoryEntry>>Modifiersasync | ||||||||
| readDirectorySync | () => Array<DirectoryEntry> | — | ||||||
ReturnsArray<DirectoryEntry> | ||||||||
| readFile | (path: string) => Promise<string> | — | ||||||
Parameters
ReturnsPromise<string>Modifiersasync | ||||||||
| readFileBinary | (path: string) => Promise<Uint8Array<ArrayBufferLike>> | — | ||||||
Parameters
ReturnsPromise<Uint8Array<ArrayBufferLike>>Modifiersasync | ||||||||
| readFileSync | () => string | — | ||||||
Returnsstring | ||||||||
| isFilePathGitIgnored | () => boolean | — | ||||||
Returnsboolean | ||||||||
| isFilePathExcludedFromTsConfig | () => boolean | — | ||||||
Returnsboolean | ||||||||
Extends
MemoryFileSystemUtility type that infers the schema output from validator functions or a Standard Schema.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Exports | — | — |
Type
InferModuleExports<Exports>Overload 1
function withSchema<Types extends ModuleExports<any>>(): ModuleLoaderWithSchema<Types, false>Provides type inference for the module loader.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | ModuleExports<any> | — |
Returns
ModuleLoaderWithSchema<Types, false>Overload 2
function withSchema<Types extends ModuleExports<any>>(runtime: ModuleRuntimeLoader<NoInfer<Types>>): ModuleLoaderWithSchema<Types, true>A function that resolves the module runtime.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | ModuleExports<any> | — |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| runtime | runtime: ModuleRuntimeLoader<NoInfer<Types>> | — |
Returns
ModuleLoaderWithSchema<Types, true>Overload 3
function withSchema<Types extends ModuleExports<any>, Schema extends ModuleExports<any>>(schema: IsNever<Types> extends true
? Schema
: Partial<ModuleExportValidators<NoInfer<Types>>>, runtime: ModuleRuntimeLoader<
IsNever<Types> extends true ? NoInfer<Schema> : NoInfer<Types>
>): ModuleLoaderWithSchema<IsNever<Types> extends true ? Schema : ModuleExportValidators<NoInfer<Types>>, false>A schema that follows the Standard Schema Spec like Zod, Valibot, and Arktype or custom validation functions to ensure file exports conform to a specific schema.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | ModuleExports<any> | never |
Schema | ModuleExports<any> | ModuleExports<any> |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| schema | schema: IsNever<Types> extends true
? Schema
: Partial<ModuleExportValidators<NoInfer<Types>>> | — |
| runtime | runtime: ModuleRuntimeLoader<
IsNever<Types> extends true ? NoInfer<Schema> : NoInfer<Types>
> | — |
Returns
ModuleLoaderWithSchema<IsNever<Types> extends true ? Schema : ModuleExportValidators<NoInfer<Types>>, false>Default module types for common file extensions.
Properties
| Property | Type | |
|---|---|---|
| md | { default: MDXContent; } | |
| mdx | { default: MDXContent; } | |
| json | JSONObject | |
Infer extension types for all loaders in a module.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Loaders | ModuleLoaders | — |
Index Signatures
| Key | Type | |
|---|---|---|
key: string | InferModuleLoaderTypes<Loaders[string]> | |
Extract keys from runtime‑capable loaders.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Loaders | — | — |
Type
LoadersWithRuntimeKeys<Loaders>Error for when a file is not found.
Constructor
(path: string | string[], extension?: any, context?: {
/** Directory path (relative to workspace) where the lookup started. */
directoryPath?: string
/** Absolute directory path (useful in server builds). */
absoluteDirectoryPath?: string
/** Root path used by the Directory (relative to workspace). */
rootPath?: string
/** Nearby entries at the point of failure (base names only). */
nearestCandidates?: string[]
}) => FileNotFoundError| Parameter | Type | Default Value |
|---|---|---|
| path | path: string | string[] | — |
| extension? | extension?: any | — |
| context? | context?: {
/** Directory path (relative to workspace) where the lookup started. */
directoryPath?: string
/** Absolute directory path (useful in server builds). */
absoluteDirectoryPath?: string
/** Root path used by the Directory (relative to workspace). */
rootPath?: string
/** Nearby entries at the point of failure (base names only). */
nearestCandidates?: string[]
} | — |
Extends
ErrorA directory or file entry.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
DirectoryTypes | Record<string, any> | any |
Extension | — | undefined |
Type
Directory<DirectoryTypes, WithDefaultTypes<DirectoryTypes>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<DirectoryTypes>, undefined>, WithDefaultTypes<DirectoryTypes>>> | FileWithExtension<DirectoryTypes, Extension>Options for the File#getPathname and File#getPathnameSegments methods.
Properties
| Property | Type | |
|---|---|---|
| includeBasePathname? | boolean | |
| includeDirectoryNamedSegment? | boolean | |
Options for a file in the file system.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | Record<string, any> | Record<string, any> |
Path | string | string |
Properties
| Property | Type | |
|---|---|---|
| path | Path | |
| basePathname? | string | null | |
| slugCasing? | SlugCasing | |
| depth? | number | |
| directory? | Directory<Types, WithDefaultTypes<Types>, ModuleLoaders, DirectoryFilter<FileSystemEntry<Types, undefined>, Types>> | |
A file in the file system.
Constructor
<DirectoryTypes extends Record<string, any>, Path extends string, Extension extends string>(options: FileOptions<DirectoryTypes, Path>) => File<DirectoryTypes, Path, Extension>| Parameter | Type | Default Value |
|---|---|---|
| options | FileOptions<DirectoryTypes, Path> | — |
Methods
| Method | Type | Modifiers | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getName | () => string | — | ||||||||||||
The intrinsic name of the file. Returnsstring | ||||||||||||||
| getBaseName | () => string | — | ||||||||||||
The base name of the file e.g. Returnsstring | ||||||||||||||
| getModifierName | () => string | undefined | — | ||||||||||||
The modifier name of the file if defined e.g. Returnsstring | undefined | ||||||||||||||
| getTitle | () => string | — | ||||||||||||
The base file name formatted as a title. Returnsstring | ||||||||||||||
| getOrder | () => string | undefined | — | ||||||||||||
The order of the file if defined. Returnsstring | undefined | ||||||||||||||
| getExtension | () => Extension | — | ||||||||||||
The extension of the file if defined. ReturnsExtension | ||||||||||||||
| getDepth | () => number | — | ||||||||||||
Get the depth of the file starting from the root directory. Returnsnumber | ||||||||||||||
| getSlug | () => string | — | ||||||||||||
Get the slug of the file. Returnsstring | ||||||||||||||
| getPathname | (options?: FilePathnameOptions) => string | — | ||||||||||||
Get the path of this file formatted for routes. The configured Parameters
Returnsstring | ||||||||||||||
| getPathnameSegments | (options?: FilePathnameOptions) => Array<string> | — | ||||||||||||
Get the route path segments for this file. Parameters
ReturnsArray<string> | ||||||||||||||
| getRelativePathToRoot | () => string | — | ||||||||||||
Get the file path relative to the root directory. Returnsstring | ||||||||||||||
| getRelativePathToWorkspace | () => string | — | ||||||||||||
Get the file path relative to the workspace root. Returnsstring | ||||||||||||||
| getAbsolutePath | () => string | — | ||||||||||||
Get the absolute file system path. Returnsstring | ||||||||||||||
| getBlameUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | ||||||||||||
Get the URL to the file git blame for the configured git repository. Parameters
Returnsstring | ||||||||||||||
| getEditUrl | (options?: Pick<GetFileUrlOptions, 'ref' | 'line'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | ||||||||||||
Get the edit URL to the file source for the configured git repository. Parameters
Returnsstring | ||||||||||||||
| getHistoryUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | ||||||||||||
Get the URL to the file history for the configured git repository. Parameters
Returnsstring | ||||||||||||||
| getRawUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | ||||||||||||
Get the URL to the raw file contents for the configured git repository. Parameters
Returnsstring | ||||||||||||||
| getSourceUrl | (options?: Pick<GetFileUrlOptions, 'ref' | 'line'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | ||||||||||||
Get the URL to the file source for the configured git repository. Parameters
Returnsstring | ||||||||||||||
| getEditorUri | (options?: Omit<GetEditorUriOptions, 'path'>) => string | — | ||||||||||||
Get the URI to the file source code for the configured editor. Parameters
Returnsstring | ||||||||||||||
| getFirstCommitDate | () => Promise<Date | undefined> | — | ||||||||||||
Get the first local git commit date of the file. ReturnsPromise<Date | undefined>Modifiersasync | ||||||||||||||
| getLastCommitDate | () => Promise<Date | undefined> | — | ||||||||||||
Get the last local git commit date of the file. ReturnsPromise<Date | undefined>Modifiersasync | ||||||||||||||
| getAuthors | () => Promise<Array<GitAuthor>> | — | ||||||||||||
Get the local git authors of the file. ReturnsPromise<Array<GitAuthor>>Modifiersasync | ||||||||||||||
| getParent | () => Directory<DirectoryTypes, WithDefaultTypes<DirectoryTypes>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<DirectoryTypes>, undefined>, WithDefaultTypes<DirectoryTypes>>> | — | ||||||||||||
Get the parent directory containing this file. ReturnsDirectory<DirectoryTypes, WithDefaultTypes<DirectoryTypes>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<DirectoryTypes>, undefined>, WithDefaultTypes<DirectoryTypes>>> | ||||||||||||||
| getSiblings | <GroupTypes extends Record<string, any>>(options?: {
collection?: Collection<GroupTypes, FileSystemEntry<any>[]>
includeDirectoryNamedSegment?: boolean
}) => Promise<[FileSystemEntry<DirectoryTypes, undefined> | undefined, FileSystemEntry<DirectoryTypes, undefined> | undefined]> | — | ||||||||||||
Get the previous and next sibling entries (files or directories) of the parent directory. If the file is an index or readme file, the siblings will be retrieved from the parent directory. Type Parameters
Parameters
ReturnsPromise<[FileSystemEntry<DirectoryTypes, undefined> | undefined, FileSystemEntry<DirectoryTypes, undefined> | undefined]>Modifiersasync | ||||||||||||||
| getText | () => Promise<string> | — | ||||||||||||
Get the source text of this file. ReturnsPromise<string>Modifiersasync | ||||||||||||||
| getBinary | () => Promise<Uint8Array<ArrayBufferLike>> | — | ||||||||||||
Get the binary contents of this file. ReturnsPromise<Uint8Array<ArrayBufferLike>>Modifiersasync | ||||||||||||||
| getArrayBuffer | () => Promise<ArrayBuffer> | — | ||||||||||||
Get the contents of this file as an ArrayBuffer. ReturnsPromise<ArrayBuffer>Modifiersasync | ||||||||||||||
| getStream | () => FileReadableStream | — | ||||||||||||
Get a readable stream for this file. ReturnsFileReadableStream | ||||||||||||||
| write | (content: FileSystemWriteFileContent) => Promise<void> | — | ||||||||||||
Write content to this file. Parameters
ReturnsPromise<void>Modifiersasync | ||||||||||||||
| writeStream | () => FileWritableStream | — | ||||||||||||
Create a writable stream for this file. ReturnsFileWritableStream | ||||||||||||||
| delete | () => Promise<void> | — | ||||||||||||
Delete this file from the file system. ReturnsPromise<void>Modifiersasync | ||||||||||||||
| exists | () => Promise<boolean> | — | ||||||||||||
Check if this file exists in the file system. ReturnsPromise<boolean>Modifiersasync | ||||||||||||||
Type
string | number | boolean | nullType
JSONPrimitive | Array<JSONValue> | JSONObjectIndex Signatures
| Key | Type | |
|---|---|---|
Key: string | JSONValue | |
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Data | Record<string, any> | JSONObject |
DirectoryTypes | Record<string, any> | Record<string, any> |
Path | string | string |
Properties
| Property | Type | |
|---|---|---|
| schema? | StandardSchemaV1<Data, Data> | (value: unknown) => Data | |
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Data | — | — |
Path | string | — |
Type
JSONPathValue<Data, Path>A JSON file in the file system.
Constructor
<Data extends Record<string, any>, DirectoryTypes extends Record<string, any>, Path extends string, Extension extends string>(fileOptions: JSONFileOptions<Data, DirectoryTypes, Path>) => JSONFile<Data, DirectoryTypes, Path, Extension>| Parameter | Type | Default Value |
|---|---|---|
| fileOptions | JSONFileOptions<Data, DirectoryTypes, Path> | — |
Methods
| Method | Type | Modifiers | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| get | () => Promise<Data> (+1 overload) | — | ||||||||||||
Overload 1() => Promise<Data>Get a value from the JSON data using dot notation. Returns ReturnsPromise<Data>ModifiersasyncOverload 2<Path extends JSONPropertyPath<Data>>(path: Path) => Promise<JSONPathValueWithSegments<Data, JSONPathSegments<Path>>>Type Parameters
Parameters
ReturnsPromise<JSONPathValueWithSegments<Data, JSONPathSegments<Path>>>Modifiersasync | ||||||||||||||
Extends
File<DirectoryTypes, Path, Extension>Error for when a module export cannot be found.
Constructor
(path: string, name: string, className: string) => ModuleExportNotFoundError| Parameter | Type | Default Value |
|---|---|---|
| path | path: string | — |
| name | name: string | — |
| className | className: string | — |
Extends
ErrorA JavaScript file export.
Constructor
<Value>(name: string, file: JavaScriptFile<any>, loader?: ModuleLoader<any>, slugCasing?: SlugCasing) => JavaScriptModuleExport<Value>| Parameter | Type | Default Value |
|---|---|---|
| name | name: string | — |
| file | JavaScriptFile<any, Record<string, any>, string, string> | — |
| loader? | ModuleLoader<any> | undefined | — |
| slugCasing? | SlugCasing | undefined | — |
Methods
| Method | Type | Modifiers | |||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| init | <Value>(name: string, file: JavaScriptFile<any>, loader?: ModuleLoader<any>, slugCasing?: SlugCasing) => Promise<JavaScriptModuleExport<Value>> | static | |||||||||||||||||||||
Type Parameters
Parameters
ReturnsPromise<JavaScriptModuleExport<Value>>Modifiersasync | |||||||||||||||||||||||
| getStaticMetadata | () => Promise<{ name: string; environment: string; jsDocMetadata: { description?: string | undefined; tags?: Array<{ name: string; text?: string | undefined; }> | undefined; } | undefined; location: DeclarationLocation; } | undefined> | protected | |||||||||||||||||||||
ReturnsPromise<{ name: string; environment: string; jsDocMetadata: { description?: string | undefined; tags?: Array<{ name: string; text?: string | undefined; }> | undefined; } | undefined; location: DeclarationLocation; } | undefined>Modifiersasync | |||||||||||||||||||||||
| getSlug | () => string | — | |||||||||||||||||||||
Get the slug of the file export. Returnsstring | |||||||||||||||||||||||
| getName | () => string | — | |||||||||||||||||||||
Get the name of the export. Default exports will use the file name or declaration name if available. Returnsstring | |||||||||||||||||||||||
| getTitle | () => string | — | |||||||||||||||||||||
The export name formatted as a title. Returnsstring | |||||||||||||||||||||||
| getDescription | () => undefined | string | — | |||||||||||||||||||||
Get the JS Doc description of the export. Returnsundefined | string | |||||||||||||||||||||||
| getTags | () => undefined | Array<{ name: string; text?: string | undefined; }> | — | |||||||||||||||||||||
Get the JS Doc tags of the export. Returnsundefined | Array<{ name: string; text?: string | undefined; }> | |||||||||||||||||||||||
| getEnvironment | () => undefined | string | — | |||||||||||||||||||||
Get the environment of the export. Returnsundefined | string | |||||||||||||||||||||||
| getText | ({
includeDependencies,
}: { includeDependencies?: boolean } = {}) => Promise<string> | — | |||||||||||||||||||||
Get the source text of the export, optionally including dependencies. Note, including dependencies can be expensive to calculate, only use when necessary. Parameters
ReturnsPromise<string>Modifiersasync | |||||||||||||||||||||||
| getPosition | () => undefined | DeclarationPosition | — | |||||||||||||||||||||
Get the start and end position of the export in the file system. Returnsundefined | DeclarationPosition | |||||||||||||||||||||||
| getEditUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | |||||||||||||||||||||
Get the edit URL to the file export source for the configured git repository. Parameters
Returnsstring | |||||||||||||||||||||||
| getSourceUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | |||||||||||||||||||||
Get the URL to the file export source for the configured git repository. Parameters
Returnsstring | |||||||||||||||||||||||
| getEditorUri | (options?: Omit<GetEditorUriOptions, 'path'>) => string | — | |||||||||||||||||||||
Get the URI to the file export source code for the configured editor. Parameters
Returnsstring | |||||||||||||||||||||||
| getType | (filter?: TypeFilter) => Promise<Kind | undefined> | — | |||||||||||||||||||||
Get the resolved type of the export. Parameters
ReturnsPromise<Kind | undefined>Modifiersasync | |||||||||||||||||||||||
| getStaticValue | () => Promise<Value> | — | |||||||||||||||||||||
Attempt to return a literal value for this export if it can be determined statically. ReturnsPromise<Value>Modifiersasync | |||||||||||||||||||||||
| getRuntimeValue | () => Promise<Value> | — | |||||||||||||||||||||
Get the runtime value of the export. An error will be thrown if the export is not found or the configured schema validation for this file extension fails. ReturnsPromise<Value>Modifiersasync | |||||||||||||||||||||||
| getValue | () => Promise<Value> | — | |||||||||||||||||||||
Get the value of this export, preferring a static value and falling back to runtime if available. ReturnsPromise<Value>Modifiersasync | |||||||||||||||||||||||
Options for a JavaScript file in the file system.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | Record<string, any> | — |
DirectoryTypes | Record<string, any> | — |
Path | string | — |
Properties
| Property | Type | |
|---|---|---|
| loader? | ModuleLoader<Types> | |
A JavaScript file in the file system.
Constructor
<Types extends InferDefaultModuleTypes<Path>, DirectoryTypes extends Record<string, any>, Path extends string, Extension extends string>({
loader,
...fileOptions
}: JavaScriptFileOptions<Types, DirectoryTypes, Path>) => JavaScriptFile<Types, DirectoryTypes, Path, Extension>| Parameter | Type | Default Value |
|---|---|---|
| { loader, ...fileOptions } | JavaScriptFileOptions<Types, DirectoryTypes, Path> | — |
Methods
| Method | Type | Modifiers | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| parseExportValue | (name: string, value: any) => any | — | |||||||||||||||||||||||||||
Parse and validate an export value using the configured schema if available. Parameters
Returnsany | |||||||||||||||||||||||||||||
| getExports | () => Promise<Array<JavaScriptModuleExport<Types[Extract<keyof Types, string>]>>> | — | |||||||||||||||||||||||||||
Get all exports from the JavaScript file. ReturnsPromise<Array<JavaScriptModuleExport<Types[Extract<keyof Types, string>]>>>Modifiersasync | |||||||||||||||||||||||||||||
| getExport | <ExportName extends Extract<keyof Types, string>>(name: ExportName) => Promise<JavaScriptModuleExport<Types[ExportName]>> | — | |||||||||||||||||||||||||||
Get a JavaScript file export by name. Type Parameters
Parameters
ReturnsPromise<JavaScriptModuleExport<Types[ExportName]>>Modifiersasync | |||||||||||||||||||||||||||||
| getNamedExport | <ExportName extends Extract<keyof Types, string>>(name: ExportName) => Promise<JavaScriptModuleExport<Types[ExportName]>> | — | |||||||||||||||||||||||||||
Get a named export from the JavaScript file. Type Parameters
Parameters
ReturnsPromise<JavaScriptModuleExport<Types[ExportName]>>Modifiersasync | |||||||||||||||||||||||||||||
| getDefaultExport | () => Promise<JavaScriptModuleExport<Types extends { default: infer DefaultType; } ? DefaultType : never>> | — | |||||||||||||||||||||||||||
Get the default export from the JavaScript file. This TypeTypes extends { default: infer _DefaultType; } ? JavaScriptFile<Types, DirectoryTypes, Path, Extension> : neverReturnsPromise<JavaScriptModuleExport<Types extends { default: infer DefaultType; } ? DefaultType : never>>Modifiersasync | |||||||||||||||||||||||||||||
| getExportLocation | (name: string) => Promise<ModuleExport | undefined> | — | |||||||||||||||||||||||||||
Get the start position of an export in the JavaScript file. Parameters
ReturnsPromise<ModuleExport | undefined>Modifiersasync | |||||||||||||||||||||||||||||
| getExportValue | <ExportName extends Extract<keyof Types, string>>(name: ExportName) => Promise<Types[ExportName]> (+1 overload) | — | |||||||||||||||||||||||||||
Overload 1<ExportName extends Extract<keyof Types, string>>(name: ExportName) => Promise<Types[ExportName]>Get the runtime value of an export in the JavaScript file. Type Parameters
Parameters
ReturnsPromise<Types[ExportName]>ModifiersasyncOverload 2<Value, ExportName extends string>(name: ExportName) => Promise<Value>Type Parameters
Parameters
ReturnsPromise<Value>Modifiersasync | |||||||||||||||||||||||||||||
| getHeadings | () => Promise<Headings> | — | |||||||||||||||||||||||||||
Get headings derived from the file exports. ReturnsPromise<Headings>Modifiersasync | |||||||||||||||||||||||||||||
| hasExport | (name: string) => Promise<boolean> | — | |||||||||||||||||||||||||||
Check if an export exists in the JavaScript file statically or at runtime. Parameters
ReturnsPromise<boolean>Modifiersasync | |||||||||||||||||||||||||||||
Extends
File<DirectoryTypes, Path, Extension>An MDX file export.
Constructor
<Value>(name: string, file: MDXFile<any>, loader?: ModuleLoader<any>, slugCasing?: SlugCasing) => MDXModuleExport<Value>| Parameter | Type | Default Value |
|---|---|---|
| name | name: string | — |
| file | MDXFile<any, Record<string, any>, string, string> | — |
| loader? | ModuleLoader<any> | undefined | — |
| slugCasing? | SlugCasing | undefined | — |
Methods
| Method | Type | Modifiers | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| getName | () => string | — | |||||||||
Returnsstring | |||||||||||
| getTitle | () => string | — | |||||||||
Returnsstring | |||||||||||
| getSlug | () => string | — | |||||||||
Returnsstring | |||||||||||
| getEditorUri | (options?: Omit<GetEditorUriOptions, 'path'>) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| getEditUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| getSourceUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| parseExportValue | (name: string, value: any) => any | — | |||||||||
Parse and validate an export value using the configured schema if available. Parameters
Returnsany | |||||||||||
| getStaticValue | () => Promise<Value> | — | |||||||||
Attempt to return a literal value for this export if it can be determined statically. ReturnsPromise<Value>Modifiersasync | |||||||||||
| getRuntimeValue | () => Promise<Value> | — | |||||||||
Get the runtime value of the export. An error will be thrown if the export is not found or the configured schema validation for the MDX file fails. ReturnsPromise<Value>Modifiersasync | |||||||||||
| getValue | () => Promise<Value> | — | |||||||||
Get the value of this export, preferring a static value and falling back to runtime if available. ReturnsPromise<Value>Modifiersasync | |||||||||||
Options for an MDX file in the file system.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | Record<string, any> | — |
DirectoryTypes | Record<string, any> | — |
Path | string | — |
Properties
| Property | Type | |
|---|---|---|
| loader? | ModuleLoader<{ default: MDXContent; } & Types> | |
An MDX file in the file system.
Constructor
<Types extends Record<string, any>, DirectoryTypes extends Record<string, any>, Path extends string, Extension extends string>({
loader,
...fileOptions
}: MDXFileOptions<{ default: MDXContent } & Types, DirectoryTypes, Path>) => MDXFile<Types, DirectoryTypes, Path, Extension>| Parameter | Type | Default Value |
|---|---|---|
| { loader, ...fileOptions } | MDXFileOptions<{ default: MDXContent; } & Types, DirectoryTypes, Path> | — |
Methods
| Method | Type | Modifiers | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getExports | () => Promise<Array<MDXModuleExport<any>>> | — | |||||||||||||||||||||||||||
ReturnsPromise<Array<MDXModuleExport<any>>>Modifiersasync | |||||||||||||||||||||||||||||
| getExport | <ExportName extends "default" | Extract<keyof Types, string>>(name: ExportName) => Promise<MDXModuleExport<({ default: MDXContent; } & Types)[ExportName]>> | — | |||||||||||||||||||||||||||
Type Parameters
Parameters
ReturnsPromise<MDXModuleExport<({ default: MDXContent; } & Types)[ExportName]>>Modifiersasync | |||||||||||||||||||||||||||||
| getNamedExport | <ExportName extends Extract<keyof Types, string>>(name: ExportName) => Promise<MDXModuleExport<Types[ExportName]>> | — | |||||||||||||||||||||||||||
Get a named export from the MDX file. Type Parameters
Parameters
ReturnsPromise<MDXModuleExport<Types[ExportName]>>Modifiersasync | |||||||||||||||||||||||||||||
| getDefaultExport | () => Promise<MDXContent> | — | |||||||||||||||||||||||||||
Get the default export from the MDX file. ReturnsPromise<MDXContent>Modifiersasync | |||||||||||||||||||||||||||||
| getContent | () => Promise<MDXContent> | — | |||||||||||||||||||||||||||
Get the rendered MDX content. ReturnsPromise<MDXContent>Modifiersasync | |||||||||||||||||||||||||||||
| getHeadings | () => Promise<Headings> | — | |||||||||||||||||||||||||||
Get headings parsed from the MDX content. ReturnsPromise<Headings>Modifiersasync | |||||||||||||||||||||||||||||
| hasExport | (name: string) => Promise<boolean> | — | |||||||||||||||||||||||||||
Check if an export exists at runtime in the MDX file. Parameters
ReturnsPromise<boolean>Modifiersasync | |||||||||||||||||||||||||||||
| getExportValue | <ExportName extends "default" | Extract<keyof Types, string>>(name: ExportName) => Promise<({ default: MDXContent; } & Types)[ExportName]> (+1 overload) | — | |||||||||||||||||||||||||||
Overload 1<ExportName extends "default" | Extract<keyof Types, string>>(name: ExportName) => Promise<({ default: MDXContent; } & Types)[ExportName]>Get the runtime value of an export in the MDX file. Type Parameters
Parameters
ReturnsPromise<({ default: MDXContent; } & Types)[ExportName]>ModifiersasyncOverload 2<Value, ExportName extends string>(name: ExportName) => Promise<Value>Type Parameters
Parameters
ReturnsPromise<Value>Modifiersasync | |||||||||||||||||||||||||||||
| getStaticExportValue | (name: string) => Promise<unknown> | — | |||||||||||||||||||||||||||
Attempt to return a literal value for a named export if it can be determined statically. Parameters
ReturnsPromise<unknown>Modifiersasync | |||||||||||||||||||||||||||||
Extends
File<DirectoryTypes, Path, Extension>Options for a Markdown file in the file system.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | Record<string, any> | — |
DirectoryTypes | Record<string, any> | — |
Path | string | — |
Properties
| Property | Type | |
|---|---|---|
| loader? | ModuleLoader<{ default: MDXContent; } & Types> | |
A Markdown file in the file system.
Constructor
<Types extends Record<string, any>, DirectoryTypes extends Record<string, any>, Path extends string, Extension extends string>({
loader,
...fileOptions
}: MarkdownFileOptions<
{ default: MDXContent } & Types,
DirectoryTypes,
Path
>) => MarkdownFile<Types, DirectoryTypes, Path, Extension>| Parameter | Type | Default Value |
|---|---|---|
| { loader, ...fileOptions } | MarkdownFileOptions<{ default: MDXContent; } & Types, DirectoryTypes, Path> | — |
Methods
| Method | Type | Modifiers | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getContent | () => Promise<MDXContent> | — | |||||||||||||||||||||||||||
Get the rendered markdown content. ReturnsPromise<MDXContent>Modifiersasync | |||||||||||||||||||||||||||||
| getHeadings | () => Promise<Headings> | — | |||||||||||||||||||||||||||
Get headings parsed from the markdown content. ReturnsPromise<Headings>Modifiersasync | |||||||||||||||||||||||||||||
| getExportValue | <ExportName extends "default" | Extract<keyof Types, string>>(name: ExportName) => Promise<({ default: MDXContent; } & Types)[ExportName]> (+1 overload) | — | |||||||||||||||||||||||||||
Overload 1<ExportName extends "default" | Extract<keyof Types, string>>(name: ExportName) => Promise<({ default: MDXContent; } & Types)[ExportName]>Get the runtime value of an export in the Markdown file. (Permissive signature for union compatibility.) Type Parameters
Parameters
ReturnsPromise<({ default: MDXContent; } & Types)[ExportName]>ModifiersasyncOverload 2<Value, ExportName extends string>(name: ExportName) => Promise<Value>Type Parameters
Parameters
ReturnsPromise<Value>Modifiersasync | |||||||||||||||||||||||||||||
Extends
File<DirectoryTypes, Path, Extension>Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Entry | FileSystemEntry<any, undefined> | — |
Types | Record<string, any> | — |
Type
(entry: FileSystemEntry<Types, undefined>) => entry is Entry | (entry: FileSystemEntry<Types, undefined>) => boolean | Promise<boolean> | stringType Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | InferModuleLoadersTypes<Loaders> | any |
LoaderTypes | Types | any |
Loaders | ModuleLoaders | ModuleLoaders |
Filter | DirectoryFilter<FileSystemEntry<LoaderTypes, undefined>, LoaderTypes> | DirectoryFilter<FileSystemEntry<LoaderTypes, undefined>, LoaderTypes> |
Properties
| Property | Type | |
|---|---|---|
| path? | string | |
| filter? | Filter | |
| loader? | Loaders | () => Loaders | |
| basePathname? | string | null | |
| tsConfigPath? | string | |
| slugCasing? | SlugCasing | |
| fileSystem? | FileSystem | |
| sort? | SortDescriptor<ResolveDirectoryFilterEntries<Filter, LoaderTypes>> | |
| repository? | Repository | RepositoryConfig | string | |
A directory containing files and subdirectories in the file system.
Constructor
<Types extends InferModuleLoadersTypes<Loaders>, LoaderTypes extends WithDefaultTypes<Types>, Loaders extends ModuleLoaders, Filter extends DirectoryFilter<FileSystemEntry<LoaderTypes, undefined>, LoaderTypes>>(options?: DirectoryOptions<Types, LoaderTypes, Loaders, Filter>) => Directory<Types, LoaderTypes, Loaders, Filter>| Parameter | Type | Default Value |
|---|---|---|
| options? | DirectoryOptions<Types, LoaderTypes, Loaders, Filter> | — |
Methods
| Method | Type | Modifiers | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getFileSystem | () => FileSystem | — | |||||||||||||||||||||||||||||||||
Get the file system for this directory. ReturnsFileSystem | |||||||||||||||||||||||||||||||||||
| getRepository | (repository?: RepositoryConfig | string | Repository) => Repository | — | |||||||||||||||||||||||||||||||||
Get the Parameters
ReturnsRepository | |||||||||||||||||||||||||||||||||||
| getDepth | () => number | — | |||||||||||||||||||||||||||||||||
Get the depth of the directory starting from the root directory. Returnsnumber | |||||||||||||||||||||||||||||||||||
| getFile | <Path extends string, Extension extends ExtractFileExtension<Path>>(path: Path) => Promise<Extension extends string ? IsJavaScriptLikeExtension<Extension> extends true ? JavaScriptFile<LoaderTypes[Extension], LoaderTypes, string, Extension> : Extension extends "mdx" ? MDXFile<LoaderTypes["mdx"], LoaderTypes, string, Extension> : Extension extends "md" ? MarkdownFile<LoaderTypes["md"], LoaderTypes, string, Extension> : Extension extends "json" ? JSONFile<JSONExtensionType<LoaderTypes>, LoaderTypes, string, Extension> : File<LoaderTypes, Path, Extension> : File<LoaderTypes, string, string>> (+1 overload) | — | |||||||||||||||||||||||||||||||||
Overload 1<Path extends string, Extension extends ExtractFileExtension<Path>>(path: Path) => Promise<Extension extends string ? IsJavaScriptLikeExtension<Extension> extends true ? JavaScriptFile<LoaderTypes[Extension], LoaderTypes, string, Extension> : Extension extends "mdx" ? MDXFile<LoaderTypes["mdx"], LoaderTypes, string, Extension> : Extension extends "md" ? MarkdownFile<LoaderTypes["md"], LoaderTypes, string, Extension> : Extension extends "json" ? JSONFile<JSONExtensionType<LoaderTypes>, LoaderTypes, string, Extension> : File<LoaderTypes, Path, Extension> : File<LoaderTypes, string, string>>Get a file at the specified If the file is not found, an error will be thrown. Use Type Parameters
Parameters
ReturnsPromise<Extension extends string ? IsJavaScriptLikeExtension<Extension> extends true ? JavaScriptFile<LoaderTypes[Extension], LoaderTypes, string, Extension> : Extension extends "mdx" ? MDXFile<LoaderTypes["mdx"], LoaderTypes, string, Extension> : Extension extends "md" ? MarkdownFile<LoaderTypes["md"], LoaderTypes, string, Extension> : Extension extends "json" ? JSONFile<JSONExtensionType<LoaderTypes>, LoaderTypes, string, Extension> : File<LoaderTypes, Path, Extension> : File<LoaderTypes, string, string>>ModifiersasyncOverload 2<ExtensionType extends keyof LoaderTypes | string, Extension extends ExtensionType | Array<Extension>>(path: string | string[], extension?: Extension | Extension[]) => Promise<Extension extends string ? IsJavaScriptLikeExtension<Extension> extends true ? JavaScriptFile<LoaderTypes[Extension], LoaderTypes, string, Extension> : Extension extends "mdx" ? MDXFile<LoaderTypes["mdx"], LoaderTypes, string, Extension> : Extension extends "md" ? MarkdownFile<LoaderTypes["md"], LoaderTypes, string, Extension> : Extension extends "json" ? JSONFile<JSONExtensionType<LoaderTypes>, LoaderTypes, string, Extension> : File<LoaderTypes, Extension, ExtractFileExtension<Extension>> : File<LoaderTypes, string, string>>Type Parameters
Parameters
ReturnsPromise<Extension extends string ? IsJavaScriptLikeExtension<Extension> extends true ? JavaScriptFile<LoaderTypes[Extension], LoaderTypes, string, Extension> : Extension extends "mdx" ? MDXFile<LoaderTypes["mdx"], LoaderTypes, string, Extension> : Extension extends "md" ? MarkdownFile<LoaderTypes["md"], LoaderTypes, string, Extension> : Extension extends "json" ? JSONFile<JSONExtensionType<LoaderTypes>, LoaderTypes, string, Extension> : File<LoaderTypes, Extension, ExtractFileExtension<Extension>> : File<LoaderTypes, string, string>>Modifiersasync | |||||||||||||||||||||||||||||||||||
| getDirectory | (path: string | string[]) => Promise<Directory<LoaderTypes, WithDefaultTypes<LoaderTypes>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<LoaderTypes>, undefined>, WithDefaultTypes<LoaderTypes>>>> | — | |||||||||||||||||||||||||||||||||
Get a directory at the specified Parameters
ReturnsPromise<Directory<LoaderTypes, WithDefaultTypes<LoaderTypes>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<LoaderTypes>, undefined>, WithDefaultTypes<LoaderTypes>>>>Modifiersasync | |||||||||||||||||||||||||||||||||||
| getEntry | (path: string | string[]) => Promise<FileSystemEntry<LoaderTypes, undefined>> | — | |||||||||||||||||||||||||||||||||
Get a directory or file at the specified
Parameters
ReturnsPromise<FileSystemEntry<LoaderTypes, undefined>>Modifiersasync | |||||||||||||||||||||||||||||||||||
| getEntries | (options?: {
/** Recursively walk every subdirectory. */
recursive?: Filter extends string
? Filter extends `**${string}`
? boolean
: undefined
: boolean
/** Include files named the same as their immediate directory (e.g. `Button/Button.tsx`). */
includeDirectoryNamedFiles?: boolean
/** Include index and readme files. */
includeIndexAndReadmeFiles?: boolean
/** Include files that are ignored by `.gitignore`. */
includeGitIgnoredFiles?: boolean
/** Include files that are excluded by the configured `tsconfig.json` file's `exclude` patterns. */
includeTsConfigExcludedFiles?: boolean
}) => Promise<Array<Filter extends string ? Filter extends `**${string}` ? Directory<LoaderTypes, WithDefaultTypes<LoaderTypes>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<LoaderTypes>, undefined>, WithDefaultTypes<LoaderTypes>>> | FileWithExtension<LoaderTypes, ExtractFileExtension<Filter>> : FileWithExtension<LoaderTypes, ExtractFileExtension<Filter>> : Filter extends DirectoryFilter<infer FilteredEntry extends FileSystemEntry<any, undefined>, LoaderTypes> ? FilteredEntry : FileSystemEntry<LoaderTypes, undefined>>> | — | |||||||||||||||||||||||||||||||||
Retrieves all entries (files and directories) within the current directory
that are not excluded by Git ignore rules or the closest Parameters
ReturnsPromise<Array<Filter extends string ? Filter extends `**${string}` ? Directory<LoaderTypes, WithDefaultTypes<LoaderTypes>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<LoaderTypes>, undefined>, WithDefaultTypes<LoaderTypes>>> | FileWithExtension<LoaderTypes, ExtractFileExtension<Filter>> : FileWithExtension<LoaderTypes, ExtractFileExtension<Filter>> : Filter extends DirectoryFilter<infer FilteredEntry extends FileSystemEntry<any, undefined>, LoaderTypes> ? FilteredEntry : FileSystemEntry<LoaderTypes, undefined>>>Modifiersasync | |||||||||||||||||||||||||||||||||||
| getRootPath | () => string | — | |||||||||||||||||||||||||||||||||
Get the root directory path. Returnsstring | |||||||||||||||||||||||||||||||||||
| getParent | () => Directory<any, any, any, DirectoryFilter<FileSystemEntry<any, undefined>, any>> | — | |||||||||||||||||||||||||||||||||
Get the parent directory containing this directory. ReturnsDirectory<any, any, any, DirectoryFilter<FileSystemEntry<any, undefined>, any>> | |||||||||||||||||||||||||||||||||||
| getSiblings | <GroupTypes extends Record<string, any>>(options?: {
collection?: Collection<GroupTypes, FileSystemEntry<any>[]>
}) => Promise<[FileSystemEntry<LoaderTypes, undefined> | undefined, FileSystemEntry<LoaderTypes, undefined> | undefined]> | — | |||||||||||||||||||||||||||||||||
Get the previous and next sibling entries (files or directories) of the parent directory. Type Parameters
Parameters
ReturnsPromise<[FileSystemEntry<LoaderTypes, undefined> | undefined, FileSystemEntry<LoaderTypes, undefined> | undefined]>Modifiersasync | |||||||||||||||||||||||||||||||||||
| getSlug | () => string | — | |||||||||||||||||||||||||||||||||
Get the slug of this directory. Returnsstring | |||||||||||||||||||||||||||||||||||
| getName | () => string | — | |||||||||||||||||||||||||||||||||
Get the base name of this directory. Returnsstring | |||||||||||||||||||||||||||||||||||
| getBaseName | () => string | — | |||||||||||||||||||||||||||||||||
Get the base name of this directory. Returnsstring | |||||||||||||||||||||||||||||||||||
| getTitle | () => string | — | |||||||||||||||||||||||||||||||||
The directory name formatted as a title. Returnsstring | |||||||||||||||||||||||||||||||||||
| getPathname | (options?: { includeBasePathname?: boolean }) => string | — | |||||||||||||||||||||||||||||||||
Get a URL-friendly path to this directory. Parameters
Returnsstring | |||||||||||||||||||||||||||||||||||
| getPathnameSegments | (options?: { includeBasePathname?: boolean }) => Array<string> | — | |||||||||||||||||||||||||||||||||
Get the route path segments to this directory. Parameters
ReturnsArray<string> | |||||||||||||||||||||||||||||||||||
| getRelativePathToRoot | () => string | — | |||||||||||||||||||||||||||||||||
Get the relative path of this directory to the root directory. Returnsstring | |||||||||||||||||||||||||||||||||||
| getRelativePathToWorkspace | () => string | — | |||||||||||||||||||||||||||||||||
Get the relative path of the directory to the workspace. Returnsstring | |||||||||||||||||||||||||||||||||||
| getAbsolutePath | () => string | — | |||||||||||||||||||||||||||||||||
Get the absolute path of this directory. Returnsstring | |||||||||||||||||||||||||||||||||||
| getHistoryUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | |||||||||||||||||||||||||||||||||
Get the URL to the directory history for the configured git repository. Parameters
Returnsstring | |||||||||||||||||||||||||||||||||||
| getSourceUrl | (options?: Pick<GetFileUrlOptions, 'ref'> & {
repository?: RepositoryConfig | string | Repository
}) => string | — | |||||||||||||||||||||||||||||||||
Get the URL to the directory source for the configured git repository. Parameters
Returnsstring | |||||||||||||||||||||||||||||||||||
| getEditorUri | (options?: Pick<GetEditorUriOptions, 'editor'>) => string | — | |||||||||||||||||||||||||||||||||
Get the URI to the directory source code for the configured editor. Parameters
Returnsstring | |||||||||||||||||||||||||||||||||||
| getFirstCommitDate | () => Promise<Date | undefined> | — | |||||||||||||||||||||||||||||||||
Get the first local git commit date of this directory. ReturnsPromise<Date | undefined>Modifiersasync | |||||||||||||||||||||||||||||||||||
| getLastCommitDate | () => Promise<Date | undefined> | — | |||||||||||||||||||||||||||||||||
Get the last local git commit date of this directory. ReturnsPromise<Date | undefined>Modifiersasync | |||||||||||||||||||||||||||||||||||
| getAuthors | () => Promise<Array<GitAuthor>> | — | |||||||||||||||||||||||||||||||||
Get the local git authors of this directory. ReturnsPromise<Array<GitAuthor>>Modifiersasync | |||||||||||||||||||||||||||||||||||
| hasEntry | (entry: FileSystemEntry<any> | undefined) => boolean | — | |||||||||||||||||||||||||||||||||
Checks if this directory contains the provided entry. Parameters
Returnsboolean | |||||||||||||||||||||||||||||||||||
| hasFile | <ExtensionType extends keyof LoaderTypes | string, Extension extends ExtensionType | Array<Extension>>(entry: FileSystemEntry<any> | undefined, extension?: Extension | Extension[]) => boolean | — | |||||||||||||||||||||||||||||||||
Checks if this directory contains the provided file. Type Parameters
Parameters
Returnsboolean | |||||||||||||||||||||||||||||||||||
Options for a Collection.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Entries | Array<FileSystemEntry<any, undefined>> | — |
Properties
| Property | Type | |
|---|---|---|
| entries | Entries | |
A group of file system entries.
Constructor
<Types extends InferModuleLoadersTypes<Loaders>, Entries extends Array<FileSystemEntry<any, undefined>>, Loaders extends ModuleLoaders>(options: CollectionOptions<Entries>) => Collection<Types, Entries, Loaders>| Parameter | Type | Default Value |
|---|---|---|
| options | CollectionOptions<Entries> | — |
Methods
| Method | Type | Modifiers | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| getEntries | (options?: {
/** Include all entries in the group recursively. */
recursive?: boolean
/** Include index and readme files in the group. */
includeIndexAndReadmeFiles?: boolean
}) => Promise<Entries> | — | |||||||||||||||
Get all entries in the group. Parameters
ReturnsPromise<Entries>Modifiersasync | |||||||||||||||||
| getEntry | (path: string | string[]) => Promise<FileSystemEntry<Types, undefined>> | — | |||||||||||||||
Get an entry in the group by its path. Parameters
ReturnsPromise<FileSystemEntry<Types, undefined>>Modifiersasync | |||||||||||||||||
| getFile | <Extension extends string | undefined>(path: string | string[], extension?: Extension | Extension[]) => Promise<Extension extends string ? IsJavaScriptLikeExtension<Extension> extends true ? JavaScriptFile<Types[Extension], Record<string, any>, string, string> : Extension extends "mdx" ? MDXFile<Types["mdx"], Record<string, any>, string, string> : Extension extends "md" ? MarkdownFile<Types["md"], Record<string, any>, string, string> : File<Types, string, string> : File<Types, string, string>> | — | |||||||||||||||
Get a file at the specified path and optional extension(s). Type Parameters
Parameters
ReturnsPromise<Extension extends string ? IsJavaScriptLikeExtension<Extension> extends true ? JavaScriptFile<Types[Extension], Record<string, any>, string, string> : Extension extends "mdx" ? MDXFile<Types["mdx"], Record<string, any>, string, string> : Extension extends "md" ? MarkdownFile<Types["md"], Record<string, any>, string, string> : File<Types, string, string> : File<Types, string, string>>Modifiersasync | |||||||||||||||||
| getDirectory | (path: string | string[]) => Promise<Directory<Types, WithDefaultTypes<Types>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<Types>, undefined>, WithDefaultTypes<Types>>>> | — | |||||||||||||||
Get a directory at the specified path. Parameters
ReturnsPromise<Directory<Types, WithDefaultTypes<Types>, ModuleLoaders, DirectoryFilter<FileSystemEntry<WithDefaultTypes<Types>, undefined>, WithDefaultTypes<Types>>>>Modifiersasync | |||||||||||||||||
Determines if a FileSystemEntry is a Directory.
function isDirectory<Types extends Record<string, any>>(entry: FileSystemEntry<Types> | Collection<Types> | undefined): booleanType Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | Record<string, any> | — |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entry | entry: FileSystemEntry<Types> | Collection<Types> | undefined | — |
Returns
booleanResolves valid extension patterns from an object of loaders.
Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
DirectoryLoaders | ModuleLoaders | — |
ExtensionUnion | — | string | Extract<keyof DirectoryLoaders, string> |
Type
ExtensionUnion | Array<ExtensionUnion>Determines if a FileSystemEntry is a File and optionally narrows the
result based on the provided extensions.
function isFile<Types extends Record<string, any>, Extension extends LoadersToExtensions<Types, StringUnion<keyof Types>>>(entry: FileSystemEntry<Types> | undefined, extension?: Extension): booleanType Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | Record<string, any> | — |
Extension | LoadersToExtensions<Types, StringUnion<keyof Types>> | — |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entry | entry: FileSystemEntry<Types> | undefined | — |
| extension? | Extension | — |
Returns
booleanDetermines if a FileSystemEntry is a JavaScriptFile.
function isJavaScriptFile<FileTypes extends Record<string, any>, DirectoryTypes extends Record<string, any>>(entry: FileSystemEntry<DirectoryTypes> | undefined): booleanType Parameters
| Parameter | Constraint | Default |
|---|---|---|
FileTypes | Record<string, any> | — |
DirectoryTypes | Record<string, any> | Record<string, any> |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entry | entry: FileSystemEntry<DirectoryTypes> | undefined | — |
Returns
booleanDetermines if a FileSystemEntry is a MarkdownFile.
function isMarkdownFile<FileTypes extends Record<string, any>, DirectoryTypes extends Record<string, any>>(entry: FileSystemEntry<DirectoryTypes> | undefined): booleanType Parameters
| Parameter | Constraint | Default |
|---|---|---|
FileTypes | Record<string, any> | — |
DirectoryTypes | Record<string, any> | Record<string, any> |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entry | entry: FileSystemEntry<DirectoryTypes> | undefined | — |
Returns
booleanDetermines if a FileSystemEntry is a JSONFile.
function isJSONFile<FileTypes extends Record<string, any>, DirectoryTypes extends Record<string, any>>(entry: FileSystemEntry<DirectoryTypes> | undefined): booleanType Parameters
| Parameter | Constraint | Default |
|---|---|---|
FileTypes | Record<string, any> | — |
DirectoryTypes | Record<string, any> | Record<string, any> |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entry | entry: FileSystemEntry<DirectoryTypes> | undefined | — |
Returns
booleanDetermines if a FileSystemEntry is an MDXFile.
function isMDXFile<FileTypes extends Record<string, any>, DirectoryTypes extends Record<string, any>>(entry: FileSystemEntry<DirectoryTypes> | undefined): booleanType Parameters
| Parameter | Constraint | Default |
|---|---|---|
FileTypes | Record<string, any> | — |
DirectoryTypes | Record<string, any> | Record<string, any> |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entry | entry: FileSystemEntry<DirectoryTypes> | undefined | — |
Returns
booleanAttempts to resolve a file from a FileSystemEntry, preferring index and
readme for directories. The result can be optionally narrowed by extension.
function resolveFileFromEntry<Types extends Record<string, any>, Extension extends keyof Types & string>(entry: FileSystemEntry<Types>, extension?: Extension | readonly Extension[]): Promise<FileWithExtension<Types, Extension> | undefined>Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Types | Record<string, any> | — |
Extension | keyof Types & string | string |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entry | FileSystemEntry<Types, undefined> | — |
| extension? | extension?: Extension | readonly Extension[] | — |
Returns
Promise<FileWithExtension<Types, Extension> | undefined>Modifiers
asyncType Parameters
| Parameter | Constraint | Default |
|---|---|---|
Entry | FileSystemEntry<any, undefined> | — |
Type
ValidSortKey<EntryTypes<Entry>> | SortKeyExtractor<Entry> | SortDescriptorObject<EntryTypes<Entry>, Entry, ValidSortKey<EntryTypes<Entry>> | SortKeyExtractor<Entry>>Compiles a set of sort descriptors into a sort function.
function sortEntries<ExtensionTypes extends Record<string, any>>(entries: FileSystemEntry<ExtensionTypes>[], descriptor: SortDescriptor<any>): Promise<void>Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
ExtensionTypes | Record<string, any> | — |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| entries | Array<FileSystemEntry<ExtensionTypes, undefined>> | — |
| descriptor | SortDescriptor<any> | — |
Returns
Promise<void>Modifiers
asyncfunction createSort<Entry extends FileSystemEntry<any, undefined>, Key extends SortKeyExtractor<Entry>>(key: Key, compare?: (a: ExtractComparable<Key>, b: ExtractComparable<Key>) => number): SortDescriptorObject<any, Entry, Key>Type Parameters
| Parameter | Constraint | Default |
|---|---|---|
Entry | FileSystemEntry<any, undefined> | — |
Key | SortKeyExtractor<Entry> | SortKeyExtractor<Entry> |
Parameters
| Parameter | Type | Default Value |
|---|---|---|
| key | Key | — |
| compare? | compare?: (a: ExtractComparable<Key>, b: ExtractComparable<Key>) => number | — |
Returns
SortDescriptorObject<any, Entry, Key>A file system that stores files in memory.
Constructor
(files: { [path: string]: MemoryFileContent }) => MemoryFileSystem| Parameter | Type | Default Value |
|---|---|---|
| files | files: { [path: string]: MemoryFileContent } | — |
Methods
| Method | Type | Modifiers | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| createFile | (path: string, content: MemoryFileContent) => void | — | |||||||||
Parameters
Returnsvoid | |||||||||||
| getProjectOptions | () => ProjectOptions | — | |||||||||
ReturnsProjectOptions | |||||||||||
| transpileFile | (path: string) => Promise<string> | — | |||||||||
Parameters
ReturnsPromise<string>Modifiersasync | |||||||||||
| getAbsolutePath | (path: string) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| getRelativePathToWorkspace | (path: string) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| getFiles | () => Map<string, MemoryFileEntry> | — | |||||||||
ReturnsMap<string, MemoryFileEntry> | |||||||||||
| getFileEntry | (path: string) => MemoryFileEntry | undefined | — | |||||||||
Parameters
ReturnsMemoryFileEntry | undefined | |||||||||||
| readDirectorySync | (path: string = '.') => Array<DirectoryEntry> | — | |||||||||
Parameters
ReturnsArray<DirectoryEntry> | |||||||||||
| readDirectory | (path: string = '.') => Promise<Array<DirectoryEntry>> | — | |||||||||
Parameters
ReturnsPromise<Array<DirectoryEntry>>Modifiersasync | |||||||||||
| readFileSync | (path: string) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| readFile | (path: string) => Promise<string> | — | |||||||||
Parameters
ReturnsPromise<string>Modifiersasync | |||||||||||
| readFileBinarySync | (path: string) => Uint8Array<ArrayBufferLike> | — | |||||||||
Parameters
ReturnsUint8Array<ArrayBufferLike> | |||||||||||
| readFileBinary | (path: string) => Promise<Uint8Array<ArrayBufferLike>> | — | |||||||||
Parameters
ReturnsPromise<Uint8Array<ArrayBufferLike>>Modifiersasync | |||||||||||
| readFileStream | (path: string) => FileReadableStream | — | |||||||||
Parameters
ReturnsFileReadableStream | |||||||||||
| writeFileSync | (path: string, content: FileSystemWriteFileContent) => void | — | |||||||||
Parameters
Returnsvoid | |||||||||||
| writeFile | (path: string, content: FileSystemWriteFileContent) => Promise<void> | — | |||||||||
Parameters
ReturnsPromise<void>Modifiersasync | |||||||||||
| writeFileStream | (path: string) => FileWritableStream | — | |||||||||
Parameters
ReturnsFileWritableStream | |||||||||||
| fileExistsSync | (path: string) => boolean | — | |||||||||
Parameters
Returnsboolean | |||||||||||
| fileExists | (path: string) => Promise<boolean> | — | |||||||||
Parameters
ReturnsPromise<boolean>Modifiersasync | |||||||||||
| deleteFileSync | (path: string) => void | — | |||||||||
Parameters
Returnsvoid | |||||||||||
| deleteFile | (path: string) => Promise<void> | — | |||||||||
Parameters
ReturnsPromise<void>Modifiersasync | |||||||||||
| isFilePathGitIgnored | (filePath: string) => boolean | — | |||||||||
Parameters
Returnsboolean | |||||||||||
Extends
FileSystemConstructor
(options: FileSystemOptions = {}) => NodeFileSystem| Parameter | Type | Default Value |
|---|---|---|
| options | FileSystemOptions | {} |
Methods
| Method | Type | Modifiers | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| getProjectOptions | () => { tsConfigFilePath: string; } | — | |||||||||
Returns{ tsConfigFilePath: string; } | |||||||||||
| getAbsolutePath | (path: string) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| getRelativePathToWorkspace | (path: string) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| readDirectorySync | (path: string = '.') => Array<DirectoryEntry> | — | |||||||||
Parameters
ReturnsArray<DirectoryEntry> | |||||||||||
| readDirectory | (path: string = '.') => Promise<Array<DirectoryEntry>> | — | |||||||||
Parameters
ReturnsPromise<Array<DirectoryEntry>>Modifiersasync | |||||||||||
| readFileSync | (path: string) => string | — | |||||||||
Parameters
Returnsstring | |||||||||||
| readFile | (path: string) => Promise<string> | — | |||||||||
Parameters
ReturnsPromise<string>Modifiersasync | |||||||||||
| readFileBinarySync | (path: string) => Uint8Array<ArrayBufferLike> | — | |||||||||
Parameters
ReturnsUint8Array<ArrayBufferLike> | |||||||||||
| readFileBinary | (path: string) => Promise<Uint8Array<ArrayBufferLike>> | — | |||||||||
Parameters
ReturnsPromise<Uint8Array<ArrayBufferLike>>Modifiersasync | |||||||||||
| readFileStream | (path: string) => FileReadableStream | — | |||||||||
Parameters
ReturnsFileReadableStream | |||||||||||
| writeFileSync | (path: string, content: FileSystemWriteFileContent) => void | — | |||||||||
Parameters
Returnsvoid | |||||||||||
| writeFile | (path: string, content: FileSystemWriteFileContent) => Promise<void> | — | |||||||||
Parameters
ReturnsPromise<void>Modifiersasync | |||||||||||
| writeFileStream | (path: string) => FileWritableStream | — | |||||||||
Parameters
ReturnsFileWritableStream | |||||||||||
| fileExistsSync | (path: string) => boolean | — | |||||||||
Parameters
Returnsboolean | |||||||||||
| fileExists | (path: string) => Promise<boolean> | — | |||||||||
Parameters
ReturnsPromise<boolean>Modifiersasync | |||||||||||
| deleteFileSync | (path: string) => void | — | |||||||||
Parameters
Returnsvoid | |||||||||||
| deleteFile | (path: string) => Promise<void> | — | |||||||||
Parameters
ReturnsPromise<void>Modifiersasync | |||||||||||
| isFilePathGitIgnored | (filePath: string) => boolean | — | |||||||||
Parameters
Returnsboolean | |||||||||||
Extends
FileSystemConstructor
(repository: RepositoryConfig | string) => Repository| Parameter | Type | Default Value |
|---|---|---|
| repository | repository: RepositoryConfig | string | — |
Methods
| Method | Type | Modifiers | ||||||
|---|---|---|---|---|---|---|---|---|
| toString | () => string | — | ||||||
Returns the string representation of the repository. Returnsstring | ||||||||
| getIssueUrl | (options: GetIssueUrlOptions) => string | — | ||||||
Constructs a new issue URL for the repository. Parameters
Returnsstring | ||||||||
| getFileUrl | (options: GetFileUrlOptions) => string | — | ||||||
Constructs a URL for a file in the repository. Parameters
Returnsstring | ||||||||
| getDirectoryUrl | (options: GetDirectoryUrlOptions) => string | — | ||||||
Constructs a URL for a directory in the repository. Parameters
Returnsstring | ||||||||