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