@umijs/bundler-utils 3.5.20 → 4.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +2 -0
  2. package/compiled/@babel/code-frame/LICENSE +22 -0
  3. package/compiled/@babel/code-frame/index.d.ts +54 -0
  4. package/compiled/@babel/code-frame/package.json +1 -0
  5. package/compiled/@babel/core/LICENSE +22 -0
  6. package/compiled/@babel/core/index.d.ts +771 -0
  7. package/compiled/@babel/core/package.json +1 -0
  8. package/compiled/@babel/generator/LICENSE +22 -0
  9. package/compiled/@babel/generator/index.d.ts +212 -0
  10. package/compiled/@babel/generator/package.json +1 -0
  11. package/compiled/@babel/parser/LICENSE +19 -0
  12. package/compiled/@babel/parser/package.json +1 -0
  13. package/compiled/@babel/parser/typings/babel-parser.d.ts +203 -0
  14. package/compiled/@babel/template/LICENSE +22 -0
  15. package/compiled/@babel/template/index.d.ts +100 -0
  16. package/compiled/@babel/template/package.json +1 -0
  17. package/compiled/@babel/traverse/LICENSE +22 -0
  18. package/compiled/@babel/traverse/index.d.ts +1172 -0
  19. package/compiled/@babel/traverse/package.json +1 -0
  20. package/compiled/@babel/types/LICENSE +22 -0
  21. package/compiled/@babel/types/lib/index-legacy.d.ts +2692 -0
  22. package/compiled/@babel/types/package.json +1 -0
  23. package/compiled/babel/code-frame.d.ts +3 -0
  24. package/compiled/babel/code-frame.js +1 -0
  25. package/compiled/babel/core.d.ts +3 -0
  26. package/compiled/babel/core.js +1 -0
  27. package/compiled/babel/generator.d.ts +3 -0
  28. package/compiled/babel/generator.js +1 -0
  29. package/compiled/babel/index.js +101726 -0
  30. package/compiled/babel/parser.d.ts +3 -0
  31. package/compiled/babel/parser.js +1 -0
  32. package/compiled/babel/plugin-proposal-decorators.js +1 -0
  33. package/compiled/babel/plugin-proposal-do-expressions.js +1 -0
  34. package/compiled/babel/plugin-proposal-export-default-from.js +1 -0
  35. package/compiled/babel/plugin-proposal-export-namespace-from.js +1 -0
  36. package/compiled/babel/plugin-proposal-function-bind.js +1 -0
  37. package/compiled/babel/plugin-proposal-partial-application.js +1 -0
  38. package/compiled/babel/plugin-proposal-pipeline-operator.js +1 -0
  39. package/compiled/babel/plugin-proposal-record-and-tuple.js +1 -0
  40. package/compiled/babel/plugin-transform-runtime.js +1 -0
  41. package/compiled/babel/preset-env.js +1 -0
  42. package/compiled/babel/preset-react.js +1 -0
  43. package/compiled/babel/preset-typescript.js +1 -0
  44. package/compiled/babel/register.js +1 -0
  45. package/compiled/babel/source-map-support.js +625 -0
  46. package/compiled/babel/template.d.ts +3 -0
  47. package/compiled/babel/template.js +1 -0
  48. package/compiled/babel/traverse.d.ts +3 -0
  49. package/compiled/babel/traverse.js +1 -0
  50. package/compiled/babel/types.d.ts +1 -0
  51. package/compiled/babel/types.js +1 -0
  52. package/compiled/cjs-module-lexer/LICENSE +10 -0
  53. package/compiled/cjs-module-lexer/index.js +1 -0
  54. package/compiled/cjs-module-lexer/lexer.d.ts +7 -0
  55. package/compiled/cjs-module-lexer/package.json +1 -0
  56. package/compiled/es-module-lexer/LICENSE +10 -0
  57. package/compiled/es-module-lexer/index.js +1 -0
  58. package/compiled/es-module-lexer/package.json +1 -0
  59. package/compiled/es-module-lexer/types/lexer.d.ts +86 -0
  60. package/compiled/esbuild/index.d.ts +1 -0
  61. package/compiled/esbuild/index.js +11 -0
  62. package/dist/index.d.ts +2 -0
  63. package/dist/index.js +5 -0
  64. package/package.json +70 -14
  65. package/lib/getBabelOpts.d.ts +0 -42
  66. package/lib/getBabelOpts.js +0 -112
  67. package/lib/getTargetsAndBrowsersList.d.ts +0 -10
  68. package/lib/getTargetsAndBrowsersList.js +0 -50
  69. package/lib/index.d.ts +0 -2
  70. package/lib/index.js +0 -42
@@ -0,0 +1,771 @@
1
+ // Type definitions for @babel/core 7.1
2
+ // Project: https://github.com/babel/babel/tree/master/packages/babel-core, https://babeljs.io
3
+ // Definitions by: Troy Gerwien <https://github.com/yortus>
4
+ // Marvin Hagemeister <https://github.com/marvinhagemeister>
5
+ // Melvin Groenhoff <https://github.com/mgroenhoff>
6
+ // Jessica Franco <https://github.com/Jessidhia>
7
+ // Ifiok Jr. <https://github.com/ifiokjr>
8
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
9
+ // Minimum TypeScript Version: 3.4
10
+
11
+ import { GeneratorOptions } from '../../@babel/generator';
12
+ import { ParserOptions } from '../../@babel/parser';
13
+ import template from '../../@babel/template';
14
+ import traverse, { Hub, NodePath, Scope, Visitor } from '../../@babel/traverse';
15
+ import * as t from '../../@babel/types';
16
+
17
+ export { ParserOptions, GeneratorOptions, t as types, template, traverse, NodePath, Visitor };
18
+
19
+ export type Node = t.Node;
20
+ export type ParseResult = t.File | t.Program;
21
+ export const version: string;
22
+ export const DEFAULT_EXTENSIONS: ['.js', '.jsx', '.es6', '.es', '.mjs'];
23
+
24
+ /**
25
+ * Source map standard format as to revision 3
26
+ * @see {@link https://sourcemaps.info/spec.html}
27
+ * @see {@link https://github.com/mozilla/source-map/blob/HEAD/source-map.d.ts}
28
+ */
29
+ interface InputSourceMap {
30
+ version: number;
31
+ sources: string[];
32
+ names: string[];
33
+ sourceRoot?: string | undefined;
34
+ sourcesContent?: string[] | undefined;
35
+ mappings: string;
36
+ file: string;
37
+ }
38
+
39
+ export interface TransformOptions {
40
+ /**
41
+ * Include the AST in the returned object
42
+ *
43
+ * Default: `false`
44
+ */
45
+ ast?: boolean | null | undefined;
46
+
47
+ /**
48
+ * Attach a comment after all non-user injected code
49
+ *
50
+ * Default: `null`
51
+ */
52
+ auxiliaryCommentAfter?: string | null | undefined;
53
+
54
+ /**
55
+ * Attach a comment before all non-user injected code
56
+ *
57
+ * Default: `null`
58
+ */
59
+ auxiliaryCommentBefore?: string | null | undefined;
60
+
61
+ /**
62
+ * Specify the "root" folder that defines the location to search for "babel.config.js", and the default folder to allow `.babelrc` files inside of.
63
+ *
64
+ * Default: `"."`
65
+ */
66
+ root?: string | null | undefined;
67
+
68
+ /**
69
+ * This option, combined with the "root" value, defines how Babel chooses its project root.
70
+ * The different modes define different ways that Babel can process the "root" value to get
71
+ * the final project root.
72
+ *
73
+ * @see https://babeljs.io/docs/en/next/options#rootmode
74
+ */
75
+ rootMode?: 'root' | 'upward' | 'upward-optional' | undefined;
76
+
77
+ /**
78
+ * The config file to load Babel's config from. Defaults to searching for "babel.config.js" inside the "root" folder. `false` will disable searching for config files.
79
+ *
80
+ * Default: `undefined`
81
+ */
82
+ configFile?: string | boolean | null | undefined;
83
+
84
+ /**
85
+ * Specify whether or not to use .babelrc and
86
+ * .babelignore files.
87
+ *
88
+ * Default: `true`
89
+ */
90
+ babelrc?: boolean | null | undefined;
91
+
92
+ /**
93
+ * Specify which packages should be search for .babelrc files when they are being compiled. `true` to always search, or a path string or an array of paths to packages to search
94
+ * inside of. Defaults to only searching the "root" package.
95
+ *
96
+ * Default: `(root)`
97
+ */
98
+ babelrcRoots?: boolean | MatchPattern | MatchPattern[] | null | undefined;
99
+
100
+ /**
101
+ * Defaults to environment variable `BABEL_ENV` if set, or else `NODE_ENV` if set, or else it defaults to `"development"`
102
+ *
103
+ * Default: env vars
104
+ */
105
+ envName?: string | undefined;
106
+
107
+ /**
108
+ * If any of patterns match, the current configuration object is considered inactive and is ignored during config processing.
109
+ */
110
+ exclude?: MatchPattern | MatchPattern[] | undefined;
111
+
112
+ /**
113
+ * Enable code generation
114
+ *
115
+ * Default: `true`
116
+ */
117
+ code?: boolean | null | undefined;
118
+
119
+ /**
120
+ * Output comments in generated output
121
+ *
122
+ * Default: `true`
123
+ */
124
+ comments?: boolean | null | undefined;
125
+
126
+ /**
127
+ * Do not include superfluous whitespace characters and line terminators. When set to `"auto"` compact is set to `true` on input sizes of >500KB
128
+ *
129
+ * Default: `"auto"`
130
+ */
131
+ compact?: boolean | 'auto' | null | undefined;
132
+
133
+ /**
134
+ * The working directory that Babel's programmatic options are loaded relative to.
135
+ *
136
+ * Default: `"."`
137
+ */
138
+ cwd?: string | null | undefined;
139
+
140
+ /**
141
+ * Utilities may pass a caller object to identify themselves to Babel and
142
+ * pass capability-related flags for use by configs, presets and plugins.
143
+ *
144
+ * @see https://babeljs.io/docs/en/next/options#caller
145
+ */
146
+ caller?: TransformCaller | undefined;
147
+
148
+ /**
149
+ * This is an object of keys that represent different environments. For example, you may have: `{ env: { production: { \/* specific options *\/ } } }`
150
+ * which will use those options when the `envName` is `production`
151
+ *
152
+ * Default: `{}`
153
+ */
154
+ env?: { [index: string]: TransformOptions | null | undefined } | null | undefined;
155
+
156
+ /**
157
+ * A path to a `.babelrc` file to extend
158
+ *
159
+ * Default: `null`
160
+ */
161
+ extends?: string | null | undefined;
162
+
163
+ /**
164
+ * Filename for use in errors etc
165
+ *
166
+ * Default: `"unknown"`
167
+ */
168
+ filename?: string | null | undefined;
169
+
170
+ /**
171
+ * Filename relative to `sourceRoot`
172
+ *
173
+ * Default: `(filename)`
174
+ */
175
+ filenameRelative?: string | null | undefined;
176
+
177
+ /**
178
+ * An object containing the options to be passed down to the babel code generator, @babel/generator
179
+ *
180
+ * Default: `{}`
181
+ */
182
+ generatorOpts?: GeneratorOptions | null | undefined;
183
+
184
+ /**
185
+ * Specify a custom callback to generate a module id with. Called as `getModuleId(moduleName)`. If falsy value is returned then the generated module id is used
186
+ *
187
+ * Default: `null`
188
+ */
189
+ getModuleId?: ((moduleName: string) => string | null | undefined) | null | undefined;
190
+
191
+ /**
192
+ * ANSI highlight syntax error code frames
193
+ *
194
+ * Default: `true`
195
+ */
196
+ highlightCode?: boolean | null | undefined;
197
+
198
+ /**
199
+ * Opposite to the `only` option. `ignore` is disregarded if `only` is specified
200
+ *
201
+ * Default: `null`
202
+ */
203
+ ignore?: MatchPattern[] | null | undefined;
204
+
205
+ /**
206
+ * This option is a synonym for "test"
207
+ */
208
+ include?: MatchPattern | MatchPattern[] | undefined;
209
+
210
+ /**
211
+ * A source map object that the output source map will be based on
212
+ *
213
+ * Default: `null`
214
+ */
215
+ inputSourceMap?: InputSourceMap | null | undefined;
216
+
217
+ /**
218
+ * Should the output be minified (not printing last semicolons in blocks, printing literal string values instead of escaped ones, stripping `()` from `new` when safe)
219
+ *
220
+ * Default: `false`
221
+ */
222
+ minified?: boolean | null | undefined;
223
+
224
+ /**
225
+ * Specify a custom name for module ids
226
+ *
227
+ * Default: `null`
228
+ */
229
+ moduleId?: string | null | undefined;
230
+
231
+ /**
232
+ * If truthy, insert an explicit id for modules. By default, all modules are anonymous. (Not available for `common` modules)
233
+ *
234
+ * Default: `false`
235
+ */
236
+ moduleIds?: boolean | null | undefined;
237
+
238
+ /**
239
+ * Optional prefix for the AMD module formatter that will be prepend to the filename on module definitions
240
+ *
241
+ * Default: `(sourceRoot)`
242
+ */
243
+ moduleRoot?: string | null | undefined;
244
+
245
+ /**
246
+ * A glob, regex, or mixed array of both, matching paths to **only** compile. Can also be an array of arrays containing paths to explicitly match. When attempting to compile
247
+ * a non-matching file it's returned verbatim
248
+ *
249
+ * Default: `null`
250
+ */
251
+ only?: MatchPattern[] | null | undefined;
252
+
253
+ /**
254
+ * Allows users to provide an array of options that will be merged into the current configuration one at a time.
255
+ * This feature is best used alongside the "test"/"include"/"exclude" options to provide conditions for which an override should apply
256
+ */
257
+ overrides?: TransformOptions[] | undefined;
258
+
259
+ /**
260
+ * An object containing the options to be passed down to the babel parser, @babel/parser
261
+ *
262
+ * Default: `{}`
263
+ */
264
+ parserOpts?: ParserOptions | null | undefined;
265
+
266
+ /**
267
+ * List of plugins to load and use
268
+ *
269
+ * Default: `[]`
270
+ */
271
+ plugins?: PluginItem[] | null | undefined;
272
+
273
+ /**
274
+ * List of presets (a set of plugins) to load and use
275
+ *
276
+ * Default: `[]`
277
+ */
278
+ presets?: PluginItem[] | null | undefined;
279
+
280
+ /**
281
+ * Retain line numbers. This will lead to wacky code but is handy for scenarios where you can't use source maps. (**NOTE**: This will not retain the columns)
282
+ *
283
+ * Default: `false`
284
+ */
285
+ retainLines?: boolean | null | undefined;
286
+
287
+ /**
288
+ * An optional callback that controls whether a comment should be output or not. Called as `shouldPrintComment(commentContents)`. **NOTE**: This overrides the `comment` option when used
289
+ *
290
+ * Default: `null`
291
+ */
292
+ shouldPrintComment?: ((commentContents: string) => boolean) | null | undefined;
293
+
294
+ /**
295
+ * Set `sources[0]` on returned source map
296
+ *
297
+ * Default: `(filenameRelative)`
298
+ */
299
+ sourceFileName?: string | null | undefined;
300
+
301
+ /**
302
+ * If truthy, adds a `map` property to returned output. If set to `"inline"`, a comment with a sourceMappingURL directive is added to the bottom of the returned code. If set to `"both"`
303
+ * then a `map` property is returned as well as a source map comment appended. **This does not emit sourcemap files by itself!**
304
+ *
305
+ * Default: `false`
306
+ */
307
+ sourceMaps?: boolean | 'inline' | 'both' | null | undefined;
308
+
309
+ /**
310
+ * The root from which all sources are relative
311
+ *
312
+ * Default: `(moduleRoot)`
313
+ */
314
+ sourceRoot?: string | null | undefined;
315
+
316
+ /**
317
+ * Indicate the mode the code should be parsed in. Can be one of "script", "module", or "unambiguous". `"unambiguous"` will make Babel attempt to guess, based on the presence of ES6
318
+ * `import` or `export` statements. Files with ES6 `import`s and `export`s are considered `"module"` and are otherwise `"script"`.
319
+ *
320
+ * Default: `("module")`
321
+ */
322
+ sourceType?: 'script' | 'module' | 'unambiguous' | null | undefined;
323
+
324
+ /**
325
+ * If all patterns fail to match, the current configuration object is considered inactive and is ignored during config processing.
326
+ */
327
+ test?: MatchPattern | MatchPattern[] | undefined;
328
+
329
+ /**
330
+ * An optional callback that can be used to wrap visitor methods. **NOTE**: This is useful for things like introspection, and not really needed for implementing anything. Called as
331
+ * `wrapPluginVisitorMethod(pluginAlias, visitorType, callback)`.
332
+ */
333
+ wrapPluginVisitorMethod?:
334
+ | ((
335
+ pluginAlias: string,
336
+ visitorType: 'enter' | 'exit',
337
+ callback: (path: NodePath, state: any) => void,
338
+ ) => (path: NodePath, state: any) => void)
339
+ | null | undefined;
340
+ }
341
+
342
+ export interface TransformCaller {
343
+ // the only required property
344
+ name: string;
345
+ // e.g. set to true by `babel-loader` and false by `babel-jest`
346
+ supportsStaticESM?: boolean | undefined;
347
+ supportsDynamicImport?: boolean | undefined;
348
+ supportsExportNamespaceFrom?: boolean | undefined;
349
+ supportsTopLevelAwait?: boolean | undefined;
350
+ // augment this with a "declare module '@babel/core' { ... }" if you need more keys
351
+ }
352
+
353
+ export type FileResultCallback = (err: Error | null, result: BabelFileResult | null) => any;
354
+
355
+ export interface MatchPatternContext {
356
+ envName: string;
357
+ dirname: string;
358
+ caller: TransformCaller | undefined;
359
+ }
360
+ export type MatchPattern = string | RegExp | ((filename: string | undefined, context: MatchPatternContext) => boolean);
361
+
362
+ /**
363
+ * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
364
+ */
365
+ export function transform(code: string, callback: FileResultCallback): void;
366
+
367
+ /**
368
+ * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
369
+ */
370
+ export function transform(code: string, opts: TransformOptions | undefined, callback: FileResultCallback): void;
371
+
372
+ /**
373
+ * Here for backward-compatibility. Ideally use `transformSync` if you want a synchronous API.
374
+ */
375
+ export function transform(code: string, opts?: TransformOptions): BabelFileResult | null;
376
+
377
+ /**
378
+ * Transforms the passed in code. Returning an object with the generated code, source map, and AST.
379
+ */
380
+ export function transformSync(code: string, opts?: TransformOptions): BabelFileResult | null;
381
+
382
+ /**
383
+ * Transforms the passed in code. Calling a callback with an object with the generated code, source map, and AST.
384
+ */
385
+ export function transformAsync(code: string, opts?: TransformOptions): Promise<BabelFileResult | null>;
386
+
387
+ /**
388
+ * Asynchronously transforms the entire contents of a file.
389
+ */
390
+ export function transformFile(filename: string, callback: FileResultCallback): void;
391
+
392
+ /**
393
+ * Asynchronously transforms the entire contents of a file.
394
+ */
395
+ export function transformFile(filename: string, opts: TransformOptions | undefined, callback: FileResultCallback): void;
396
+
397
+ /**
398
+ * Synchronous version of `babel.transformFile`. Returns the transformed contents of the `filename`.
399
+ */
400
+ export function transformFileSync(filename: string, opts?: TransformOptions): BabelFileResult | null;
401
+
402
+ /**
403
+ * Asynchronously transforms the entire contents of a file.
404
+ */
405
+ export function transformFileAsync(filename: string, opts?: TransformOptions): Promise<BabelFileResult | null>;
406
+
407
+ /**
408
+ * Given an AST, transform it.
409
+ */
410
+ export function transformFromAst(ast: Node, code: string | undefined, callback: FileResultCallback): void;
411
+
412
+ /**
413
+ * Given an AST, transform it.
414
+ */
415
+ export function transformFromAst(
416
+ ast: Node,
417
+ code: string | undefined,
418
+ opts: TransformOptions | undefined,
419
+ callback: FileResultCallback,
420
+ ): void;
421
+
422
+ /**
423
+ * Here for backward-compatibility. Ideally use ".transformSync" if you want a synchronous API.
424
+ */
425
+ export function transformFromAstSync(ast: Node, code?: string, opts?: TransformOptions): BabelFileResult | null;
426
+
427
+ /**
428
+ * Given an AST, transform it.
429
+ */
430
+ export function transformFromAstAsync(
431
+ ast: Node,
432
+ code?: string,
433
+ opts?: TransformOptions,
434
+ ): Promise<BabelFileResult | null>;
435
+
436
+ // A babel plugin is a simple function which must return an object matching
437
+ // the following interface. Babel will throw if it finds unknown properties.
438
+ // The list of allowed plugin keys is here:
439
+ // https://github.com/babel/babel/blob/4e50b2d9d9c376cee7a2cbf56553fe5b982ea53c/packages/babel-core/src/config/option-manager.js#L71
440
+ export interface PluginObj<S = PluginPass> {
441
+ name?: string | undefined;
442
+ manipulateOptions?(opts: any, parserOpts: any): void;
443
+ pre?(this: S, file: BabelFile): void;
444
+ visitor: Visitor<S>;
445
+ post?(this: S, file: BabelFile): void;
446
+ inherits?: any;
447
+ }
448
+
449
+ export interface BabelFile {
450
+ ast: t.File;
451
+ opts: TransformOptions;
452
+ hub: Hub;
453
+ metadata: object;
454
+ path: NodePath<t.Program>;
455
+ scope: Scope;
456
+ inputMap: object | null;
457
+ code: string;
458
+ }
459
+
460
+ export interface PluginPass {
461
+ file: BabelFile;
462
+ key: string;
463
+ opts: PluginOptions;
464
+ cwd: string;
465
+ filename: string | undefined;
466
+ [key: string]: unknown;
467
+ }
468
+
469
+ export interface BabelFileResult {
470
+ ast?: t.File | null | undefined;
471
+ code?: string | null | undefined;
472
+ ignored?: boolean | undefined;
473
+ map?: {
474
+ version: number;
475
+ sources: string[];
476
+ names: string[];
477
+ sourceRoot?: string | undefined;
478
+ sourcesContent?: string[] | undefined;
479
+ mappings: string;
480
+ file: string;
481
+ } | null | undefined;
482
+ metadata?: BabelFileMetadata | undefined;
483
+ }
484
+
485
+ export interface BabelFileMetadata {
486
+ usedHelpers: string[];
487
+ marked: Array<{
488
+ type: string;
489
+ message: string;
490
+ loc: object;
491
+ }>;
492
+ modules: BabelFileModulesMetadata;
493
+ }
494
+
495
+ export interface BabelFileModulesMetadata {
496
+ imports: object[];
497
+ exports: {
498
+ exported: object[];
499
+ specifiers: object[];
500
+ };
501
+ }
502
+
503
+ export type FileParseCallback = (err: Error | null, result: ParseResult | null) => any;
504
+
505
+ /**
506
+ * Given some code, parse it using Babel's standard behavior.
507
+ * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
508
+ */
509
+ export function parse(code: string, callback: FileParseCallback): void;
510
+
511
+ /**
512
+ * Given some code, parse it using Babel's standard behavior.
513
+ * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
514
+ */
515
+ export function parse(code: string, options: TransformOptions | undefined, callback: FileParseCallback): void;
516
+
517
+ /**
518
+ * Given some code, parse it using Babel's standard behavior.
519
+ * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
520
+ */
521
+ export function parse(code: string, options?: TransformOptions): ParseResult | null;
522
+
523
+ /**
524
+ * Given some code, parse it using Babel's standard behavior.
525
+ * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
526
+ */
527
+ export function parseSync(code: string, options?: TransformOptions): ParseResult | null;
528
+
529
+ /**
530
+ * Given some code, parse it using Babel's standard behavior.
531
+ * Referenced presets and plugins will be loaded such that optional syntax plugins are automatically enabled.
532
+ */
533
+ export function parseAsync(code: string, options?: TransformOptions): Promise<ParseResult | null>;
534
+
535
+ /**
536
+ * Resolve Babel's options fully, resulting in an options object where:
537
+ *
538
+ * * opts.plugins is a full list of Plugin instances.
539
+ * * opts.presets is empty and all presets are flattened into opts.
540
+ * * It can be safely passed back to Babel. Fields like babelrc have been set to false so that later calls to Babel
541
+ * will not make a second attempt to load config files.
542
+ *
543
+ * Plugin instances aren't meant to be manipulated directly, but often callers will serialize this opts to JSON to
544
+ * use it as a cache key representing the options Babel has received. Caching on this isn't 100% guaranteed to
545
+ * invalidate properly, but it is the best we have at the moment.
546
+ */
547
+ export function loadOptions(options?: TransformOptions): object | null;
548
+
549
+ /**
550
+ * To allow systems to easily manipulate and validate a user's config, this function resolves the plugins and
551
+ * presets and proceeds no further. The expectation is that callers will take the config's .options, manipulate it
552
+ * as then see fit and pass it back to Babel again.
553
+ *
554
+ * * `babelrc: string | void` - The path of the `.babelrc` file, if there was one.
555
+ * * `babelignore: string | void` - The path of the `.babelignore` file, if there was one.
556
+ * * `options: ValidatedOptions` - The partially resolved options, which can be manipulated and passed back
557
+ * to Babel again.
558
+ * * `plugins: Array<ConfigItem>` - See below.
559
+ * * `presets: Array<ConfigItem>` - See below.
560
+ * * It can be safely passed back to Babel. Fields like `babelrc` have been set to false so that later calls to
561
+ * Babel will not make a second attempt to load config files.
562
+ *
563
+ * `ConfigItem` instances expose properties to introspect the values, but each item should be treated as
564
+ * immutable. If changes are desired, the item should be removed from the list and replaced with either a normal
565
+ * Babel config value, or with a replacement item created by `babel.createConfigItem`. See that function for
566
+ * information about `ConfigItem` fields.
567
+ */
568
+ export function loadPartialConfig(options?: TransformOptions): Readonly<PartialConfig> | null;
569
+ export function loadPartialConfigAsync(options?: TransformOptions): Promise<Readonly<PartialConfig> | null>;
570
+
571
+ export interface PartialConfig {
572
+ options: TransformOptions;
573
+ babelrc?: string | undefined;
574
+ babelignore?: string | undefined;
575
+ config?: string | undefined;
576
+ hasFilesystemConfig: () => boolean;
577
+ }
578
+
579
+ export interface ConfigItem {
580
+ /**
581
+ * The name that the user gave the plugin instance, e.g. `plugins: [ ['env', {}, 'my-env'] ]`
582
+ */
583
+ name?: string | undefined;
584
+
585
+ /**
586
+ * The resolved value of the plugin.
587
+ */
588
+ value: object | ((...args: any[]) => any);
589
+
590
+ /**
591
+ * The options object passed to the plugin.
592
+ */
593
+ options?: object | false | undefined;
594
+
595
+ /**
596
+ * The path that the options are relative to.
597
+ */
598
+ dirname: string;
599
+
600
+ /**
601
+ * Information about the plugin's file, if Babel knows it.
602
+ * *
603
+ */
604
+ file?: {
605
+ /**
606
+ * The file that the user requested, e.g. `"@babel/env"`
607
+ */
608
+ request: string;
609
+
610
+ /**
611
+ * The full path of the resolved file, e.g. `"/tmp/node_modules/@babel/preset-env/lib/index.js"`
612
+ */
613
+ resolved: string;
614
+ } | null | undefined;
615
+ }
616
+
617
+ export type PluginOptions = object | undefined | false;
618
+
619
+ export type PluginTarget = string | object | ((...args: any[]) => any);
620
+
621
+ export type PluginItem =
622
+ | ConfigItem
623
+ | PluginObj<any>
624
+ | PluginTarget
625
+ | [PluginTarget, PluginOptions]
626
+ | [PluginTarget, PluginOptions, string | undefined];
627
+
628
+ export function resolvePlugin(name: string, dirname: string): string | null;
629
+ export function resolvePreset(name: string, dirname: string): string | null;
630
+
631
+ export interface CreateConfigItemOptions {
632
+ dirname?: string | undefined;
633
+ type?: 'preset' | 'plugin' | undefined;
634
+ }
635
+
636
+ /**
637
+ * Allows build tooling to create and cache config items up front. If this function is called multiple times for a
638
+ * given plugin, Babel will call the plugin's function itself multiple times. If you have a clear set of expected
639
+ * plugins and presets to inject, pre-constructing the config items would be recommended.
640
+ */
641
+ export function createConfigItem(
642
+ value: PluginTarget | [PluginTarget, PluginOptions] | [PluginTarget, PluginOptions, string | undefined],
643
+ options?: CreateConfigItemOptions,
644
+ ): ConfigItem;
645
+
646
+ // NOTE: the documentation says the ConfigAPI also exposes @babel/core's exports, but it actually doesn't
647
+ /**
648
+ * @see https://babeljs.io/docs/en/next/config-files#config-function-api
649
+ */
650
+ export interface ConfigAPI {
651
+ /**
652
+ * The version string for the Babel version that is loading the config file.
653
+ *
654
+ * @see https://babeljs.io/docs/en/next/config-files#apiversion
655
+ */
656
+ version: string;
657
+ /**
658
+ * @see https://babeljs.io/docs/en/next/config-files#apicache
659
+ */
660
+ cache: SimpleCacheConfigurator;
661
+ /**
662
+ * @see https://babeljs.io/docs/en/next/config-files#apienv
663
+ */
664
+ env: EnvFunction;
665
+ // undocumented; currently hardcoded to return 'false'
666
+ // async(): boolean
667
+ /**
668
+ * This API is used as a way to access the `caller` data that has been passed to Babel.
669
+ * Since many instances of Babel may be running in the same process with different `caller` values,
670
+ * this API is designed to automatically configure `api.cache`, the same way `api.env()` does.
671
+ *
672
+ * The `caller` value is available as the first parameter of the callback function.
673
+ * It is best used with something like this to toggle configuration behavior
674
+ * based on a specific environment:
675
+ *
676
+ * @example
677
+ * function isBabelRegister(caller?: { name: string }) {
678
+ * return !!(caller && caller.name === "@babel/register")
679
+ * }
680
+ * api.caller(isBabelRegister)
681
+ *
682
+ * @see https://babeljs.io/docs/en/next/config-files#apicallercb
683
+ */
684
+ caller<T extends SimpleCacheKey>(callerCallback: (caller: TransformOptions['caller']) => T): T;
685
+ /**
686
+ * While `api.version` can be useful in general, it's sometimes nice to just declare your version.
687
+ * This API exposes a simple way to do that with:
688
+ *
689
+ * @example
690
+ * api.assertVersion(7) // major version only
691
+ * api.assertVersion("^7.2")
692
+ *
693
+ * @see https://babeljs.io/docs/en/next/config-files#apiassertversionrange
694
+ */
695
+ assertVersion(versionRange: number | string): boolean;
696
+ // NOTE: this is an undocumented reexport from "@babel/parser" but it's missing from its types
697
+ // tokTypes: typeof tokTypes
698
+ }
699
+
700
+ /**
701
+ * JS configs are great because they can compute a config on the fly,
702
+ * but the downside there is that it makes caching harder.
703
+ * Babel wants to avoid re-executing the config function every time a file is compiled,
704
+ * because then it would also need to re-execute any plugin and preset functions
705
+ * referenced in that config.
706
+ *
707
+ * To avoid this, Babel expects users of config functions to tell it how to manage caching
708
+ * within a config file.
709
+ *
710
+ * @see https://babeljs.io/docs/en/next/config-files#apicache
711
+ */
712
+ export interface SimpleCacheConfigurator {
713
+ // there is an undocumented call signature that is a shorthand for forever()/never()/using().
714
+ // (ever: boolean): void
715
+ // <T extends SimpleCacheKey>(callback: CacheCallback<T>): T
716
+ /**
717
+ * Permacache the computed config and never call the function again.
718
+ */
719
+ forever(): void;
720
+ /**
721
+ * Do not cache this config, and re-execute the function every time.
722
+ */
723
+ never(): void;
724
+ /**
725
+ * Any time the using callback returns a value other than the one that was expected,
726
+ * the overall config function will be called again and a new entry will be added to the cache.
727
+ *
728
+ * @example
729
+ * api.cache.using(() => process.env.NODE_ENV)
730
+ */
731
+ using<T extends SimpleCacheKey>(callback: SimpleCacheCallback<T>): T;
732
+ /**
733
+ * Any time the using callback returns a value other than the one that was expected,
734
+ * the overall config function will be called again and all entries in the cache will
735
+ * be replaced with the result.
736
+ *
737
+ * @example
738
+ * api.cache.invalidate(() => process.env.NODE_ENV)
739
+ */
740
+ invalidate<T extends SimpleCacheKey>(callback: SimpleCacheCallback<T>): T;
741
+ }
742
+
743
+ // https://github.com/babel/babel/blob/v7.3.3/packages/babel-core/src/config/caching.js#L231
744
+ export type SimpleCacheKey = string | boolean | number | null | undefined;
745
+ export type SimpleCacheCallback<T extends SimpleCacheKey> = () => T;
746
+
747
+ /**
748
+ * Since `NODE_ENV` is a fairly common way to toggle behavior, Babel also includes an API function
749
+ * meant specifically for that. This API is used as a quick way to check the `"envName"` that Babel
750
+ * was loaded with, which takes `NODE_ENV` into account if no other overriding environment is set.
751
+ *
752
+ * @see https://babeljs.io/docs/en/next/config-files#apienv
753
+ */
754
+ export interface EnvFunction {
755
+ /**
756
+ * @returns the current `envName` string
757
+ */
758
+ (): string;
759
+ /**
760
+ * @returns `true` if the `envName` is `===` any of the given strings
761
+ */
762
+ (envName: string | ReadonlyArray<string>): boolean;
763
+ // the official documentation is misleading for this one...
764
+ // this just passes the callback to `cache.using` but with an additional argument.
765
+ // it returns its result instead of necessarily returning a boolean.
766
+ <T extends SimpleCacheKey>(envCallback: (envName: NonNullable<TransformOptions['envName']>) => T): T;
767
+ }
768
+
769
+ export type ConfigFunction = (api: ConfigAPI) => TransformOptions;
770
+
771
+ export as namespace babel;