@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
1 lines • 15.8 kB
Source Map (JSON)
{"version":3,"sources":["../../src/types/vfs.ts"],"names":["__VFS_INIT__","__VFS_REVERT__","__VFS_CACHE__","__VFS_RESOLVER__","__VFS_VIRTUAL__","__VFS_UNIFIED__"],"mappings":";;;AAmCO,IAAMA,YAAAA,GAAe;AAGrB,IAAMC,cAAAA,GAAiB;AAGvB,IAAMC,aAAAA,GAAgB;AAGtB,IAAMC,gBAAAA,GAAmB;AAGzB,IAAMC,eAAAA,GAAkB;AAGxB,IAAMC,eAAAA,GAAkB","file":"chunk-N2HLPYZL.cjs","sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Storm Stack\n\n This code was released as part of the Storm Stack project. Storm Stack\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/storm-stack.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/storm-stack\n Documentation: https://docs.stormsoftware.com/projects/storm-stack\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { Volume } from \"memfs/lib/volume\";\nimport {\n MakeDirectoryOptions as FsMakeDirectoryOptions,\n WriteFileOptions as FsWriteFileOptions,\n Mode,\n PathLike,\n PathOrFileDescriptor,\n RmDirOptions,\n RmOptions,\n Stats,\n StatSyncOptions\n} from \"node:fs\";\nimport { IUnionFs } from \"unionfs\";\n\nexport type VirtualFileExtension = \"js\" | \"ts\" | \"jsx\" | \"tsx\";\n\n// eslint-disable-next-line ts/naming-convention\nexport const __VFS_INIT__ = \"__VFS_INIT__\";\n\n// eslint-disable-next-line ts/naming-convention\nexport const __VFS_REVERT__ = \"__VFS_REVERT__\";\n\n// eslint-disable-next-line ts/naming-convention\nexport const __VFS_CACHE__ = \"__VFS_CACHE__\";\n\n// eslint-disable-next-line ts/naming-convention\nexport const __VFS_RESOLVER__ = \"__VFS_RESOLVER__\";\n\n// eslint-disable-next-line ts/naming-convention\nexport const __VFS_VIRTUAL__ = \"__VFS_VIRTUAL__\";\n\n// eslint-disable-next-line ts/naming-convention\nexport const __VFS_UNIFIED__ = \"__VFS_UNIFIED__\";\n\nexport interface VirtualFile {\n /**\n * A virtual path to the file in the virtual file system.\n */\n path: string;\n\n /**\n * The contents of the virtual file.\n */\n contents: string;\n}\n\nexport interface VirtualRuntimeFile extends VirtualFile {\n /**\n * The unique identifier for the virtual file.\n *\n * @remarks\n * This property is read-only and is set when the file is created.\n */\n id: string;\n}\n\nexport type OutputModeType = \"fs\" | \"memory\";\n\nexport interface ResolveFSOptions {\n outputMode?: OutputModeType;\n}\n\nexport type MakeDirectoryOptions = (Mode | FsMakeDirectoryOptions) &\n ResolveFSOptions;\n\nexport interface ResolvePathOptions extends ResolveFSOptions {\n /**\n * Should the resolved path include the file extension?\n *\n * @defaultValue true\n */\n withExtension?: boolean;\n\n /**\n * The paths to search for the file.\n */\n paths?: string[];\n\n /**\n * The type of the path to resolve.\n */\n type?: \"file\" | \"directory\";\n}\n\nexport type WriteFileOptions = FsWriteFileOptions & ResolveFSOptions;\n\nexport interface WriteRuntimeFileOptions extends ResolveFSOptions {\n skipFormat?: boolean;\n}\n\nexport interface VirtualFileSystemInterface {\n [__VFS_INIT__]: () => void;\n [__VFS_REVERT__]: () => void;\n\n /**\n * The underlying runtime Ids.\n */\n runtimeIdMap: Map<string, string>;\n\n /**\n * Checks if a path or ID corresponds to a runtime file.\n *\n * @param id - The id of the runtime file to check against.\n * @param pathOrId - The path or id of the file to check.\n * @returns Whether the path or ID corresponds to a runtime file.\n */\n isMatchingRuntimeId: (id: string, pathOrId: string) => boolean;\n\n /**\n * Checks if a provided string is a valid runtime ID (does not need to already be created in the file system).\n *\n * @param id - The ID to check.\n * @returns Whether the ID is a valid runtime ID.\n */\n isValidRuntimeId: (id: string) => boolean;\n\n /**\n * Check if a path or ID corresponds to a virtual file.\n *\n * @param pathOrId - The path or ID to check.\n * @param options - Optional parameters for resolving the path.\n * @returns Whether the path or ID corresponds to a virtual file.\n */\n isVirtualFile: (pathOrId: string, options?: ResolvePathOptions) => boolean;\n\n /**\n * Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.\n *\n * @see https://www.typescriptlang.org/tsconfig#paths\n *\n * @param pathOrId - The path or ID to check.\n * @returns Whether the path or ID corresponds to a virtual file.\n */\n isTsconfigPath: (pathOrId: string) => boolean;\n\n /**\n * Checks if a given path or ID corresponds to a runtime file.\n */\n isRuntimeFile: (pathOrID: string, options?: ResolvePathOptions) => boolean;\n\n /**\n * Returns a list of runtime files in the virtual file system.\n */\n listRuntimeFiles: () => Promise<VirtualRuntimeFile[]>;\n\n /**\n * Checks if a file exists in the virtual file system (VFS).\n */\n existsSync: (pathOrId: string) => boolean;\n\n /**\n * Checks if a file exists in the virtual file system (VFS).\n *\n * @param path - The path of the file to check.\n * @returns `true` if the file exists, otherwise `false`.\n */\n fileExistsSync: (path: string) => boolean;\n\n /**\n * Checks if a directory exists in the virtual file system (VFS).\n *\n * @param path - The path of the directory to check.\n * @returns `true` if the directory exists, otherwise `false`.\n */\n directoryExistsSync: (path: string) => boolean;\n\n /**\n * Checks if a path exists in the virtual file system (VFS).\n *\n * @param path - The path to check.\n * @returns `true` if the path exists, otherwise `false`.\n */\n pathExistsSync: (path: string) => boolean;\n\n /**\n * Gets the stats of a file in the virtual file system (VFS).\n *\n * @param pathOrId - The path or id of the file.\n * @param options - Optional parameters for getting the stats.\n * @returns The stats of the file if it exists, otherwise undefined.\n */\n lstat: (\n pathOrId: string,\n options?: StatSyncOptions & {\n bigint?: false | undefined;\n throwIfNoEntry: false;\n }\n ) => Promise<Stats>;\n\n /**\n * Gets the stats of a file in the virtual file system (VFS).\n *\n * @param pathOrId - The path or id of the file.\n * @param options - Optional parameters for getting the stats.\n * @returns The stats of the file if it exists, otherwise undefined.\n */\n lstatSync: (\n pathOrId: string,\n options?: StatSyncOptions & {\n bigint?: false | undefined;\n throwIfNoEntry: false;\n }\n ) => Stats | undefined;\n\n /**\n * Gets the stats of a file in the virtual file system (VFS).\n *\n * @param pathOrId - The path or id of the file.\n * @returns The stats of the file if it exists, otherwise false.\n */\n stat: (\n pathOrId: string,\n options?: StatSyncOptions & {\n bigint?: false | undefined;\n throwIfNoEntry: false;\n }\n ) => Promise<Stats>;\n\n /**\n * Gets the stats of a file in the virtual file system (VFS).\n *\n * @param pathOrId - The path or id of the file.\n * @returns The stats of the file if it exists, otherwise false.\n */\n statSync: (\n pathOrId: string,\n options?: StatSyncOptions & {\n bigint?: false | undefined;\n throwIfNoEntry: false;\n }\n ) => Stats | undefined;\n\n /**\n * Lists files in a given path.\n *\n * @param path - The path to list files from.\n * @param options - Options for listing files, such as encoding and recursion.\n * @returns An array of file names in the specified path.\n */\n readdirSync: (\n path: string,\n options?:\n | {\n encoding: BufferEncoding | null;\n withFileTypes?: false | undefined;\n recursive?: boolean | undefined;\n }\n | BufferEncoding\n ) => string[];\n\n /**\n * Lists files in a given path.\n *\n * @param path - The path to list files from.\n * @param options - Options for listing files, such as encoding and recursion.\n * @returns An array of file names in the specified path.\n */\n readdir: (\n path: string,\n options?:\n | {\n encoding: BufferEncoding | null;\n withFileTypes?: false | undefined;\n recursive?: boolean | undefined;\n }\n | BufferEncoding\n ) => Promise<string[]>;\n\n /**\n * Removes a file or symbolic link in the virtual file system (VFS).\n *\n * @param path - The path to the file to remove.\n * @returns A promise that resolves when the file is removed.\n */\n unlinkSync: (path: PathLike, options?: ResolveFSOptions) => void;\n\n /**\n * Asynchronously removes a file or symbolic link in the virtual file system (VFS).\n *\n * @param path - The path to the file to remove.\n * @returns A promise that resolves when the file is removed.\n */\n unlink: (path: string, options?: ResolveFSOptions) => Promise<void>;\n\n /**\n * Removes a directory in the virtual file system (VFS).\n *\n * @param path - The path to create the directory at.\n * @param options - Options for creating the directory.\n */\n rmdirSync: (path: PathLike, options?: RmDirOptions & ResolveFSOptions) => any;\n\n /**\n * Removes a directory in the virtual file system (VFS).\n *\n * @param path - The path to create the directory at.\n * @param options - Options for creating the directory.\n * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.\n */\n rmdir: (\n path: PathLike,\n options?: RmDirOptions & ResolveFSOptions\n ) => Promise<void>;\n\n /**\n * Removes a file in the virtual file system (VFS).\n *\n * @param path - The path to the file to remove.\n * @param options - Options for removing the file.\n * @returns A promise that resolves when the file is removed.\n */\n rm: (path: PathLike, options?: RmOptions & ResolveFSOptions) => Promise<void>;\n\n /**\n * Creates a directory in the virtual file system (VFS).\n *\n * @param path - The path to create the directory at.\n * @param options - Options for creating the directory.\n * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.\n */\n mkdirSync: (\n path: PathLike,\n options?: MakeDirectoryOptions\n ) => string | undefined;\n\n /**\n * Creates a directory in the virtual file system (VFS).\n *\n * @param path - The path to create the directory at.\n * @param options - Options for creating the directory.\n * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.\n */\n mkdir: (\n path: PathLike,\n options?: MakeDirectoryOptions\n ) => Promise<string | undefined>;\n\n /**\n * Reads a file from the virtual file system (VFS).\n *\n * @param pathOrId - The path or id of the file.\n * @returns The contents of the file if it exists, otherwise undefined.\n */\n readFile: (pathOrId: string) => Promise<string | undefined>;\n\n /**\n * Reads a file from the virtual file system (VFS).\n *\n * @param pathOrId - The path or id of the file.\n */\n readFileSync: (pathOrId: string) => string | undefined;\n\n /**\n * Writes a file to the virtual file system (VFS).\n *\n * @param file - The path to the file.\n * @param data - The contents of the file.\n * @param options - Optional parameters for writing the file.\n * @returns A promise that resolves when the file is written.\n */\n writeFile: (\n file: PathOrFileDescriptor,\n data: string | NodeJS.ArrayBufferView,\n options?: WriteFileOptions\n ) => Promise<void>;\n\n /**\n * Writes a file to the virtual file system (VFS).\n *\n * @param file - The path to the file.\n * @param data - The contents of the file.\n * @param options - Optional parameters for writing the file.\n */\n writeFileSync: (\n file: PathOrFileDescriptor,\n data: string | NodeJS.ArrayBufferView,\n options?: WriteFileOptions\n ) => void;\n\n /**\n * Adds a runtime file to the virtual file system.\n *\n * @param id - The unique identifier for the runtime file.\n * @param path - The path to the runtime file.\n * @param contents - The contents of the runtime file.\n * @param options - Optional parameters for writing the runtime file.\n */\n writeRuntimeFile: (\n id: string,\n path: string,\n contents: string,\n options?: { skipFormat?: boolean }\n ) => Promise<void>;\n\n /**\n * Adds an entry file to the virtual file system.\n *\n * @param name - The unique identifier for the entry file.\n * @param contents - The contents of the entry file.\n * @param options - Optional parameters for writing the entry file.\n */\n writeEntryFile: (\n name: string,\n contents: string,\n options?: { skipFormat?: boolean }\n ) => Promise<void>;\n\n /**\n * Writes a file to disk from the physical file system (on disk).\n *\n * @param path - The path to the file to write.\n * @param contents - The contents of the file to write.\n * @param options - Optional parameters for writing the file.\n * @returns A promise that resolves when the file is written.\n */\n writeFileToDisk: (\n path: string,\n contents: string,\n options?: { skipFormat?: boolean }\n ) => Promise<void>;\n\n /**\n * Resolves a path or ID to a file path in the virtual file system.\n *\n * @param pathOrId - The path or id of the file to resolve.\n * @param options - Optional parameters for resolving the path.\n * @returns The resolved path of the file if it exists, otherwise false.\n */\n resolvePath: (\n pathOrId: string,\n options?: ResolvePathOptions\n ) => string | false;\n\n /**\n * Resolves a path or ID to a file path in the virtual file system.\n *\n * @param pathOrId - The path or id of the file to resolve.\n * @returns The resolved path of the file if it exists, otherwise false.\n */\n realpathSync: (pathOrId: string) => string;\n\n /**\n * Resolves a path or ID to a runtime file id in the virtual file system.\n *\n * @param pathOrId - The path or id of the file to resolve.\n * @param paths - Optional array of paths to search for the file.\n * @returns The resolved id of the runtime file if it exists, otherwise false.\n */\n resolveId: (pathOrId: string) => string | false;\n\n /**\n * Resolves a path based on TypeScript's `tsconfig.json` paths.\n *\n * @see https://www.typescriptlang.org/tsconfig#paths\n *\n * @param path - The path to check.\n * @returns The resolved file path if it exists, otherwise undefined.\n */\n resolveTsconfigPath: (path: string) => string | false;\n\n /**\n * Resolves a package name based on TypeScript's `tsconfig.json` paths.\n *\n * @see https://www.typescriptlang.org/tsconfig#paths\n *\n * @param path - The path to check.\n * @returns The resolved package name if it exists, otherwise undefined.\n */\n resolveTsconfigPathPackage: (path: string) => string | false;\n\n /**\n * A map of cached file paths to their underlying file content.\n */\n [__VFS_CACHE__]: Map<string, string>;\n\n /**\n * A reference to the underlying virtual file system.\n */\n [__VFS_VIRTUAL__]: Volume;\n\n /**\n * A reference to the underlying unified file system.\n */\n [__VFS_UNIFIED__]: IUnionFs;\n}\n"]}