UNPKG

14.1 kBTypeScriptView Raw
1/**
2 * Webpack module API - variables and global functions available inside modules
3 */
4
5declare namespace __WebpackModuleApi {
6 type ModuleId = string | number;
7
8 interface RequireResolve {
9 (id: string): ModuleId;
10 }
11
12 interface RequireContext {
13 keys(): string[];
14 (id: string): any;
15 <T>(id: string): T;
16 resolve(id: string): string;
17 /** The module id of the context module. This may be useful for module.hot.accept. */
18 id: ModuleId;
19 }
20
21 interface RequireFunction {
22 /**
23 * Returns the exports from a dependency. The call is sync. No request to the server is fired. The compiler ensures that the dependency is available.
24 */
25 (path: string): any;
26 <T>(path: string): T;
27 /**
28 * Behaves similar to require.ensure, but the callback is called with the exports of each dependency in the paths array. There is no option to provide a chunk name.
29 */
30 (paths: string[], callback: (...modules: any[]) => void): void;
31 /**
32 * Download additional dependencies on demand. The paths array lists modules that should be available. When they are, callback is called. If the callback is a function expression, dependencies in that source part are extracted and also loaded on demand. A single request is fired to the server, except if all modules are already available.
33 *
34 * This creates a chunk. The chunk can be named. If a chunk with this name already exists, the dependencies are merged into that chunk and that chunk is used.
35 */
36 ensure(paths: string[], callback: (require: NodeRequire) => void, chunkName?: string): void;
37 ensure(
38 paths: string[],
39 callback: (require: NodeRequire) => void,
40 errorCallback?: (error: any) => void,
41 chunkName?: string,
42 ): void;
43 context(
44 path: string,
45 deep?: boolean,
46 filter?: RegExp,
47 mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once",
48 ): RequireContext;
49 /**
50 * Returns the module id of a dependency. The call is sync. No request to the server is fired. The compiler ensures that the dependency is available.
51 *
52 * The module id is a number in webpack (in contrast to node.js where it is a string, the filename).
53 */
54 resolve: NodeJS.RequireResolve;
55 /**
56 * Like require.resolve, but doesn’t include the module into the bundle. It’s a weak dependency.
57 */
58 resolveWeak(path: string): ModuleId;
59 /**
60 * Ensures that the dependency is available, but don’t execute it. This can be use for optimizing the position of a module in the chunks.
61 */
62 include(path: string): void;
63 /**
64 * Multiple requires to the same module result in only one module execution and only one export. Therefore a cache in the runtime exists. Removing values from this cache cause new module execution and a new export. This is only needed in rare cases (for compatibility!).
65 */
66 cache: {
67 [id: string]: NodeModule | undefined;
68 };
69 }
70
71 interface Module {
72 exports: any;
73 id: ModuleId;
74 filename: string;
75 loaded: boolean;
76 parent: NodeModule | null | undefined;
77 children: NodeModule[];
78 hot?: Hot | undefined;
79 }
80
81 interface HotNotifierInfo {
82 type:
83 | "self-declined"
84 | "declined"
85 | "unaccepted"
86 | "accepted"
87 | "disposed"
88 | "accept-errored"
89 | "self-accept-errored"
90 | "self-accept-error-handler-errored";
91 /**
92 * The module in question.
93 */
94 moduleId: number;
95 /**
96 * For errors: the module id owning the accept handler.
97 */
98 dependencyId?: number | undefined;
99 /**
100 * For declined/accepted/unaccepted: the chain from where the update was propagated.
101 */
102 chain?: number[] | undefined;
103 /**
104 * For declined: the module id of the declining parent
105 */
106 parentId?: number | undefined;
107 /**
108 * For accepted: the modules that are outdated and will be disposed
109 */
110 outdatedModules?: number[] | undefined;
111 /**
112 * For accepted: The location of accept handlers that will handle the update
113 */
114 outdatedDependencies?: {
115 [dependencyId: number]: number[];
116 } | undefined;
117 /**
118 * For errors: the thrown error
119 */
120 error?: Error | undefined;
121 /**
122 * For self-accept-error-handler-errored: the error thrown by the module
123 * before the error handler tried to handle it.
124 */
125 originalError?: Error | undefined;
126 }
127
128 interface Hot {
129 /**
130 * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
131 * @param dependencies
132 * @param callback
133 * @param errorHandler
134 */
135 accept(
136 dependencies: string[],
137 callback?: (updatedDependencies: ModuleId[]) => void,
138 errorHandler?: (err: Error) => void,
139 ): void;
140 /**
141 * Accept code updates for the specified dependencies. The callback is called when dependencies were replaced.
142 * @param dependency
143 * @param callback
144 * @param errorHandler
145 */
146 accept(dependency: string, callback?: () => void, errorHandler?: (err: Error) => void): void;
147 /**
148 * Accept code updates for this module without notification of parents.
149 * This should only be used if the module doesn’t export anything.
150 * The errHandler can be used to handle errors that occur while loading the updated module.
151 * @param errHandler
152 */
153 accept(errHandler?: (err: Error) => void): void;
154 /**
155 * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
156 */
157 decline(dependencies: string[]): void;
158 /**
159 * Do not accept updates for the specified dependencies. If any dependencies is updated, the code update fails with code "decline".
160 */
161 decline(dependency: string): void;
162 /**
163 * Flag the current module as not update-able. If updated the update code would fail with code "decline".
164 */
165 decline(): void;
166 /**
167 * Add a one time handler, which is executed when the current module code is replaced.
168 * Here you should destroy/remove any persistent resource you have claimed/created.
169 * If you want to transfer state to the new module, add it to data object.
170 * The data will be available at module.hot.data on the new module.
171 * @param callback
172 */
173 dispose(callback: (data: any) => void): void;
174 dispose(callback: <T>(data: T) => void): void;
175 /**
176 * Add a one time handler, which is executed when the current module code is replaced.
177 * Here you should destroy/remove any persistent resource you have claimed/created.
178 * If you want to transfer state to the new module, add it to data object.
179 * The data will be available at module.hot.data on the new module.
180 * @param callback
181 */
182 addDisposeHandler(callback: (data: any) => void): void;
183 addDisposeHandler<T>(callback: (data: T) => void): void;
184 /**
185 * Remove a handler.
186 * This can useful to add a temporary dispose handler. You could i. e. replace code while in the middle of a multi-step async function.
187 * @param callback
188 */
189 removeDisposeHandler(callback: (data: any) => void): void;
190 removeDisposeHandler<T>(callback: (data: T) => void): void;
191 /**
192 * Throws an exceptions if status() is not idle.
193 * Check all currently loaded modules for updates and apply updates if found.
194 * If no update was found, the callback is called with null.
195 * If autoApply is truthy the callback will be called with all modules that were disposed.
196 * apply() is automatically called with autoApply as options parameter.
197 * If autoApply is not set the callback will be called with all modules that will be disposed on apply().
198 * @param autoApply
199 */
200 check(autoApply?: boolean): Promise<null | ModuleId[]>;
201 /**
202 * If status() != "ready" it throws an error.
203 * Continue the update process.
204 * @param options
205 */
206 apply(options?: AcceptOptions): Promise<ModuleId[]>;
207 /**
208 * Return one of idle, check, watch, watch-delay, prepare, ready, dispose, apply, abort or fail.
209 */
210 status(): string;
211 /** Register a callback on status change. */
212 status(callback: (status: string) => void): void;
213 /** Register a callback on status change. */
214 addStatusHandler(callback: (status: string) => void): void;
215 /**
216 * Remove a registered status change handler.
217 * @param callback
218 */
219 removeStatusHandler(callback: (status: string) => void): void;
220
221 active: boolean;
222 data: any;
223 }
224
225 interface AcceptOptions {
226 /**
227 * If true the update process continues even if some modules are not accepted (and would bubble to the entry point).
228 */
229 ignoreUnaccepted?: boolean | undefined;
230 /**
231 * Ignore changes made to declined modules.
232 */
233 ignoreDeclined?: boolean | undefined;
234 /**
235 * Ignore errors throw in accept handlers, error handlers and while reevaluating module.
236 */
237 ignoreErrored?: boolean | undefined;
238 /**
239 * Notifier for declined modules.
240 */
241 onDeclined?: ((info: HotNotifierInfo) => void) | undefined;
242 /**
243 * Notifier for unaccepted modules.
244 */
245 onUnaccepted?: ((info: HotNotifierInfo) => void) | undefined;
246 /**
247 * Notifier for accepted modules.
248 */
249 onAccepted?: ((info: HotNotifierInfo) => void) | undefined;
250 /**
251 * Notifier for disposed modules.
252 */
253 onDisposed?: ((info: HotNotifierInfo) => void) | undefined;
254 /**
255 * Notifier for errors.
256 */
257 onErrored?: ((info: HotNotifierInfo) => void) | undefined;
258 /**
259 * Indicates that apply() is automatically called by check function
260 */
261 autoApply?: boolean | undefined;
262 }
263 /**
264 * Inside env you can pass any variable
265 */
266 interface NodeProcess {
267 env?: any;
268 }
269
270 type __Require1 = (id: string) => any;
271 type __Require2 = <T>(id: string) => T;
272 type RequireLambda = __Require1 & __Require2;
273}
274
275interface NodeRequire extends NodeJS.Require {}
276
277declare var require: NodeRequire;
278
279/**
280 * The resource query of the current module.
281 *
282 * e.g. __resourceQuery === "?test" // Inside "file.js?test"
283 */
284declare var __resourceQuery: string;
285
286/**
287 * Equals the config options output.publicPath.
288 */
289declare var __webpack_public_path__: string;
290
291/**
292 * The raw require function. This expression isn’t parsed by the Parser for dependencies.
293 */
294declare var __webpack_require__: any;
295
296/**
297 * The internal chunk loading function
298 *
299 * @param chunkId The id for the chunk to load.
300 */
301declare var __webpack_chunk_load__: (chunkId: any) => Promise<any>;
302
303/**
304 * Access to the internal object of all modules.
305 */
306declare var __webpack_modules__: any[];
307
308/**
309 * Access to the hash of the compilation.
310 *
311 * Only available with the HotModuleReplacementPlugin or the ExtendedAPIPlugin
312 */
313declare var __webpack_hash__: any;
314
315/**
316 * Generates a require function that is not parsed by webpack. Can be used to do cool stuff with a global require function if available.
317 */
318declare var __non_webpack_require__: any;
319
320/**
321 * Initializes the shared scope. Fills it with known provided modules from this build and all remotes
322 */
323declare var __webpack_init_sharing__: (scope: string) => Promise<void>;
324
325/**
326 * Adds nonce to all scripts that webpack loads.
327 *
328 * To activate the feature a __webpack_nonce__ variable needs to be set in your entry script.
329 */
330declare var __webpack_nonce__: string;
331
332/**
333 * Equals the config option debug
334 */
335declare var DEBUG: boolean;
336
337interface ImportMeta {
338 /**
339 * `import.meta.url` is the `file:` url of the current file (similar to `__filename` but as file url)
340 */
341 url: string;
342 /**
343 * `import.meta.webpack` is the webpack major version as number
344 */
345 webpack: number;
346 /**
347 * `import.meta.webpackHot` is an alias for` module.hot` which is also available in strict ESM
348 */
349 webpackHot?: __WebpackModuleApi.Hot | undefined;
350 /**
351 * `import.meta.webpackContext` as ESM alternative to `require.context`
352 * Available: 5.70.0+
353 */
354 webpackContext?: (
355 request: string,
356 options?: {
357 recursive?: boolean;
358 regExp?: RegExp;
359 include?: RegExp;
360 exclude?: RegExp;
361 preload?: boolean | number;
362 prefetch?: boolean | number;
363 chunkName?: string;
364 exports?: string | string[][];
365 mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
366 },
367 ) => __WebpackModuleApi.RequireContext;
368}
369
370interface NodeModule extends NodeJS.Module {}
371
372declare var module: NodeModule;
373
374/**
375 * Declare process variable
376 */
377declare namespace NodeJS {
378 interface Process extends __WebpackModuleApi.NodeProcess {}
379 interface RequireResolve extends __WebpackModuleApi.RequireResolve {}
380 interface Module extends __WebpackModuleApi.Module {}
381 interface Require extends __WebpackModuleApi.RequireFunction {}
382}
383declare var process: NodeJS.Process;