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