/// import type { InstallOptions as EsinstallOptions } from '../vendor/types/esinstall'; import type * as http from 'http'; export interface RawSourceMap { version: number; sources: string[]; names: string[]; sourceRoot?: string; sourcesContent?: string[]; mappings: string; file: string; } export declare type DeepPartial = { [P in keyof T]?: T[P] extends Array ? Array> : T[P] extends ReadonlyArray ? ReadonlyArray> : DeepPartial; }; export interface SSRLoaderConfig { load: (url: string) => Promise<{ contents: string; }>; } export interface SSRLoader { importModule: (url: string) => Promise>; invalidateModule: (url: string) => void; } export interface ESMRuntimeModule { exports: T; css: string[]; } export interface LoadResult { contents: T; originalFileLoc: string | null; contentType: string | false; checkStale?: () => Promise; } export declare type OnFileChangeCallback = ({ filePath: string }: { filePath: any; }) => any; export interface SnowpackDevServer { port: number; loadUrl: { (reqUrl: string, opt?: { isSSR?: boolean | undefined; allowStale?: boolean | undefined; encoding?: undefined; } | undefined): Promise>; (reqUrl: string, opt: { isSSR?: boolean; allowStale?: boolean; encoding: BufferEncoding; }): Promise>; (reqUrl: string, opt: { isSSR?: boolean; allowStale?: boolean; encoding: null; }): Promise>; }; handleRequest: (req: http.IncomingMessage, res: http.ServerResponse, options?: { handleError?: boolean; }) => Promise; sendResponseFile: (req: http.IncomingMessage, res: http.ServerResponse, { contents, originalFileLoc, contentType }: LoadResult) => void; getServerRuntime: (options?: { invalidateOnChange?: boolean; }) => SSRLoader; sendResponseError: (req: http.IncomingMessage, res: http.ServerResponse, status: number) => void; getUrlForFile: (fileLoc: string) => string | null; onFileChange: (callback: OnFileChangeCallback) => void; shutdown(): Promise; } export declare type SnowpackBuildResultFileManifest = Record; export interface SnowpackBuildResult { result: SnowpackBuildResultFileManifest; onFileChange: (callback: OnFileChangeCallback) => void; shutdown(): Promise; } export declare type SnowpackBuiltFile = { code: string | Buffer; map?: string; }; export declare type SnowpackBuildMap = Record; /** Standard file interface */ export interface SnowpackSourceFile { /** base extension (e.g. `.js`) */ baseExt: string; /** file contents */ contents: Type; /** if no location on disk, assume this exists in memory */ locOnDisk: string; /** project "root" directory */ root: string; } export interface PluginLoadOptions { /** The absolute file path of the source file, on disk. */ filePath: string; /** A helper for just the file extension of the source file (ex: ".js", ".svelte") */ fileExt: string; /** True if builder is in dev mode (`snowpack dev` or `snowpack build --watch`) */ isDev: boolean; /** True if builder is in SSR mode */ isSSR: boolean; /** True if HMR is enabled (add any HMR code to the output here). */ isHmrEnabled: boolean; } export interface PluginTransformOptions { id: string; fileExt: string; contents: string | Buffer; isDev: boolean; isHmrEnabled: boolean; } export interface PluginRunOptions { isDev: boolean; } /** map of extensions -> code (e.g. { ".js": "[code]", ".css": "[code]" }) */ export declare type PluginLoadResult = SnowpackBuildMap; export declare type PluginTransformResult = { contents: string; map: string | RawSourceMap; }; export interface PluginOptimizeOptions { buildDirectory: string; } export interface SnowpackPlugin { /** name of the plugin */ name: string; /** Tell Snowpack how the load() function will resolve files. */ resolve?: { /** file extensions that this load function takes as input (e.g. [".jsx", ".js", …]) */ input: string[]; /** file extensions that this load function outputs (e.g. [".js", ".css"]) */ output: string[]; }; /** load a file that matches resolve.input */ load?(options: PluginLoadOptions): Promise; /** transform a file that matches resolve.input */ transform?(options: PluginTransformOptions): Promise; /** runs a command, unrelated to file building (e.g. TypeScript, ESLint) */ run?(options: PluginRunOptions): Promise; /** optimize the entire built application */ optimize?(options: PluginOptimizeOptions): Promise; /** cleanup any long-running instances/services before exiting. */ cleanup?(): void | Promise; /** Known dependencies that should be installed */ knownEntrypoints?: string[]; /** read and modify the Snowpack config object */ config?(snowpackConfig: SnowpackConfig): void; /** Called when a watched file changes during development. */ onChange?({ filePath }: { filePath: string; }): void; /** (internal interface, not set by the user) Mark a file as changed. */ markChanged?(file: string): void; } /** Snowpack Build Plugin type */ export declare type SnowpackPluginFactory = (snowpackConfig: SnowpackConfig, pluginOptions?: PluginOptions) => SnowpackPlugin; export declare type MountEntry = { url: string; static: boolean; resolve: boolean; }; export interface OptimizeOptions { entrypoints: 'auto' | string[] | ((options: { files: string[]; }) => string[]); preload: boolean; bundle: boolean; splitting: boolean; treeshake: boolean; manifest: boolean; minify: boolean; target: 'es2020' | 'es2019' | 'es2018' | 'es2017'; } export interface RouteConfigObject { src: string; dest: string | ((req: http.IncomingMessage, res: http.ServerResponse) => void); match: 'routes' | 'all'; _srcRegex: RegExp; } export interface PackageSourceLocal extends Omit { source: 'local'; external: string[]; knownEntrypoints: string[]; } export interface PackageSourceRemote { source: 'remote'; origin: string; external: string[]; cache: string; types: boolean; } export interface SnowpackConfig { root: string; extends?: string; exclude: string[]; mount: Record; alias: Record; plugins: SnowpackPlugin[]; devOptions: { secure: boolean; hostname: string; port: number; fallback: string; open: string; output: 'stream' | 'dashboard'; hmr?: boolean; hmrDelay: number; hmrPort: number | undefined; hmrErrorOverlay: boolean; }; buildOptions: { out: string; baseUrl: string; metaUrlPath: string; clean: boolean; sourcemap: boolean; watch: boolean; htmlFragments: boolean; jsxFactory: string | undefined; jsxFragment: string | undefined; ssr: boolean; }; testOptions: { files: string[]; }; packageOptions: PackageSourceLocal | PackageSourceRemote; /** Optimize your site for production. */ optimize?: OptimizeOptions; /** Configure routes during development. */ routes: RouteConfigObject[]; /** EXPERIMENTAL - This section is experimental and not yet finalized. May change across minor versions. */ experiments: {}; _extensionMap: Record; } export declare type SnowpackUserConfig = { root?: string; install?: string[]; extends?: string; exclude?: string[]; mount?: Record>; alias?: Record; plugins?: (string | [string, any])[]; devOptions?: Partial; buildOptions?: Partial; testOptions?: Partial; packageOptions?: Partial; optimize?: Partial; routes?: Pick[]; experiments?: {}; }; export interface CLIFlags { help?: boolean; version?: boolean; reload?: boolean; root?: string; config?: string; env?: string[]; open?: string[]; secure?: boolean; verbose?: boolean; quiet?: boolean; [flag: string]: any; } export interface ImportMap { imports: { [specifier: string]: string; }; } export interface LockfileManifest { dependencies: { [packageName: string]: string; }; lock: { [specifier: string]: string; }; } export interface CommandOptions { config: SnowpackConfig; lockfile: LockfileManifest | null; } export declare type LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent'; export declare type LoggerEvent = 'debug' | 'info' | 'warn' | 'error'; export interface LoggerOptions { /** (optional) change name at beginning of line */ name?: string; /** (optional) do some additional work after logging a message, if log level is enabled */ task?: Function; } /** PackageSource - a common interface for loading and interacting with dependencies. */ export interface PackageSource { /** * Do any work needed before starting the dev server or build. Either will wait * for this to complete before continuing. Example: For "local", this involves * running esinstall (if needed) to prepare your local dependencies as ESM. */ prepare(commandOptions: CommandOptions): Promise; /** * Load a dependency with the given spec (ex: "/pkg/react" -> "react") * If load fails or is unsuccessful, reject the promise. */ load(spec: string, options: { config: SnowpackConfig; lockfile: LockfileManifest | null; }): Promise; /** Resolve a package import to URL (ex: "react" -> "/pkg/react") */ resolvePackageImport(spec: string, importMap: ImportMap, config: SnowpackConfig): string | false; /** Handle 1+ missing package imports before failing, if possible. */ recoverMissingPackageImport(missingPackages: string[], config: SnowpackConfig): Promise; /** Modify the build install config for optimized build install. */ modifyBuildInstallOptions(options: { installOptions: EsinstallOptions; config: SnowpackConfig; lockfile: LockfileManifest | null; }): EsinstallOptions; getCacheFolder(config: SnowpackConfig): string; clearCache(): void | Promise; }