@powerlines/plugin-unbuild 0.5.55 → 0.5.57

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.
@@ -1,1494 +0,0 @@
1
- import { UnbuildOptions } from '@storm-software/unbuild/types';
2
- import { EnvPaths } from '@stryke/env/get-env-paths';
3
- import { MaybePromise, NonUndefined, FunctionLike } from '@stryke/types/base';
4
- import { PackageJson } from '@stryke/types/package-json';
5
- import { Jiti } from 'jiti';
6
- import { SourceMap } from 'magic-string';
7
- import { Range } from 'semver';
8
- import { Project } from 'ts-morph';
9
- import { UnpluginMessage, ExternalIdResult, UnpluginContext, UnpluginBuildContext, TransformResult as TransformResult$1, HookFilter, UnpluginOptions } from 'unplugin';
10
- import { Format } from '@storm-software/build-tools/types';
11
- import { LogLevelLabel } from '@storm-software/config-tools/types';
12
- import { StormWorkspaceConfig } from '@storm-software/config/types';
13
- import { TypeDefinitionParameter, TypeDefinition } from '@stryke/types/configuration';
14
- import { AssetGlob } from '@stryke/types/file';
15
- import { PreviewOptions, ResolvedPreviewOptions } from 'vite';
16
- import { ResolveOptions as ResolveOptions$1 } from '@stryke/fs/resolve';
17
- import { ArrayValues } from '@stryke/types/array';
18
- import { TsConfigJson, CompilerOptions } from '@stryke/types/tsconfig';
19
- import ts from 'typescript';
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
- type UnbuildBuildConfig = Partial<Omit<UnbuildOptions, "tsconfig" | "tsconfigRaw" | "assets" | "outputPath" | "mode" | "format" | "platform" | "projectRoot" | "env" | "entry" | "entryPoints">> & BuildConfig;
157
- type UnbuildResolvedBuildConfig = UnbuildOptions & BuildResolvedConfig;
158
-
159
- declare enum StoragePreset {
160
- VIRTUAL = "virtual",
161
- FS = "fs"
162
- }
163
- /**
164
- * Interface defining the methods and properties for a storage adapter.
165
- */
166
- interface StorageAdapter {
167
- /**
168
- * A name identifying the storage adapter type.
169
- */
170
- name: string;
171
- /**
172
- * Checks if a key exists in the storage.
173
- *
174
- * @param key - The key to check for existence.
175
- * @returns A promise that resolves to `true` if the key exists, otherwise `false`.
176
- */
177
- exists: (key: string) => Promise<boolean>;
178
- /**
179
- * Synchronously checks if a key exists in the storage.
180
- *
181
- * @param key - The key to check for existence.
182
- * @returns Returns `true` if the key exists, otherwise `false`.
183
- */
184
- existsSync: (key: string) => boolean;
185
- /**
186
- * Read a value associated with a key from the storage.
187
- *
188
- * @param key - The key to read the value for.
189
- * @returns A promise that resolves to the value if found, otherwise `null`.
190
- */
191
- get: (key: string) => Promise<string | null>;
192
- /**
193
- * Synchronously reads the value associated with a key from the storage.
194
- *
195
- * @param key - The key to read the value for.
196
- * @returns The value if found, otherwise `null`.
197
- */
198
- getSync: (key: string) => string | null;
199
- /**
200
- * Writes a value to the storage for the given key.
201
- *
202
- * @param key - The key to associate the value with.
203
- * @param value - The value to store.
204
- */
205
- set: (key: string, value: string) => Promise<void>;
206
- /**
207
- * Synchronously writes a value to the storage for the given key.
208
- *
209
- * @param key - The key to associate the value with.
210
- * @param value - The value to store.
211
- */
212
- setSync: (key: string, value: string) => void;
213
- /**
214
- * Removes a value from the storage.
215
- *
216
- * @param key - The key whose value should be removed.
217
- */
218
- remove: (key: string) => Promise<void>;
219
- /**
220
- * Synchronously removes a value from the storage.
221
- *
222
- * @param key - The key whose value should be removed.
223
- */
224
- removeSync: (key: string) => void;
225
- /**
226
- * Remove all entries from the storage that match the provided base path.
227
- *
228
- * @param base - The base path or prefix to clear entries from.
229
- */
230
- clear: (base?: string) => Promise<void>;
231
- /**
232
- * Synchronously remove all entries from the storage that match the provided base path.
233
- *
234
- * @param base - The base path or prefix to clear entries from.
235
- */
236
- clearSync: (base?: string) => void;
237
- /**
238
- * Lists all keys under the provided base path.
239
- *
240
- * @param base - The base path or prefix to list keys from.
241
- * @returns A promise resolving to the list of keys.
242
- */
243
- list: (base?: string) => Promise<string[]>;
244
- /**
245
- * Synchronously lists all keys under the provided base path.
246
- *
247
- * @param base - The base path or prefix to list keys from.
248
- * @returns The list of keys.
249
- */
250
- listSync: (base?: string) => string[];
251
- /**
252
- * Releases any resources held by the storage adapter.
253
- */
254
- dispose: () => MaybePromise<void>;
255
- }
256
- /**
257
- * A mapping of file paths to storage adapter names and their corresponding {@link StorageAdapter} instances.
258
- */
259
- type StoragePort = Record<string, StorageAdapter>;
260
- interface VirtualFileMetadata {
261
- /**
262
- * The identifier for the file data.
263
- */
264
- id: string;
265
- /**
266
- * The timestamp of the virtual file.
267
- */
268
- timestamp: number;
269
- /**
270
- * The type of the file.
271
- *
272
- * @remarks
273
- * This string represents the purpose/function of the file in the virtual file system. A potential list of variants includes:
274
- * - `builtin`: Indicates that the file is a built-in module provided by the system.
275
- * - `entry`: Indicates that the file is an entry point for execution.
276
- * - `normal`: Indicates that the file is a standard file without any special role.
277
- */
278
- type: string;
279
- /**
280
- * Additional metadata associated with the file.
281
- */
282
- properties: Record<string, string>;
283
- }
284
- interface VirtualFileData {
285
- /**
286
- * The identifier for the file data.
287
- */
288
- id?: string;
289
- /**
290
- * The contents of the virtual file.
291
- */
292
- code: string;
293
- /**
294
- * The type of the file.
295
- *
296
- * @remarks
297
- * This string represents the purpose/function of the file in the virtual file system. A potential list of variants includes:
298
- * - `builtin`: Indicates that the file is a built-in module provided by the system.
299
- * - `entry`: Indicates that the file is an entry point for execution.
300
- * - `normal`: Indicates that the file is a standard file without any special role.
301
- */
302
- type?: string;
303
- /**
304
- * Additional metadata associated with the file.
305
- */
306
- properties?: Record<string, string>;
307
- }
308
- interface VirtualFile extends Required<VirtualFileData>, VirtualFileMetadata {
309
- /**
310
- * An additional name for the file.
311
- */
312
- path: string;
313
- /**
314
- * The timestamp of the virtual file.
315
- */
316
- timestamp: number;
317
- }
318
- interface WriteOptions {
319
- /**
320
- * Should the file skip formatting before being written?
321
- *
322
- * @defaultValue false
323
- */
324
- skipFormat?: boolean;
325
- /**
326
- * Additional metadata for the file.
327
- */
328
- meta?: VirtualFileMetadata;
329
- }
330
- interface ResolveOptions extends ResolveOptions$1 {
331
- /**
332
- * If true, the module is being resolved as an entry point.
333
- */
334
- isEntry?: boolean;
335
- /**
336
- * If true, the resolver will skip using the cache when resolving modules.
337
- */
338
- skipCache?: boolean;
339
- /**
340
- * An array of external modules or patterns to exclude from resolution.
341
- */
342
- external?: (string | RegExp)[];
343
- /**
344
- * An array of modules or patterns to include in the resolution, even if they are marked as external.
345
- */
346
- noExternal?: (string | RegExp)[];
347
- /**
348
- * An array of patterns to match when resolving modules.
349
- */
350
- skipNodeModulesBundle?: boolean;
351
- }
352
- interface VirtualFileSystemInterface {
353
- /**
354
- * The underlying file metadata.
355
- */
356
- metadata: Readonly<Record<string, VirtualFileMetadata>>;
357
- /**
358
- * A map of file paths to their module ids.
359
- */
360
- ids: Readonly<Record<string, string>>;
361
- /**
362
- * A map of module ids to their file paths.
363
- */
364
- paths: Readonly<Record<string, string>>;
365
- /**
366
- * Checks if a file exists in the virtual file system (VFS).
367
- *
368
- * @param path - The path or id of the file.
369
- * @returns `true` if the file exists, otherwise `false`.
370
- */
371
- exists: (path: string) => Promise<boolean>;
372
- /**
373
- * Synchronously Checks if a file exists in the virtual file system (VFS).
374
- *
375
- * @param path - The path or id of the file.
376
- * @returns `true` if the file exists, otherwise `false`.
377
- */
378
- existsSync: (path: string) => boolean;
379
- /**
380
- * Checks if a file is virtual in the virtual file system (VFS).
381
- *
382
- * @param path - The path or id of the file.
383
- * @returns `true` if the file is virtual, otherwise `false`.
384
- */
385
- isVirtual: (path: string) => boolean;
386
- /**
387
- * Gets the metadata of a file in the virtual file system (VFS).
388
- *
389
- * @param path - The path or id of the file.
390
- * @returns The metadata of the file if it exists, otherwise undefined.
391
- */
392
- getMetadata: (path: string) => VirtualFileMetadata | undefined;
393
- /**
394
- * Lists files in a given path.
395
- *
396
- * @param path - The path to list files from.
397
- * @returns An array of file names in the specified path.
398
- */
399
- listSync: (path: string) => string[];
400
- /**
401
- * Lists files in a given path.
402
- *
403
- * @param path - The path to list files from.
404
- * @returns An array of file names in the specified path.
405
- */
406
- list: (path: string) => Promise<string[]>;
407
- /**
408
- * Removes a file or symbolic link in the virtual file system (VFS).
409
- *
410
- * @param path - The path to the file to remove.
411
- * @returns A promise that resolves when the file is removed.
412
- */
413
- removeSync: (path: string) => void;
414
- /**
415
- * Asynchronously removes a file or symbolic link in the virtual file system (VFS).
416
- *
417
- * @param path - The path to the file to remove.
418
- * @returns A promise that resolves when the file is removed.
419
- */
420
- remove: (path: string) => Promise<void>;
421
- /**
422
- * Reads a file from the virtual file system (VFS).
423
- *
424
- * @param path - The path or id of the file.
425
- * @returns The contents of the file if it exists, otherwise undefined.
426
- */
427
- read: (path: string) => Promise<string | undefined>;
428
- /**
429
- * Reads a file from the virtual file system (VFS).
430
- *
431
- * @param path - The path or id of the file.
432
- */
433
- readSync: (path: string) => string | undefined;
434
- /**
435
- * Writes a file to the virtual file system (VFS).
436
- *
437
- * @param path - The path to the file.
438
- * @param data - The contents of the file.
439
- * @param options - Options for writing the file.
440
- * @returns A promise that resolves when the file is written.
441
- */
442
- write: (path: string, data: string, options?: WriteOptions) => Promise<void>;
443
- /**
444
- * Writes a file to the virtual file system (VFS).
445
- *
446
- * @param path - The path to the file.
447
- * @param data - The contents of the file.
448
- * @param options - Options for writing the file.
449
- */
450
- writeSync: (path: string, data: string, options?: WriteOptions) => void;
451
- /**
452
- * Moves a file from one path to another in the virtual file system (VFS).
453
- *
454
- * @param srcPath - The source path to move
455
- * @param destPath - The destination path to move to
456
- */
457
- move: (srcPath: string, destPath: string) => Promise<void>;
458
- /**
459
- * Synchronously moves a file from one path to another in the virtual file system (VFS).
460
- *
461
- * @param srcPath - The source path to move
462
- * @param destPath - The destination path to move to
463
- */
464
- moveSync: (srcPath: string, destPath: string) => void;
465
- /**
466
- * Copies a file from one path to another in the virtual file system (VFS).
467
- *
468
- * @param srcPath - The source path to copy
469
- * @param destPath - The destination path to copy to
470
- */
471
- copy: (srcPath: string, destPath: string) => Promise<void>;
472
- /**
473
- * Synchronously copies a file from one path to another in the virtual file system (VFS).
474
- *
475
- * @param srcPath - The source path to copy
476
- * @param destPath - The destination path to copy to
477
- */
478
- copySync: (srcPath: string, destPath: string) => void;
479
- /**
480
- * Glob files in the virtual file system (VFS) based on the provided pattern(s).
481
- *
482
- * @param pattern - A pattern (or multiple patterns) to use to determine the file paths to return
483
- * @returns An array of file paths matching the provided pattern(s)
484
- */
485
- glob: (pattern: string | string[]) => Promise<string[]>;
486
- /**
487
- * Synchronously glob files in the virtual file system (VFS) based on the provided pattern(s).
488
- *
489
- * @param pattern - A pattern (or multiple patterns) to use to determine the file paths to return
490
- * @returns An array of file paths matching the provided pattern(s)
491
- */
492
- globSync: (pattern: string | string[]) => string[];
493
- /**
494
- * A helper function to resolve modules using the Jiti resolver
495
- *
496
- * @remarks
497
- * This function can be used to resolve modules relative to the project root directory.
498
- *
499
- * @example
500
- * ```ts
501
- * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
502
- * ```
503
- *
504
- * @param id - The module to resolve.
505
- * @param importer - An optional path to the importer module.
506
- * @param options - Additional resolution options.
507
- * @returns A promise that resolves to the resolved module path.
508
- */
509
- resolve: (id: string, importer?: string, options?: ResolveOptions) => Promise<string | undefined>;
510
- /**
511
- * A synchronous helper function to resolve modules using the Jiti resolver
512
- *
513
- * @remarks
514
- * This function can be used to resolve modules relative to the project root directory.
515
- *
516
- * @example
517
- * ```ts
518
- * const resolvedPath = context.resolveSync("some-module", "/path/to/importer");
519
- * ```
520
- *
521
- * @param id - The module to resolve.
522
- * @param importer - An optional path to the importer module.
523
- * @param options - Additional resolution options.
524
- * @returns The resolved module path.
525
- */
526
- resolveSync: (id: string, importer?: string, options?: ResolveOptions) => string | undefined;
527
- /**
528
- * Disposes of the virtual file system (VFS), writes any virtual file changes to disk, and releases any associated resources.
529
- */
530
- dispose: () => Promise<void>;
531
- }
532
-
533
- type ReflectionMode = "default" | "explicit" | "never";
534
- type RawReflectionMode = ReflectionMode | "" | boolean | string | string[] | undefined;
535
- /**
536
- * Defines the level of reflection to be used during the transpilation process.
537
- *
538
- * @remarks
539
- * The level determines how much extra data is captured in the byte code for each type. This can be one of the following values:
540
- * - `minimal` - Only the essential type information is captured.
541
- * - `normal` - Additional type information is captured, including some contextual data.
542
- * - `verbose` - All available type information is captured, including detailed contextual data.
543
- */
544
- type ReflectionLevel = "minimal" | "normal" | "verbose";
545
- interface DeepkitOptions {
546
- /**
547
- * Either true to activate reflection for all files compiled using this tsconfig,
548
- * or a list of globs/file paths relative to this tsconfig.json.
549
- * Globs/file paths can be prefixed with a ! to exclude them.
550
- */
551
- reflection?: RawReflectionMode;
552
- /**
553
- * Defines the level of reflection to be used during the transpilation process.
554
- *
555
- * @remarks
556
- * The level determines how much extra data is captured in the byte code for each type. This can be one of the following values:
557
- * - `minimal` - Only the essential type information is captured.
558
- * - `normal` - Additional type information is captured, including some contextual data.
559
- * - `verbose` - All available type information is captured, including detailed contextual data.
560
- */
561
- reflectionLevel?: ReflectionLevel;
562
- }
563
- type TSCompilerOptions = CompilerOptions & DeepkitOptions;
564
- /**
565
- * The TypeScript compiler configuration.
566
- *
567
- * @see https://www.typescriptlang.org/docs/handbook/tsconfig-json.html
568
- */
569
- interface TSConfig extends Omit<TsConfigJson, "reflection"> {
570
- /**
571
- * Either true to activate reflection for all files compiled using this tsconfig,
572
- * or a list of globs/file paths relative to this tsconfig.json.
573
- * Globs/file paths can be prefixed with a ! to exclude them.
574
- */
575
- reflection?: RawReflectionMode;
576
- /**
577
- * Defines the level of reflection to be used during the transpilation process.
578
- *
579
- * @remarks
580
- * The level determines how much extra data is captured in the byte code for each type. This can be one of the following values:
581
- * - `minimal` - Only the essential type information is captured.
582
- * - `normal` - Additional type information is captured, including some contextual data.
583
- * - `verbose` - All available type information is captured, including detailed contextual data.
584
- */
585
- reflectionLevel?: ReflectionLevel;
586
- /**
587
- * Instructs the TypeScript compiler how to compile `.ts` files.
588
- */
589
- compilerOptions?: TSCompilerOptions;
590
- }
591
- type ParsedTypeScriptConfig = ts.ParsedCommandLine & {
592
- originalTsconfigJson: TsConfigJson;
593
- tsconfigJson: TSConfig;
594
- tsconfigFilePath: string;
595
- };
596
-
597
- type LogFn = (type: LogLevelLabel, ...args: string[]) => void;
598
- /**
599
- * The {@link StormWorkspaceConfig | configuration} object for an entire Powerlines workspace
600
- */
601
- type WorkspaceConfig = Partial<StormWorkspaceConfig> & Required<Pick<StormWorkspaceConfig, "workspaceRoot">>;
602
- type PluginFactory<in out TContext extends PluginContext = PluginContext, TOptions = any> = (options: TOptions) => MaybePromise<Plugin<TContext>>;
603
- /**
604
- * A configuration tuple for a Powerlines plugin.
605
- */
606
- type PluginConfigTuple<TContext extends PluginContext = PluginContext, TOptions = any> = [string | PluginFactory<TContext, TOptions>, TOptions] | [Plugin<TContext>];
607
- /**
608
- * A configuration object for a Powerlines plugin.
609
- */
610
- type PluginConfigObject<TContext extends PluginContext = PluginContext, TOptions = any> = {
611
- plugin: string | PluginFactory<TContext, TOptions>;
612
- options: TOptions;
613
- } | {
614
- plugin: Plugin<TContext>;
615
- options?: never;
616
- };
617
- /**
618
- * A configuration tuple for a Powerlines plugin.
619
- */
620
- type PluginConfig<TContext extends PluginContext = PluginContext> = string | PluginFactory<TContext, void> | Plugin<TContext> | Promise<Plugin<TContext>> | PluginConfigTuple<TContext> | PluginConfigObject<TContext>;
621
- type ProjectType = "application" | "library";
622
- interface OutputConfig {
623
- /**
624
- * The path to output the final compiled files to
625
- *
626
- * @remarks
627
- * If a value is not provided, Powerlines will attempt to:
628
- * 1. Use the `outDir` value in the `tsconfig.json` file.
629
- * 2. Use the `dist` directory in the project root directory.
630
- *
631
- * @defaultValue "dist/\{projectRoot\}"
632
- */
633
- outputPath?: string;
634
- /**
635
- * The output directory path for the project build.
636
- *
637
- * @remarks
638
- * This path is used to determine where the built files will be placed after the build process completes. This will be used in scenarios where the monorepo uses TSConfig paths to link packages together.
639
- *
640
- * @defaultValue "\{projectRoot\}/dist"
641
- */
642
- buildPath?: string;
643
- /**
644
- * The folder where the generated runtime artifacts will be located
645
- *
646
- * @remarks
647
- * This folder will contain all runtime artifacts and builtins generated during the "prepare" phase.
648
- *
649
- * @defaultValue "\{projectRoot\}/.powerlines"
650
- */
651
- artifactsPath?: string;
652
- /**
653
- * The path of the generated runtime declaration file relative to the workspace root.
654
- *
655
- * @defaultValue "\{projectRoot\}/powerlines.d.ts"
656
- */
657
- dts?: string | false;
658
- /**
659
- * A prefix to use for identifying builtin modules
660
- *
661
- * @remarks
662
- * 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"`.
663
- *
664
- * @defaultValue "powerlines"
665
- */
666
- builtinPrefix?: string;
667
- /**
668
- * The module format of the output files
669
- *
670
- * @remarks
671
- * 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.
672
- *
673
- * @defaultValue "esm"
674
- */
675
- format?: Format | Format[];
676
- /**
677
- * A list of assets to copy to the output directory
678
- *
679
- * @remarks
680
- * 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.
681
- */
682
- assets?: Array<string | AssetGlob>;
683
- /**
684
- * A string preset or a custom {@link StoragePort} to provide fine-grained control over generated/output file storage.
685
- *
686
- * @remarks
687
- * If a string preset is provided, it must be one of the following values:
688
- * - `"virtual"`: Uses the local file system for storage.
689
- * - `"fs"`: Uses an in-memory virtual file system for storage.
690
- *
691
- * If a custom {@link StoragePort} is provided, it will be used for all file storage operations during the build process.
692
- *
693
- * @defaultValue "virtual"
694
- */
695
- storage?: StoragePort | StoragePreset;
696
- }
697
- interface BaseConfig {
698
- /**
699
- * The entry point(s) for the application
700
- */
701
- entry?: TypeDefinitionParameter | TypeDefinitionParameter[];
702
- /**
703
- * Configuration for the output of the build process
704
- */
705
- output?: OutputConfig;
706
- /**
707
- * Configuration for linting the source code
708
- *
709
- * @remarks
710
- * If set to `false`, linting will be disabled.
711
- */
712
- lint?: Record<string, any> | false;
713
- /**
714
- * Configuration for testing the source code
715
- *
716
- * @remarks
717
- * If set to `false`, testing will be disabled.
718
- */
719
- test?: Record<string, any> | false;
720
- /**
721
- * Configuration for the transformation of the source code
722
- */
723
- transform?: Record<string, any>;
724
- /**
725
- * Configuration provided to build processes
726
- *
727
- * @remarks
728
- * This configuration can be used by plugins during the `build` command. It will generally contain options specific to the selected {@link BuildVariant | build variant}.
729
- */
730
- build?: BuildConfig;
731
- /**
732
- * Configuration for documentation generation
733
- *
734
- * @remarks
735
- * This configuration will be used by the documentation generation plugins during the `docs` command.
736
- */
737
- docs?: Record<string, any>;
738
- /**
739
- * Configuration for deploying the source code
740
- *
741
- * @remarks
742
- * If set to `false`, the deployment will be disabled.
743
- */
744
- deploy?: Record<string, any> | false;
745
- /**
746
- * The path to the tsconfig file to be used by the compiler
747
- *
748
- * @remarks
749
- * 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).
750
- *
751
- * @defaultValue "\{projectRoot\}/tsconfig.json"
752
- */
753
- tsconfig?: string;
754
- /**
755
- * The raw {@link TSConfig} object to be used by the compiler. This object will be merged with the `tsconfig.json` file.
756
- *
757
- * @see https://www.typescriptlang.org/tsconfig
758
- *
759
- * @remarks
760
- * If populated, this option takes higher priority than `tsconfig`
761
- */
762
- tsconfigRaw?: TSConfig;
763
- }
764
- interface EnvironmentConfig extends BaseConfig {
765
- /**
766
- * Configuration options for the preview server
767
- */
768
- preview?: PreviewOptions;
769
- /**
770
- * A flag indicating whether the build is for a Server-Side Rendering environment.
771
- */
772
- ssr?: boolean;
773
- /**
774
- * Define if this environment is used for Server-Side Rendering
775
- *
776
- * @defaultValue "server" (if it isn't the client environment)
777
- */
778
- consumer?: "client" | "server";
779
- }
780
- interface CommonUserConfig extends BaseConfig {
781
- /**
782
- * The name of the project
783
- */
784
- name?: string;
785
- /**
786
- * The project display title
787
- *
788
- * @remarks
789
- * This option is used in documentation generation and other places where a human-readable title is needed.
790
- */
791
- title?: string;
792
- /**
793
- * A description of the project
794
- *
795
- * @remarks
796
- * If this option is not provided, the build process will try to use the \`description\` value from the `\package.json\` file.
797
- */
798
- description?: string;
799
- /**
800
- * The log level to use for the Powerlines processes.
801
- *
802
- * @defaultValue "info"
803
- */
804
- logLevel?: LogLevelLabel | null;
805
- /**
806
- * A custom logger function to use for logging messages
807
- */
808
- customLogger?: LogFn;
809
- /**
810
- * 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.
811
- *
812
- * @defaultValue "production"
813
- */
814
- mode?: "development" | "test" | "production";
815
- /**
816
- * The type of project being built
817
- *
818
- * @defaultValue "application"
819
- */
820
- type?: ProjectType;
821
- /**
822
- * The root directory of the project
823
- */
824
- root: string;
825
- /**
826
- * The root directory of the project's source code
827
- *
828
- * @defaultValue "\{root\}/src"
829
- */
830
- sourceRoot?: string;
831
- /**
832
- * A path to a custom configuration file to be used instead of the default `storm.json`, `powerlines.config.js`, or `powerlines.config.ts` files.
833
- *
834
- * @remarks
835
- * This option is useful for running Powerlines commands with different configuration files, such as in CI/CD environments or when testing different configurations.
836
- */
837
- configFile?: string;
838
- /**
839
- * Should the Powerlines CLI processes skip installing missing packages?
840
- *
841
- * @remarks
842
- * This option is useful for CI/CD environments where the installation of packages is handled by a different process.
843
- *
844
- * @defaultValue false
845
- */
846
- skipInstalls?: boolean;
847
- /**
848
- * Should the compiler processes skip any improvements that make use of cache?
849
- *
850
- * @defaultValue false
851
- */
852
- skipCache?: boolean;
853
- /**
854
- * A list of resolvable paths to plugins used during the build process
855
- */
856
- plugins?: PluginConfig<PluginContext<any>>[];
857
- /**
858
- * Environment-specific configurations
859
- */
860
- environments?: Record<string, EnvironmentConfig>;
861
- /**
862
- * A string identifier that allows a child framework or tool to identify itself when using Powerlines.
863
- *
864
- * @remarks
865
- * If no values are provided for {@link OutputConfig.dts | output.dts}, {@link OutputConfig.builtinPrefix | output.builtinPrefix}, or {@link OutputConfig.artifactsPath | output.artifactsFolder}, this value will be used as the default.
866
- *
867
- * @defaultValue "powerlines"
868
- */
869
- framework?: string;
870
- }
871
- type UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> = Omit<CommonUserConfig, "build"> & {
872
- /**
873
- * Configuration provided to build processes
874
- *
875
- * @remarks
876
- * This configuration can be used by plugins during the `build` command. It will generally contain options specific to the selected {@link BuildVariant | build variant}.
877
- */
878
- build: Omit<TBuildConfig, "override"> & {
879
- /**
880
- * The build variant being used by the Powerlines engine.
881
- */
882
- variant?: TBuildVariant;
883
- /**
884
- * An optional set of override options to apply to the selected build variant.
885
- *
886
- * @remarks
887
- * 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.
888
- */
889
- override?: Partial<TBuildResolvedConfig>;
890
- };
891
- };
892
- type UnbuildUserConfig = UserConfig<UnbuildBuildConfig, UnbuildResolvedBuildConfig, "unbuild">;
893
- type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "deploy" | "clean";
894
- /**
895
- * The configuration provided while executing Powerlines commands.
896
- */
897
- type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
898
- /**
899
- * A string identifier for the Powerlines command being executed
900
- */
901
- command: PowerlinesCommand;
902
- };
903
-
904
- interface ResolvedEntryTypeDefinition extends TypeDefinition {
905
- /**
906
- * The user provided entry point in the source code
907
- */
908
- input: TypeDefinition;
909
- /**
910
- * An optional name to use in the package export during the build process
911
- */
912
- output?: string;
913
- }
914
- type EnvironmentResolvedConfig = Omit<EnvironmentConfig, "consumer" | "ssr" | "preview"> & Required<Pick<EnvironmentConfig, "consumer" | "ssr">> & {
915
- /**
916
- * The name of the environment
917
- */
918
- name: string;
919
- /**
920
- * Configuration options for the preview server
921
- */
922
- preview?: ResolvedPreviewOptions;
923
- };
924
- type ResolvedAssetGlob = AssetGlob & Required<Pick<AssetGlob, "input">>;
925
- type OutputResolvedConfig = Required<Omit<OutputConfig, "assets" | "storage"> & {
926
- assets: ResolvedAssetGlob[];
927
- }> & Pick<OutputConfig, "storage">;
928
- /**
929
- * The resolved options for the Powerlines project configuration.
930
- */
931
- 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">> & {
932
- /**
933
- * The configuration options that were provided inline to the Powerlines CLI.
934
- */
935
- inlineConfig: InlineConfig<TUserConfig>;
936
- /**
937
- * The original configuration options that were provided by the user to the Powerlines process.
938
- */
939
- userConfig: TUserConfig;
940
- /**
941
- * A string identifier for the Powerlines command being executed.
942
- */
943
- command: NonUndefined<InlineConfig<TUserConfig>["command"]>;
944
- /**
945
- * The root directory of the project's source code
946
- *
947
- * @defaultValue "\{projectRoot\}/src"
948
- */
949
- sourceRoot: NonUndefined<TUserConfig["sourceRoot"]>;
950
- /**
951
- * The root directory of the project.
952
- */
953
- projectRoot: NonUndefined<TUserConfig["root"]>;
954
- /**
955
- * The type of project being built.
956
- */
957
- projectType: NonUndefined<TUserConfig["type"]>;
958
- /**
959
- * The output configuration options to use for the build process
960
- */
961
- output: OutputResolvedConfig;
962
- /**
963
- * Configuration provided to build processes
964
- *
965
- * @remarks
966
- * This configuration can be used by plugins during the `build` command. It will generally contain options specific to the selected {@link BuildVariant | build variant}.
967
- */
968
- build: Omit<TUserConfig["build"], "override"> & Required<Pick<Required<TUserConfig["build"]>, "override">>;
969
- /**
970
- * The log level to use for the Powerlines processes.
971
- *
972
- * @defaultValue "info"
973
- */
974
- logLevel: "error" | "warn" | "info" | "debug" | "trace" | null;
975
- };
976
- type UnbuildResolvedConfig = ResolvedConfig<UnbuildUserConfig>;
977
-
978
- interface MetaInfo {
979
- /**
980
- * The checksum generated from the resolved options
981
- */
982
- checksum: string;
983
- /**
984
- * The build id
985
- */
986
- buildId: string;
987
- /**
988
- * The release id
989
- */
990
- releaseId: string;
991
- /**
992
- * The build timestamp
993
- */
994
- timestamp: number;
995
- /**
996
- * A hash that represents the path to the project root directory
997
- */
998
- projectRootHash: string;
999
- /**
1000
- * A hash that represents the path to the project root directory
1001
- */
1002
- configHash: string;
1003
- }
1004
- interface Resolver extends Jiti {
1005
- plugin: Jiti;
1006
- }
1007
- interface TransformResult {
1008
- code: string;
1009
- map: SourceMap | null;
1010
- }
1011
- interface InitContextOptions {
1012
- /**
1013
- * If false, the plugin will be loaded after all other plugins.
1014
- *
1015
- * @defaultValue true
1016
- */
1017
- isHighPriority: boolean;
1018
- }
1019
- /**
1020
- * The unresolved Powerlines context.
1021
- *
1022
- * @remarks
1023
- * This context is used before the user configuration has been fully resolved after the `config`.
1024
- */
1025
- interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
1026
- /**
1027
- * The Storm workspace configuration
1028
- */
1029
- workspaceConfig: WorkspaceConfig;
1030
- /**
1031
- * An object containing the options provided to Powerlines
1032
- */
1033
- config: Omit<TResolvedConfig["userConfig"], "build" | "output"> & Required<Pick<TResolvedConfig["userConfig"], "build" | "output">> & {
1034
- projectRoot: NonUndefined<TResolvedConfig["userConfig"]["root"]>;
1035
- output: TResolvedConfig["output"];
1036
- };
1037
- /**
1038
- * A logging function for the Powerlines engine
1039
- */
1040
- log: LogFn;
1041
- /**
1042
- * A logging function for fatal messages
1043
- */
1044
- fatal: (message: string | UnpluginMessage) => void;
1045
- /**
1046
- * A logging function for error messages
1047
- */
1048
- error: (message: string | UnpluginMessage) => void;
1049
- /**
1050
- * A logging function for warning messages
1051
- */
1052
- warn: (message: string | UnpluginMessage) => void;
1053
- /**
1054
- * A logging function for informational messages
1055
- */
1056
- info: (message: string | UnpluginMessage) => void;
1057
- /**
1058
- * A logging function for debug messages
1059
- */
1060
- debug: (message: string | UnpluginMessage) => void;
1061
- /**
1062
- * A logging function for trace messages
1063
- */
1064
- trace: (message: string | UnpluginMessage) => void;
1065
- /**
1066
- * The metadata information
1067
- */
1068
- meta: MetaInfo;
1069
- /**
1070
- * The metadata information currently written to disk
1071
- */
1072
- persistedMeta?: MetaInfo;
1073
- /**
1074
- * The Powerlines artifacts directory
1075
- */
1076
- artifactsPath: string;
1077
- /**
1078
- * The path to the Powerlines builtin runtime modules directory
1079
- */
1080
- builtinsPath: string;
1081
- /**
1082
- * The path to the Powerlines entry modules directory
1083
- */
1084
- entryPath: string;
1085
- /**
1086
- * The path to the Powerlines TypeScript declaration files directory
1087
- */
1088
- dtsPath: string;
1089
- /**
1090
- * The path to a directory where the reflection data buffers (used by the build processes) are stored
1091
- */
1092
- dataPath: string;
1093
- /**
1094
- * The path to a directory where the project cache (used by the build processes) is stored
1095
- */
1096
- cachePath: string;
1097
- /**
1098
- * The Powerlines environment paths
1099
- */
1100
- envPaths: EnvPaths;
1101
- /**
1102
- * The file system path to the Powerlines package installation
1103
- */
1104
- powerlinesPath: string;
1105
- /**
1106
- * The relative path to the Powerlines workspace root directory
1107
- */
1108
- relativeToWorkspaceRoot: string;
1109
- /**
1110
- * The project's `package.json` file content
1111
- */
1112
- packageJson: PackageJson & Record<string, any>;
1113
- /**
1114
- * The project's `project.json` file content
1115
- */
1116
- projectJson?: Record<string, any>;
1117
- /**
1118
- * The dependency installations required by the project
1119
- */
1120
- dependencies: Record<string, string | Range>;
1121
- /**
1122
- * The development dependency installations required by the project
1123
- */
1124
- devDependencies: Record<string, string | Range>;
1125
- /**
1126
- * The parsed TypeScript configuration from the `tsconfig.json` file
1127
- */
1128
- tsconfig: ParsedTypeScriptConfig;
1129
- /**
1130
- * The entry points of the source code
1131
- */
1132
- entry: ResolvedEntryTypeDefinition[];
1133
- /**
1134
- * The virtual file system manager used during the build process to reference generated runtime files
1135
- */
1136
- fs: VirtualFileSystemInterface;
1137
- /**
1138
- * The Jiti module resolver
1139
- */
1140
- resolver: Resolver;
1141
- /**
1142
- * The builtin module id that exist in the Powerlines virtual file system
1143
- */
1144
- builtins: string[];
1145
- /**
1146
- * The {@link Project} instance used for type reflection and module manipulation
1147
- *
1148
- * @see https://ts-morph.com/
1149
- *
1150
- * @remarks
1151
- * This instance is created lazily on first access.
1152
- */
1153
- program: Project;
1154
- /**
1155
- * A helper function to resolve modules using the Jiti resolver
1156
- *
1157
- * @remarks
1158
- * This function can be used to resolve modules relative to the project root directory.
1159
- *
1160
- * @example
1161
- * ```ts
1162
- * const resolvedPath = await context.resolve("some-module", "/path/to/importer");
1163
- * ```
1164
- *
1165
- * @param id - The module to resolve.
1166
- * @param importer - An optional path to the importer module.
1167
- * @param options - Additional resolution options.
1168
- * @returns A promise that resolves to the resolved module path.
1169
- */
1170
- resolve: (id: string, importer?: string, options?: ResolveOptions) => Promise<ExternalIdResult | undefined>;
1171
- /**
1172
- * A helper function to load modules using the Jiti resolver
1173
- *
1174
- * @remarks
1175
- * This function can be used to load modules relative to the project root directory.
1176
- *
1177
- * @example
1178
- * ```ts
1179
- * const module = await context.load("some-module", "/path/to/importer");
1180
- * ```
1181
- *
1182
- * @param id - The module to load.
1183
- * @returns A promise that resolves to the loaded module.
1184
- */
1185
- load: (id: string) => Promise<TransformResult | undefined>;
1186
- /**
1187
- * The Powerlines builtin virtual files
1188
- */
1189
- getBuiltins: () => Promise<VirtualFile[]>;
1190
- /**
1191
- * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
1192
- *
1193
- * @param code - The source code of the builtin file
1194
- * @param id - The unique identifier of the builtin file
1195
- * @param path - An optional path to write the builtin file to
1196
- */
1197
- emitBuiltin: (code: string, id: string, path?: string) => Promise<void>;
1198
- /**
1199
- * Resolves a entry virtual file and writes it to the VFS if it does not already exist
1200
- *
1201
- * @param code - The source code of the entry file
1202
- * @param path - An optional path to write the entry file to
1203
- */
1204
- emitEntry: (code: string, path: string) => Promise<void>;
1205
- /**
1206
- * A function to update the context fields using a new user configuration options
1207
- */
1208
- withUserConfig: (userConfig: UserConfig, options?: InitContextOptions) => Promise<void>;
1209
- /**
1210
- * A function to update the context fields using inline configuration options
1211
- */
1212
- withInlineConfig: (inlineConfig: InlineConfig, options?: InitContextOptions) => Promise<void>;
1213
- /**
1214
- * Create a new logger instance
1215
- *
1216
- * @param name - The name to use for the logger instance
1217
- * @returns A logger function
1218
- */
1219
- createLog: (name: string | null) => LogFn;
1220
- /**
1221
- * Extend the current logger instance with a new name
1222
- *
1223
- * @param name - The name to use for the extended logger instance
1224
- * @returns A logger function
1225
- */
1226
- extendLog: (name: string) => LogFn;
1227
- /**
1228
- * Generates a checksum representing the current context state
1229
- *
1230
- * @returns A promise that resolves to a string representing the checksum
1231
- */
1232
- generateChecksum: () => Promise<string>;
1233
- }
1234
- type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<UnresolvedContext<TResolvedConfig>, "config"> & {
1235
- /**
1236
- * The fully resolved Powerlines configuration
1237
- */
1238
- config: TResolvedConfig;
1239
- };
1240
- interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
1241
- /**
1242
- * The environment specific resolved configuration
1243
- */
1244
- environment: EnvironmentResolvedConfig;
1245
- /**
1246
- * An alternative property name for the {@link log} property
1247
- *
1248
- * @remarks
1249
- * This is provided for compatibility with other logging libraries that expect a `logger` property.
1250
- */
1251
- logger: LogFn;
1252
- }
1253
- type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = PluginContext<TResolvedConfig> & Omit<UnpluginBuildContext, "parse">;
1254
-
1255
- declare const SUPPORTED_COMMANDS: readonly ["new", "clean", "prepare", "lint", "test", "build", "docs", "deploy", "finalize"];
1256
- type CommandType = ArrayValues<typeof SUPPORTED_COMMANDS>;
1257
-
1258
- interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> {
1259
- /**
1260
- * The order in which the plugin should be applied.
1261
- */
1262
- order?: "pre" | "post" | null | undefined;
1263
- /**
1264
- * A filter to determine when the hook should be called.
1265
- */
1266
- filter?: Pick<HookFilter, TFilter>;
1267
- /**
1268
- * The hook function to be called.
1269
- */
1270
- handler: THookFunction;
1271
- }
1272
- type PluginHook<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
1273
- /**
1274
- * A result returned by the plugin from the `generateTypes` hook that describes the declaration types output file.
1275
- */
1276
- interface GenerateTypesResult {
1277
- directives?: string[];
1278
- code: string;
1279
- }
1280
- type DeepPartial<T> = {
1281
- [K in keyof T]?: DeepPartial<T[K]>;
1282
- };
1283
- type ConfigResult<TContext extends PluginContext = PluginContext> = DeepPartial<TContext["config"]> & Record<string, any>;
1284
- interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext> extends Record<CommandType, (this: TContext) => MaybePromise<void>> {
1285
- /**
1286
- * A function that returns configuration options to be merged with the build context's options.
1287
- *
1288
- * @remarks
1289
- * 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.
1290
- *
1291
- * @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.
1292
- *
1293
- * @see https://vitejs.dev/guide/api-plugin#config
1294
- *
1295
- * @param this - The build context.
1296
- * @param config - The partial configuration object to be modified.
1297
- * @returns A promise that resolves to a partial configuration object.
1298
- */
1299
- config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>;
1300
- /**
1301
- * 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.
1302
- *
1303
- * @remarks
1304
- * 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.
1305
- *
1306
- * @see https://vitejs.dev/guide/api-plugin#configenvironment
1307
- *
1308
- * @param this - The build context.
1309
- * @param name - The name of the environment being configured.
1310
- * @param environment - The Vite-like environment object containing information about the current build environment.
1311
- * @returns A promise that resolves when the hook is complete.
1312
- */
1313
- configEnvironment: (this: TContext, name: string, environment: EnvironmentConfig) => MaybePromise<Partial<EnvironmentResolvedConfig> | undefined | null>;
1314
- /**
1315
- * A hook that is called when the plugin is resolved.
1316
- *
1317
- * @see https://vitejs.dev/guide/api-plugin#configresolved
1318
- *
1319
- * @param this - The build context.
1320
- * @returns A promise that resolves when the hook is complete.
1321
- */
1322
- configResolved: (this: TContext) => MaybePromise<void>;
1323
- /**
1324
- * 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.
1325
- *
1326
- * @param this - The build context.
1327
- * @param code - The source code to generate types for.
1328
- * @returns A promise that resolves when the hook is complete.
1329
- */
1330
- generateTypes: (this: TContext, code: string) => MaybePromise<GenerateTypesResult | string | undefined | null>;
1331
- /**
1332
- * A hook that is called at the start of the build process.
1333
- *
1334
- * @param this - The build context and unplugin build context.
1335
- * @returns A promise that resolves when the hook is complete.
1336
- */
1337
- buildStart: (this: BuildPluginContext<TContext["config"]> & TContext) => MaybePromise<void>;
1338
- /**
1339
- * A hook that is called at the end of the build process.
1340
- *
1341
- * @param this - The build context and unplugin build context.
1342
- * @returns A promise that resolves when the hook is complete.
1343
- */
1344
- buildEnd: (this: BuildPluginContext<TContext["config"]> & TContext) => MaybePromise<void>;
1345
- /**
1346
- * A hook that is called to transform the source code.
1347
- *
1348
- * @param this - The build context, unplugin build context, and unplugin context.
1349
- * @param code - The source code to transform.
1350
- * @param id - The identifier of the source code.
1351
- * @returns A promise that resolves when the hook is complete.
1352
- */
1353
- transform: (this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult$1>;
1354
- /**
1355
- * A hook that is called to load 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
- * @returns A promise that resolves when the hook is complete.
1360
- */
1361
- load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult$1>;
1362
- /**
1363
- * A hook that is called to resolve the identifier of the source code.
1364
- *
1365
- * @param this - The build context, unplugin build context, and unplugin context.
1366
- * @param id - The identifier of the source code.
1367
- * @param importer - The importer of the source code.
1368
- * @param options - The options for resolving the identifier.
1369
- * @returns A promise that resolves when the hook is complete.
1370
- */
1371
- resolveId: (this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
1372
- isEntry: boolean;
1373
- }) => MaybePromise<string | ExternalIdResult | null | undefined>;
1374
- /**
1375
- * A hook that is called to write the bundle to disk.
1376
- *
1377
- * @param this - The build context.
1378
- * @returns A promise that resolves when the hook is complete.
1379
- */
1380
- writeBundle: (this: TContext) => MaybePromise<void>;
1381
- }
1382
- type BuildPlugin<TContext extends PluginContext = PluginContext, TBuildVariant extends UnpluginBuildVariant = UnpluginBuildVariant, TOptions extends Required<UnpluginOptions>[TBuildVariant] = Required<UnpluginOptions>[TBuildVariant]> = {
1383
- [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];
1384
- };
1385
- type PluginHooks<TContext extends PluginContext = PluginContext> = {
1386
- [TKey in keyof BasePluginHookFunctions<TContext>]: PluginHook<BasePluginHookFunctions<TContext>[TKey]>;
1387
- } & {
1388
- /**
1389
- * A function that returns configuration options to be merged with the build context's options.
1390
- *
1391
- * @remarks
1392
- * 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.
1393
- *
1394
- * @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.
1395
- *
1396
- * @see https://vitejs.dev/guide/api-plugin#config
1397
- *
1398
- * @param this - The build context.
1399
- * @param config - The partial configuration object to be modified.
1400
- * @returns A promise that resolves to a partial configuration object.
1401
- */
1402
- config: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>> | ConfigResult<TContext>;
1403
- /**
1404
- * A hook that is called to transform the source code.
1405
- *
1406
- * @param this - The build context, unplugin build context, and unplugin context.
1407
- * @param code - The source code to transform.
1408
- * @param id - The identifier of the source code.
1409
- * @returns A promise that resolves when the hook is complete.
1410
- */
1411
- transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult$1>, "code" | "id">;
1412
- /**
1413
- * A hook that is called to load the source code.
1414
- *
1415
- * @param this - The build context, unplugin build context, and unplugin context.
1416
- * @param id - The identifier of the source code.
1417
- * @returns A promise that resolves when the hook is complete.
1418
- */
1419
- load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult$1>, "id">;
1420
- /**
1421
- * A hook that is called to resolve the identifier of the source code.
1422
- *
1423
- * @param this - The build context, unplugin build context, and unplugin context.
1424
- * @param id - The identifier of the source code.
1425
- * @param importer - The importer of the source code.
1426
- * @param options - The options for resolving the identifier.
1427
- * @returns A promise that resolves when the hook is complete.
1428
- */
1429
- resolveId: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
1430
- isEntry: boolean;
1431
- }) => MaybePromise<string | ExternalIdResult | null | undefined>, "id">;
1432
- };
1433
- type PluginBuildPlugins<TContext extends PluginContext = PluginContext> = {
1434
- [TBuildVariant in UnpluginBuildVariant]?: BuildPlugin<TContext, TBuildVariant>;
1435
- };
1436
- interface Plugin<in out TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> extends Partial<PluginHooks<TContext>>, PluginBuildPlugins<TContext> {
1437
- /**
1438
- * The name of the plugin, for use in deduplication, error messages and logs.
1439
- */
1440
- name: string;
1441
- /**
1442
- * An API object that can be used for inter-plugin communication.
1443
- *
1444
- * @see https://rollupjs.org/plugin-development/#direct-plugin-communication
1445
- */
1446
- api?: Record<string, any>;
1447
- /**
1448
- * Enforce plugin invocation tier similar to webpack loaders. Hooks ordering is still subject to the `order` property in the hook object.
1449
- *
1450
- * @remarks
1451
- * The Plugin invocation order is as follows:
1452
- * - `enforce: 'pre'` plugins
1453
- * - `order: 'pre'` plugin hooks
1454
- * - any other plugins (normal)
1455
- * - `order: 'post'` plugin hooks
1456
- * - `enforce: 'post'` plugins
1457
- *
1458
- * @see https://vitejs.dev/guide/api-plugin.html#plugin-ordering
1459
- * @see https://rollupjs.org/plugin-development/#build-hooks
1460
- * @see https://webpack.js.org/concepts/loaders/#enforce---pre-and-post
1461
- * @see https://esbuild.github.io/plugins/#concepts
1462
- */
1463
- enforce?: "pre" | "post";
1464
- /**
1465
- * A function to determine if two plugins are the same and can be de-duplicated.
1466
- *
1467
- * @remarks
1468
- * If this is not provided, plugins are de-duplicated by comparing their names.
1469
- *
1470
- * @param other - The other plugin to compare against.
1471
- * @returns `true` if the two plugins are the same, `false` otherwise.
1472
- */
1473
- dedupe?: false | ((other: Plugin<any>) => boolean);
1474
- /**
1475
- * A list of pre-requisite plugins that must be loaded before this plugin can be used.
1476
- */
1477
- dependsOn?: PluginConfig<any>[];
1478
- /**
1479
- * Define environments where this plugin should be active. By default, the plugin is active in all environments.
1480
- *
1481
- * @param environment - The environment to check.
1482
- * @returns `true` if the plugin should be active in the specified environment, `false` otherwise.
1483
- */
1484
- applyToEnvironment?: (environment: EnvironmentResolvedConfig) => MaybePromise<boolean | Plugin<TContext>>;
1485
- }
1486
-
1487
- type UnbuildPluginOptions = Partial<UnbuildBuildConfig>;
1488
- type UnbuildPluginResolvedConfig = UnbuildResolvedConfig;
1489
- type UnbuildPluginContext<TResolvedConfig extends UnbuildPluginResolvedConfig = UnbuildPluginResolvedConfig> = PluginContext<TResolvedConfig>;
1490
- declare type __ΩUnbuildPluginOptions = any[];
1491
- declare type __ΩUnbuildPluginResolvedConfig = any[];
1492
- declare type __ΩUnbuildPluginContext = any[];
1493
-
1494
- export type { Plugin as P, UnbuildPluginContext as U, __ΩUnbuildPluginOptions as _, UnbuildPluginOptions as a, UnbuildPluginResolvedConfig as b, __ΩUnbuildPluginResolvedConfig as c, __ΩUnbuildPluginContext as d };