@powerlines/plugin-satori 0.1.123 → 0.1.125

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,7 +1,9 @@
1
1
  import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.cjs";
2
2
  import { ParsedTypeScriptConfig } from "./tsconfig.cjs";
3
3
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.cjs";
4
+ import { HooksList, InferHooksListItem } from "./hooks.cjs";
4
5
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.cjs";
6
+ import { Plugin } from "./plugin.cjs";
5
7
  import { NonUndefined } from "@stryke/types/base";
6
8
  import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage } from "unplugin";
7
9
  import { EnvPaths } from "@stryke/env/get-env-paths";
@@ -49,6 +51,9 @@ interface TransformResult$1 {
49
51
  code: string;
50
52
  map: SourceMap | null;
51
53
  }
54
+ interface SelectHooksOptions {
55
+ order?: "pre" | "post" | "normal";
56
+ }
52
57
  /**
53
58
  * Options for initializing or updating the context with new configuration values
54
59
  */
@@ -385,6 +390,112 @@ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<Unr
385
390
  */
386
391
  config: TResolvedConfig;
387
392
  };
393
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
394
+ /**
395
+ * The expected plugins options for the Powerlines project.
396
+ *
397
+ * @remarks
398
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
399
+ */
400
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
401
+ /**
402
+ * A function to add a plugin to the context and update the configuration options
403
+ */
404
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
405
+ /**
406
+ * A table for storing the current context for each configured environment
407
+ */
408
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
409
+ /**
410
+ * Retrieves the context for a specific environment by name
411
+ *
412
+ * @throws Will throw an error if the environment does not exist
413
+ *
414
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
415
+ * @returns A promise that resolves to the environment context.
416
+ *
417
+ * @example
418
+ * ```ts
419
+ * const devEnv = await apiContext.getEnvironment("development");
420
+ * const defaultEnv = await apiContext.getEnvironment();
421
+ * ```
422
+ */
423
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
424
+ /**
425
+ * Safely retrieves the context for a specific environment by name
426
+ *
427
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
428
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
429
+ *
430
+ * @example
431
+ * ```ts
432
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
433
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
434
+ * ```
435
+ *
436
+ * @remarks
437
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
438
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
439
+ *
440
+ * ```ts
441
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
442
+ * if (testEnv) {
443
+ * // Environment exists, safe to use it
444
+ * } else {
445
+ * // Environment does not exist, handle accordingly
446
+ * }
447
+ * ```
448
+ *
449
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
450
+ */
451
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
452
+ /**
453
+ * A function to copy the context and update the fields for a specific environment
454
+ *
455
+ * @param environment - The environment configuration to use.
456
+ * @returns A new context instance with the updated environment.
457
+ */
458
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
459
+ /**
460
+ * A function to merge all configured environments into a single context
461
+ *
462
+ * @returns A promise that resolves to the merged environment context.
463
+ */
464
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
465
+ }
466
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
467
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
468
+ context: PluginContext<TResolvedConfig>;
469
+ }
470
+ type SelectHookResultItem<TContext extends PluginContext, TKey extends string> = InferHooksListItem<TContext, TKey> & {
471
+ context: TContext;
472
+ };
473
+ type SelectHookResult<TContext extends PluginContext, TKey extends string> = SelectHookResultItem<TContext, TKey>[];
474
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
475
+ /**
476
+ * The expected plugins options for the Powerlines project.
477
+ *
478
+ * @remarks
479
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
480
+ */
481
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
482
+ /**
483
+ * A function to add a plugin to the context and update the configuration options
484
+ */
485
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
486
+ /**
487
+ * The environment specific resolved configuration
488
+ */
489
+ environment: EnvironmentResolvedConfig;
490
+ /**
491
+ * A table holding references to hook functions registered by plugins
492
+ */
493
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
494
+ /**
495
+ * Retrieves the hook handlers for a specific hook name
496
+ */
497
+ selectHooks: <TKey extends string>(key: TKey, options?: SelectHooksOptions) => SelectHookResult<PluginContext<TResolvedConfig>, TKey>;
498
+ }
388
499
  interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
389
500
  /**
390
501
  * The environment specific resolved configuration
@@ -399,5 +510,6 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
399
510
  logger: LogFn;
400
511
  }
401
512
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
513
+ type WithUnpluginBuildContext<TContext extends PluginContext> = UnpluginBuildContext & TContext;
402
514
  //#endregion
403
- export { BuildPluginContext, PluginContext, UnresolvedContext };
515
+ export { APIContext, BuildPluginContext, Context, EnvironmentContext, PluginContext, SelectHooksOptions, UnresolvedContext, WithUnpluginBuildContext };
@@ -1,9 +1,9 @@
1
1
  import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.mjs";
2
2
  import { ParsedTypeScriptConfig } from "./tsconfig.mjs";
3
3
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.mjs";
4
- import "./hooks.mjs";
4
+ import { HooksList, InferHooksListItem } from "./hooks.mjs";
5
5
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.mjs";
6
- import "./plugin.mjs";
6
+ import { Plugin } from "./plugin.mjs";
7
7
  import { NonUndefined } from "@stryke/types/base";
8
8
  import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage } from "unplugin";
9
9
  import { EnvPaths } from "@stryke/env/get-env-paths";
@@ -51,6 +51,9 @@ interface TransformResult$1 {
51
51
  code: string;
52
52
  map: SourceMap | null;
53
53
  }
54
+ interface SelectHooksOptions {
55
+ order?: "pre" | "post" | "normal";
56
+ }
54
57
  /**
55
58
  * Options for initializing or updating the context with new configuration values
56
59
  */
@@ -387,6 +390,112 @@ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<Unr
387
390
  */
388
391
  config: TResolvedConfig;
389
392
  };
393
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
394
+ /**
395
+ * The expected plugins options for the Powerlines project.
396
+ *
397
+ * @remarks
398
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
399
+ */
400
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
401
+ /**
402
+ * A function to add a plugin to the context and update the configuration options
403
+ */
404
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
405
+ /**
406
+ * A table for storing the current context for each configured environment
407
+ */
408
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
409
+ /**
410
+ * Retrieves the context for a specific environment by name
411
+ *
412
+ * @throws Will throw an error if the environment does not exist
413
+ *
414
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
415
+ * @returns A promise that resolves to the environment context.
416
+ *
417
+ * @example
418
+ * ```ts
419
+ * const devEnv = await apiContext.getEnvironment("development");
420
+ * const defaultEnv = await apiContext.getEnvironment();
421
+ * ```
422
+ */
423
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
424
+ /**
425
+ * Safely retrieves the context for a specific environment by name
426
+ *
427
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
428
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
429
+ *
430
+ * @example
431
+ * ```ts
432
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
433
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
434
+ * ```
435
+ *
436
+ * @remarks
437
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
438
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
439
+ *
440
+ * ```ts
441
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
442
+ * if (testEnv) {
443
+ * // Environment exists, safe to use it
444
+ * } else {
445
+ * // Environment does not exist, handle accordingly
446
+ * }
447
+ * ```
448
+ *
449
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
450
+ */
451
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
452
+ /**
453
+ * A function to copy the context and update the fields for a specific environment
454
+ *
455
+ * @param environment - The environment configuration to use.
456
+ * @returns A new context instance with the updated environment.
457
+ */
458
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
459
+ /**
460
+ * A function to merge all configured environments into a single context
461
+ *
462
+ * @returns A promise that resolves to the merged environment context.
463
+ */
464
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
465
+ }
466
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
467
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
468
+ context: PluginContext<TResolvedConfig>;
469
+ }
470
+ type SelectHookResultItem<TContext extends PluginContext, TKey extends string> = InferHooksListItem<TContext, TKey> & {
471
+ context: TContext;
472
+ };
473
+ type SelectHookResult<TContext extends PluginContext, TKey extends string> = SelectHookResultItem<TContext, TKey>[];
474
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
475
+ /**
476
+ * The expected plugins options for the Powerlines project.
477
+ *
478
+ * @remarks
479
+ * This is a record of plugin identifiers to their respective options. This field is populated by the Powerlines engine during both plugin initialization and the `init` command.
480
+ */
481
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
482
+ /**
483
+ * A function to add a plugin to the context and update the configuration options
484
+ */
485
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
486
+ /**
487
+ * The environment specific resolved configuration
488
+ */
489
+ environment: EnvironmentResolvedConfig;
490
+ /**
491
+ * A table holding references to hook functions registered by plugins
492
+ */
493
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
494
+ /**
495
+ * Retrieves the hook handlers for a specific hook name
496
+ */
497
+ selectHooks: <TKey extends string>(key: TKey, options?: SelectHooksOptions) => SelectHookResult<PluginContext<TResolvedConfig>, TKey>;
498
+ }
390
499
  interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
391
500
  /**
392
501
  * The environment specific resolved configuration
@@ -401,5 +510,6 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
401
510
  logger: LogFn;
402
511
  }
403
512
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
513
+ type WithUnpluginBuildContext<TContext extends PluginContext> = UnpluginBuildContext & TContext;
404
514
  //#endregion
405
- export { BuildPluginContext, PluginContext, UnresolvedContext };
515
+ export { APIContext, BuildPluginContext, Context, EnvironmentContext, PluginContext, SelectHooksOptions, UnresolvedContext, WithUnpluginBuildContext };
@@ -0,0 +1,32 @@
1
+ import { UnpluginBuilderVariant } from "./build.cjs";
2
+ import { PluginContext, WithUnpluginBuildContext } from "./context.cjs";
3
+ import { Plugin, PluginHookFields, PluginHookFunctions } from "./plugin.cjs";
4
+ import { UnpluginOptions } from "unplugin";
5
+
6
+ //#region ../powerlines/src/types/hooks.d.ts
7
+ type HookListOrders = "preOrdered" | "preEnforced" | "normal" | "postEnforced" | "postOrdered";
8
+ type UnpluginHookFunctions<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant, TField$1 extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1] = keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1]> = Required<UnpluginOptions>[TUnpluginBuilderVariant$1][TField$1] extends infer THandler | {
9
+ handler: infer THandler;
10
+ } ? THandler extends ((this: infer THandlerOriginalContext, ...args: infer THandlerArgs) => infer THandlerReturn) ? (this: THandlerOriginalContext & WithUnpluginBuildContext<TContext>, ...args: THandlerArgs) => THandlerReturn : THandler extends {
11
+ handler: infer THandlerFunction;
12
+ } ? THandlerFunction extends ((this: infer THandlerFunctionOriginalContext, ...args: infer THandlerFunctionArgs) => infer THandlerFunctionReturn) ? (this: THandlerFunctionOriginalContext & WithUnpluginBuildContext<TContext>, ...args: THandlerFunctionArgs) => THandlerFunctionReturn : never : never : never;
13
+ interface PluginHooksListItem<TContext extends PluginContext = PluginContext, TFields extends PluginHookFields<TContext> = PluginHookFields<TContext>> {
14
+ plugin: Plugin<TContext>;
15
+ handler: PluginHookFunctions<TContext>[TFields];
16
+ }
17
+ type PluginHooksList<TContext extends PluginContext = PluginContext, TFields extends PluginHookFields<TContext> = PluginHookFields<TContext>> = { [TKey in HookListOrders]?: PluginHooksListItem<TContext, TFields>[] | undefined };
18
+ interface UnpluginHooksListItem<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant, TField$1 extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1] = keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1]> {
19
+ plugin: Plugin<TContext>;
20
+ handler: UnpluginHookFunctions<TContext, TUnpluginBuilderVariant$1, TField$1>;
21
+ }
22
+ type UnpluginHookList<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant, TField$1 extends keyof UnpluginOptions[TUnpluginBuilderVariant$1] = keyof UnpluginOptions[TUnpluginBuilderVariant$1]> = { [TKey in HookListOrders]?: UnpluginHooksListItem<TContext, TUnpluginBuilderVariant$1, TField$1>[] | undefined };
23
+ type UnpluginHookVariantField<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant> = { [TKey in keyof UnpluginOptions[TUnpluginBuilderVariant$1]]?: UnpluginHookList<TContext, TUnpluginBuilderVariant$1, TKey> };
24
+ type UnpluginHookVariant<TContext extends PluginContext = PluginContext> = { [TKey in UnpluginBuilderVariant]?: UnpluginHookVariantField<TContext, TKey> };
25
+ type HookFields<TContext extends PluginContext = PluginContext> = PluginHookFields<TContext> | UnpluginBuilderVariant;
26
+ type HooksList<TContext extends PluginContext = PluginContext> = { [TField in HookFields<TContext>]?: TField extends PluginHookFields<TContext> ? PluginHooksList<TContext, TField> : TField extends UnpluginBuilderVariant ? UnpluginHookVariant<TContext>[TField] : never };
27
+ type InferHooksListItem<TContext extends PluginContext, TKey$1 extends string> = TKey$1 extends `${infer TUnpluginBuilderVariant}:${infer TUnpluginField}` ? TUnpluginBuilderVariant extends UnpluginBuilderVariant ? TUnpluginField extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant] ? UnpluginHooksListItem<TContext, TUnpluginBuilderVariant, TUnpluginField> : never : never : TKey$1 extends keyof PluginHookFunctions<TContext> ? PluginHooksListItem<TContext, TKey$1> : never;
28
+ type InferHookFunction<TContext extends PluginContext, TKey$1 extends string> = TKey$1 extends `${infer TUnpluginBuilderVariant}:${infer TUnpluginField}` ? TUnpluginBuilderVariant extends UnpluginBuilderVariant ? TUnpluginField extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant] ? UnpluginHookFunctions<TContext, TUnpluginBuilderVariant, TUnpluginField> : never : never : TKey$1 extends keyof PluginHookFunctions<TContext> ? PluginHookFunctions<TContext>[TKey$1] : never;
29
+ type InferHookReturnType<TContext extends PluginContext, TKey$1 extends string> = ReturnType<InferHookFunction<TContext, TKey$1>>;
30
+ type InferHookParameters<TContext extends PluginContext, TKey$1 extends string> = Parameters<InferHookFunction<TContext, TKey$1>>;
31
+ //#endregion
32
+ export { HooksList, InferHookParameters, InferHookReturnType, InferHooksListItem };
@@ -1,2 +1,32 @@
1
- import "./context.mjs";
2
- import "./plugin.mjs";
1
+ import { UnpluginBuilderVariant } from "./build.mjs";
2
+ import { PluginContext, WithUnpluginBuildContext } from "./context.mjs";
3
+ import { Plugin, PluginHookFields, PluginHookFunctions } from "./plugin.mjs";
4
+ import { UnpluginOptions } from "unplugin";
5
+
6
+ //#region ../powerlines/src/types/hooks.d.ts
7
+ type HookListOrders = "preOrdered" | "preEnforced" | "normal" | "postEnforced" | "postOrdered";
8
+ type UnpluginHookFunctions<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant, TField$1 extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1] = keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1]> = Required<UnpluginOptions>[TUnpluginBuilderVariant$1][TField$1] extends infer THandler | {
9
+ handler: infer THandler;
10
+ } ? THandler extends ((this: infer THandlerOriginalContext, ...args: infer THandlerArgs) => infer THandlerReturn) ? (this: THandlerOriginalContext & WithUnpluginBuildContext<TContext>, ...args: THandlerArgs) => THandlerReturn : THandler extends {
11
+ handler: infer THandlerFunction;
12
+ } ? THandlerFunction extends ((this: infer THandlerFunctionOriginalContext, ...args: infer THandlerFunctionArgs) => infer THandlerFunctionReturn) ? (this: THandlerFunctionOriginalContext & WithUnpluginBuildContext<TContext>, ...args: THandlerFunctionArgs) => THandlerFunctionReturn : never : never : never;
13
+ interface PluginHooksListItem<TContext extends PluginContext = PluginContext, TFields extends PluginHookFields<TContext> = PluginHookFields<TContext>> {
14
+ plugin: Plugin<TContext>;
15
+ handler: PluginHookFunctions<TContext>[TFields];
16
+ }
17
+ type PluginHooksList<TContext extends PluginContext = PluginContext, TFields extends PluginHookFields<TContext> = PluginHookFields<TContext>> = { [TKey in HookListOrders]?: PluginHooksListItem<TContext, TFields>[] | undefined };
18
+ interface UnpluginHooksListItem<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant, TField$1 extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1] = keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1]> {
19
+ plugin: Plugin<TContext>;
20
+ handler: UnpluginHookFunctions<TContext, TUnpluginBuilderVariant$1, TField$1>;
21
+ }
22
+ type UnpluginHookList<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant, TField$1 extends keyof UnpluginOptions[TUnpluginBuilderVariant$1] = keyof UnpluginOptions[TUnpluginBuilderVariant$1]> = { [TKey in HookListOrders]?: UnpluginHooksListItem<TContext, TUnpluginBuilderVariant$1, TField$1>[] | undefined };
23
+ type UnpluginHookVariantField<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant> = { [TKey in keyof UnpluginOptions[TUnpluginBuilderVariant$1]]?: UnpluginHookList<TContext, TUnpluginBuilderVariant$1, TKey> };
24
+ type UnpluginHookVariant<TContext extends PluginContext = PluginContext> = { [TKey in UnpluginBuilderVariant]?: UnpluginHookVariantField<TContext, TKey> };
25
+ type HookFields<TContext extends PluginContext = PluginContext> = PluginHookFields<TContext> | UnpluginBuilderVariant;
26
+ type HooksList<TContext extends PluginContext = PluginContext> = { [TField in HookFields<TContext>]?: TField extends PluginHookFields<TContext> ? PluginHooksList<TContext, TField> : TField extends UnpluginBuilderVariant ? UnpluginHookVariant<TContext>[TField] : never };
27
+ type InferHooksListItem<TContext extends PluginContext, TKey$1 extends string> = TKey$1 extends `${infer TUnpluginBuilderVariant}:${infer TUnpluginField}` ? TUnpluginBuilderVariant extends UnpluginBuilderVariant ? TUnpluginField extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant] ? UnpluginHooksListItem<TContext, TUnpluginBuilderVariant, TUnpluginField> : never : never : TKey$1 extends keyof PluginHookFunctions<TContext> ? PluginHooksListItem<TContext, TKey$1> : never;
28
+ type InferHookFunction<TContext extends PluginContext, TKey$1 extends string> = TKey$1 extends `${infer TUnpluginBuilderVariant}:${infer TUnpluginField}` ? TUnpluginBuilderVariant extends UnpluginBuilderVariant ? TUnpluginField extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant] ? UnpluginHookFunctions<TContext, TUnpluginBuilderVariant, TUnpluginField> : never : never : TKey$1 extends keyof PluginHookFunctions<TContext> ? PluginHookFunctions<TContext>[TKey$1] : never;
29
+ type InferHookReturnType<TContext extends PluginContext, TKey$1 extends string> = ReturnType<InferHookFunction<TContext, TKey$1>>;
30
+ type InferHookParameters<TContext extends PluginContext, TKey$1 extends string> = Parameters<InferHookFunction<TContext, TKey$1>>;
31
+ //#endregion
32
+ export { HooksList, InferHookParameters, InferHookReturnType, InferHooksListItem };
@@ -1,14 +1,16 @@
1
- import { UnpluginBuildVariant } from "./build.cjs";
1
+ import { BuilderVariant } from "./build.cjs";
2
2
  import { EnvironmentConfig, PluginConfig } from "./config.cjs";
3
3
  import { EnvironmentResolvedConfig, ResolvedConfig } from "./resolved.cjs";
4
4
  import { BuildPluginContext, PluginContext, UnresolvedContext } from "./context.cjs";
5
5
  import { CommandType } from "./commands.cjs";
6
+ import { InferUnpluginOptions } from "./unplugin.cjs";
6
7
  import { ArrayValues } from "@stryke/types/array";
7
- import { FunctionLike, MaybePromise } from "@stryke/types/base";
8
- import { ExternalIdResult, HookFilter, TransformResult, UnpluginOptions } from "unplugin";
8
+ import { AnyFunction, MaybePromise } from "@stryke/types/base";
9
+ import { LoadResult } from "rollup";
10
+ import { ExternalIdResult, HookFilter, TransformResult } from "unplugin";
9
11
 
10
12
  //#region ../powerlines/src/types/plugin.d.ts
11
- interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> {
13
+ interface PluginHookObject<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> {
12
14
  /**
13
15
  * The order in which the plugin should be applied.
14
16
  */
@@ -22,7 +24,7 @@ interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends k
22
24
  */
23
25
  handler: THookFunction;
24
26
  }
25
- type PluginHook<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
27
+ type PluginHook<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
26
28
  /**
27
29
  * A result returned by the plugin from the `types` hook that describes the declaration types output file.
28
30
  */
@@ -30,9 +32,7 @@ interface TypesResult {
30
32
  directives?: string[];
31
33
  code: string;
32
34
  }
33
- type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
34
- type ConfigResult<TContext extends PluginContext = PluginContext> = DeepPartial<TContext["config"]> & Record<string, any>;
35
- interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext> extends Record<CommandType, (this: TContext) => MaybePromise<void>> {
35
+ type PluginHookFunctions<TContext extends PluginContext> = { [TCommandType in CommandType]: (this: TContext) => MaybePromise<void> } & {
36
36
  /**
37
37
  * A function that returns configuration options to be merged with the build context's options.
38
38
  *
@@ -47,7 +47,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
47
47
  * @param config - The partial configuration object to be modified.
48
48
  * @returns A promise that resolves to a partial configuration object.
49
49
  */
50
- config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>;
50
+ config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>;
51
51
  /**
52
52
  * 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.
53
53
  *
@@ -109,7 +109,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
109
109
  * @param id - The identifier of the source code.
110
110
  * @returns A promise that resolves when the hook is complete.
111
111
  */
112
- load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>;
112
+ load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<LoadResult>;
113
113
  /**
114
114
  * A hook that is called to resolve the identifier of the source code.
115
115
  *
@@ -129,56 +129,14 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
129
129
  * @returns A promise that resolves when the hook is complete.
130
130
  */
131
131
  writeBundle: (this: TContext) => MaybePromise<void>;
132
- }
133
- type BuildPlugin<TContext extends PluginContext = PluginContext, TBuildVariant$1 extends UnpluginBuildVariant = UnpluginBuildVariant, TOptions extends Required<UnpluginOptions>[TBuildVariant$1] = Required<UnpluginOptions>[TBuildVariant$1]> = { [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] };
134
- type PluginHooks<TContext extends PluginContext = PluginContext> = { [TKey in keyof BasePluginHookFunctions<TContext>]: PluginHook<BasePluginHookFunctions<TContext>[TKey]> } & {
135
- /**
136
- * A function that returns configuration options to be merged with the build context's options.
137
- *
138
- * @remarks
139
- * 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.
140
- *
141
- * @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.
142
- *
143
- * @see https://vitejs.dev/guide/api-plugin#config
144
- *
145
- * @param this - The build context.
146
- * @param config - The partial configuration object to be modified.
147
- * @returns A promise that resolves to a partial configuration object.
148
- */
149
- config: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>> | ConfigResult<TContext>;
150
- /**
151
- * A hook that is called to transform the source code.
152
- *
153
- * @param this - The build context, unplugin build context, and unplugin context.
154
- * @param code - The source code to transform.
155
- * @param id - The identifier of the source code.
156
- * @returns A promise that resolves when the hook is complete.
157
- */
158
- transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>, "code" | "id">;
159
- /**
160
- * A hook that is called to load the source code.
161
- *
162
- * @param this - The build context, unplugin build context, and unplugin context.
163
- * @param id - The identifier of the source code.
164
- * @returns A promise that resolves when the hook is complete.
165
- */
166
- load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>, "id">;
167
- /**
168
- * A hook that is called to resolve the identifier of the source code.
169
- *
170
- * @param this - The build context, unplugin build context, and unplugin context.
171
- * @param id - The identifier of the source code.
172
- * @param importer - The importer of the source code.
173
- * @param options - The options for resolving the identifier.
174
- * @returns A promise that resolves when the hook is complete.
175
- */
176
- resolveId: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
177
- isEntry: boolean;
178
- }) => MaybePromise<string | ExternalIdResult | null | undefined>, "id">;
179
132
  };
180
- type PluginBuildPlugins<TContext extends PluginContext = PluginContext> = { [TBuildVariant in UnpluginBuildVariant]?: BuildPlugin<TContext, TBuildVariant> };
181
- interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> extends Partial<PluginHooks<TContext>>, PluginBuildPlugins<TContext> {
133
+ type PluginHooks<TContext extends PluginContext> = { [TPluginHook in keyof PluginHookFunctions<TContext>]?: PluginHook<PluginHookFunctions<TContext>[TPluginHook]> } & {
134
+ transform: PluginHook<PluginHookFunctions<TContext>["transform"], "code" | "id">;
135
+ load: PluginHook<PluginHookFunctions<TContext>["load"], "id">;
136
+ resolveId: PluginHook<PluginHookFunctions<TContext>["resolveId"], "id">;
137
+ };
138
+ type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
139
+ type Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> = Partial<PluginHooks<TContext>> & {
182
140
  /**
183
141
  * The name of the plugin, for use in deduplication, error messages and logs.
184
142
  */
@@ -226,6 +184,22 @@ interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<
226
184
  * @returns `true` if the plugin should be active in the specified environment, `false` otherwise.
227
185
  */
228
186
  applyToEnvironment?: (environment: EnvironmentResolvedConfig) => boolean | PluginConfig<TContext>;
229
- }
187
+ /**
188
+ * A function that returns configuration options to be merged with the build context's options.
189
+ *
190
+ * @remarks
191
+ * 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.
192
+ *
193
+ * @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.
194
+ *
195
+ * @see https://vitejs.dev/guide/api-plugin#config
196
+ *
197
+ * @param this - The build context.
198
+ * @param config - The partial configuration object to be modified.
199
+ * @returns A promise that resolves to a partial configuration object.
200
+ */
201
+ config?: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>> | (DeepPartial<TContext["config"]> & Record<string, any>);
202
+ } & { [TBuilderVariant in BuilderVariant]?: InferUnpluginOptions<TContext, TBuilderVariant> };
203
+ type PluginHookFields<TContext extends PluginContext = PluginContext> = keyof PluginHookFunctions<TContext>;
230
204
  //#endregion
231
- export { Plugin };
205
+ export { Plugin, PluginHook, PluginHookFields, PluginHookFunctions };