You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

394 lines
9.6KB

  1. declare module "*.json";
  2. // Deprecated NodeJS API usages in Webpack
  3. declare namespace NodeJS {
  4. interface Process {
  5. binding(internalModule: string): any;
  6. }
  7. }
  8. // TODO remove when https://github.com/DefinitelyTyped/DefinitelyTyped/pull/38753 is merged
  9. declare module "util" {
  10. function deprecate<T extends Function>(
  11. fn: T,
  12. message: string,
  13. code: string
  14. ): T;
  15. }
  16. declare module "neo-async" {
  17. interface QueueObject<T, E> {
  18. push(item: T): void;
  19. drain: () => void;
  20. error: (err: E) => void;
  21. }
  22. export interface Dictionary<T> {
  23. [key: string]: T;
  24. }
  25. export type IterableCollection<T> = T[] | Iterable<T> | Dictionary<T>;
  26. export interface ErrorCallback<T> {
  27. (err?: T): void;
  28. }
  29. export interface AsyncBooleanResultCallback<E> {
  30. (err?: E, truthValue?: boolean): void;
  31. }
  32. export interface AsyncResultCallback<T, E> {
  33. (err?: E, result?: T): void;
  34. }
  35. export interface AsyncResultArrayCallback<T, E> {
  36. (err?: E, results?: Array<T | undefined>): void;
  37. }
  38. export interface AsyncResultObjectCallback<T, E> {
  39. (err: E | undefined, results: Dictionary<T | undefined>): void;
  40. }
  41. export interface AsyncFunction<T, E> {
  42. (callback: (err?: E, result?: T) => void): void;
  43. }
  44. export interface AsyncFunctionEx<T, E> {
  45. (callback: (err?: E, ...results: T[]) => void): void;
  46. }
  47. export interface AsyncIterator<T, E> {
  48. (item: T, callback: ErrorCallback<E>): void;
  49. }
  50. export interface AsyncForEachOfIterator<T, E> {
  51. (item: T, key: number | string, callback: ErrorCallback<E>): void;
  52. }
  53. export interface AsyncResultIterator<T, R, E> {
  54. (item: T, callback: AsyncResultCallback<R, E>): void;
  55. }
  56. export interface AsyncMemoIterator<T, R, E> {
  57. (memo: R | undefined, item: T, callback: AsyncResultCallback<R, E>): void;
  58. }
  59. export interface AsyncBooleanIterator<T, E> {
  60. (item: T, callback: AsyncBooleanResultCallback<E>): void;
  61. }
  62. export interface AsyncWorker<T, E> {
  63. (task: T, callback: ErrorCallback<E>): void;
  64. }
  65. export interface AsyncVoidFunction<E> {
  66. (callback: ErrorCallback<E>): void;
  67. }
  68. export type AsyncAutoTasks<R extends Dictionary<any>, E> = {
  69. [K in keyof R]: AsyncAutoTask<R[K], R, E>;
  70. };
  71. export type AsyncAutoTask<R1, R extends Dictionary<any>, E> =
  72. | AsyncAutoTaskFunctionWithoutDependencies<R1, E>
  73. | (keyof R | AsyncAutoTaskFunction<R1, R, E>)[];
  74. export interface AsyncAutoTaskFunctionWithoutDependencies<R1, E> {
  75. (cb: AsyncResultCallback<R1, E> | ErrorCallback<E>): void;
  76. }
  77. export interface AsyncAutoTaskFunction<R1, R extends Dictionary<any>, E> {
  78. (results: R, cb: AsyncResultCallback<R1, E> | ErrorCallback<E>): void;
  79. }
  80. export function each<T, E>(
  81. arr: IterableCollection<T>,
  82. iterator: AsyncIterator<T, E>,
  83. callback?: ErrorCallback<E>
  84. ): void;
  85. export function eachLimit<T, E>(
  86. arr: IterableCollection<T>,
  87. limit: number,
  88. iterator: AsyncIterator<T, E>,
  89. callback?: ErrorCallback<E>
  90. ): void;
  91. export function map<T, R, E>(
  92. arr: T[] | IterableIterator<T>,
  93. iterator: AsyncResultIterator<T, R, E>,
  94. callback?: AsyncResultArrayCallback<R, E>
  95. ): void;
  96. export function map<T, R, E>(
  97. arr: Dictionary<T>,
  98. iterator: AsyncResultIterator<T, R, E>,
  99. callback?: AsyncResultArrayCallback<R, E>
  100. ): void;
  101. export function parallel<T, E>(
  102. tasks: Array<AsyncFunction<T, E>>,
  103. callback?: AsyncResultArrayCallback<T, E>
  104. ): void;
  105. export function parallel<T, E>(
  106. tasks: Dictionary<AsyncFunction<T, E>>,
  107. callback?: AsyncResultObjectCallback<T, E>
  108. ): void;
  109. export function queue<T, E>(
  110. worker: AsyncFunction<T, E>,
  111. concurrency?: number
  112. ): QueueObject<T, E>;
  113. export const forEach: typeof each;
  114. export const forEachLimit: typeof eachLimit;
  115. }
  116. // There are no typings for @webassemblyjs/ast
  117. declare module "@webassemblyjs/ast" {
  118. export function traverse(
  119. ast: any,
  120. visitor: {
  121. ModuleImport?: (p: NodePath<ModuleImport>) => void;
  122. ModuleExport?: (p: NodePath<ModuleExport>) => void;
  123. Start?: (p: NodePath<Start>) => void;
  124. Global?: (p: NodePath<Global>) => void;
  125. }
  126. ): void;
  127. export class NodePath<T> {
  128. node: T;
  129. }
  130. export class Node {}
  131. export class Identifier extends Node {
  132. value: string;
  133. }
  134. export class Start extends Node {
  135. index: Identifier;
  136. }
  137. export class ModuleImportDescription {
  138. type: string;
  139. valtype?: string;
  140. id?: Identifier;
  141. signature?: Signature;
  142. }
  143. export class ModuleImport extends Node {
  144. module: string;
  145. descr: ModuleImportDescription;
  146. name: string;
  147. }
  148. export class ModuleExport extends Node {
  149. name: string;
  150. descr: ModuleExportDescr;
  151. }
  152. type Index = Identifier | NumberLiteral;
  153. export class ModuleExportDescr extends Node {
  154. type: string;
  155. exportType: string;
  156. id: Index;
  157. }
  158. export class NumberLiteral extends Node {
  159. value: number;
  160. raw: string;
  161. }
  162. export class FloatLiteral extends Node {}
  163. export class GlobalType extends Node {
  164. valtype: string;
  165. }
  166. export class Global extends Node {
  167. init: Instruction[];
  168. globalType: GlobalType;
  169. }
  170. export class FuncParam extends Node {
  171. valtype: string;
  172. }
  173. export class Instruction extends Node {
  174. id: string;
  175. args: NumberLiteral[];
  176. }
  177. export class CallInstruction extends Instruction {}
  178. export class ObjectInstruction extends Instruction {}
  179. export class Func extends Node {
  180. signature: Signature;
  181. }
  182. export class Signature {
  183. type: "Signature";
  184. params: FuncParam[];
  185. results: string[];
  186. }
  187. export class TypeInstruction extends Node {}
  188. export class IndexInFuncSection extends Node {}
  189. export function indexLiteral(index: number): Index;
  190. export function numberLiteralFromRaw(num: number): NumberLiteral;
  191. export function floatLiteral(
  192. value: number,
  193. nan?: boolean,
  194. inf?: boolean,
  195. raw?: string
  196. ): FloatLiteral;
  197. export function global(globalType: string, nodes: Node[]): Global;
  198. export function identifier(indentifier: string): Identifier;
  199. export function funcParam(valType: string, id: Identifier): FuncParam;
  200. export function instruction(inst: string, args?: Node[]): Instruction;
  201. export function callInstruction(funcIndex: Index): CallInstruction;
  202. export function objectInstruction(
  203. kind: string,
  204. type: string,
  205. init: Node[]
  206. ): ObjectInstruction;
  207. export function signature(params: FuncParam[], results: string[]): Signature;
  208. export function func(initFuncId, signature: Signature, funcBody): Func;
  209. export function typeInstruction(
  210. id: Identifier,
  211. functype: Signature
  212. ): TypeInstruction;
  213. export function indexInFuncSection(index: Index): IndexInFuncSection;
  214. export function moduleExport(
  215. identifier: string,
  216. descr: ModuleExportDescr
  217. ): ModuleExport;
  218. export function moduleExportDescr(
  219. type: string,
  220. index: Index
  221. ): ModuleExportDescr;
  222. export function getSectionMetadata(ast: any, section: string);
  223. export class FuncSignature {
  224. args: string[];
  225. result: string[];
  226. }
  227. // Node matcher
  228. export function isGlobalType(n: Node): boolean;
  229. export function isTable(n: Node): boolean;
  230. export function isMemory(n: Node): boolean;
  231. export function isFuncImportDescr(n: Node): boolean;
  232. }
  233. declare module "webpack-sources" {
  234. type MapOptions = { columns?: boolean; module?: boolean };
  235. export abstract class Source {
  236. size(): number;
  237. map(options?: MapOptions): Object;
  238. sourceAndMap(
  239. options?: MapOptions
  240. ): {
  241. source: string | Buffer;
  242. map: Object;
  243. };
  244. updateHash(hash: import("./lib/util/Hash")): void;
  245. source(): string | Buffer;
  246. buffer(): Buffer;
  247. }
  248. export class RawSource extends Source {
  249. constructor(source: string | Buffer, convertToString?: boolean);
  250. isBuffer(): boolean;
  251. }
  252. export class OriginalSource extends Source {
  253. constructor(source: string | Buffer, name: string);
  254. getName(): string;
  255. }
  256. export class ReplaceSource extends Source {
  257. constructor(source: Source, name?: string);
  258. replace(start: number, end: number, newValue: string, name?: string): void;
  259. insert(pos: number, newValue: string, name?: string): void;
  260. getName(): string;
  261. original(): string;
  262. getReplacements(): {
  263. start: number;
  264. end: number;
  265. content: string;
  266. insertIndex: number;
  267. name: string;
  268. }[];
  269. }
  270. export class SourceMapSource extends Source {
  271. constructor(
  272. source: string | Buffer,
  273. name: string,
  274. sourceMap: Object | string | Buffer,
  275. originalSource?: string | Buffer,
  276. innerSourceMap?: Object | string | Buffer
  277. );
  278. getArgsAsBuffers(): [
  279. Buffer,
  280. string,
  281. Buffer,
  282. Buffer | undefined,
  283. Buffer | undefined
  284. ];
  285. }
  286. export class ConcatSource extends Source {
  287. constructor(...args: (string | Source)[]);
  288. getChildren(): Source[];
  289. add(item: string | Source): void;
  290. addAllSkipOptimizing(items: Source[]): void;
  291. }
  292. export class PrefixSource extends Source {
  293. constructor(prefix: string, source: string | Source);
  294. original(): Source;
  295. getPrefix(): string;
  296. }
  297. export class CachedSource extends Source {
  298. constructor(source: Source, cachedData?: any);
  299. original(): Source;
  300. getCachedData(): any;
  301. }
  302. export class SizeOnlySource extends Source {
  303. constructor(size: number);
  304. }
  305. }
  306. declare module "enhanced-resolve" {
  307. type ResolveFunction = (
  308. path: string,
  309. request: string,
  310. resolveContext: ResolveContext,
  311. callback: (
  312. err?: NodeJS.ErrnoException,
  313. result?: string,
  314. additionalInfo?: Object
  315. ) => void
  316. ) => void;
  317. export function create(options: any): ResolveFunction;
  318. interface WriteOnlySet<T> {
  319. add(item: T): void;
  320. }
  321. interface ResolveContext {
  322. log?: (message: string) => void;
  323. fileDependencies?: WriteOnlySet<string>;
  324. contextDependencies?: WriteOnlySet<string>;
  325. missingDependencies?: WriteOnlySet<string>;
  326. stack?: Set<string>;
  327. }
  328. export class Resolver {
  329. resolve(
  330. context: Object,
  331. path: string,
  332. request: string,
  333. resolveContext: ResolveContext,
  334. callback: (
  335. err?: NodeJS.ErrnoException,
  336. result?: string,
  337. additionalInfo?: Object
  338. ) => void
  339. ): void;
  340. }
  341. export class ResolverFactory {
  342. static createResolver(options: TODO): Resolver;
  343. }
  344. }
  345. type TODO = any;