UNPKG

@oazmi/esbuild-generic-loader

Version:

a utility library for building generic file loading plugins for esbuild

63 lines 3.38 kB
/** this submodule contains utility functions for writing esbuild's virtual output to the filesystem. * * this submodule is separated from the rest since it performs filesystem operations, which is runtime-dependant, * and we don't want to impact the portability of the main module. * * @module */ import "./_dnt.polyfills.js"; import { type WriteFileConfig } from "./deps.js"; import type { AbsolutePath, Path, RelativePath } from "./typedefs.js"; export type { WriteFileConfig } from "./deps.js"; /** get the current working directory (i.e. `process.cwd()` or `Deno.cwd`) in posix path format. */ export declare const getCwdPath: () => AbsolutePath; /** resolve a file path so that it becomes absolute, with unix directory separator ("/"). */ export declare const resolvePath: ((...segments: Path[]) => AbsolutePath); /** the tuple description of a writable (or appendable) file. * - the first entry of the array must describe the destination path of the file, * relative to the directory defined in {@link CreateFilesConfig.dir}). * - the second entry should be the file's contents, which can either be a `string` text, a `ReadableStream`, or a `Uint8Array` binary. * - the third and optional entry lets you specify additional {@link WriteFileConfig | deno-like file writing options}, * such as `"append"` the new text, or permit the creation (`"create"`) of new file if it doesn't exist, etc... */ export type WritableFileConfig = [ destination: RelativePath, content: string | Uint8Array, options?: WriteFileConfig ]; /** configuration options for {@link createFiles}. */ export interface CreateFilesConfig { /** the desired output directory. * if a relative path is provided, then it will be resolved as a path relative to the current working directory. * (which is generally where `package.json` or `deno.json` resides) */ dir?: Path; /** select logging level: * - `false` or `"none"`: skip logging. * - `true` or `"basic"`: log what is being carried out at the top level. * - `"verbose"`: in addition to basic logging, it also logs which files/folders are being copied or generated. * * @defaultValue `"basic"` */ log?: boolean | "none" | "basic" | "verbose"; /** enable `dryrun` if you wish for nothing to be written onto the the filesystem. * * @defaultValue `false` */ dryrun?: boolean; } /** the in-memory output file description generated by `esbuild`. */ export interface EsbuildOutputFile { path: AbsolutePath; text?: string; contents?: Uint8Array; hash?: string; } /** write a collection of virtual files to your filesystem. * this function accepts virtual files that are either in text (`string`), binary (`Uint8Array`), or streamable text/binary (`ReadableStream<string | Uint8Array>`) formats. * it is important that you provide the configuration parameter's {@link config["dir"] | `dir`} field, so that relative paths can be resolved according to the provided directory. */ export declare const createFiles: (virtual_files: Array<WritableFileConfig>, config?: CreateFilesConfig) => Promise<void>; /** write `esbuild` output files (`BuildResult.outputFiles`) to the filesystem. */ export declare const writeOutputFiles: (virtual_files: Array<EsbuildOutputFile>, config?: CreateFilesConfig) => Promise<void>; //# sourceMappingURL=fs.d.ts.map