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