@powerlines/plugin-capnp 0.1.1 → 0.1.2

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