@atlaspack/types-internal 2.14.1-dev.11 → 2.14.1-dev.123

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.
package/src/index.js DELETED
@@ -1,2158 +0,0 @@
1
- // @flow strict-local
2
-
3
- import type {Readable} from 'stream';
4
- import type SourceMap from '@parcel/source-map';
5
- import type {
6
- Diagnostic,
7
- Diagnostifiable,
8
- DiagnosticWithoutOrigin,
9
- } from '@atlaspack/diagnostic';
10
- import type {FeatureFlags} from '@atlaspack/feature-flags';
11
- import type {Event, BackendType} from '@parcel/watcher';
12
-
13
- import type {Cache} from './Cache';
14
- import type {
15
- FileSystem,
16
- FileOptions,
17
- Stats as FileStats,
18
- ReaddirOptions,
19
- Encoding,
20
- Dirent,
21
- } from './FileSystem';
22
- import type {AST as _AST, ConfigResult as _ConfigResult} from './unsafe';
23
- import type {FilePath} from './FilePath';
24
- import type {Glob} from './Glob';
25
- import type {PackageName} from './PackageName';
26
- import type {
27
- PackageManager,
28
- PackageManagerResolveResult,
29
- Invalidations,
30
- PackageInstaller,
31
- ModuleRequest,
32
- InstallOptions,
33
- InstallerOptions,
34
- } from './PackageManager';
35
- import type {SemverRange} from './SemverRange';
36
- import type {DependencySpecifier} from './DependencySpecifier';
37
- import type {
38
- FileCreateInvalidation,
39
- GlobInvalidation,
40
- FileInvalidation,
41
- FileAboveInvalidation,
42
- } from './FileCreateInvalidation';
43
- import type {NapiWorkerPool} from './NapiWorkerPool';
44
-
45
- export interface TraceMeasurement {
46
- end(): void;
47
- }
48
-
49
- export type {
50
- FilePath,
51
- FileSystem,
52
- FileOptions,
53
- FileStats,
54
- ReaddirOptions,
55
- Encoding,
56
- Dirent,
57
- PackageName,
58
- Glob,
59
- DependencySpecifier,
60
- SemverRange,
61
- FileCreateInvalidation,
62
- GlobInvalidation,
63
- FileInvalidation,
64
- FileAboveInvalidation,
65
- PackageManager,
66
- PackageManagerResolveResult,
67
- Invalidations,
68
- PackageInstaller,
69
- ModuleRequest,
70
- InstallOptions,
71
- InstallerOptions,
72
- Cache,
73
- NapiWorkerPool,
74
- };
75
-
76
- /** Plugin-specific AST, <code>any</code> */
77
- export type AST = _AST;
78
- export type ConfigResult = _ConfigResult;
79
- /** Plugin-specific config result, <code>any</code> */
80
- export type ConfigResultWithFilePath<T> = {|
81
- contents: T,
82
- filePath: FilePath,
83
- |};
84
- /** <code>process.env</code> */
85
- export type EnvMap = typeof process.env;
86
-
87
- export type JSONValue =
88
- | null
89
- | void // ? Is this okay?
90
- | boolean
91
- | number
92
- | string
93
- | Array<JSONValue>
94
- | JSONObject;
95
-
96
- /** A JSON object (as in "map") */
97
- export type JSONObject = {[key: string]: JSONValue, ...};
98
-
99
- export type Semver = string;
100
- /** A pipeline as specified in the config mapping to <code>T</code> */
101
- export type GlobMap<T> = {[Glob]: T, ...};
102
-
103
- export type RawAtlaspackConfigPipeline = Array<PackageName>;
104
- export type RawParcelConfigPipeline = RawAtlaspackConfigPipeline;
105
-
106
- export type HMROptions = {
107
- port?: number,
108
- host?: string,
109
- ...
110
- };
111
-
112
- /** The format of .parcelrc */
113
- export type RawAtlaspackConfig = {|
114
- extends?: PackageName | FilePath | Array<PackageName | FilePath>,
115
- resolvers?: RawAtlaspackConfigPipeline,
116
- transformers?: {[Glob]: RawAtlaspackConfigPipeline, ...},
117
- bundler?: PackageName,
118
- namers?: RawAtlaspackConfigPipeline,
119
- runtimes?: RawAtlaspackConfigPipeline,
120
- packagers?: {[Glob]: PackageName, ...},
121
- optimizers?: {[Glob]: RawAtlaspackConfigPipeline, ...},
122
- compressors?: {[Glob]: RawAtlaspackConfigPipeline, ...},
123
- reporters?: RawAtlaspackConfigPipeline,
124
- validators?: {[Glob]: RawAtlaspackConfigPipeline, ...},
125
- |};
126
- export type RawParcelConfig = RawAtlaspackConfig;
127
-
128
- /** A .parcelrc where all package names are resolved */
129
- export type ResolvedAtlaspackConfigFile = {|
130
- ...RawAtlaspackConfig,
131
- +filePath: FilePath,
132
- +resolveFrom?: FilePath,
133
- |};
134
- export type ResolvedParcelConfigFile = ResolvedAtlaspackConfigFile;
135
-
136
- /** Corresponds to <code>pkg#engines</code> */
137
- export type Engines = {
138
- +atlaspack?: SemverRange,
139
- +browsers?: string | Array<string>,
140
- +electron?: SemverRange,
141
- +node?: SemverRange,
142
- +parcel?: SemverRange,
143
- ...
144
- };
145
-
146
- /** Corresponds to <code>pkg#targets.*.sourceMap</code> */
147
- export type TargetSourceMapOptions = {|
148
- +sourceRoot?: string,
149
- +inline?: boolean,
150
- +inlineSources?: boolean,
151
- |};
152
-
153
- /**
154
- * A parsed version of PackageTargetDescriptor
155
- */
156
- export interface Target {
157
- /** The output filename of the entry */
158
- +distEntry: ?FilePath;
159
- /** The output folder */
160
- +distDir: FilePath;
161
- +env: Environment;
162
- +name: string;
163
- +publicUrl: string;
164
- /** The location that created this Target, e.g. `package.json#main`*/
165
- +loc: ?SourceLocation;
166
- }
167
-
168
- /** In which environment the output should run (influces e.g. bundle loaders) */
169
- export type EnvironmentContext =
170
- | 'browser'
171
- | 'web-worker'
172
- | 'service-worker'
173
- | 'worklet'
174
- | 'node'
175
- | 'electron-main'
176
- | 'electron-renderer';
177
-
178
- /** The JS module format for the bundle output */
179
- export type OutputFormat = 'esmodule' | 'commonjs' | 'global';
180
-
181
- /**
182
- * The format of <code>pkg#targets.*</code>
183
- *
184
- * See Environment and Target.
185
- */
186
- export type PackageTargetDescriptor = {|
187
- +context?: EnvironmentContext,
188
- +engines?: Engines,
189
- +includeNodeModules?:
190
- | boolean
191
- | Array<PackageName>
192
- | {[PackageName]: boolean, ...},
193
- +outputFormat?: OutputFormat,
194
- +publicUrl?: string,
195
- +distDir?: FilePath,
196
- +sourceMap?: boolean | TargetSourceMapOptions,
197
- +isLibrary?: boolean,
198
- +optimize?: boolean,
199
- +scopeHoist?: boolean,
200
- +source?: FilePath | Array<FilePath>,
201
- +__unstable_singleFileOutput?: boolean,
202
- |};
203
-
204
- /**
205
- * The target format when using the JS API.
206
- *
207
- * (Same as PackageTargetDescriptor, but <code>distDir</code> is required.)
208
- */
209
- export type TargetDescriptor = {|
210
- ...PackageTargetDescriptor,
211
- +distDir: FilePath,
212
- +distEntry?: FilePath,
213
- |};
214
-
215
- export type SourceType = 'script' | 'module';
216
-
217
- /**
218
- * This is used when creating an Environment (see that).
219
- */
220
- export type EnvironmentOptions = {|
221
- +context?: EnvironmentContext,
222
- +engines?: Engines,
223
- +includeNodeModules?:
224
- | boolean
225
- | Array<PackageName>
226
- | {[PackageName]: boolean, ...},
227
- +outputFormat?: OutputFormat,
228
- +sourceType?: SourceType,
229
- +isLibrary?: boolean,
230
- +shouldOptimize?: boolean,
231
- +shouldScopeHoist?: boolean,
232
- +sourceMap?: ?TargetSourceMapOptions,
233
- +loc?: ?SourceLocation,
234
- +unstableSingleFileOutput?: boolean,
235
- |};
236
-
237
- /**
238
- * A resolved browserslist, e.g.:
239
- * <pre><code>
240
- * {
241
- * edge: '76',
242
- * firefox: '67',
243
- * chrome: '63',
244
- * safari: '11.1',
245
- * opera: '50',
246
- * }
247
- * </code></pre>
248
- */
249
- export type VersionMap = {
250
- [string]: string,
251
- ...
252
- };
253
-
254
- export type EnvironmentFeature =
255
- | 'esmodules'
256
- | 'dynamic-import'
257
- | 'worker-module'
258
- | 'service-worker-module'
259
- | 'import-meta-url'
260
- | 'arrow-functions'
261
- | 'global-this';
262
-
263
- /**
264
- * Defines the environment in for the output bundle
265
- */
266
- export interface Environment {
267
- +id: string;
268
- +context: EnvironmentContext;
269
- +engines: Engines;
270
- /** Whether to include all/none packages \
271
- * (<code>true / false</code>), an array of package names to include, or an object \
272
- * (of a package is not specified, it's included).
273
- */
274
- +includeNodeModules:
275
- | boolean
276
- | Array<PackageName>
277
- | {[PackageName]: boolean, ...};
278
- +outputFormat: OutputFormat;
279
- +sourceType: SourceType;
280
- /** Whether this is a library build (e.g. less loaders) */
281
- +isLibrary: boolean;
282
- /** Whether the output should be minified. */
283
- +shouldOptimize: boolean;
284
- /** Whether scope hoisting is enabled. */
285
- +shouldScopeHoist: boolean;
286
- +sourceMap: ?TargetSourceMapOptions;
287
- +loc: ?SourceLocation;
288
- +unstableSingleFileOutput: boolean;
289
-
290
- /** Whether <code>context</code> specifies a browser context. */
291
- isBrowser(): boolean;
292
- /** Whether <code>context</code> specifies a node context. */
293
- isNode(): boolean;
294
- /** Whether <code>context</code> specifies an electron context. */
295
- isElectron(): boolean;
296
- /** Whether <code>context</code> specifies a worker context. */
297
- isWorker(): boolean;
298
- /** Whether <code>context</code> specifies a worklet context. */
299
- isWorklet(): boolean;
300
- /** Whether <code>context</code> specifies an isolated context (can't access other loaded ancestor bundles). */
301
- isIsolated(): boolean;
302
- matchesEngines(minVersions: VersionMap, defaultValue?: boolean): boolean;
303
- supports(feature: EnvironmentFeature, defaultValue?: boolean): boolean;
304
- }
305
-
306
- /**
307
- * Format of <code>pkg#dependencies</code>, <code>pkg#devDependencies</code>, <code>pkg#peerDependencies</code>
308
- */
309
- type PackageDependencies = {|
310
- [PackageName]: Semver,
311
- |};
312
-
313
- /**
314
- * Format of <code>package.json</code>
315
- */
316
- export type PackageJSON = {
317
- name: PackageName,
318
- version: Semver,
319
- type?: 'module',
320
- main?: FilePath,
321
- module?: FilePath,
322
- types?: FilePath,
323
- browser?: FilePath | {[FilePath]: FilePath | boolean, ...},
324
- source?: FilePath | Array<FilePath>,
325
- alias?: {
326
- [PackageName | FilePath | Glob]:
327
- | PackageName
328
- | FilePath
329
- | {|global: string|},
330
- ...
331
- },
332
- browserslist?: Array<string> | {[string]: Array<string>},
333
- engines?: Engines,
334
- targets?: {[string]: PackageTargetDescriptor, ...},
335
- dependencies?: PackageDependencies,
336
- devDependencies?: PackageDependencies,
337
- peerDependencies?: PackageDependencies,
338
- sideEffects?: boolean | FilePath | Array<FilePath>,
339
- bin?: string | {|[string]: FilePath|},
340
- ...
341
- };
342
-
343
- export type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'verbose';
344
- export type BuildMode = 'development' | 'production' | string;
345
- export type DetailedReportOptions = {|
346
- assetsPerBundle?: number,
347
- |};
348
-
349
- declare type GlobPattern = string;
350
-
351
- export type InitialAtlaspackOptionsInternal<WorkerFarm> = {|
352
- +entries?: FilePath | Array<FilePath>,
353
- +config?: DependencySpecifier,
354
- +defaultConfig?: DependencySpecifier,
355
- +env?: EnvMap,
356
- +targets?: ?(Array<string> | {+[string]: TargetDescriptor, ...}),
357
-
358
- +shouldDisableCache?: boolean,
359
- +cacheDir?: FilePath,
360
- +watchDir?: FilePath,
361
- +watchBackend?: BackendType,
362
- +watchIgnore?: Array<FilePath | GlobPattern>,
363
- +mode?: BuildMode,
364
- +hmrOptions?: ?HMROptions,
365
- +shouldContentHash?: boolean,
366
- +serveOptions?: InitialServerOptions | false,
367
- +shouldAutoInstall?: boolean,
368
- +logLevel?: LogLevel,
369
- +shouldProfile?: boolean,
370
- +shouldTrace?: boolean,
371
- +shouldPatchConsole?: boolean,
372
- +shouldBuildLazily?: boolean,
373
- +lazyIncludes?: string[],
374
- +lazyExcludes?: string[],
375
- +shouldBundleIncrementally?: boolean,
376
- +unstableFileInvalidations?: Array<Event>,
377
-
378
- +inputFS?: FileSystem,
379
- +outputFS?: FileSystem,
380
- +cache?: Cache,
381
- +workerFarm?: WorkerFarm,
382
- +napiWorkerPool?: NapiWorkerPool,
383
- +packageManager?: PackageManager,
384
- +detailedReport?: ?DetailedReportOptions,
385
-
386
- +defaultTargetOptions?: {|
387
- +shouldOptimize?: boolean,
388
- +shouldScopeHoist?: boolean,
389
- +sourceMaps?: boolean,
390
- +publicUrl?: string,
391
- +distDir?: FilePath,
392
- +engines?: Engines,
393
- +outputFormat?: OutputFormat,
394
- +isLibrary?: boolean,
395
- |},
396
-
397
- +additionalReporters?: Array<{|
398
- packageName: DependencySpecifier,
399
- resolveFrom: FilePath,
400
- |}>,
401
-
402
- +featureFlags?: $Partial<FeatureFlags>,
403
-
404
- // throwErrors
405
- // global?
406
- |};
407
- export type InitialParcelOptionsInternal<WorkerFarm> =
408
- InitialAtlaspackOptionsInternal<WorkerFarm>;
409
-
410
- export type InitialServerOptions = {|
411
- +publicUrl?: string,
412
- +host?: string,
413
- +port: number,
414
- +https?: HTTPSOptions | boolean,
415
- |};
416
-
417
- export interface PluginOptions {
418
- +mode: BuildMode;
419
- +parcelVersion: string;
420
- +env: EnvMap;
421
- +hmrOptions: ?HMROptions;
422
- +serveOptions: ServerOptions | false;
423
- +shouldBuildLazily: boolean;
424
- +shouldAutoInstall: boolean;
425
- +logLevel: LogLevel;
426
- +projectRoot: FilePath;
427
- +cacheDir: FilePath;
428
- +inputFS: FileSystem;
429
- +outputFS: FileSystem;
430
- +packageManager: PackageManager;
431
- +instanceId: string;
432
- +detailedReport: ?DetailedReportOptions;
433
- +featureFlags: FeatureFlags;
434
- }
435
-
436
- export type ServerOptions = {|
437
- +distDir: FilePath,
438
- +host?: string,
439
- +port: number,
440
- +https?: HTTPSOptions | boolean,
441
- +publicUrl?: string,
442
- |};
443
-
444
- export type HTTPSOptions = {|
445
- +cert: FilePath,
446
- +key: FilePath,
447
- |};
448
-
449
- /**
450
- * Source locations are 1-based, meaning lines and columns start at 1
451
- */
452
- export type SourceLocation = {|
453
- +filePath: string,
454
- /** inclusive */
455
- +start: {|
456
- +line: number,
457
- +column: number,
458
- |},
459
- /** exclusive */
460
- +end: {|
461
- +line: number,
462
- +column: number,
463
- |},
464
- |};
465
-
466
- /**
467
- * An object that plugins can write arbitrary data to.
468
- */
469
- export type Meta = JSONObject;
470
-
471
- /**
472
- * An identifier in an asset (likely imported/exported).
473
- */
474
- export type Symbol = string;
475
-
476
- /**
477
- * A map of export names to the corresponding asset's local variable names.
478
- */
479
- export interface AssetSymbols // eslint-disable-next-line no-undef
480
- extends Iterable<
481
- [Symbol, {|local: Symbol, loc: ?SourceLocation, meta?: ?Meta|}],
482
- > {
483
- /**
484
- * The exports of the asset are unknown, rather than just empty.
485
- * This is the default state.
486
- */
487
- +isCleared: boolean;
488
- get(exportSymbol: Symbol): ?{|
489
- local: Symbol,
490
- loc: ?SourceLocation,
491
- meta?: ?Meta,
492
- |};
493
- hasExportSymbol(exportSymbol: Symbol): boolean;
494
- hasLocalSymbol(local: Symbol): boolean;
495
- exportSymbols(): Iterable<Symbol>;
496
- }
497
-
498
- export interface MutableAssetSymbols extends AssetSymbols {
499
- /**
500
- * Initializes the map, sets isCleared to false.
501
- */
502
- ensure(): void;
503
- set(
504
- exportSymbol: Symbol,
505
- local: Symbol,
506
- loc: ?SourceLocation,
507
- meta?: ?Meta,
508
- ): void;
509
- delete(exportSymbol: Symbol): void;
510
- }
511
-
512
- /**
513
- * isWeak means: the symbol is not used by the parent asset itself and is merely reexported
514
- */
515
- export interface MutableDependencySymbols // eslint-disable-next-line no-undef
516
- extends Iterable<
517
- [
518
- Symbol,
519
- {|local: Symbol, loc: ?SourceLocation, isWeak: boolean, meta?: ?Meta|},
520
- ],
521
- > {
522
- /**
523
- * Initializes the map, sets isCleared to false.
524
- */
525
- ensure(): void;
526
- /**
527
- * The symbols that are imports are unknown, rather than just empty.
528
- * This is the default state.
529
- */
530
- +isCleared: boolean;
531
- get(exportSymbol: Symbol): ?{|
532
- local: Symbol,
533
- loc: ?SourceLocation,
534
- isWeak: boolean,
535
- meta?: ?Meta,
536
- |};
537
- hasExportSymbol(exportSymbol: Symbol): boolean;
538
- hasLocalSymbol(local: Symbol): boolean;
539
- exportSymbols(): Iterable<Symbol>;
540
- set(
541
- exportSymbol: Symbol,
542
- local: Symbol,
543
- loc: ?SourceLocation,
544
- isWeak: ?boolean,
545
- ): void;
546
- delete(exportSymbol: Symbol): void;
547
- }
548
-
549
- export type DependencyPriority = 'sync' | 'parallel' | 'lazy' | 'conditional';
550
- export type SpecifierType = 'commonjs' | 'esm' | 'url' | 'custom';
551
-
552
- /**
553
- * Used when creating a Dependency, see that.
554
- * @section transformer
555
- */
556
- export type DependencyOptions = {|
557
- /** The specifier used to resolve the dependency. */
558
- +specifier: DependencySpecifier,
559
- /**
560
- * How the specifier should be interpreted.
561
- * - esm: An ES module specifier. It is parsed as a URL, but bare specifiers are treated as node_modules.
562
- * - commonjs: A CommonJS specifier. It is not parsed as a URL.
563
- * - url: A URL that works as in a browser. Bare specifiers are treated as relative URLs.
564
- * - custom: A custom specifier. Must be handled by a custom resolver plugin.
565
- */
566
- +specifierType: SpecifierType,
567
- /**
568
- * When the dependency should be loaded.
569
- * - sync: The dependency should be resolvable synchronously. The resolved asset will be placed
570
- * in the same bundle as the parent, or another bundle that's already on the page.
571
- * - parallel: The dependency should be placed in a separate bundle that's loaded in parallel
572
- * with the current bundle.
573
- * - lazy: The dependency should be placed in a separate bundle that's loaded later.
574
- * @default 'sync'
575
- */
576
- +priority?: DependencyPriority,
577
- /**
578
- * Controls the behavior of the bundle the resolved asset is placed into. Use in combination with `priority`
579
- * to determine when the bundle is loaded.
580
- * - inline: The resolved asset will be placed into a new inline bundle. Inline bundles are not written
581
- * to a separate file, but embedded into the parent bundle.
582
- * - isolated: The resolved asset will be isolated from its parents in a separate bundle.
583
- * Shared assets will be duplicated.
584
- */
585
- +bundleBehavior?: BundleBehavior,
586
- /**
587
- * When the dependency is a bundle entry (priority is "parallel" or "lazy"), this controls the naming
588
- * of that bundle. `needsStableName` indicates that the name should be stable over time, even when the
589
- * content of the bundle changes. This is useful for entries that a user would manually enter the URL
590
- * for, as well as for things like service workers or RSS feeds, where the URL must remain consistent
591
- * over time.
592
- */
593
- +needsStableName?: boolean,
594
- /** Whether the dependency is optional. If the dependency cannot be resolved, this will not fail the build. */
595
- +isOptional?: boolean,
596
- /** The location within the source file where the dependency was found. */
597
- +loc?: SourceLocation,
598
- /** The environment of the dependency. */
599
- +env?: EnvironmentOptions,
600
- /**
601
- * A list of custom conditions to use when resolving package.json "exports" and "imports".
602
- * This is combined with the conditions from the environment. However, it overrides the
603
- * default "import" and "require" conditions inferred from the specifierType. To include those
604
- * in addition to custom conditions, explicitly add them to this list.
605
- */
606
- +packageConditions?: Array<string>,
607
- /** Plugin-specific metadata for the dependency. */
608
- +meta?: Meta,
609
- /** The pipeline defined in .parcelrc that the dependency should be processed with. */
610
- +pipeline?: string,
611
- /**
612
- * The file path where the dependency should be resolved from.
613
- * By default, this is the path of the source file where the dependency was specified.
614
- */
615
- +resolveFrom?: FilePath,
616
- /** The semver version range expected for the dependency. */
617
- +range?: SemverRange,
618
- /** The symbols within the resolved module that the source file depends on. */
619
- +symbols?: $ReadOnlyMap<
620
- Symbol,
621
- {|local: Symbol, loc: ?SourceLocation, isWeak: boolean, meta?: Meta|},
622
- >,
623
- |};
624
-
625
- /**
626
- * A Dependency denotes a connection between two assets \
627
- * (likely some effect from the importee is expected - be it a side effect or a value is being imported).
628
- *
629
- * @section transformer
630
- */
631
- export interface Dependency {
632
- /** The id of the dependency. */
633
- +id: string;
634
- /** The specifier used to resolve the dependency. */
635
- +specifier: DependencySpecifier;
636
- /**
637
- * How the specifier should be interpreted.
638
- * - esm: An ES module specifier. It is parsed as a URL, but bare specifiers are treated as node_modules.
639
- * - commonjs: A CommonJS specifier. It is not parsed as a URL.
640
- * - url: A URL that works as in a browser. Bare specifiers are treated as relative URLs.
641
- * - custom: A custom specifier. Must be handled by a custom resolver plugin.
642
- */
643
- +specifierType: SpecifierType;
644
- /**
645
- * When the dependency should be loaded.
646
- * - sync: The dependency should be resolvable synchronously. The resolved asset will be placed
647
- * in the same bundle as the parent, or another bundle that's already on the page.
648
- * - parallel: The dependency should be placed in a separate bundle that's loaded in parallel
649
- * with the current bundle.
650
- * - lazy: The dependency should be placed in a separate bundle that's loaded later.
651
- * @default 'sync'
652
- */
653
- +priority: DependencyPriority;
654
- /**
655
- * Controls the behavior of the bundle the resolved asset is placed into. Use in combination with `priority`
656
- * to determine when the bundle is loaded.
657
- * - inline: The resolved asset will be placed into a new inline bundle. Inline bundles are not written
658
- * to a separate file, but embedded into the parent bundle.
659
- * - isolated: The resolved asset will be isolated from its parents in a separate bundle.
660
- * Shared assets will be duplicated.
661
- */
662
- +bundleBehavior: ?BundleBehavior;
663
- /**
664
- * When the dependency is a bundle entry (priority is "parallel" or "lazy"), this controls the naming
665
- * of that bundle. `needsStableName` indicates that the name should be stable over time, even when the
666
- * content of the bundle changes. This is useful for entries that a user would manually enter the URL
667
- * for, as well as for things like service workers or RSS feeds, where the URL must remain consistent
668
- * over time.
669
- */
670
- +needsStableName: boolean;
671
- /** Whether the dependency is optional. If the dependency cannot be resolved, this will not fail the build. */
672
- +isOptional: boolean;
673
- /** Whether the dependency is an entry. */
674
- +isEntry: boolean;
675
- /** The location within the source file where the dependency was found. */
676
- +loc: ?SourceLocation;
677
- /** The environment of the dependency. */
678
- +env: Environment;
679
- /**
680
- * A list of custom conditions to use when resolving package.json "exports" and "imports".
681
- * This is combined with the conditions from the environment. However, it overrides the
682
- * default "import" and "require" conditions inferred from the specifierType. To include those
683
- * in addition to custom conditions, explicitly add them to this list.
684
- */
685
- +packageConditions: ?Array<string>;
686
- /** Plugin-specific metadata for the dependency. */
687
- +meta: Meta;
688
- /** If this is an entry, this is the target that is associated with that entry. */
689
- +target: ?Target;
690
- /** The id of the asset with this dependency. */
691
- +sourceAssetId: ?string;
692
- /** The file path of the asset with this dependency. */
693
- +sourcePath: ?FilePath;
694
- /** The type of the asset that referenced this dependency. */
695
- +sourceAssetType: ?string;
696
- /**
697
- * The file path where the dependency should be resolved from.
698
- * By default, this is the path of the source file where the dependency was specified.
699
- */
700
- +resolveFrom: ?FilePath;
701
- /** The semver version range expected for the dependency. */
702
- +range: ?SemverRange;
703
- /** The pipeline defined in .parcelrc that the dependency should be processed with. */
704
- +pipeline: ?string;
705
-
706
- // TODO make immutable
707
- /** The symbols within the resolved module that the source file depends on. */
708
- +symbols: MutableDependencySymbols;
709
- }
710
-
711
- export type File = {|
712
- +filePath: FilePath,
713
- +hash?: string,
714
- |};
715
-
716
- /**
717
- * @section transformer
718
- */
719
- export type ASTGenerator = {|
720
- type: string,
721
- version: Semver,
722
- |};
723
-
724
- export type BundleBehavior = 'inline' | 'isolated';
725
-
726
- export type AtlaspackTransformOptions = {|
727
- filePath: FilePath,
728
- code?: string,
729
- env?: EnvironmentOptions,
730
- query?: ?string,
731
- |};
732
- export type ParcelTransformOptions = AtlaspackTransformOptions;
733
-
734
- export type AtlaspackResolveOptions = {|
735
- specifier: DependencySpecifier,
736
- specifierType: SpecifierType,
737
- env?: EnvironmentOptions,
738
- resolveFrom?: FilePath,
739
- |};
740
- export type ParcelResolveOptions = AtlaspackResolveOptions;
741
-
742
- export type AtlaspackResolveResult = {|
743
- filePath: FilePath,
744
- code?: string,
745
- query?: ?string,
746
- sideEffects?: boolean,
747
- |};
748
- export type ParcelResolveResult = AtlaspackResolveResult;
749
-
750
- /**
751
- * An asset represents a file or part of a file. It may represent any data type, including source code,
752
- * binary data, etc. Assets may exist in the file system or may be virtual.
753
- *
754
- * @section transformer
755
- */
756
- export interface BaseAsset {
757
- /** The id of the asset. */
758
- +id: string;
759
- /** The file system where the source is located. */
760
- +fs: FileSystem;
761
- /** The file path of the asset. */
762
- +filePath: FilePath;
763
- /**
764
- * The asset's type. This initially corresponds to the source file extension,
765
- * but it may be changed during transformation.
766
- */
767
- +type: string;
768
- /** The transformer options for the asset from the dependency query string. */
769
- +query: URLSearchParams;
770
- /** The environment of the asset. */
771
- +env: Environment;
772
- /**
773
- * Whether this asset is part of the project, and not an external dependency (e.g. in node_modules).
774
- * This indicates that transformation using the project's configuration should be applied.
775
- */
776
- +isSource: boolean;
777
- /** Plugin-specific metadata for the asset. */
778
- +meta: Meta;
779
- /**
780
- * Controls which bundle the asset is placed into.
781
- * - inline: The asset will be placed into a new inline bundle. Inline bundles are not written
782
- * to a separate file, but embedded into the parent bundle.
783
- * - isolated: The asset will be isolated from its parents in a separate bundle. Shared assets
784
- * will be duplicated.
785
- */
786
- +bundleBehavior: ?BundleBehavior;
787
- /**
788
- * If the asset is used as a bundle entry, this controls whether that bundle can be split
789
- * into multiple, or whether all of the dependencies must be placed in a single bundle.
790
- */
791
- +isBundleSplittable: boolean;
792
- /**
793
- * Whether this asset can be omitted if none of its exports are being used.
794
- * This is initially set by the resolver, but can be overridden by transformers.
795
- */
796
- +sideEffects: boolean;
797
- /**
798
- * When a transformer returns multiple assets, it can give them unique keys to identify them.
799
- * This can be used to find assets during packaging, or to create dependencies between multiple
800
- * assets returned by a transformer by using the unique key as the dependency specifier.
801
- */
802
- +uniqueKey: ?string;
803
- /** The type of the AST. */
804
- +astGenerator: ?ASTGenerator;
805
- /** The pipeline defined in .parcelrc that the asset should be processed with. */
806
- +pipeline: ?string;
807
- /** The symbols that the asset exports. */
808
- +symbols: AssetSymbols;
809
- /** Returns the current AST. */
810
- getAST(): Promise<?AST>;
811
- /** Returns the asset contents as a string. */
812
- getCode(): Promise<string>;
813
- /** Returns the asset contents as a buffer. */
814
- getBuffer(): Promise<Buffer>;
815
- /** Returns the asset contents as a stream. */
816
- getStream(): Readable;
817
- /** Returns the source map for the asset, if available. */
818
- getMap(): Promise<?SourceMap>;
819
- /** Returns a buffer representation of the source map, if available. */
820
- getMapBuffer(): Promise<?Buffer>;
821
- /** Returns a list of dependencies for the asset. */
822
- getDependencies(): $ReadOnlyArray<Dependency>;
823
- }
824
-
825
- /**
826
- * A mutable Asset, available during transformation.
827
- * @section transformer
828
- */
829
- export interface MutableAsset extends BaseAsset {
830
- /**
831
- * The asset's type. This initially corresponds to the source file extension,
832
- * but it may be changed during transformation.
833
- */
834
- type: string;
835
- /**
836
- * Controls which bundle the asset is placed into.
837
- * - inline: The asset will be placed into a new inline bundle. Inline bundles are not written
838
- * to a separate file, but embedded into the parent bundle.
839
- * - isolated: The asset will be isolated from its parents in a separate bundle. Shared assets
840
- * will be duplicated.
841
- */
842
- bundleBehavior: ?BundleBehavior;
843
- /**
844
- * If the asset is used as a bundle entry, this controls whether that bundle can be split
845
- * into multiple, or whether all of the dependencies must be placed in a single bundle.
846
- * @default true
847
- */
848
- isBundleSplittable: boolean;
849
- /**
850
- * Whether this asset can be omitted if none of its exports are being used.
851
- * This is initially set by the resolver, but can be overridden by transformers.
852
- */
853
- sideEffects: boolean;
854
- /**
855
- * When a transformer returns multiple assets, it can give them unique keys to identify them.
856
- * This can be used to find assets during packaging, or to create dependencies between multiple
857
- * assets returned by a transformer by using the unique key as the dependency specifier.
858
- */
859
- uniqueKey: ?string;
860
- /** The symbols that the asset exports. */
861
- +symbols: MutableAssetSymbols;
862
-
863
- /** Adds a dependency to the asset. */
864
- addDependency(DependencyOptions): string;
865
- /**
866
- * Adds a url dependency to the asset.
867
- * This is a shortcut for addDependency that sets the specifierType to 'url' and priority to 'lazy'.
868
- */
869
- addURLDependency(url: string, opts: $Shape<DependencyOptions>): string;
870
- /** Invalidates the transformation when the given file is modified or deleted. */
871
- invalidateOnFileChange(FilePath): void;
872
- /** Invalidates the transformation when matched files are created. */
873
- invalidateOnFileCreate(FileCreateInvalidation): void;
874
- /** Invalidates the transformation when the given environment variable changes. */
875
- invalidateOnEnvChange(string): void;
876
- /** Invalidates the transformation only when Atlaspack restarts. */
877
- invalidateOnStartup(): void;
878
- /** Invalidates the transformation on every build. */
879
- invalidateOnBuild(): void;
880
- /** Sets the asset contents as a string. */
881
- setCode(string): void;
882
- /** Sets the asset contents as a buffer. */
883
- setBuffer(Buffer): void;
884
- /** Sets the asset contents as a stream. */
885
- setStream(Readable): void;
886
- /** Sets the asset's AST. */
887
- setAST(AST): void;
888
- /** Returns whether the AST has been modified. */
889
- isASTDirty(): boolean;
890
- /** Sets the asset's source map. */
891
- setMap(?SourceMap): void;
892
- setEnvironment(opts: EnvironmentOptions): void;
893
- }
894
-
895
- /**
896
- * An immutable Asset, available after transformation.
897
- * @section transformer
898
- */
899
- export interface Asset extends BaseAsset {
900
- /** Statistics about the asset. */
901
- +stats: Stats;
902
- }
903
-
904
- export type DevDepOptions = {|
905
- specifier: DependencySpecifier,
906
- resolveFrom: FilePath,
907
- range?: ?SemverRange,
908
- /**
909
- * When this dev dependency is invalidated, also invalidate these dependencies.
910
- * This is useful if the parcel plugin or another parent dependency
911
- * has its own cache for this dev dependency other than Node's require cache.
912
- */
913
- additionalInvalidations?: Array<{|
914
- specifier: DependencySpecifier,
915
- resolveFrom: FilePath,
916
- range?: ?SemverRange,
917
- |}>,
918
- |};
919
-
920
- /**
921
- * @section transformer
922
- */
923
- export interface Config {
924
- /**
925
- * Whether this config is part of the project, and not an external dependency (e.g. in node_modules).
926
- * This indicates that transformation using the project's configuration should be applied.
927
- */
928
- +isSource: boolean;
929
- /** The path of the file to start searching for config from. */
930
- +searchPath: FilePath;
931
- /** The environment */
932
- +env: Environment;
933
-
934
- /** Invalidates the config when the given file is modified or deleted. */
935
- invalidateOnFileChange(FilePath): void;
936
- /** Invalidates the config when matched files are created. */
937
- invalidateOnFileCreate(FileCreateInvalidation): void;
938
- /** Invalidates the config when the given environment variable changes. */
939
- invalidateOnEnvChange(string): void;
940
- /** Invalidates the config only when Atlaspack restarts. */
941
- invalidateOnStartup(): void;
942
- /** Invalidates the config on every build. */
943
- invalidateOnBuild(): void;
944
- /**
945
- * Adds a dev dependency to the config. If the dev dependency or any of its
946
- * dependencies change, the config will be invalidated.
947
- */
948
- addDevDependency(DevDepOptions): void;
949
- /**
950
- * Sets the cache key for the config. By default, this is computed as a hash of the
951
- * files passed to invalidateOnFileChange or loaded by getConfig. If none, then a
952
- * hash of the result returned from loadConfig is used. This method can be used to
953
- * override this behavior and explicitly control the cache key. This can be useful
954
- * in cases where only part of a file is used to avoid unnecessary invalidations,
955
- * or when the result is not hashable (i.e. contains non-serializable properties like functions).
956
- */
957
- setCacheKey(string): void;
958
-
959
- /**
960
- * Searches for config files with the given names in all parent directories
961
- * of the config's searchPath.
962
- */
963
- getConfig<T>(
964
- filePaths: Array<FilePath>,
965
- options?: {|
966
- packageKey?: string,
967
- parse?: boolean,
968
- exclude?: boolean,
969
- |},
970
- ): Promise<?ConfigResultWithFilePath<T>>;
971
- /**
972
- * Searches for config files with the given names in all parent directories
973
- * of the passed searchPath.
974
- */
975
- getConfigFrom<T>(
976
- searchPath: FilePath,
977
- filePaths: Array<FilePath>,
978
- options?: {|
979
- packageKey?: string,
980
- parse?: boolean,
981
- exclude?: boolean,
982
- |},
983
- ): Promise<?ConfigResultWithFilePath<T>>;
984
- /** Finds the nearest package.json from the config's searchPath. */
985
- getPackage(): Promise<?PackageJSON>;
986
- }
987
-
988
- export type Stats = {|
989
- time: number,
990
- size: number,
991
- |};
992
-
993
- /**
994
- * @section transformer
995
- */
996
- export type GenerateOutput = {|
997
- +content: Blob,
998
- +map?: ?SourceMap,
999
- |};
1000
-
1001
- export type Blob = string | Buffer | Readable;
1002
-
1003
- /**
1004
- * Transformers can return multiple result objects to create new assets.
1005
- * For example, a file may contain multiple parts of different types,
1006
- * which should be processed by their respective transformation pipelines.
1007
- *
1008
- * @section transformer
1009
- */
1010
- export type TransformerResult = {|
1011
- /** The asset's type. */
1012
- +type: string,
1013
- /** The content of the asset. Either content or an AST is required. */
1014
- +content?: ?Blob,
1015
- /** The asset's AST. Either content or an AST is required. */
1016
- +ast?: ?AST,
1017
- /** The source map for the asset. */
1018
- +map?: ?SourceMap,
1019
- /** The dependencies of the asset. */
1020
- +dependencies?: $ReadOnlyArray<DependencyOptions>,
1021
- /** The environment of the asset. The options are merged with the input asset's environment. */
1022
- +env?: EnvironmentOptions | Environment,
1023
- /**
1024
- * Controls which bundle the asset is placed into.
1025
- * - inline: The asset will be placed into a new inline bundle. Inline bundles are not written
1026
- * to a separate file, but embedded into the parent bundle.
1027
- * - isolated: The asset will be isolated from its parents in a separate bundle. Shared assets
1028
- * will be duplicated.
1029
- */
1030
- +bundleBehavior?: ?BundleBehavior,
1031
- /**
1032
- * If the asset is used as a bundle entry, this controls whether that bundle can be split
1033
- * into multiple, or whether all of the dependencies must be placed in a single bundle.
1034
- */
1035
- +isBundleSplittable?: boolean,
1036
- /** Plugin-specific metadata for the asset. */
1037
- +meta?: Meta,
1038
- /** The pipeline defined in .parcelrc that the asset should be processed with. */
1039
- +pipeline?: ?string,
1040
- /**
1041
- * Whether this asset can be omitted if none of its exports are being used.
1042
- * This is initially set by the resolver, but can be overridden by transformers.
1043
- */
1044
- +sideEffects?: boolean,
1045
- /** The symbols that the asset exports. */
1046
- +symbols?: $ReadOnlyMap<Symbol, {|local: Symbol, loc: ?SourceLocation|}>,
1047
- /**
1048
- * When a transformer returns multiple assets, it can give them unique keys to identify them.
1049
- * This can be used to find assets during packaging, or to create dependencies between multiple
1050
- * assets returned by a transformer by using the unique key as the dependency specifier.
1051
- */
1052
- +uniqueKey?: ?string,
1053
- |};
1054
-
1055
- export type Async<T> = T | Promise<T>;
1056
-
1057
- export interface PluginLogger {
1058
- /** Logs a diagnostic at the verbose log level. */
1059
- verbose(
1060
- diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
1061
- ): void;
1062
-
1063
- /** Logs a diagnostic at the info log level. */
1064
- info(
1065
- diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
1066
- ): void;
1067
-
1068
- /** Synonym for logger.info. */
1069
- log(
1070
- diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
1071
- ): void;
1072
-
1073
- /** Logs a diagnostic at the verbose warning log level. */
1074
- warn(
1075
- diagnostic: DiagnosticWithoutOrigin | Array<DiagnosticWithoutOrigin>,
1076
- ): void;
1077
-
1078
- /** Logs a diagnostic at the verbose error log level. */
1079
- error(
1080
- input:
1081
- | Diagnostifiable
1082
- | DiagnosticWithoutOrigin
1083
- | Array<DiagnosticWithoutOrigin>,
1084
- ): void;
1085
- }
1086
-
1087
- /**
1088
- * @section transformer
1089
- */
1090
- export type ResolveOptions = {|
1091
- /**
1092
- * How the specifier should be interpreted.
1093
- * - esm: An ES module specifier. It is parsed as a URL, but bare specifiers are treated as node_modules.
1094
- * - commonjs: A CommonJS specifier. It is not parsed as a URL.
1095
- * - url: A URL that works as in a browser. Bare specifiers are treated as relative URLs.
1096
- * - custom: A custom specifier. Must be handled by a custom resolver plugin.
1097
- */
1098
- +specifierType?: SpecifierType,
1099
- /** A list of custom conditions to use when resolving package.json "exports" and "imports". */
1100
- +packageConditions?: Array<string>,
1101
- |};
1102
-
1103
- /**
1104
- * @section transformer
1105
- */
1106
- export type ResolveFn = (
1107
- from: FilePath,
1108
- to: string,
1109
- options?: ResolveOptions,
1110
- ) => Promise<FilePath>;
1111
-
1112
- /**
1113
- * @section validator
1114
- * @experimental
1115
- */
1116
- type ResolveConfigFn = (configNames: Array<FilePath>) => Promise<?FilePath>;
1117
-
1118
- /**
1119
- * @section validator
1120
- * @experimental
1121
- */
1122
- type ResolveConfigWithPathFn = (
1123
- configNames: Array<FilePath>,
1124
- assetFilePath: string,
1125
- ) => Promise<?FilePath>;
1126
-
1127
- /**
1128
- * @section validator
1129
- * @experimental
1130
- */
1131
- export type ValidateResult = {|
1132
- warnings: Array<Diagnostic>,
1133
- errors: Array<Diagnostic>,
1134
- |};
1135
-
1136
- /**
1137
- * @section validator
1138
- * @experimental
1139
- */
1140
- export type DedicatedThreadValidator = {|
1141
- validateAll: ({|
1142
- assets: Asset[],
1143
- resolveConfigWithPath: ResolveConfigWithPathFn,
1144
- options: PluginOptions,
1145
- logger: PluginLogger,
1146
- tracer: PluginTracer,
1147
- |}) => Async<Array<?ValidateResult>>,
1148
- |};
1149
-
1150
- /**
1151
- * @section validator
1152
- * @experimental
1153
- */
1154
- export type MultiThreadValidator = {|
1155
- validate: ({|
1156
- asset: Asset,
1157
- config: ConfigResult | void,
1158
- options: PluginOptions,
1159
- logger: PluginLogger,
1160
- tracer: PluginTracer,
1161
- |}) => Async<ValidateResult | void>,
1162
- getConfig?: ({|
1163
- asset: Asset,
1164
- resolveConfig: ResolveConfigFn,
1165
- options: PluginOptions,
1166
- logger: PluginLogger,
1167
- tracer: PluginTracer,
1168
- |}) => Async<ConfigResult | void>,
1169
- |};
1170
-
1171
- /**
1172
- * @section validator
1173
- */
1174
- export type Validator = DedicatedThreadValidator | MultiThreadValidator;
1175
-
1176
- /**
1177
- * The methods for a transformer plugin.
1178
- * @section transformer
1179
- */
1180
- export type Transformer<ConfigType> = {|
1181
- loadConfig?: ({|
1182
- config: Config,
1183
- options: PluginOptions,
1184
- logger: PluginLogger,
1185
- tracer: PluginTracer,
1186
- |}) => Promise<ConfigType> | ConfigType,
1187
- /** Whether an AST from a previous transformer can be reused (to prevent double-parsing) */
1188
- canReuseAST?: ({|
1189
- ast: AST,
1190
- options: PluginOptions,
1191
- logger: PluginLogger,
1192
- tracer: PluginTracer,
1193
- |}) => boolean,
1194
- /** Parse the contents into an ast */
1195
- parse?: ({|
1196
- asset: Asset,
1197
- config: ConfigType,
1198
- resolve: ResolveFn,
1199
- options: PluginOptions,
1200
- logger: PluginLogger,
1201
- tracer: PluginTracer,
1202
- |}) => Async<?AST>,
1203
- /** Transform the asset and/or add new assets */
1204
- transform({|
1205
- asset: MutableAsset,
1206
- config: ConfigType,
1207
- resolve: ResolveFn,
1208
- options: PluginOptions,
1209
- logger: PluginLogger,
1210
- tracer: PluginTracer,
1211
- |}): Async<Array<TransformerResult | MutableAsset>>,
1212
- /**
1213
- * Do some processing after the transformation
1214
- * @experimental
1215
- */
1216
- postProcess?: ({|
1217
- assets: Array<MutableAsset>,
1218
- config: ConfigType,
1219
- resolve: ResolveFn,
1220
- options: PluginOptions,
1221
- logger: PluginLogger,
1222
- tracer: PluginTracer,
1223
- |}) => Async<Array<TransformerResult>>,
1224
- /** Stringify the AST */
1225
- generate?: ({|
1226
- asset: Asset,
1227
- ast: AST,
1228
- options: PluginOptions,
1229
- logger: PluginLogger,
1230
- tracer: PluginTracer,
1231
- |}) => Async<GenerateOutput>,
1232
- |};
1233
-
1234
- /**
1235
- * Used to control a traversal
1236
- * @section bundler
1237
- */
1238
- export type TraversalActions = {|
1239
- /** Skip the current node's children and continue the traversal if there are other nodes in the queue. */
1240
- skipChildren(): void,
1241
- /** Stop the traversal */
1242
- stop(): void,
1243
- |};
1244
-
1245
- /**
1246
- * Essentially GraphTraversalCallback, but allows adding specific node enter and exit callbacks.
1247
- * @section bundler
1248
- */
1249
- export type GraphVisitor<TNode, TContext> =
1250
- | GraphTraversalCallback<TNode, TContext>
1251
- | {|
1252
- enter?: GraphTraversalCallback<TNode, TContext>,
1253
- exit?: GraphTraversalCallback<TNode, TContext>,
1254
- |};
1255
-
1256
- /**
1257
- * A generic callback for graph traversals
1258
- * @param context The parent node's return value is passed as a parameter to the children's callback. \
1259
- * This can be used to forward information from the parent to children in a DFS (unlike a global variable).
1260
- * @section bundler
1261
- */
1262
- export type GraphTraversalCallback<TNode, TContext> = (
1263
- node: TNode,
1264
- context: ?TContext,
1265
- actions: TraversalActions,
1266
- ) => ?TContext;
1267
-
1268
- /**
1269
- * @section bundler
1270
- */
1271
- export type BundleTraversable =
1272
- | {|+type: 'asset', value: Asset|}
1273
- | {|+type: 'dependency', value: Dependency|};
1274
-
1275
- /**
1276
- * @section bundler
1277
- */
1278
- export type BundleGraphTraversable =
1279
- | {|+type: 'asset', value: Asset|}
1280
- | {|+type: 'dependency', value: Dependency|};
1281
-
1282
- /**
1283
- * Options for MutableBundleGraph's <code>createBundle</code>.
1284
- *
1285
- * If an <code>entryAsset</code> is provided, <code>uniqueKey</code> (for the bundle id),
1286
- * <code>type</code>, and <code>env</code> will be inferred from the <code>entryAsset</code>.
1287
- *
1288
- * If an <code>entryAsset</code> is not provided, <code>uniqueKey</code> (for the bundle id),
1289
- * <code>type</code>, and <code>env</code> must be provided.
1290
- *
1291
- * isSplittable defaults to <code>entryAsset.isSplittable</code> or <code>false</code>
1292
- * @section bundler
1293
- */
1294
- export type CreateBundleOpts =
1295
- // If an entryAsset is provided, a bundle id, type, and environment will be
1296
- // inferred from the entryAsset.
1297
- | {|
1298
- /** The entry asset of the bundle. If provided, many bundle properties will be inferred from it. */
1299
- +entryAsset: Asset,
1300
- /** The target of the bundle. Should come from the dependency that created the bundle. */
1301
- +target: Target,
1302
- /**
1303
- * Indicates that the bundle's file name should be stable over time, even when the content of the bundle
1304
- * changes. This is useful for entries that a user would manually enter the URL for, as well as for things
1305
- * like service workers or RSS feeds, where the URL must remain consistent over time.
1306
- */
1307
- +needsStableName?: ?boolean,
1308
- /**
1309
- * Controls the behavior of the bundle.
1310
- * to determine when the bundle is loaded.
1311
- * - inline: Inline bundles are not written to a separate file, but embedded into the parent bundle.
1312
- * - isolated: The bundle will be isolated from its parents. Shared assets will be duplicated.
1313
- */
1314
- +bundleBehavior?: ?BundleBehavior,
1315
- /** Name of the manual shared bundle config that caused this bundle to be created */
1316
- +manualSharedBundle?: ?string,
1317
- +conditions?: Array<string>,
1318
- |}
1319
- // If an entryAsset is not provided, a bundle id, type, and environment must
1320
- // be provided.
1321
- | {|
1322
- /** The type of the bundle. */
1323
- +type: string,
1324
- /** The environment of the bundle. */
1325
- +env: Environment,
1326
- /** A unique value for the bundle to be used in its id. */
1327
- +uniqueKey: string,
1328
- /** The target of the bundle. Should come from the dependency that created the bundle. */
1329
- +target: Target,
1330
- /**
1331
- * Indicates that the bundle's file name should be stable over time, even when the content of the bundle
1332
- * changes. This is useful for entries that a user would manually enter the URL for, as well as for things
1333
- * like service workers or RSS feeds, where the URL must remain consistent over time.
1334
- */
1335
- +needsStableName?: ?boolean,
1336
- /**
1337
- * Controls the behavior of the bundle.
1338
- * to determine when the bundle is loaded.
1339
- * - inline: Inline bundles are not written to a separate file, but embedded into the parent bundle.
1340
- * - isolated: The bundle will be isolated from its parents. Shared assets will be duplicated.
1341
- */
1342
- +bundleBehavior?: ?BundleBehavior,
1343
- /**
1344
- * Whether the bundle can be split. If false, then all dependencies of the bundle will be kept
1345
- * internal to the bundle, rather than referring to other bundles. This may result in assets
1346
- * being duplicated between multiple bundles, but can be useful for things like server side rendering.
1347
- */
1348
- +isSplittable?: ?boolean,
1349
- /** The bundle's pipeline, to be used for optimization. Usually based on the pipeline of the entry asset. */
1350
- +pipeline?: ?string,
1351
- /** Name of the manual shared bundle config that caused this bundle to be created */
1352
- +manualSharedBundle?: ?string,
1353
- +conditions?: Array<string>,
1354
- |};
1355
-
1356
- /**
1357
- * Specifies a symbol in an asset
1358
- * @section packager
1359
- */
1360
- export type SymbolResolution = {|
1361
- /** The Asset which exports the symbol. */
1362
- +asset: Asset,
1363
- /** under which name the symbol is exported */
1364
- +exportSymbol: Symbol | string,
1365
- /** The identifier under which the symbol can be referenced. */
1366
- +symbol: void | null | false | Symbol,
1367
- /** The location of the specifier that lead to this result. */
1368
- +loc: ?SourceLocation,
1369
- |};
1370
-
1371
- /**
1372
- * @section packager
1373
- */
1374
- export type ExportSymbolResolution = {|
1375
- ...SymbolResolution,
1376
- +exportAs: Symbol | string,
1377
- |};
1378
-
1379
- /**
1380
- * A Bundle (a collection of assets)
1381
- *
1382
- * @section bundler
1383
- */
1384
- export interface Bundle {
1385
- /** The bundle id. */
1386
- +id: string;
1387
- /** The type of the bundle. */
1388
- +type: string;
1389
- /** The environment of the bundle. */
1390
- +env: Environment;
1391
- /** The bundle's target. */
1392
- +target: Target;
1393
- /** Assets that run when the bundle is loaded (e.g. runtimes could be added). VERIFY */
1394
- /**
1395
- * Indicates that the bundle's file name should be stable over time, even when the content of the bundle
1396
- * changes. This is useful for entries that a user would manually enter the URL for, as well as for things
1397
- * like service workers or RSS feeds, where the URL must remain consistent over time.
1398
- */
1399
- +needsStableName: ?boolean;
1400
- /**
1401
- * Controls the behavior of the bundle.
1402
- * to determine when the bundle is loaded.
1403
- * - inline: Inline bundles are not written to a separate file, but embedded into the parent bundle.
1404
- * - isolated: The bundle will be isolated from its parents. Shared assets will be duplicated.
1405
- */
1406
- +bundleBehavior: ?BundleBehavior;
1407
- /**
1408
- * Whether the bundle can be split. If false, then all dependencies of the bundle will be kept
1409
- * internal to the bundle, rather than referring to other bundles. This may result in assets
1410
- * being duplicated between multiple bundles, but can be useful for things like server side rendering.
1411
- */
1412
- +isSplittable: ?boolean;
1413
- /**
1414
- * A placeholder for the bundle's content hash that can be used in the bundle's name or the contents of another
1415
- * bundle. Hash references are replaced with a content hash of the bundle after packaging and optimizing.
1416
- */
1417
- +hashReference: string;
1418
- /**
1419
- * Name of the manual shared bundle config, if that caused this bundle to be created
1420
- */
1421
- +manualSharedBundle: ?string;
1422
- /**
1423
- * Returns the assets that are executed immediately when the bundle is loaded.
1424
- * Some bundles may not have any entry assets, for example, shared bundles.
1425
- */
1426
- getEntryAssets(): Array<Asset>;
1427
- /**
1428
- * Returns the main entry of the bundle, which will provide the bundle's exports.
1429
- * Some bundles do not have a main entry, for example, shared bundles.
1430
- */
1431
- getMainEntry(): ?Asset;
1432
- /** Returns whether the bundle includes the given asset. */
1433
- hasAsset(Asset): boolean;
1434
- /** Returns whether the bundle includes the given dependency. */
1435
- hasDependency(Dependency): boolean;
1436
- /** Traverses the assets in the bundle. */
1437
- traverseAssets<TContext>(
1438
- visit: GraphVisitor<Asset, TContext>,
1439
- startAsset?: Asset,
1440
- ): ?TContext;
1441
- /** Traverses assets and dependencies in the bundle. */
1442
- traverse<TContext>(
1443
- visit: GraphVisitor<BundleTraversable, TContext>,
1444
- ): ?TContext;
1445
- }
1446
-
1447
- /**
1448
- * A Bundle that got named by a Namer
1449
- * @section bundler
1450
- */
1451
- export interface NamedBundle extends Bundle {
1452
- /** A shortened version of the bundle id that is used to refer to the bundle at runtime. */
1453
- +publicId: string;
1454
- /**
1455
- * The bundle's name. This is a file path relative to the bundle's target directory.
1456
- * The bundle name may include a hash reference, but not the final content hash.
1457
- */
1458
- +name: string;
1459
- /** A version of the bundle's name with hash references removed for display. */
1460
- +displayName: string;
1461
- }
1462
-
1463
- export interface PackagedBundle extends NamedBundle {
1464
- /** The absolute file path of the written bundle, including the final content hash if any. */
1465
- +filePath: FilePath;
1466
- /** Statistics about the bundle. */
1467
- +stats: Stats;
1468
- }
1469
-
1470
- /**
1471
- * A collection of sibling bundles (which are stored in the BundleGraph) that should be loaded together (in order).
1472
- * @section bundler
1473
- */
1474
- export interface BundleGroup {
1475
- /** The target of the bundle group. */
1476
- +target: Target;
1477
- /** The id of the entry asset in the bundle group, which is executed immediately when the bundle group is loaded. */
1478
- +entryAssetId: string;
1479
- }
1480
-
1481
- /**
1482
- * A BundleGraph in the Bundler that can be modified
1483
- * @section bundler
1484
- * @experimental
1485
- */
1486
- export interface MutableBundleGraph extends BundleGraph<Bundle> {
1487
- /** Add asset and all child nodes to the bundle. */
1488
- addAssetGraphToBundle(
1489
- Asset,
1490
- Bundle,
1491
- shouldSkipDependency?: (Dependency) => boolean,
1492
- ): void;
1493
- addAssetToBundle(Asset, Bundle): void;
1494
- /**
1495
- * Adds an asset as an entry to a bundle. Entry assets are executed immediately
1496
- * when the bundle is loaded.
1497
- */
1498
- addEntryToBundle(
1499
- Asset,
1500
- Bundle,
1501
- shouldSkipDependency?: (Dependency) => boolean,
1502
- ): void;
1503
- /** Adds the Bundle to the BundleGroup, loading it along with others in the group */
1504
- addBundleToBundleGroup(Bundle, BundleGroup): void;
1505
- createAssetReference(Dependency, Asset, Bundle): void;
1506
- createBundleReference(Bundle, Bundle): void;
1507
- /** Creates a conditional relationship in the graph between two bundles
1508
- * Used to track which bundles conditionally reference another
1509
- */
1510
- createBundleConditionalReference(Bundle, Bundle): void;
1511
- createBundle(CreateBundleOpts): Bundle;
1512
- /** Turns an edge (Dependency -> Asset-s) into (Dependency -> BundleGroup -> Asset-s) */
1513
- createBundleGroup(Dependency, Target): BundleGroup;
1514
- /** @returns all Asset-s attached to the Dependency */
1515
- getDependencyAssets(Dependency): Array<Asset>;
1516
- /** Get Bundles that load this bundle asynchronously. */
1517
- getParentBundlesOfBundleGroup(BundleGroup): Array<Bundle>;
1518
- /** @returns the size in bytes of an asset and all assets in its subgraph */
1519
- getTotalSize(Asset): number;
1520
- /**
1521
- * Recursively removes an asset and its dependencies from a bundle. Stops at
1522
- * bundle group boundaries.
1523
- */
1524
- removeAssetGraphFromBundle(Asset, Bundle): void;
1525
- /**
1526
- * Removes a BundleGroup from the graph. If any of the group's Bundle-s no
1527
- * longer exist in the graph, those are removed as well.
1528
- */
1529
- removeBundleGroup(bundleGroup: BundleGroup): void;
1530
- /** Turns a dependency to a different bundle into a dependency to an asset inside <code>bundle</code>. */
1531
- internalizeAsyncDependency(bundle: Bundle, dependency: Dependency): void;
1532
- }
1533
-
1534
- /**
1535
- * A Graph that contains Bundle-s, Asset-s, Dependency-s, BundleGroup-s
1536
- * @section bundler
1537
- */
1538
- export interface BundleGraph<TBundle: Bundle> {
1539
- /** Retrieves an asset by id. */
1540
- getAssetById(id: string): Asset;
1541
- /** Returns the public (short) id for an asset. */
1542
- getAssetPublicId(asset: Asset): string;
1543
- /** Returns a list of bundles in the bundle graph. By default, inline bundles are excluded. */
1544
- getBundles(opts?: {|includeInline: boolean|}): Array<TBundle>;
1545
- /** Traverses the assets and dependencies in the bundle graph, in depth first order. */
1546
- traverse<TContext>(
1547
- visit: GraphVisitor<BundleGraphTraversable, TContext>,
1548
- startAsset: ?Asset,
1549
- options?: {|skipUnusedDependencies?: boolean|},
1550
- ): ?TContext;
1551
- /** Traverses all bundles in the bundle graph, including inline bundles, in depth first order. */
1552
- traverseBundles<TContext>(
1553
- visit: GraphVisitor<TBundle, TContext>,
1554
- startBundle: ?Bundle,
1555
- ): ?TContext;
1556
- /** Returns a list of bundle groups that load the given bundle. */
1557
- getBundleGroupsContainingBundle(bundle: Bundle): Array<BundleGroup>;
1558
- /** Returns a list of bundles that load together in the given bundle group. */
1559
- getBundlesInBundleGroup(
1560
- bundleGroup: BundleGroup,
1561
- opts?: {|includeInline: boolean|},
1562
- ): Array<TBundle>;
1563
- /** Returns a list of bundles that this bundle loads asynchronously. */
1564
- getChildBundles(bundle: Bundle): Array<TBundle>;
1565
- /** Returns a list of bundles that load this bundle asynchronously. */
1566
- getParentBundles(bundle: Bundle): Array<TBundle>;
1567
- /** Returns whether the bundle was loaded by another bundle of the given type. */
1568
- hasParentBundleOfType(bundle: Bundle, type: string): boolean;
1569
- /** Returns a list of bundles that are referenced by this bundle. By default, inline bundles are excluded. */
1570
- getReferencedBundles(
1571
- bundle: Bundle,
1572
- opts?: {|recursive?: boolean, includeInline?: boolean|},
1573
- ): Array<TBundle>;
1574
- /** Returns a list of bundles that reference this bundle. */
1575
- getReferencingBundles(bundle: Bundle): Array<TBundle>;
1576
- /** Get the dependencies that the asset requires */
1577
- getDependencies(asset: Asset): Array<Dependency>;
1578
- /** Get the dependencies that require the asset */
1579
- getIncomingDependencies(asset: Asset): Array<Dependency>;
1580
- /** Get the asset that created the dependency. */
1581
- getAssetWithDependency(dep: Dependency): ?Asset;
1582
- /** Returns whether the given bundle group is an entry. */
1583
- isEntryBundleGroup(bundleGroup: BundleGroup): boolean;
1584
- /**
1585
- * Returns undefined if the specified dependency was excluded or wasn't async \
1586
- * and otherwise the BundleGroup or Asset that the dependency resolves to.
1587
- */
1588
- resolveAsyncDependency(
1589
- dependency: Dependency,
1590
- bundle: ?Bundle,
1591
- ): ?(
1592
- | {|type: 'bundle_group', value: BundleGroup|}
1593
- | {|type: 'asset', value: Asset|}
1594
- );
1595
- /** Returns whether a dependency was excluded because it had no used symbols. */
1596
- isDependencySkipped(dependency: Dependency): boolean;
1597
- /**
1598
- * Returns the asset that the dependency resolved to.
1599
- * If a bundle is given, assets in that bundle are preferred.
1600
- * Returns null if the dependency was excluded.
1601
- */
1602
- getResolvedAsset(dependency: Dependency, bundle: ?Bundle): ?Asset;
1603
- /** Returns the bundle that a dependency in a given bundle references, if any. */
1604
- getReferencedBundle(dependency: Dependency, bundle: Bundle): ?TBundle;
1605
- /** Returns a list of bundles that contain the given asset. */
1606
- getBundlesWithAsset(Asset): Array<TBundle>;
1607
- /** Returns a list of bundles that contain the given dependency. */
1608
- getBundlesWithDependency(Dependency): Array<TBundle>;
1609
- /**
1610
- * Returns whether the given asset is reachable in a sibling, or all possible
1611
- * ancestries of the given bundle. This indicates that the asset may be excluded
1612
- * from the given bundle.
1613
- */
1614
- isAssetReachableFromBundle(asset: Asset, bundle: Bundle): boolean;
1615
- /** Returns whether an asset is referenced outside the given bundle. */
1616
- isAssetReferenced(bundle: Bundle, asset: Asset): boolean;
1617
- /**
1618
- * Resolves the export `symbol` of `asset` to the source,
1619
- * stopping at the first asset after leaving `bundle`.
1620
- * `symbol === null`: bailout (== caller should do `asset.exports[exportsSymbol]`)
1621
- * `symbol === undefined`: symbol not found
1622
- * `symbol === false`: skipped
1623
- *
1624
- * <code>asset</code> exports <code>symbol</code>, try to find the asset where the \
1625
- * corresponding variable lives (resolves re-exports). Stop resolving transitively once \
1626
- * <code>boundary</code> was left (<code>bundle.hasAsset(asset) === false</code>), then <code>result.symbol</code> is undefined.
1627
- */
1628
- getSymbolResolution(
1629
- asset: Asset,
1630
- symbol: Symbol,
1631
- boundary: ?Bundle,
1632
- ): SymbolResolution;
1633
- /** Returns a list of symbols that are exported by the asset, including re-exports. */
1634
- getExportedSymbols(
1635
- asset: Asset,
1636
- boundary: ?Bundle,
1637
- ): Array<ExportSymbolResolution>;
1638
- /**
1639
- * Returns a list of symbols from an asset or dependency that are referenced by a dependent asset.
1640
- *
1641
- * Returns null if symbol propagation didn't run (so the result is unknown).
1642
- */
1643
- getUsedSymbols(Asset | Dependency): ?$ReadOnlySet<Symbol>;
1644
- /** Returns the common root directory for the entry assets of a target. */
1645
- getEntryRoot(target: Target): FilePath;
1646
- getConditionalBundleMapping(): Map<
1647
- TBundle,
1648
- Map<
1649
- string,
1650
- {|
1651
- ifTrueBundles: Array<TBundle>,
1652
- ifFalseBundles: Array<TBundle>,
1653
- |},
1654
- >,
1655
- >;
1656
- getConditionsForDependencies(
1657
- deps: Array<Dependency>,
1658
- bundle: NamedBundle,
1659
- ): Set<{|
1660
- publicId: string,
1661
- key: string,
1662
- ifTrueDependency: Dependency,
1663
- ifFalseDependency: Dependency,
1664
- ifTrueBundles: Array<TBundle>,
1665
- ifFalseBundles: Array<TBundle>,
1666
- ifTrueAssetId: string,
1667
- ifFalseAssetId: string,
1668
- |}>;
1669
- getReferencedConditionalBundles(bundle: Bundle): Array<TBundle>;
1670
- }
1671
-
1672
- /**
1673
- * @section bundler
1674
- */
1675
- export type BundleResult = {|
1676
- +contents: Blob,
1677
- +ast?: AST,
1678
- +map?: ?SourceMap,
1679
- +type?: string,
1680
- |};
1681
-
1682
- /**
1683
- * @section resolver
1684
- */
1685
- export type ResolveResult = {|
1686
- /** An absolute path to the resolved file. */
1687
- +filePath?: FilePath,
1688
- /** An optional named pipeline to use to compile the resolved file. */
1689
- +pipeline?: ?string,
1690
- /** Query parameters to be used by transformers when compiling the resolved file. */
1691
- +query?: URLSearchParams,
1692
- /** Whether the resolved file should be excluded from the build. */
1693
- +isExcluded?: boolean,
1694
- /** Overrides the priority set on the dependency. */
1695
- +priority?: DependencyPriority,
1696
- /** Corresponds to BaseAsset's <code>sideEffects</code>. */
1697
- +sideEffects?: boolean,
1698
- /** The code of the resolved asset. If provided, this is used rather than reading the file from disk. */
1699
- +code?: string,
1700
- /** Whether this dependency can be deferred by Atlaspack itself (true by default). */
1701
- +canDefer?: boolean,
1702
- /** A resolver might return diagnostics to also run subsequent resolvers while still providing a reason why it failed. */
1703
- +diagnostics?: Diagnostic | Array<Diagnostic>,
1704
- /** Is spread (shallowly merged) onto the request's dependency.meta */
1705
- +meta?: JSONObject,
1706
- /** A list of file paths or patterns that should invalidate the resolution if created. */
1707
- +invalidateOnFileCreate?: Array<FileCreateInvalidation>,
1708
- /** A list of files that should invalidate the resolution if modified or deleted. */
1709
- +invalidateOnFileChange?: Array<FilePath>,
1710
- /** Invalidates the resolution when the given environment variable changes.*/
1711
- +invalidateOnEnvChange?: Array<string>,
1712
- |};
1713
-
1714
- /**
1715
- * Turns an asset graph into a BundleGraph.
1716
- *
1717
- * bundle and optimize run in series and are functionally identitical.
1718
- * @section bundler
1719
- */
1720
- export type Bundler<ConfigType> = {|
1721
- loadConfig?: ({|
1722
- config: Config,
1723
- options: PluginOptions,
1724
- logger: PluginLogger,
1725
- tracer: PluginTracer,
1726
- |}) => Promise<ConfigType> | ConfigType,
1727
- bundle({|
1728
- bundleGraph: MutableBundleGraph,
1729
- config: ConfigType,
1730
- options: PluginOptions,
1731
- logger: PluginLogger,
1732
- tracer: PluginTracer,
1733
- |}): Async<void>,
1734
- optimize({|
1735
- bundleGraph: MutableBundleGraph,
1736
- config: ConfigType,
1737
- options: PluginOptions,
1738
- logger: PluginLogger,
1739
- |}): Async<void>,
1740
- |};
1741
-
1742
- /**
1743
- * @section namer
1744
- */
1745
- export type Namer<ConfigType> = {|
1746
- loadConfig?: ({|
1747
- config: Config,
1748
- options: PluginOptions,
1749
- logger: PluginLogger,
1750
- tracer: PluginTracer,
1751
- |}) => Promise<ConfigType> | ConfigType,
1752
- /** Return a filename/-path for <code>bundle</code> or nullish to leave it to the next namer plugin. */
1753
- name({|
1754
- bundle: Bundle,
1755
- bundleGraph: BundleGraph<Bundle>,
1756
- config: ConfigType,
1757
- options: PluginOptions,
1758
- logger: PluginLogger,
1759
- tracer: PluginTracer,
1760
- |}): Async<?FilePath>,
1761
- |};
1762
-
1763
- type RuntimeAssetPriority = 'sync' | 'parallel';
1764
-
1765
- /**
1766
- * A "synthetic" asset that will be inserted into the bundle graph.
1767
- * @section runtime
1768
- */
1769
- export type RuntimeAsset = {|
1770
- +filePath: FilePath,
1771
- +code: string,
1772
- +dependency?: Dependency,
1773
- +isEntry?: boolean,
1774
- +env?: EnvironmentOptions,
1775
- +priority?: RuntimeAssetPriority,
1776
- |};
1777
-
1778
- /**
1779
- * @section runtime
1780
- */
1781
- export type Runtime<ConfigType> = {|
1782
- loadConfig?: ({|
1783
- config: Config,
1784
- options: PluginOptions,
1785
- logger: PluginLogger,
1786
- tracer: PluginTracer,
1787
- |}) => Promise<ConfigType> | ConfigType,
1788
- apply({|
1789
- bundle: NamedBundle,
1790
- bundleGraph: BundleGraph<NamedBundle>,
1791
- config: ConfigType,
1792
- options: PluginOptions,
1793
- logger: PluginLogger,
1794
- tracer: PluginTracer,
1795
- |}): Async<void | RuntimeAsset | Array<RuntimeAsset>>,
1796
- |};
1797
-
1798
- /**
1799
- * @section packager
1800
- */
1801
- export type Packager<ConfigType, BundleConfigType> = {|
1802
- loadConfig?: ({|
1803
- config: Config,
1804
- options: PluginOptions,
1805
- logger: PluginLogger,
1806
- tracer: PluginTracer,
1807
- |}) => Async<ConfigType>,
1808
- loadBundleConfig?: ({|
1809
- bundle: NamedBundle,
1810
- bundleGraph: BundleGraph<NamedBundle>,
1811
- config: Config,
1812
- options: PluginOptions,
1813
- logger: PluginLogger,
1814
- tracer: PluginTracer,
1815
- |}) => Async<BundleConfigType>,
1816
- package({|
1817
- bundle: NamedBundle,
1818
- bundleGraph: BundleGraph<NamedBundle>,
1819
- options: PluginOptions,
1820
- logger: PluginLogger,
1821
- tracer: PluginTracer,
1822
- config: ConfigType,
1823
- bundleConfig: BundleConfigType,
1824
- getInlineBundleContents: (
1825
- Bundle,
1826
- BundleGraph<NamedBundle>,
1827
- ) => Async<{|contents: Blob|}>,
1828
- getSourceMapReference: (map: ?SourceMap) => Async<?string>,
1829
- |}): Async<BundleResult>,
1830
- |};
1831
-
1832
- /**
1833
- * @section optimizer
1834
- */
1835
- export type Optimizer<ConfigType, BundleConfigType> = {|
1836
- loadConfig?: ({|
1837
- config: Config,
1838
- options: PluginOptions,
1839
- logger: PluginLogger,
1840
- tracer: PluginTracer,
1841
- |}) => Async<ConfigType>,
1842
- loadBundleConfig?: ({|
1843
- bundle: NamedBundle,
1844
- bundleGraph: BundleGraph<NamedBundle>,
1845
- config: Config,
1846
- options: PluginOptions,
1847
- logger: PluginLogger,
1848
- tracer: PluginTracer,
1849
- |}) => Async<BundleConfigType>,
1850
- optimize({|
1851
- bundle: NamedBundle,
1852
- bundleGraph: BundleGraph<NamedBundle>,
1853
- contents: Blob,
1854
- map: ?SourceMap,
1855
- options: PluginOptions,
1856
- logger: PluginLogger,
1857
- tracer: PluginTracer,
1858
- config: ConfigType,
1859
- bundleConfig: BundleConfigType,
1860
- getSourceMapReference: (map: ?SourceMap) => Async<?string>,
1861
- |}): Async<BundleResult>,
1862
- |};
1863
-
1864
- /**
1865
- * @section compressor
1866
- */
1867
- export type Compressor = {|
1868
- compress({|
1869
- stream: Readable,
1870
- options: PluginOptions,
1871
- logger: PluginLogger,
1872
- tracer: PluginTracer,
1873
- |}): Async<?{|
1874
- stream: Readable,
1875
- type?: string,
1876
- |}>,
1877
- |};
1878
-
1879
- /**
1880
- * @section resolver
1881
- */
1882
- export type Resolver<ConfigType> = {|
1883
- loadConfig?: ({|
1884
- config: Config,
1885
- options: PluginOptions,
1886
- logger: PluginLogger,
1887
- tracer: PluginTracer,
1888
- |}) => Promise<ConfigType> | ConfigType,
1889
- resolve({|
1890
- dependency: Dependency,
1891
- options: PluginOptions,
1892
- logger: PluginLogger,
1893
- tracer: PluginTracer,
1894
- specifier: FilePath,
1895
- pipeline: ?string,
1896
- config: ConfigType,
1897
- |}): Async<?ResolveResult>,
1898
- |};
1899
-
1900
- /**
1901
- * @section reporter
1902
- */
1903
- export type ProgressLogEvent = {|
1904
- +type: 'log',
1905
- +level: 'progress',
1906
- +phase?: string,
1907
- +message: string,
1908
- |};
1909
-
1910
- /**
1911
- * A log event with a rich diagnostic
1912
- * @section reporter
1913
- */
1914
- export type DiagnosticLogEvent = {|
1915
- +type: 'log',
1916
- +level: 'error' | 'warn' | 'info' | 'verbose',
1917
- +diagnostics: Array<Diagnostic>,
1918
- |};
1919
-
1920
- /**
1921
- * @section reporter
1922
- */
1923
- export type TextLogEvent = {|
1924
- +type: 'log',
1925
- +level: 'success',
1926
- +message: string,
1927
- |};
1928
-
1929
- /**
1930
- * @section reporter
1931
- */
1932
- export type LogEvent = ProgressLogEvent | DiagnosticLogEvent | TextLogEvent;
1933
-
1934
- /**
1935
- * The build just started.
1936
- * @section reporter
1937
- */
1938
- export type BuildStartEvent = {|
1939
- +type: 'buildStart',
1940
- |};
1941
-
1942
- /**
1943
- * The build just started in watch mode.
1944
- * @section reporter
1945
- */
1946
- export type WatchStartEvent = {|
1947
- +type: 'watchStart',
1948
- |};
1949
-
1950
- /**
1951
- * The build just ended in watch mode.
1952
- * @section reporter
1953
- */
1954
- export type WatchEndEvent = {|
1955
- +type: 'watchEnd',
1956
- |};
1957
-
1958
- /**
1959
- * A new Dependency is being resolved.
1960
- * @section reporter
1961
- */
1962
- export type ResolvingProgressEvent = {|
1963
- +type: 'buildProgress',
1964
- +phase: 'resolving',
1965
- +dependency: Dependency,
1966
- |};
1967
-
1968
- /**
1969
- * A new Asset is being transformed.
1970
- * @section reporter
1971
- */
1972
- export type TransformingProgressEvent = {|
1973
- +type: 'buildProgress',
1974
- +phase: 'transforming',
1975
- +filePath: FilePath,
1976
- |};
1977
-
1978
- /**
1979
- * The BundleGraph is generated.
1980
- * @section reporter
1981
- */
1982
- export type BundlingProgressEvent = {|
1983
- +type: 'buildProgress',
1984
- +phase: 'bundling',
1985
- |};
1986
-
1987
- export type BundledProgressEvent = {|
1988
- +type: 'buildProgress',
1989
- +phase: 'bundled',
1990
- +bundleGraph: BundleGraph<NamedBundle>,
1991
- +changedAssets: Map<string, Asset>,
1992
- |};
1993
-
1994
- /**
1995
- * A new Bundle is being packaged.
1996
- * @section reporter
1997
- */
1998
- export type PackagingProgressEvent = {|
1999
- +type: 'buildProgress',
2000
- +phase: 'packaging',
2001
- +bundle: NamedBundle,
2002
- |};
2003
-
2004
- /**
2005
- * A new Bundle is being optimized.
2006
- * @section reporter
2007
- */
2008
- export type OptimizingProgressEvent = {|
2009
- +type: 'buildProgress',
2010
- +phase: 'optimizing',
2011
- +bundle: NamedBundle,
2012
- |};
2013
-
2014
- /**
2015
- * @section reporter
2016
- */
2017
- export type BuildProgressEvent =
2018
- | ResolvingProgressEvent
2019
- | TransformingProgressEvent
2020
- | BundlingProgressEvent
2021
- | BundledProgressEvent
2022
- | PackagingProgressEvent
2023
- | OptimizingProgressEvent;
2024
-
2025
- /**
2026
- * The build was successful.
2027
- * @section reporter
2028
- */
2029
- export type BuildSuccessEvent = {|
2030
- +type: 'buildSuccess',
2031
- +bundleGraph: BundleGraph<PackagedBundle>,
2032
- +buildTime: number,
2033
- +changedAssets: Map<string, Asset>,
2034
- +requestBundle: (bundle: NamedBundle) => Promise<BuildSuccessEvent>,
2035
- +unstable_requestStats: {[requestType: string]: number},
2036
- |};
2037
-
2038
- /**
2039
- * The build failed.
2040
- * @section reporter
2041
- */
2042
- export type BuildFailureEvent = {|
2043
- +type: 'buildFailure',
2044
- +diagnostics: Array<Diagnostic>,
2045
- +unstable_requestStats: {[requestType: string]: number},
2046
- |};
2047
-
2048
- /**
2049
- * @section reporter
2050
- */
2051
- export type BuildEvent = BuildFailureEvent | BuildSuccessEvent;
2052
-
2053
- /**
2054
- * A new file is being validated.
2055
- * @section reporter
2056
- */
2057
- export type ValidationEvent = {|
2058
- +type: 'validation',
2059
- +filePath: FilePath,
2060
- |};
2061
-
2062
- /**
2063
- * A trace event has occured.
2064
- * Loosely modeled on Chrome's Trace Event format: https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview
2065
- *
2066
- * @section reporter
2067
- */
2068
- export type TraceEvent = {|
2069
- +type: 'trace',
2070
- +ts: number,
2071
- +duration: number,
2072
- +name: string,
2073
- +tid: number,
2074
- +pid: number,
2075
- +categories: string[],
2076
- +args?: {[key: string]: mixed},
2077
- |};
2078
-
2079
- export type CacheEvent = {|
2080
- type: 'cache',
2081
- phase: string,
2082
- total: number,
2083
- size: number,
2084
- |};
2085
-
2086
- /**
2087
- * @section reporter
2088
- */
2089
- export type ReporterEvent =
2090
- | LogEvent
2091
- | BuildStartEvent
2092
- | BuildProgressEvent
2093
- | BuildSuccessEvent
2094
- | BuildFailureEvent
2095
- | WatchStartEvent
2096
- | WatchEndEvent
2097
- | ValidationEvent
2098
- | TraceEvent
2099
- | CacheEvent;
2100
-
2101
- /**
2102
- * @section reporter
2103
- */
2104
- export type Reporter = {|
2105
- report({|
2106
- event: ReporterEvent,
2107
- options: PluginOptions,
2108
- logger: PluginLogger,
2109
- tracer: PluginTracer,
2110
- |}): Async<void>,
2111
- |};
2112
-
2113
- export interface ErrorWithCode extends Error {
2114
- +code?: string;
2115
- }
2116
-
2117
- export interface IDisposable {
2118
- dispose(): mixed;
2119
- }
2120
-
2121
- export type AsyncSubscription = {|
2122
- unsubscribe(): Promise<mixed>,
2123
- |};
2124
-
2125
- export interface PluginTracer {
2126
- /** Returns whether the tracer is enabled. Use this to avoid possibly expensive calculations
2127
- * of arguments to `createMeasurement` - for example if you need to determine the entry of a bundle to pass it
2128
- * in as the <code>argumentName</code>, you would only do this if the tracer is enabled.
2129
- */
2130
- +enabled: boolean;
2131
-
2132
- /**
2133
- * Creates a new trace measurement with the specified name. This name should reflect the current plugin or
2134
- * function being executed (for example, the name of a Babel transform). The category will default to the name of your plugin,
2135
- * however it should be set to reflect the type of operation (for example, for a hypothetical operation
2136
- * to find CSS in an asset within a Compiled plugin you might set this to <code>find_css<code>).
2137
- *
2138
- * If this is an operation that executes multiple times on different things - whether that's assets, bundles, or
2139
- * otherwise - specify the name of the context object in <code>argumentName</code>.
2140
- *
2141
- * <code>otherArgs</code> can be used for specifying any other key/value pairs
2142
- * that should be written to the trace.
2143
- *
2144
- * For example: <code>tracer.createMeasurement('compiled', 'find_css', path.relative(options.projecRoot, asset.filePath), { meta: 'data' })</code>
2145
- */
2146
- createMeasurement(
2147
- name: string,
2148
- category?: string,
2149
- argumentName?: string,
2150
- otherArgs?: {[key: string]: mixed},
2151
- ): TraceMeasurement | null;
2152
- }
2153
-
2154
- export type ConditionMeta = {|
2155
- key: string,
2156
- ifTruePlaceholder: string,
2157
- ifFalsePlaceholder: string,
2158
- |};