1 |
|
2 | import type { InstallOptions as EsinstallOptions } from '../vendor/types/esinstall';
|
3 | import type * as http from 'http';
|
4 | export interface RawSourceMap {
|
5 | version: number;
|
6 | sources: string[];
|
7 | names: string[];
|
8 | sourceRoot?: string;
|
9 | sourcesContent?: string[];
|
10 | mappings: string;
|
11 | file: string;
|
12 | }
|
13 | export declare type DeepPartial<T> = {
|
14 | [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>;
|
15 | };
|
16 | export interface SSRLoaderConfig {
|
17 | load: (url: string) => Promise<{
|
18 | contents: string;
|
19 | }>;
|
20 | }
|
21 | export interface SSRLoader {
|
22 | importModule: <T = any>(url: string) => Promise<ESMRuntimeModule<T>>;
|
23 | invalidateModule: (url: string) => void;
|
24 | }
|
25 | export interface ESMRuntimeModule<T> {
|
26 | exports: T;
|
27 | css: string[];
|
28 | }
|
29 | export interface LoadResult<T = Buffer | string> {
|
30 | contents: T;
|
31 | originalFileLoc: string | null;
|
32 | contentType: string | false;
|
33 | checkStale?: () => Promise<void>;
|
34 | }
|
35 | export declare type OnFileChangeCallback = ({ filePath: string }: {
|
36 | filePath: any;
|
37 | }) => any;
|
38 | export interface SnowpackDevServer {
|
39 | port: number;
|
40 | loadUrl: {
|
41 | (reqUrl: string, opt?: {
|
42 | isSSR?: boolean | undefined;
|
43 | allowStale?: boolean | undefined;
|
44 | encoding?: undefined;
|
45 | } | undefined): Promise<LoadResult<Buffer | string>>;
|
46 | (reqUrl: string, opt: {
|
47 | isSSR?: boolean;
|
48 | allowStale?: boolean;
|
49 | encoding: BufferEncoding;
|
50 | }): Promise<LoadResult<string>>;
|
51 | (reqUrl: string, opt: {
|
52 | isSSR?: boolean;
|
53 | allowStale?: boolean;
|
54 | encoding: null;
|
55 | }): Promise<LoadResult<Buffer>>;
|
56 | };
|
57 | handleRequest: (req: http.IncomingMessage, res: http.ServerResponse, options?: {
|
58 | handleError?: boolean;
|
59 | }) => Promise<void>;
|
60 | sendResponseFile: (req: http.IncomingMessage, res: http.ServerResponse, { contents, originalFileLoc, contentType }: LoadResult) => void;
|
61 | getServerRuntime: (options?: {
|
62 | invalidateOnChange?: boolean;
|
63 | }) => SSRLoader;
|
64 | sendResponseError: (req: http.IncomingMessage, res: http.ServerResponse, status: number) => void;
|
65 | getUrlForFile: (fileLoc: string) => string | null;
|
66 | onFileChange: (callback: OnFileChangeCallback) => void;
|
67 | shutdown(): Promise<void>;
|
68 | }
|
69 | export declare type SnowpackBuildResultFileManifest = Record<string, {
|
70 | source: string | null;
|
71 | contents: string | Buffer;
|
72 | }>;
|
73 | export interface SnowpackBuildResult {
|
74 | result: SnowpackBuildResultFileManifest;
|
75 | onFileChange: (callback: OnFileChangeCallback) => void;
|
76 | shutdown(): Promise<void>;
|
77 | }
|
78 | export declare type SnowpackBuiltFile = {
|
79 | code: string | Buffer;
|
80 | map?: string;
|
81 | };
|
82 | export declare type SnowpackBuildMap = Record<string, SnowpackBuiltFile>;
|
83 |
|
84 | export interface SnowpackSourceFile<Type = string | Buffer> {
|
85 |
|
86 | baseExt: string;
|
87 |
|
88 | contents: Type;
|
89 |
|
90 | locOnDisk: string;
|
91 |
|
92 | root: string;
|
93 | }
|
94 | export interface PluginLoadOptions {
|
95 |
|
96 | filePath: string;
|
97 |
|
98 | fileExt: string;
|
99 |
|
100 | isDev: boolean;
|
101 |
|
102 | isSSR: boolean;
|
103 |
|
104 | isHmrEnabled: boolean;
|
105 | }
|
106 | export interface PluginTransformOptions {
|
107 | id: string;
|
108 | fileExt: string;
|
109 | contents: string | Buffer;
|
110 | isDev: boolean;
|
111 | isHmrEnabled: boolean;
|
112 | }
|
113 | export interface PluginRunOptions {
|
114 | isDev: boolean;
|
115 | }
|
116 |
|
117 | export declare type PluginLoadResult = SnowpackBuildMap;
|
118 | export declare type PluginTransformResult = {
|
119 | contents: string;
|
120 | map: string | RawSourceMap;
|
121 | };
|
122 | export interface PluginOptimizeOptions {
|
123 | buildDirectory: string;
|
124 | }
|
125 | export interface SnowpackPlugin {
|
126 |
|
127 | name: string;
|
128 |
|
129 | resolve?: {
|
130 | |
131 |
|
132 |
|
133 |
|
134 | input: string[];
|
135 | |
136 |
|
137 |
|
138 | output: string[];
|
139 | };
|
140 |
|
141 | load?(options: PluginLoadOptions): Promise<PluginLoadResult | string | null | undefined | void>;
|
142 |
|
143 | transform?(options: PluginTransformOptions): Promise<PluginTransformResult | string | null | undefined | void>;
|
144 |
|
145 | run?(options: PluginRunOptions): Promise<unknown>;
|
146 |
|
147 | optimize?(options: PluginOptimizeOptions): Promise<void>;
|
148 |
|
149 | cleanup?(): void | Promise<void>;
|
150 |
|
151 | knownEntrypoints?: string[];
|
152 |
|
153 | config?(snowpackConfig: SnowpackConfig): void;
|
154 |
|
155 | onChange?({ filePath }: {
|
156 | filePath: string;
|
157 | }): void;
|
158 |
|
159 | markChanged?(file: string): void;
|
160 | }
|
161 |
|
162 | export declare type SnowpackPluginFactory<PluginOptions = object> = (snowpackConfig: SnowpackConfig, pluginOptions?: PluginOptions) => SnowpackPlugin;
|
163 | export declare type MountEntry = {
|
164 | url: string;
|
165 | static: boolean;
|
166 | resolve: boolean;
|
167 | };
|
168 | export interface OptimizeOptions {
|
169 | entrypoints: 'auto' | string[] | ((options: {
|
170 | files: string[];
|
171 | }) => string[]);
|
172 | preload: boolean;
|
173 | bundle: boolean;
|
174 | splitting: boolean;
|
175 | treeshake: boolean;
|
176 | manifest: boolean;
|
177 | minify: boolean;
|
178 | target: 'es2020' | 'es2019' | 'es2018' | 'es2017';
|
179 | }
|
180 | export interface RouteConfigObject {
|
181 | src: string;
|
182 | dest: string | ((req: http.IncomingMessage, res: http.ServerResponse) => void);
|
183 | match: 'routes' | 'all';
|
184 | _srcRegex: RegExp;
|
185 | }
|
186 | export interface PackageSourceLocal extends Omit<EsinstallOptions, 'alias' | 'dest' | 'sourcemap' | 'verbose' | 'logger' | 'cwd' | 'dest' | 'treeshake'> {
|
187 | source: 'local';
|
188 | external: string[];
|
189 | knownEntrypoints: string[];
|
190 | }
|
191 | export interface PackageSourceRemote {
|
192 | source: 'remote';
|
193 | origin: string;
|
194 | external: string[];
|
195 | cache: string;
|
196 | types: boolean;
|
197 | }
|
198 | export interface SnowpackConfig {
|
199 | root: string;
|
200 | extends?: string;
|
201 | exclude: string[];
|
202 | mount: Record<string, MountEntry>;
|
203 | alias: Record<string, string>;
|
204 | plugins: SnowpackPlugin[];
|
205 | devOptions: {
|
206 | secure: boolean;
|
207 | hostname: string;
|
208 | port: number;
|
209 | fallback: string;
|
210 | open: string;
|
211 | output: 'stream' | 'dashboard';
|
212 | hmr?: boolean;
|
213 | hmrDelay: number;
|
214 | hmrPort: number | undefined;
|
215 | hmrErrorOverlay: boolean;
|
216 | };
|
217 | buildOptions: {
|
218 | out: string;
|
219 | baseUrl: string;
|
220 | metaUrlPath: string;
|
221 | clean: boolean;
|
222 | sourcemap: boolean;
|
223 | watch: boolean;
|
224 | htmlFragments: boolean;
|
225 | jsxFactory: string | undefined;
|
226 | jsxFragment: string | undefined;
|
227 | ssr: boolean;
|
228 | };
|
229 | testOptions: {
|
230 | files: string[];
|
231 | };
|
232 | packageOptions: PackageSourceLocal | PackageSourceRemote;
|
233 | /** Optimize your site for production. */
|
234 | optimize?: OptimizeOptions;
|
235 | /** Configure routes during development. */
|
236 | routes: RouteConfigObject[];
|
237 | /** EXPERIMENTAL - This section is experimental and not yet finalized. May change across minor versions. */
|
238 | experiments: {};
|
239 | _extensionMap: Record<string, string[]>;
|
240 | }
|
241 | export declare type SnowpackUserConfig = {
|
242 | root?: string;
|
243 | install?: string[];
|
244 | extends?: string;
|
245 | exclude?: string[];
|
246 | mount?: Record<string, string | Partial<MountEntry>>;
|
247 | alias?: Record<string, string>;
|
248 | plugins?: (string | [string, any])[];
|
249 | devOptions?: Partial<SnowpackConfig['devOptions']>;
|
250 | buildOptions?: Partial<SnowpackConfig['buildOptions']>;
|
251 | testOptions?: Partial<SnowpackConfig['testOptions']>;
|
252 | packageOptions?: Partial<SnowpackConfig['packageOptions']>;
|
253 | optimize?: Partial<SnowpackConfig['optimize']>;
|
254 | routes?: Pick<RouteConfigObject, 'src' | 'dest' | 'match'>[];
|
255 | experiments?: {};
|
256 | };
|
257 | export interface CLIFlags {
|
258 | help?: boolean;
|
259 | version?: boolean;
|
260 | reload?: boolean;
|
261 | root?: string;
|
262 | config?: string;
|
263 | env?: string[];
|
264 | open?: string[];
|
265 | secure?: boolean;
|
266 | verbose?: boolean;
|
267 | quiet?: boolean;
|
268 | [flag: string]: any;
|
269 | }
|
270 | export interface ImportMap {
|
271 | imports: {
|
272 | [specifier: string]: string;
|
273 | };
|
274 | }
|
275 | export interface LockfileManifest {
|
276 | dependencies: {
|
277 | [packageName: string]: string;
|
278 | };
|
279 | lock: {
|
280 | [specifier: string]: string;
|
281 | };
|
282 | }
|
283 | export interface CommandOptions {
|
284 | config: SnowpackConfig;
|
285 | lockfile: LockfileManifest | null;
|
286 | }
|
287 | export declare type LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
288 | export declare type LoggerEvent = 'debug' | 'info' | 'warn' | 'error';
|
289 | export interface LoggerOptions {
|
290 | /** (optional) change name at beginning of line */
|
291 | name?: string;
|
292 | /** (optional) do some additional work after logging a message, if log level is enabled */
|
293 | task?: Function;
|
294 | }
|
295 | /** PackageSource - a common interface for loading and interacting with dependencies. */
|
296 | export interface PackageSource {
|
297 | /**
|
298 | * Do any work needed before starting the dev server or build. Either will wait
|
299 | * for this to complete before continuing. Example: For "local", this involves
|
300 | * running esinstall (if needed) to prepare your local dependencies as ESM.
|
301 | */
|
302 | prepare(commandOptions: CommandOptions): Promise<ImportMap>;
|
303 | /**
|
304 | * Load a dependency with the given spec (ex: "/pkg/react" -> "react")
|
305 | * If load fails or is unsuccessful, reject the promise.
|
306 | */
|
307 | load(spec: string, options: {
|
308 | config: SnowpackConfig;
|
309 | lockfile: LockfileManifest | null;
|
310 | }): Promise<Buffer | string>;
|
311 | /** Resolve a package import to URL (ex: "react" -> "/pkg/react") */
|
312 | resolvePackageImport(spec: string, importMap: ImportMap, config: SnowpackConfig): string | false;
|
313 | /** Handle 1+ missing package imports before failing, if possible. */
|
314 | recoverMissingPackageImport(missingPackages: string[], config: SnowpackConfig): Promise<ImportMap>;
|
315 | /** Modify the build install config for optimized build install. */
|
316 | modifyBuildInstallOptions(options: {
|
317 | installOptions: EsinstallOptions;
|
318 | config: SnowpackConfig;
|
319 | lockfile: LockfileManifest | null;
|
320 | }): EsinstallOptions;
|
321 | getCacheFolder(config: SnowpackConfig): string;
|
322 | clearCache(): void | Promise<void>;
|
323 | }
|
324 |
|
\ | No newline at end of file |