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