@stylexjs/rollup-plugin 0.16.2 → 0.16.3

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