@powerlines/plugin-vite 0.13.7 → 0.14.0

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