@powerlines/plugin-rollup 0.7.7 → 0.7.9

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.
@@ -0,0 +1,1316 @@
1
+ import { RollupOptions, OutputOptions } from 'rollup';
2
+ import { EnvPaths } from '@stryke/env/get-env-paths';
3
+ import { PackageJson } from '@stryke/types/package-json';
4
+ import { Jiti } from 'jiti';
5
+ import { ParserOptions, ParseResult } from 'oxc-parser';
6
+ import { Range } from 'semver';
7
+ import { UnpluginContext, UnpluginBuildContext, TransformResult, ExternalIdResult, HookFilter, UnpluginOptions } from 'unplugin';
8
+ import { Format } from '@storm-software/build-tools/types';
9
+ import { LogLevelLabel } from '@storm-software/config-tools/types';
10
+ import { StormWorkspaceConfig } from '@storm-software/config/types';
11
+ import { MaybePromise, NonUndefined, FunctionLike } from '@stryke/types/base';
12
+ import { TypeDefinitionParameter, TypeDefinition } from '@stryke/types/configuration';
13
+ import { AssetGlob } from '@stryke/types/file';
14
+ import { PreviewOptions, ResolvedPreviewOptions } from 'vite';
15
+ import { ArrayValues } from '@stryke/types/array';
16
+ import { TsConfigJson, CompilerOptions } from '@stryke/types/tsconfig';
17
+ import ts from 'typescript';
18
+ import { PrimitiveJsonValue } from '@stryke/json/types';
19
+ import { Volume } from 'memfs';
20
+ import { PathLike, StatSyncOptions, Stats, RmDirOptions, RmOptions, Mode, MakeDirectoryOptions as MakeDirectoryOptions$1, PathOrFileDescriptor, WriteFileOptions as WriteFileOptions$1 } from 'node:fs';
21
+ import { IUnionFs } from 'unionfs';
22
+
23
+ type UnpluginBuildVariant = "rollup" | "webpack" | "rspack" | "vite" | "esbuild" | "farm" | "unloader" | "rolldown";
24
+ interface BuildConfig {
25
+ /**
26
+ * The platform to build the project for
27
+ *
28
+ * @defaultValue "neutral"
29
+ */
30
+ platform?: "node" | "browser" | "neutral";
31
+ /**
32
+ * The alias mappings to use for module resolution during the build process.
33
+ *
34
+ * @remarks
35
+ * This option allows you to define custom path aliases for modules, which can be useful for simplifying imports and managing dependencies.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * {
40
+ * alias: {
41
+ * "@utils": "./src/utils",
42
+ * "@components": "./src/components"
43
+ * }
44
+ * }
45
+ * ```
46
+ */
47
+ alias?: Record<string, string>;
48
+ /**
49
+ * A list of modules that should not be bundled, even if they are external dependencies.
50
+ *
51
+ * @remarks
52
+ * This option is useful for excluding specific modules from the bundle, such as Node.js built-in modules or other libraries that should not be bundled.
53
+ */
54
+ external?: (string | RegExp)[];
55
+ /**
56
+ * A list of modules that should always be bundled, even if they are external dependencies.
57
+ */
58
+ noExternal?: (string | RegExp)[];
59
+ /**
60
+ * Should the Powerlines CLI processes skip bundling the `node_modules` directory?
61
+ */
62
+ skipNodeModulesBundle?: boolean;
63
+ /**
64
+ * Should the Powerlines processes skip the `"prepare"` task prior to building?
65
+ *
66
+ * @defaultValue false
67
+ */
68
+ skipPrepare?: boolean;
69
+ }
70
+ type BuildResolvedConfig = BuildConfig;
71
+ type RollupBuildOutputConfig = Omit<OutputOptions, "dir" | "format">;
72
+ type RollupBuildConfig = Omit<RollupOptions, "entry" | "external" | "input" | "output" | "logLevel"> & {
73
+ output: RollupBuildOutputConfig | RollupBuildOutputConfig[];
74
+ } & BuildConfig;
75
+ type RollupResolvedBuildConfig = RollupOptions & BuildResolvedConfig;
76
+
77
+ type ReflectionMode = "default" | "explicit" | "never";
78
+ type RawReflectionMode = ReflectionMode | "" | boolean | string | string[] | undefined;
79
+ /**
80
+ * Defines the level of reflection to be used during the transpilation process.
81
+ *
82
+ * @remarks
83
+ * The level determines how much extra data is captured in the byte code for each type. This can be one of the following values:
84
+ * - `minimal` - Only the essential type information is captured.
85
+ * - `normal` - Additional type information is captured, including some contextual data.
86
+ * - `verbose` - All available type information is captured, including detailed contextual data.
87
+ */
88
+ type ReflectionLevel = "minimal" | "normal" | "verbose";
89
+ interface DeepkitOptions {
90
+ /**
91
+ * Either true to activate reflection for all files compiled using this tsconfig,
92
+ * or a list of globs/file paths relative to this tsconfig.json.
93
+ * Globs/file paths can be prefixed with a ! to exclude them.
94
+ */
95
+ reflection?: RawReflectionMode;
96
+ /**
97
+ * Defines the level of reflection to be used during the transpilation process.
98
+ *
99
+ * @remarks
100
+ * The level determines how much extra data is captured in the byte code for each type. This can be one of the following values:
101
+ * - `minimal` - Only the essential type information is captured.
102
+ * - `normal` - Additional type information is captured, including some contextual data.
103
+ * - `verbose` - All available type information is captured, including detailed contextual data.
104
+ */
105
+ reflectionLevel?: ReflectionLevel;
106
+ }
107
+ type TSCompilerOptions = CompilerOptions & DeepkitOptions;
108
+ /**
109
+ * The TypeScript compiler configuration.
110
+ *
111
+ * @see https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
112
+ */
113
+ interface TSConfig extends Omit<TsConfigJson, "reflection"> {
114
+ /**
115
+ * Either true to activate reflection for all files compiled using this tsconfig,
116
+ * or a list of globs/file paths relative to this tsconfig.json.
117
+ * Globs/file paths can be prefixed with a ! to exclude them.
118
+ */
119
+ reflection?: RawReflectionMode;
120
+ /**
121
+ * Defines the level of reflection to be used during the transpilation process.
122
+ *
123
+ * @remarks
124
+ * The level determines how much extra data is captured in the byte code for each type. This can be one of the following values:
125
+ * - `minimal` - Only the essential type information is captured.
126
+ * - `normal` - Additional type information is captured, including some contextual data.
127
+ * - `verbose` - All available type information is captured, including detailed contextual data.
128
+ */
129
+ reflectionLevel?: ReflectionLevel;
130
+ /**
131
+ * Instructs the TypeScript compiler how to compile `.ts` files.
132
+ */
133
+ compilerOptions?: TSCompilerOptions;
134
+ }
135
+ type ParsedTypeScriptConfig = ts.ParsedCommandLine & {
136
+ originalTsconfigJson: TsConfigJson;
137
+ tsconfigJson: TSConfig;
138
+ tsconfigFilePath: string;
139
+ };
140
+
141
+ declare const __VFS_INIT__ = "__VFS_INIT__";
142
+ declare const __VFS_REVERT__ = "__VFS_REVERT__";
143
+ declare const __VFS_CACHE__ = "__VFS_CACHE__";
144
+ declare const __VFS_VIRTUAL__ = "__VFS_VIRTUAL__";
145
+ declare const __VFS_UNIFIED__ = "__VFS_UNIFIED__";
146
+ type OutputModeType = "fs" | "virtual";
147
+ interface VirtualFile {
148
+ /**
149
+ * The unique identifier for the virtual file.
150
+ *
151
+ * @remarks
152
+ * If no specific id is provided, it defaults to the file's {@link path}.
153
+ */
154
+ id: string;
155
+ /**
156
+ * Additional metadata associated with the virtual file.
157
+ */
158
+ details: Record<string, PrimitiveJsonValue>;
159
+ /**
160
+ * The variant of the file.
161
+ *
162
+ * @remarks
163
+ * This string represents the purpose/function of the file in the virtual file system. A potential list of variants includes:
164
+ * - `builtin`: Indicates that the file is a built-in module provided by the system.
165
+ * - `entry`: Indicates that the file is an entry point for execution.
166
+ * - `normal`: Indicates that the file is a standard file without any special role.
167
+ */
168
+ variant: string;
169
+ /**
170
+ * The output mode of the file.
171
+ *
172
+ * @remarks
173
+ * This indicates whether the file is intended to be written to the actual file system (`fs`) or kept in the virtual file system (`virtual`).
174
+ */
175
+ mode: OutputModeType;
176
+ /**
177
+ * A virtual (or actual) path to the file in the file system.
178
+ */
179
+ path: string;
180
+ /**
181
+ * The contents of the file.
182
+ */
183
+ code: string | NodeJS.ArrayBufferView;
184
+ }
185
+ type VirtualFileSystemMetadata = Pick<VirtualFile, "id" | "details" | "variant" | "mode">;
186
+ interface ResolveFSOptions {
187
+ mode?: OutputModeType;
188
+ }
189
+ type MakeDirectoryOptions = (Mode | MakeDirectoryOptions$1) & ResolveFSOptions;
190
+ interface PowerlinesWriteFileOptions extends ResolveFSOptions {
191
+ skipFormat?: boolean;
192
+ }
193
+ type NodeWriteFileOptions = WriteFileOptions$1;
194
+ type WriteFileOptions = NodeWriteFileOptions | PowerlinesWriteFileOptions;
195
+ type PowerLinesWriteFileData = Partial<Omit<VirtualFile, "path" | "mode" | "code">> & Pick<VirtualFile, "code">;
196
+ type WriteFileData = string | NodeJS.ArrayBufferView | PowerLinesWriteFileData;
197
+ interface ResolvePathOptions extends ResolveFSOptions {
198
+ /**
199
+ * Should the resolved path include the file extension?
200
+ *
201
+ * @defaultValue true
202
+ */
203
+ withExtension?: boolean;
204
+ /**
205
+ * The paths to search for the file.
206
+ */
207
+ paths?: string[];
208
+ /**
209
+ * The type of the path to resolve.
210
+ */
211
+ type?: "file" | "directory";
212
+ }
213
+ interface VirtualFileSystemInterface {
214
+ [__VFS_INIT__]: () => void;
215
+ [__VFS_REVERT__]: () => void;
216
+ /**
217
+ * The underlying file metadata.
218
+ */
219
+ meta: Record<string, VirtualFileSystemMetadata | undefined>;
220
+ /**
221
+ * A map of module ids to their file paths.
222
+ */
223
+ ids: Record<string, string>;
224
+ /**
225
+ * Check if a path or id corresponds to a virtual file **(does not actually exists on disk)**.
226
+ *
227
+ * @param pathOrId - The path or id to check.
228
+ * @param options - Optional parameters for resolving the path.
229
+ * @returns Whether the path or id corresponds to a virtual file **(does not actually exists on disk)**.
230
+ */
231
+ isVirtual: (pathOrId: string, options?: ResolvePathOptions) => boolean;
232
+ /**
233
+ * Check if a path or id corresponds to a file written to the file system **(actually exists on disk)**.
234
+ *
235
+ * @param pathOrId - The path or id to check.
236
+ * @param options - Optional parameters for resolving the path.
237
+ * @returns Whether the path or id corresponds to a file written to the file system **(actually exists on disk)**.
238
+ */
239
+ isFs: (pathOrId: string, options?: ResolvePathOptions) => boolean;
240
+ /**
241
+ * Checks if a file exists in the virtual file system (VFS).
242
+ *
243
+ * @param path - The path of the file to check.
244
+ * @returns `true` if the file exists, otherwise `false`.
245
+ */
246
+ isFile: (path: string) => boolean;
247
+ /**
248
+ * Checks if a directory exists in the virtual file system (VFS).
249
+ *
250
+ * @param path - The path of the directory to check.
251
+ * @returns `true` if the directory exists, otherwise `false`.
252
+ */
253
+ isDirectory: (path: string) => boolean;
254
+ /**
255
+ * Check if a path exists within one of the directories specified in the tsconfig.json's `path` field.
256
+ *
257
+ * @see https://www.typescriptlang.org/tsconfig#paths
258
+ *
259
+ * @param pathOrId - The path or id to check.
260
+ * @returns Whether the path or id corresponds to a virtual file.
261
+ */
262
+ isTsconfigPath: (pathOrId: string) => boolean;
263
+ /**
264
+ * Checks if a file exists in the virtual file system (VFS).
265
+ *
266
+ * @param pathOrId - The path or id of the file.
267
+ * @returns `true` if the file exists, otherwise `false`.
268
+ */
269
+ existsSync: (pathOrId: string) => boolean;
270
+ /**
271
+ * Gets the metadata of a file in the virtual file system (VFS).
272
+ *
273
+ * @param pathOrId - The path or id of the file.
274
+ * @returns The metadata of the file if it exists, otherwise undefined.
275
+ */
276
+ getMetadata: (pathOrId: PathLike) => VirtualFileSystemMetadata | undefined;
277
+ /**
278
+ * Gets the stats of a file in the virtual file system (VFS).
279
+ *
280
+ * @param pathOrId - The path or id of the file.
281
+ * @param options - Optional parameters for getting the stats.
282
+ * @returns The stats of the file if it exists, otherwise undefined.
283
+ */
284
+ lstat: (pathOrId: string, options?: StatSyncOptions & {
285
+ bigint?: false | undefined;
286
+ throwIfNoEntry: false;
287
+ }) => Promise<Stats>;
288
+ /**
289
+ * Gets the stats of a file in the virtual file system (VFS).
290
+ *
291
+ * @param pathOrId - The path or id of the file.
292
+ * @param options - Optional parameters for getting the stats.
293
+ * @returns The stats of the file if it exists, otherwise undefined.
294
+ */
295
+ lstatSync: (pathOrId: string, options?: StatSyncOptions & {
296
+ bigint?: false | undefined;
297
+ throwIfNoEntry: false;
298
+ }) => Stats | undefined;
299
+ /**
300
+ * Gets the stats of a file in the virtual file system (VFS).
301
+ *
302
+ * @param pathOrId - The path or id of the file.
303
+ * @returns The stats of the file if it exists, otherwise false.
304
+ */
305
+ stat: (pathOrId: string, options?: StatSyncOptions & {
306
+ bigint?: false | undefined;
307
+ throwIfNoEntry: false;
308
+ }) => Promise<Stats>;
309
+ /**
310
+ * Gets the stats of a file in the virtual file system (VFS).
311
+ *
312
+ * @param pathOrId - The path or id of the file.
313
+ * @returns The stats of the file if it exists, otherwise false.
314
+ */
315
+ statSync: (pathOrId: string, options?: StatSyncOptions & {
316
+ bigint?: false | undefined;
317
+ throwIfNoEntry: false;
318
+ }) => Stats | undefined;
319
+ /**
320
+ * Lists files in a given path.
321
+ *
322
+ * @param path - The path to list files from.
323
+ * @param options - Options for listing files, such as encoding and recursion.
324
+ * @returns An array of file names in the specified path.
325
+ */
326
+ readdirSync: (path: string, options?: {
327
+ encoding: BufferEncoding | null;
328
+ withFileTypes?: false | undefined;
329
+ recursive?: boolean | undefined;
330
+ } | BufferEncoding) => string[];
331
+ /**
332
+ * Lists files in a given path.
333
+ *
334
+ * @param path - The path to list files from.
335
+ * @param options - Options for listing files, such as encoding and recursion.
336
+ * @returns An array of file names in the specified path.
337
+ */
338
+ readdir: (path: string, options?: {
339
+ encoding: BufferEncoding | null;
340
+ withFileTypes?: false | undefined;
341
+ recursive?: boolean | undefined;
342
+ } | BufferEncoding) => Promise<string[]>;
343
+ /**
344
+ * Removes a file or symbolic link in the virtual file system (VFS).
345
+ *
346
+ * @param path - The path to the file to remove.
347
+ * @returns A promise that resolves when the file is removed.
348
+ */
349
+ unlinkSync: (path: PathLike, options?: ResolveFSOptions) => void;
350
+ /**
351
+ * Asynchronously removes a file or symbolic link in the virtual file system (VFS).
352
+ *
353
+ * @param path - The path to the file to remove.
354
+ * @returns A promise that resolves when the file is removed.
355
+ */
356
+ unlink: (path: string, options?: ResolveFSOptions) => Promise<void>;
357
+ /**
358
+ * Removes a directory in the virtual file system (VFS).
359
+ *
360
+ * @param path - The path to create the directory at.
361
+ * @param options - Options for creating the directory.
362
+ */
363
+ rmdirSync: (path: PathLike, options?: RmDirOptions & ResolveFSOptions) => any;
364
+ /**
365
+ * Removes a directory in the virtual file system (VFS).
366
+ *
367
+ * @param path - The path to create the directory at.
368
+ * @param options - Options for creating the directory.
369
+ * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
370
+ */
371
+ rmdir: (path: PathLike, options?: RmDirOptions & ResolveFSOptions) => Promise<void>;
372
+ /**
373
+ * Removes a file or directory in the virtual file system (VFS).
374
+ *
375
+ * @param path - The path to the file or directory to remove.
376
+ * @param options - Options for removing the file or directory.
377
+ * @returns A promise that resolves when the file or directory is removed.
378
+ */
379
+ rm: (path: PathLike, options?: RmOptions & ResolveFSOptions) => Promise<void>;
380
+ /**
381
+ * Synchronously removes a file or directory in the virtual file system (VFS).
382
+ *
383
+ * @param path - The path to the file or directory to remove.
384
+ * @param options - Options for removing the file or directory.
385
+ */
386
+ rmSync: (path: PathLike, options?: RmOptions & ResolveFSOptions) => void;
387
+ /**
388
+ * Creates a directory in the virtual file system (VFS).
389
+ *
390
+ * @param path - The path to create the directory at.
391
+ * @param options - Options for creating the directory.
392
+ * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
393
+ */
394
+ mkdirSync: (path: PathLike, options?: MakeDirectoryOptions) => string | undefined;
395
+ /**
396
+ * Creates a directory in the virtual file system (VFS).
397
+ *
398
+ * @param path - The path to create the directory at.
399
+ * @param options - Options for creating the directory.
400
+ * @returns A promise that resolves to the path of the created directory, or undefined if the directory could not be created.
401
+ */
402
+ mkdir: (path: PathLike, options?: MakeDirectoryOptions) => Promise<string | undefined>;
403
+ /**
404
+ * Reads a file from the virtual file system (VFS).
405
+ *
406
+ * @param pathOrId - The path or id of the file.
407
+ * @returns The contents of the file if it exists, otherwise undefined.
408
+ */
409
+ readFile: (pathOrId: string) => Promise<string | undefined>;
410
+ /**
411
+ * Reads a file from the virtual file system (VFS).
412
+ *
413
+ * @param pathOrId - The path or id of the file.
414
+ */
415
+ readFileSync: (pathOrId: string) => string | undefined;
416
+ /**
417
+ * Writes a file to the virtual file system (VFS).
418
+ *
419
+ * @param path - The path to the file.
420
+ * @param data - The contents of the file.
421
+ * @param options - Optional parameters for writing the file.
422
+ * @returns A promise that resolves when the file is written.
423
+ */
424
+ writeFile: (path: PathOrFileDescriptor, data?: WriteFileData, options?: WriteFileOptions) => Promise<void>;
425
+ /**
426
+ * Writes a file to the virtual file system (VFS).
427
+ *
428
+ * @param path - The path to the file.
429
+ * @param data - The contents of the file.
430
+ * @param options - Optional parameters for writing the file.
431
+ */
432
+ writeFileSync: (path: PathOrFileDescriptor, data?: WriteFileData, options?: WriteFileOptions) => void;
433
+ /**
434
+ * Moves a file from one path to another in the virtual file system (VFS).
435
+ *
436
+ * @param srcPath - The source path to move
437
+ * @param destPath - The destination path to move to
438
+ */
439
+ move: (srcPath: string, destPath: string) => Promise<void>;
440
+ /**
441
+ * Synchronously moves a file from one path to another in the virtual file system (VFS).
442
+ *
443
+ * @param srcPath - The source path to move
444
+ * @param destPath - The destination path to move to
445
+ */
446
+ moveSync: (srcPath: string, destPath: string) => void;
447
+ /**
448
+ * Copies a file from one path to another in the virtual file system (VFS).
449
+ *
450
+ * @param srcPath - The source path to copy
451
+ * @param destPath - The destination path to copy to
452
+ */
453
+ copy: (srcPath: string, destPath: string) => Promise<void>;
454
+ /**
455
+ * Synchronously copies a file from one path to another in the virtual file system (VFS).
456
+ *
457
+ * @param srcPath - The source path to copy
458
+ * @param destPath - The destination path to copy to
459
+ */
460
+ copySync: (srcPath: string, destPath: string) => void;
461
+ /**
462
+ * Glob files in the virtual file system (VFS) based on the provided pattern(s).
463
+ *
464
+ * @param pattern - A pattern (or multiple patterns) to use to determine the file paths to return
465
+ * @returns An array of file paths matching the provided pattern(s)
466
+ */
467
+ glob: (pattern: string | string[]) => Promise<string[]>;
468
+ /**
469
+ * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
470
+ *
471
+ * @param pattern - A pattern (or multiple patterns) to use to determine the file paths to return
472
+ * @returns An array of file paths matching the provided pattern(s)
473
+ */
474
+ globSync: (pattern: string | string[]) => string[];
475
+ /**
476
+ * Resolves a path or id to a file path in the virtual file system.
477
+ *
478
+ * @param pathOrId - The path or id of the file to resolve.
479
+ * @param options - Optional parameters for resolving the path.
480
+ * @returns The resolved path of the file if it exists, otherwise false.
481
+ */
482
+ resolve: (pathOrId: string, options?: ResolvePathOptions) => string | false;
483
+ /**
484
+ * Resolves a path based on TypeScript's `tsconfig.json` paths.
485
+ *
486
+ * @see https://www.typescriptlang.org/tsconfig#paths
487
+ *
488
+ * @param path - The path to check.
489
+ * @returns The resolved file path if it exists, otherwise undefined.
490
+ */
491
+ resolveTsconfigPath: (path: string) => string | false;
492
+ /**
493
+ * Resolves a package name based on TypeScript's `tsconfig.json` paths.
494
+ *
495
+ * @see https://www.typescriptlang.org/tsconfig#paths
496
+ *
497
+ * @param path - The path to check.
498
+ * @returns The resolved package name if it exists, otherwise undefined.
499
+ */
500
+ resolveTsconfigPathPackage: (path: string) => string | false;
501
+ /**
502
+ * Resolves a path or id to a file path in the virtual file system.
503
+ *
504
+ * @param pathOrId - The path or id of the file to resolve.
505
+ * @returns The resolved path of the file if it exists, otherwise false.
506
+ */
507
+ realpathSync: (pathOrId: string) => string;
508
+ /**
509
+ * Retrieves a partial metadata mapping of all files in the virtual file system (VFS).
510
+ *
511
+ * @returns A record mapping file paths to their partial metadata.
512
+ */
513
+ getPartialMeta: () => Record<string, Partial<VirtualFileSystemMetadata>>;
514
+ /**
515
+ * A map of cached file paths to their underlying file content.
516
+ */
517
+ [__VFS_CACHE__]: Map<string, string>;
518
+ /**
519
+ * A reference to the underlying virtual file system.
520
+ */
521
+ [__VFS_VIRTUAL__]: Volume;
522
+ /**
523
+ * A reference to the underlying unified file system.
524
+ */
525
+ [__VFS_UNIFIED__]: IUnionFs;
526
+ }
527
+
528
+ type LogFn = (type: LogLevelLabel, ...args: string[]) => void;
529
+ /**
530
+ * The {@link StormWorkspaceConfig | configuration} object for an entire Powerlines workspace
531
+ */
532
+ type WorkspaceConfig = Partial<StormWorkspaceConfig> & Required<Pick<StormWorkspaceConfig, "workspaceRoot">>;
533
+ type PluginFactory<in out TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => MaybePromise<Plugin<TContext>>;
534
+ /**
535
+ * A configuration tuple for a Powerlines plugin.
536
+ */
537
+ type PluginConfigTuple<TContext extends PluginContext = PluginContext, TOptions = any> = [string | PluginFactory<TContext, TOptions>, TOptions] | [Plugin<TContext>];
538
+ /**
539
+ * A configuration object for a Powerlines plugin.
540
+ */
541
+ type PluginConfigObject<TContext extends PluginContext = PluginContext, TOptions = any> = {
542
+ plugin: string | PluginFactory<TContext, TOptions>;
543
+ options: TOptions;
544
+ } | {
545
+ plugin: Plugin<TContext>;
546
+ options?: never;
547
+ };
548
+ /**
549
+ * A configuration tuple for a Powerlines plugin.
550
+ */
551
+ type PluginConfig<TContext extends PluginContext = PluginContext> = string | PluginFactory<TContext, void> | Plugin<TContext> | Promise<Plugin<TContext>> | PluginConfigTuple<TContext> | PluginConfigObject<TContext>;
552
+ type ProjectType = "application" | "library";
553
+ interface OutputConfig {
554
+ /**
555
+ * The path to output the final compiled files to
556
+ *
557
+ * @remarks
558
+ * If a value is not provided, Powerlines will attempt to:
559
+ * 1. Use the `outDir` value in the `tsconfig.json` file.
560
+ * 2. Use the `dist` directory in the project root directory.
561
+ *
562
+ * @defaultValue "dist/\{projectRoot\}"
563
+ */
564
+ outputPath?: string;
565
+ /**
566
+ * The format of the output files
567
+ *
568
+ * @defaultValue "virtual"
569
+ */
570
+ mode?: OutputModeType;
571
+ /**
572
+ * The path of the generated runtime declaration file relative to the workspace root.
573
+ *
574
+ * @defaultValue "\{projectRoot\}/powerlines.d.ts"
575
+ */
576
+ dts?: string | false;
577
+ /**
578
+ * A prefix to use for identifying builtin modules
579
+ *
580
+ * @remarks
581
+ * This prefix will be used to identify all builtin modules generated during the "prepare" phase. An example builtin ID for a module called `"utils"` would be `"{builtinPrefix}:utils"`.
582
+ *
583
+ * @defaultValue "powerlines"
584
+ */
585
+ builtinPrefix?: string;
586
+ /**
587
+ * The folder where the generated runtime artifacts will be located
588
+ *
589
+ * @remarks
590
+ * This folder will contain all runtime artifacts and builtins generated during the "prepare" phase.
591
+ *
592
+ * @defaultValue "\{projectRoot\}/.powerlines"
593
+ */
594
+ artifactsFolder?: string;
595
+ /**
596
+ * The module format of the output files
597
+ *
598
+ * @remarks
599
+ * This option can be a single format or an array of formats. If an array is provided, multiple builds will be generated for each format.
600
+ *
601
+ * @defaultValue "esm"
602
+ */
603
+ format?: Format | Format[];
604
+ /**
605
+ * A list of assets to copy to the output directory
606
+ *
607
+ * @remarks
608
+ * The assets can be specified as a string (path to the asset) or as an object with a `glob` property (to match multiple files). The paths are relative to the project root directory.
609
+ */
610
+ assets?: Array<string | AssetGlob>;
611
+ }
612
+ interface BaseConfig {
613
+ /**
614
+ * The name of the project
615
+ */
616
+ name?: string;
617
+ /**
618
+ * The project display title
619
+ *
620
+ * @remarks
621
+ * This option is used in documentation generation and other places where a human-readable title is needed.
622
+ */
623
+ title?: string;
624
+ /**
625
+ * A description of the project
626
+ *
627
+ * @remarks
628
+ * If this option is not provided, the build process will try to use the \`description\` value from the `\package.json\` file.
629
+ */
630
+ description?: string;
631
+ /**
632
+ * The log level to use for the Powerlines processes.
633
+ *
634
+ * @defaultValue "info"
635
+ */
636
+ logLevel?: LogLevelLabel | null;
637
+ /**
638
+ * A custom logger function to use for logging messages
639
+ */
640
+ customLogger?: LogFn;
641
+ /**
642
+ * Explicitly set a mode to run in. This mode will be used at various points throughout the Powerlines processes, such as when compiling the source code.
643
+ *
644
+ * @defaultValue "production"
645
+ */
646
+ mode?: "development" | "test" | "production";
647
+ /**
648
+ * The entry point(s) for the application
649
+ */
650
+ entry?: TypeDefinitionParameter | TypeDefinitionParameter[];
651
+ /**
652
+ * Configuration for linting the source code
653
+ */
654
+ lint?: Record<string, any> | false;
655
+ /**
656
+ * Configuration for testing the source code
657
+ */
658
+ test?: Record<string, any> | false;
659
+ /**
660
+ * Configuration for the output of the build process
661
+ */
662
+ output?: OutputConfig;
663
+ /**
664
+ * Configuration for the transformation of the source code
665
+ */
666
+ transform?: Record<string, any>;
667
+ /**
668
+ * Options to to provide to the build process
669
+ */
670
+ build?: BuildConfig;
671
+ /**
672
+ * Configuration for documentation generation
673
+ *
674
+ * @remarks
675
+ * This configuration will be used by the documentation generation plugins during the `docs` command.
676
+ */
677
+ docs?: Record<string, any>;
678
+ /**
679
+ * The path to the tsconfig file to be used by the compiler
680
+ *
681
+ * @remarks
682
+ * If a value is not provided, the plugin will attempt to find the `tsconfig.json` file in the project root directory. The parsed tsconfig compiler options will be merged with the {@link Options.tsconfigRaw} value (if provided).
683
+ *
684
+ * @defaultValue "\{projectRoot\}/tsconfig.json"
685
+ */
686
+ tsconfig?: string;
687
+ /**
688
+ * The raw {@link TSConfig} object to be used by the compiler. This object will be merged with the `tsconfig.json` file.
689
+ *
690
+ * @see https://www.typescriptlang.org/tsconfig
691
+ *
692
+ * @remarks
693
+ * If populated, this option takes higher priority than `tsconfig`
694
+ */
695
+ tsconfigRaw?: TSConfig;
696
+ }
697
+ interface EnvironmentConfig extends BaseConfig {
698
+ /**
699
+ * Array of strings indicating the order in which fields in a package.json file should be resolved to determine the entry point for a module.
700
+ *
701
+ * @defaultValue `['browser', 'module', 'jsnext:main', 'jsnext']`
702
+ */
703
+ mainFields?: string[];
704
+ /**
705
+ * Array of strings indicating what conditions should be used for module resolution.
706
+ */
707
+ conditions?: string[];
708
+ /**
709
+ * Array of strings indicating what conditions should be used for external modules.
710
+ */
711
+ externalConditions?: string[];
712
+ /**
713
+ * Array of strings indicating what file extensions should be used for module resolution.
714
+ *
715
+ * @defaultValue `['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json']`
716
+ */
717
+ extensions?: string[];
718
+ /**
719
+ * Array of strings indicating what modules should be deduplicated to a single version in the build.
720
+ *
721
+ * @remarks
722
+ * This option is useful for ensuring that only one version of a module is included in the bundle, which can help reduce bundle size and avoid conflicts.
723
+ */
724
+ dedupe?: string[];
725
+ /**
726
+ * Array of strings or regular expressions that indicate what modules are builtin for the environment.
727
+ */
728
+ builtins?: (string | RegExp)[];
729
+ /**
730
+ * Configuration options for the preview server
731
+ */
732
+ preview?: PreviewOptions;
733
+ /**
734
+ * A flag indicating whether the build is for a Server-Side Rendering environment.
735
+ */
736
+ ssr?: boolean;
737
+ /**
738
+ * Define if this environment is used for Server-Side Rendering
739
+ *
740
+ * @defaultValue "server" (if it isn't the client environment)
741
+ */
742
+ consumer?: "client" | "server";
743
+ }
744
+ interface CommonUserConfig extends BaseConfig {
745
+ /**
746
+ * The type of project being built
747
+ *
748
+ * @defaultValue "application"
749
+ */
750
+ type?: ProjectType;
751
+ /**
752
+ * The root directory of the project
753
+ */
754
+ root: string;
755
+ /**
756
+ * The root directory of the project's source code
757
+ *
758
+ * @defaultValue "\{root\}/src"
759
+ */
760
+ sourceRoot?: string;
761
+ /**
762
+ * A path to a custom configuration file to be used instead of the default `storm.json`, `powerlines.config.js`, or `powerlines.config.ts` files.
763
+ *
764
+ * @remarks
765
+ * This option is useful for running Powerlines commands with different configuration files, such as in CI/CD environments or when testing different configurations.
766
+ */
767
+ configFile?: string;
768
+ /**
769
+ * Should the Powerlines CLI processes skip installing missing packages?
770
+ *
771
+ * @remarks
772
+ * This option is useful for CI/CD environments where the installation of packages is handled by a different process.
773
+ *
774
+ * @defaultValue false
775
+ */
776
+ skipInstalls?: boolean;
777
+ /**
778
+ * Should the compiler processes skip any improvements that make use of cache?
779
+ *
780
+ * @defaultValue false
781
+ */
782
+ skipCache?: boolean;
783
+ /**
784
+ * A list of resolvable paths to plugins used during the build process
785
+ */
786
+ plugins?: PluginConfig<PluginContext<any>>[];
787
+ /**
788
+ * Environment-specific configurations
789
+ */
790
+ environments?: Record<string, EnvironmentConfig>;
791
+ /**
792
+ * A string identifier that allows a child framework or tool to identify itself when using Powerlines.
793
+ *
794
+ * @remarks
795
+ * If no values are provided for {@link OutputConfig.dts | output.dts}, {@link OutputConfig.builtinPrefix | output.builtinPrefix}, or {@link OutputConfig.artifactsFolder | output.artifactsFolder}, this value will be used as the default.
796
+ *
797
+ * @defaultValue "powerlines"
798
+ */
799
+ framework?: string;
800
+ }
801
+ type UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> = CommonUserConfig & {
802
+ build?: TBuildConfig & {
803
+ /**
804
+ * The build variant being used by the Powerlines engine.
805
+ */
806
+ variant?: TBuildVariant;
807
+ };
808
+ override?: Partial<TBuildResolvedConfig>;
809
+ };
810
+ type RollupUserConfig = UserConfig<RollupBuildConfig, RollupResolvedBuildConfig, "rollup">;
811
+ type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "release" | "clean";
812
+ /**
813
+ * The configuration provided while executing Powerlines commands.
814
+ */
815
+ type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
816
+ /**
817
+ * A string identifier for the Powerlines command being executed
818
+ */
819
+ command: PowerlinesCommand;
820
+ };
821
+
822
+ interface ResolvedEntryTypeDefinition extends TypeDefinition {
823
+ /**
824
+ * The user provided entry point in the source code
825
+ */
826
+ input: TypeDefinition;
827
+ /**
828
+ * An optional name to use in the package export during the build process
829
+ */
830
+ output?: string;
831
+ }
832
+ type EnvironmentResolvedConfig = Omit<EnvironmentConfig, "consumer" | "mode" | "ssr" | "preview" | "mainFields" | "extensions"> & Required<Pick<EnvironmentConfig, "consumer" | "mode" | "ssr" | "mainFields" | "extensions">> & {
833
+ /**
834
+ * The name of the environment
835
+ */
836
+ name: string;
837
+ /**
838
+ * Configuration options for the preview server
839
+ */
840
+ preview?: ResolvedPreviewOptions;
841
+ };
842
+ type ResolvedAssetGlob = AssetGlob & Required<Pick<AssetGlob, "input">>;
843
+ type OutputResolvedConfig = Required<Omit<OutputConfig, "assets"> & {
844
+ assets: ResolvedAssetGlob[];
845
+ }>;
846
+ /**
847
+ * The resolved options for the Powerlines project configuration.
848
+ */
849
+ type ResolvedConfig<TUserConfig extends UserConfig = UserConfig> = Omit<TUserConfig, "name" | "title" | "plugins" | "mode" | "environments" | "platform" | "tsconfig" | "lint" | "test" | "build" | "transform" | "override" | "root" | "variant" | "type" | "output" | "logLevel" | "framework"> & Required<Pick<TUserConfig, "name" | "title" | "plugins" | "mode" | "environments" | "tsconfig" | "lint" | "test" | "build" | "transform" | "override" | "framework">> & {
850
+ /**
851
+ * The configuration options that were provided inline to the Powerlines CLI.
852
+ */
853
+ inlineConfig: InlineConfig<TUserConfig>;
854
+ /**
855
+ * The original configuration options that were provided by the user to the Powerlines process.
856
+ */
857
+ userConfig: TUserConfig;
858
+ /**
859
+ * A string identifier for the Powerlines command being executed.
860
+ */
861
+ command: NonUndefined<InlineConfig<TUserConfig>["command"]>;
862
+ /**
863
+ * The root directory of the project's source code
864
+ *
865
+ * @defaultValue "\{projectRoot\}/src"
866
+ */
867
+ sourceRoot: NonUndefined<TUserConfig["sourceRoot"]>;
868
+ /**
869
+ * The root directory of the project.
870
+ */
871
+ projectRoot: NonUndefined<TUserConfig["root"]>;
872
+ /**
873
+ * The type of project being built.
874
+ */
875
+ projectType: NonUndefined<TUserConfig["type"]>;
876
+ /**
877
+ * The output configuration options to use for the build process
878
+ */
879
+ output: OutputResolvedConfig;
880
+ /**
881
+ * The log level to use for the Powerlines processes.
882
+ *
883
+ * @defaultValue "info"
884
+ */
885
+ logLevel: "error" | "warn" | "info" | "debug" | "trace" | null;
886
+ };
887
+ type RollupResolvedConfig = ResolvedConfig<RollupUserConfig>;
888
+
889
+ interface MetaInfo {
890
+ /**
891
+ * The checksum generated from the resolved options
892
+ */
893
+ checksum: string;
894
+ /**
895
+ * The build id
896
+ */
897
+ buildId: string;
898
+ /**
899
+ * The release id
900
+ */
901
+ releaseId: string;
902
+ /**
903
+ * The build timestamp
904
+ */
905
+ timestamp: number;
906
+ /**
907
+ * A hash that represents the path to the project root directory
908
+ */
909
+ projectRootHash: string;
910
+ /**
911
+ * A hash that represents the path to the project root directory
912
+ */
913
+ configHash: string;
914
+ /**
915
+ * A mapping of runtime ids to their corresponding file paths
916
+ */
917
+ builtinIdMap: Record<string, string>;
918
+ /**
919
+ * A mapping of virtual file paths to their corresponding file contents
920
+ */
921
+ virtualFiles: Record<string, string | null>;
922
+ }
923
+ interface Resolver extends Jiti {
924
+ plugin: Jiti;
925
+ }
926
+ interface InitContextOptions {
927
+ /**
928
+ * If false, the plugin will be loaded after all other plugins.
929
+ *
930
+ * @defaultValue true
931
+ */
932
+ isHighPriority: boolean;
933
+ }
934
+ interface Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
935
+ /**
936
+ * The Storm workspace configuration
937
+ */
938
+ workspaceConfig: WorkspaceConfig;
939
+ /**
940
+ * An object containing the options provided to Powerlines
941
+ */
942
+ config: TResolvedConfig;
943
+ /**
944
+ * A logging function for the Powerlines engine
945
+ */
946
+ log: LogFn;
947
+ /**
948
+ * The metadata information
949
+ */
950
+ meta: MetaInfo;
951
+ /**
952
+ * The metadata information currently written to disk
953
+ */
954
+ persistedMeta?: MetaInfo;
955
+ /**
956
+ * The Powerlines artifacts directory
957
+ */
958
+ artifactsPath: string;
959
+ /**
960
+ * The path to the Powerlines builtin runtime modules directory
961
+ */
962
+ builtinsPath: string;
963
+ /**
964
+ * The path to the Powerlines entry modules directory
965
+ */
966
+ entryPath: string;
967
+ /**
968
+ * The path to the Powerlines TypeScript declaration files directory
969
+ */
970
+ dtsPath: string;
971
+ /**
972
+ * The path to a directory where the reflection data buffers (used by the build processes) are stored
973
+ */
974
+ dataPath: string;
975
+ /**
976
+ * The path to a directory where the project cache (used by the build processes) is stored
977
+ */
978
+ cachePath: string;
979
+ /**
980
+ * The Powerlines environment paths
981
+ */
982
+ envPaths: EnvPaths;
983
+ /**
984
+ * The file system path to the Powerlines package installation
985
+ */
986
+ powerlinesPath: string;
987
+ /**
988
+ * The relative path to the Powerlines workspace root directory
989
+ */
990
+ relativeToWorkspaceRoot: string;
991
+ /**
992
+ * The project's `package.json` file content
993
+ */
994
+ packageJson: PackageJson & Record<string, any>;
995
+ /**
996
+ * The project's `project.json` file content
997
+ */
998
+ projectJson?: Record<string, any>;
999
+ /**
1000
+ * The dependency installations required by the project
1001
+ */
1002
+ dependencies: Record<string, string | Range>;
1003
+ /**
1004
+ * The development dependency installations required by the project
1005
+ */
1006
+ devDependencies: Record<string, string | Range>;
1007
+ /**
1008
+ * The parsed TypeScript configuration from the `tsconfig.json` file
1009
+ */
1010
+ tsconfig: ParsedTypeScriptConfig;
1011
+ /**
1012
+ * The entry points of the source code
1013
+ */
1014
+ entry: ResolvedEntryTypeDefinition[];
1015
+ /**
1016
+ * The virtual file system manager used during the build process to reference generated runtime files
1017
+ */
1018
+ fs: VirtualFileSystemInterface;
1019
+ /**
1020
+ * The Jiti module resolver
1021
+ */
1022
+ resolver: Resolver;
1023
+ /**
1024
+ * The builtin module id that exist in the Powerlines virtual file system
1025
+ */
1026
+ builtins: string[];
1027
+ /**
1028
+ * The Powerlines builtin virtual files
1029
+ */
1030
+ getBuiltins: () => Promise<VirtualFile[]>;
1031
+ /**
1032
+ * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
1033
+ *
1034
+ * @param code - The source code of the builtin file
1035
+ * @param id - The unique identifier of the builtin file
1036
+ * @param path - An optional path to write the builtin file to
1037
+ * @param options - Options for writing the file
1038
+ */
1039
+ writeBuiltin: (code: string, id: string, path?: string, options?: PowerlinesWriteFileOptions) => Promise<void>;
1040
+ /**
1041
+ * Resolves a entry virtual file and writes it to the VFS if it does not already exist
1042
+ *
1043
+ * @param code - The source code of the entry file
1044
+ * @param path - An optional path to write the entry file to
1045
+ * @param options - Options for writing the file
1046
+ */
1047
+ writeEntry: (code: string, path: string, options?: PowerlinesWriteFileOptions) => Promise<void>;
1048
+ /**
1049
+ * Parses the source code and returns a {@link ParseResult} object.
1050
+ */
1051
+ parse: (code: string, id: string, options?: ParserOptions | null) => Promise<ParseResult>;
1052
+ /**
1053
+ * A function to update the context fields using a new user configuration options
1054
+ */
1055
+ withUserConfig: (userConfig: UserConfig, options?: InitContextOptions) => Promise<void>;
1056
+ /**
1057
+ * A function to update the context fields using inline configuration options
1058
+ */
1059
+ withInlineConfig: (inlineConfig: InlineConfig, options?: InitContextOptions) => Promise<void>;
1060
+ /**
1061
+ * Create a new logger instance
1062
+ *
1063
+ * @param name - The name to use for the logger instance
1064
+ * @returns A logger function
1065
+ */
1066
+ createLog: (name: string | null) => LogFn;
1067
+ /**
1068
+ * Extend the current logger instance with a new name
1069
+ *
1070
+ * @param name - The name to use for the extended logger instance
1071
+ * @returns A logger function
1072
+ */
1073
+ extendLog: (name: string) => LogFn;
1074
+ }
1075
+ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
1076
+ /**
1077
+ * The environment specific resolved configuration
1078
+ */
1079
+ environment: EnvironmentResolvedConfig;
1080
+ /**
1081
+ * An alternative property name for the {@link log} property
1082
+ *
1083
+ * @remarks
1084
+ * This is provided for compatibility with other logging libraries that expect a `logger` property.
1085
+ */
1086
+ logger: LogFn;
1087
+ }
1088
+ type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = PluginContext<TResolvedConfig> & Omit<UnpluginBuildContext, "parse">;
1089
+
1090
+ declare const SUPPORTED_COMMANDS: readonly ["new", "clean", "prepare", "lint", "test", "build", "docs", "release", "finalize"];
1091
+ type CommandType = ArrayValues<typeof SUPPORTED_COMMANDS>;
1092
+
1093
+ interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends keyof HookFilter | undefined = undefined> {
1094
+ /**
1095
+ * The order in which the plugin should be applied.
1096
+ */
1097
+ order?: "pre" | "post" | null | undefined;
1098
+ /**
1099
+ * A filter to determine when the hook should be called.
1100
+ */
1101
+ filter?: TFilter;
1102
+ /**
1103
+ * The hook function to be called.
1104
+ */
1105
+ handler: THookFunction;
1106
+ }
1107
+ type PluginHook<THookFunction extends FunctionLike, TFilter extends keyof HookFilter | undefined = undefined> = THookFunction | PluginHookObject<THookFunction, TFilter>;
1108
+ /**
1109
+ * A result returned by the plugin from the `generateTypes` hook that describes the declaration types output file.
1110
+ */
1111
+ interface GenerateTypesResult {
1112
+ directives?: string[];
1113
+ code: string;
1114
+ }
1115
+ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext> extends Record<CommandType, (this: TContext) => MaybePromise<void>> {
1116
+ /**
1117
+ * A function that returns configuration options to be merged with the build context's options.
1118
+ *
1119
+ * @remarks
1120
+ * Modify config before it's resolved. The hook can either mutate {@link Context.config} on the passed-in context directly, or return a partial config object that will be deeply merged into existing config.
1121
+ *
1122
+ * @warning User plugins are resolved before running this hook so injecting other plugins inside the config hook will have no effect. If you want to add plugins, consider doing so in the {@link Plugin.dependsOn} property instead.
1123
+ *
1124
+ * @see https://vitejs.dev/guide/api-plugin#config
1125
+ *
1126
+ * @param this - The build context.
1127
+ * @param config - The partial configuration object to be modified.
1128
+ * @returns A promise that resolves to a partial configuration object.
1129
+ */
1130
+ config: (this: Context<TContext["config"]>) => MaybePromise<Partial<TContext["config"]["userConfig"]>>;
1131
+ /**
1132
+ * Modify environment configs before it's resolved. The hook can either mutate the passed-in environment config directly, or return a partial config object that will be deeply merged into existing config.
1133
+ *
1134
+ * @remarks
1135
+ * This hook is called for each environment with a partially resolved environment config that already accounts for the default environment config values set at the root level. If plugins need to modify the config of a given environment, they should do it in this hook instead of the config hook. Leaving the config hook only for modifying the root default environment config.
1136
+ *
1137
+ * @see https://vitejs.dev/guide/api-plugin#configenvironment
1138
+ *
1139
+ * @param this - The build context.
1140
+ * @param name - The name of the environment being configured.
1141
+ * @param environment - The Vite-like environment object containing information about the current build environment.
1142
+ * @returns A promise that resolves when the hook is complete.
1143
+ */
1144
+ configEnvironment: (this: TContext, name: string, environment: EnvironmentConfig) => MaybePromise<Partial<EnvironmentResolvedConfig> | undefined | null>;
1145
+ /**
1146
+ * A hook that is called when the plugin is resolved.
1147
+ *
1148
+ * @see https://vitejs.dev/guide/api-plugin#configresolved
1149
+ *
1150
+ * @param this - The build context.
1151
+ * @returns A promise that resolves when the hook is complete.
1152
+ */
1153
+ configResolved: (this: TContext) => MaybePromise<void>;
1154
+ /**
1155
+ * A hook that is called to overwrite the generated declaration types file (.d.ts). The generated type definitions should describe the built-in modules/logic added during the `prepare` task.
1156
+ *
1157
+ * @param this - The build context.
1158
+ * @param code - The source code to generate types for.
1159
+ * @returns A promise that resolves when the hook is complete.
1160
+ */
1161
+ generateTypes: (this: TContext, code: string) => MaybePromise<GenerateTypesResult | string | undefined | null>;
1162
+ /**
1163
+ * A hook that is called at the start of the build process.
1164
+ *
1165
+ * @param this - The build context and unplugin build context.
1166
+ * @returns A promise that resolves when the hook is complete.
1167
+ */
1168
+ buildStart: (this: BuildPluginContext<TContext["config"]> & TContext) => MaybePromise<void>;
1169
+ /**
1170
+ * A hook that is called at the end of the build process.
1171
+ *
1172
+ * @param this - The build context and unplugin build context.
1173
+ * @returns A promise that resolves when the hook is complete.
1174
+ */
1175
+ buildEnd: (this: BuildPluginContext<TContext["config"]> & TContext) => MaybePromise<void>;
1176
+ /**
1177
+ * A hook that is called to transform the source code.
1178
+ *
1179
+ * @param this - The build context, unplugin build context, and unplugin context.
1180
+ * @param code - The source code to transform.
1181
+ * @param id - The identifier of the source code.
1182
+ * @returns A promise that resolves when the hook is complete.
1183
+ */
1184
+ transform: (this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>;
1185
+ /**
1186
+ * A hook that is called to load the source code.
1187
+ *
1188
+ * @param this - The build context, unplugin build context, and unplugin context.
1189
+ * @param id - The identifier of the source code.
1190
+ * @returns A promise that resolves when the hook is complete.
1191
+ */
1192
+ load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>;
1193
+ /**
1194
+ * A hook that is called to resolve the identifier of the source code.
1195
+ *
1196
+ * @param this - The build context, unplugin build context, and unplugin context.
1197
+ * @param id - The identifier of the source code.
1198
+ * @param importer - The importer of the source code.
1199
+ * @param options - The options for resolving the identifier.
1200
+ * @returns A promise that resolves when the hook is complete.
1201
+ */
1202
+ resolveId: (this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
1203
+ isEntry: boolean;
1204
+ }) => MaybePromise<string | ExternalIdResult | null | undefined>;
1205
+ /**
1206
+ * A hook that is called to write the bundle to disk.
1207
+ *
1208
+ * @param this - The build context.
1209
+ * @returns A promise that resolves when the hook is complete.
1210
+ */
1211
+ writeBundle: (this: TContext) => MaybePromise<void>;
1212
+ }
1213
+ type BuildPlugin<TContext extends PluginContext = PluginContext, TBuildVariant extends UnpluginBuildVariant = UnpluginBuildVariant, TOptions extends Required<UnpluginOptions>[TBuildVariant] = Required<UnpluginOptions>[TBuildVariant]> = {
1214
+ [TKey in keyof TOptions]: TOptions[TKey] extends FunctionLike ? (this: ThisParameterType<TOptions[TKey]> & TContext, ...args: Parameters<TOptions[TKey]>) => ReturnType<TOptions[TKey]> | MaybePromise<ReturnType<TOptions[TKey]>> : TOptions[TKey];
1215
+ };
1216
+ type PluginHooks<TContext extends PluginContext = PluginContext> = {
1217
+ [TKey in keyof BasePluginHookFunctions<TContext>]: PluginHook<BasePluginHookFunctions<TContext>[TKey]>;
1218
+ } & {
1219
+ /**
1220
+ * A function that returns configuration options to be merged with the build context's options.
1221
+ *
1222
+ * @remarks
1223
+ * Modify config before it's resolved. The hook can either mutate {@link Context.config} on the passed-in context directly, or return a partial config object that will be deeply merged into existing config.
1224
+ *
1225
+ * @warning User plugins are resolved before running this hook so injecting other plugins inside the config hook will have no effect. If you want to add plugins, consider doing so in the {@link Plugin.dependsOn} property instead.
1226
+ *
1227
+ * @see https://vitejs.dev/guide/api-plugin#config
1228
+ *
1229
+ * @param this - The build context.
1230
+ * @param config - The partial configuration object to be modified.
1231
+ * @returns A promise that resolves to a partial configuration object.
1232
+ */
1233
+ config: PluginHook<(this: Context<TContext["config"]>) => MaybePromise<Partial<TContext["config"]["userConfig"]>>> | Partial<TContext["config"]["userConfig"]>;
1234
+ /**
1235
+ * A hook that is called to transform the source code.
1236
+ *
1237
+ * @param this - The build context, unplugin build context, and unplugin context.
1238
+ * @param code - The source code to transform.
1239
+ * @param id - The identifier of the source code.
1240
+ * @returns A promise that resolves when the hook is complete.
1241
+ */
1242
+ transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>, "code" | "id">;
1243
+ /**
1244
+ * A hook that is called to load the source code.
1245
+ *
1246
+ * @param this - The build context, unplugin build context, and unplugin context.
1247
+ * @param id - The identifier of the source code.
1248
+ * @returns A promise that resolves when the hook is complete.
1249
+ */
1250
+ load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>, "id">;
1251
+ /**
1252
+ * A hook that is called to resolve the identifier of the source code.
1253
+ *
1254
+ * @param this - The build context, unplugin build context, and unplugin context.
1255
+ * @param id - The identifier of the source code.
1256
+ * @param importer - The importer of the source code.
1257
+ * @param options - The options for resolving the identifier.
1258
+ * @returns A promise that resolves when the hook is complete.
1259
+ */
1260
+ resolveId: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
1261
+ isEntry: boolean;
1262
+ }) => MaybePromise<string | ExternalIdResult | null | undefined>, "id">;
1263
+ };
1264
+ type PluginBuildPlugins<TContext extends PluginContext = PluginContext> = {
1265
+ [TBuildVariant in UnpluginBuildVariant]?: BuildPlugin<TContext, TBuildVariant>;
1266
+ };
1267
+ interface Plugin<in out TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> extends Partial<PluginHooks<TContext>>, PluginBuildPlugins<TContext> {
1268
+ /**
1269
+ * The name of the plugin, for use in deduplication, error messages and logs.
1270
+ */
1271
+ name: string;
1272
+ /**
1273
+ * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering is still subject to the `order` property in the hook object.
1274
+ *
1275
+ * @remarks
1276
+ * The Plugin invocation order is as follows:
1277
+ * - `enforce: 'pre'` plugins
1278
+ * - `order: 'pre'` plugin hooks
1279
+ * - any other plugins (normal)
1280
+ * - `order: 'post'` plugin hooks
1281
+ * - `enforce: 'post'` plugins
1282
+ *
1283
+ * @see https://vitejs.dev/guide/api-plugin.html#plugin-ordering
1284
+ * @see https://rollupjs.org/plugin-development/#build-hooks
1285
+ * @see https://webpack.js.org/concepts/loaders/#enforce---pre-and-post
1286
+ * @see https://esbuild.github.io/plugins/#concepts
1287
+ */
1288
+ enforce?: "pre" | "post";
1289
+ /**
1290
+ * A function to determine if two plugins are the same and can be de-duplicated.
1291
+ *
1292
+ * @remarks
1293
+ * If this is not provided, plugins are de-duplicated by comparing their names.
1294
+ *
1295
+ * @param other - The other plugin to compare against.
1296
+ * @returns `true` if the two plugins are the same, `false` otherwise.
1297
+ */
1298
+ dedupe?: false | ((other: Plugin<any>) => boolean);
1299
+ /**
1300
+ * A list of pre-requisite plugins that must be loaded before this plugin can be used.
1301
+ */
1302
+ dependsOn?: PluginConfig<any>[];
1303
+ /**
1304
+ * Define environments where this plugin should be active. By default, the plugin is active in all environments.
1305
+ *
1306
+ * @param environment - The environment to check.
1307
+ * @returns `true` if the plugin should be active in the specified environment, `false` otherwise.
1308
+ */
1309
+ applyToEnvironment?: (environment: EnvironmentResolvedConfig) => MaybePromise<boolean | Plugin<any>>;
1310
+ }
1311
+
1312
+ type RollupPluginOptions = Partial<RollupBuildConfig>;
1313
+ type RollupPluginResolvedConfig = RollupResolvedConfig;
1314
+ type RollupPluginContext<TResolvedConfig extends RollupPluginResolvedConfig = RollupPluginResolvedConfig> = PluginContext<TResolvedConfig>;
1315
+
1316
+ export type { Plugin as P, RollupPluginContext as R, RollupPluginOptions as a, RollupPluginResolvedConfig as b };