@powerlines/plugin-date 0.12.147 → 0.12.148

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,4 +1,4 @@
1
- import { BuildConfig, BuildResolvedConfig } from "./build.mjs";
1
+ import { BuildConfig, BuildResolvedConfig, ESBuildBuildConfig, ESBuildResolvedBuildConfig, FarmBuildConfig, FarmResolvedBuildConfig, RolldownBuildConfig, RolldownResolvedBuildConfig, RollupBuildConfig, RollupResolvedBuildConfig, RspackBuildConfig, RspackResolvedBuildConfig, TsdownBuildConfig, TsdownResolvedBuildConfig, TsupBuildConfig, TsupResolvedBuildConfig, UnbuildBuildConfig, UnbuildResolvedBuildConfig, ViteBuildConfig, ViteResolvedBuildConfig, WebpackBuildConfig, WebpackResolvedBuildConfig } from "./build.mjs";
2
2
  import { BabelTransformPluginOptions } from "./babel.mjs";
3
3
  import { StoragePort, StoragePreset } from "./fs.mjs";
4
4
  import { TSConfig } from "./tsconfig.mjs";
@@ -353,7 +353,7 @@ interface CommonUserConfig extends BaseConfig {
353
353
  */
354
354
  framework?: string;
355
355
  }
356
- interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
356
+ interface UserConfig$1<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
357
357
  /**
358
358
  * Configuration provided to build processes
359
359
  *
@@ -374,15 +374,71 @@ interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResol
374
374
  override?: Partial<TBuildResolvedConfig>;
375
375
  };
376
376
  }
377
+ type WebpackUserConfig = UserConfig$1<WebpackBuildConfig, WebpackResolvedBuildConfig, "webpack">;
378
+ type RspackUserConfig = UserConfig$1<RspackBuildConfig, RspackResolvedBuildConfig, "rspack">;
379
+ type RollupUserConfig = UserConfig$1<RollupBuildConfig, RollupResolvedBuildConfig, "rollup">;
380
+ type RolldownUserConfig = UserConfig$1<RolldownBuildConfig, RolldownResolvedBuildConfig, "rolldown">;
381
+ type ViteUserConfig = UserConfig$1<ViteBuildConfig, ViteResolvedBuildConfig, "vite">;
382
+ type ESBuildUserConfig = UserConfig$1<ESBuildBuildConfig, ESBuildResolvedBuildConfig, "esbuild">;
383
+ type UnbuildUserConfig = UserConfig$1<UnbuildBuildConfig, UnbuildResolvedBuildConfig, "unbuild">;
384
+ type TsupUserConfig = UserConfig$1<TsupBuildConfig, TsupResolvedBuildConfig, "tsup">;
385
+ type TsdownUserConfig = UserConfig$1<TsdownBuildConfig, TsdownResolvedBuildConfig, "tsdown">;
386
+ type FarmUserConfig = UserConfig$1<FarmBuildConfig, FarmResolvedBuildConfig, "farm">;
377
387
  type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "deploy" | "clean";
378
388
  /**
379
389
  * The configuration provided while executing Powerlines commands.
380
390
  */
381
- type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
391
+ type InlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = Partial<TUserConfig> & {
382
392
  /**
383
393
  * A string identifier for the Powerlines command being executed
384
394
  */
385
395
  command: PowerlinesCommand;
386
396
  };
397
+ type NewInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & Required<Pick<InlineConfig<TUserConfig>, "root">> & {
398
+ /**
399
+ * A string identifier for the Powerlines command being executed
400
+ */
401
+ command: "new";
402
+ /**
403
+ * The package name (from the \`package.json\`) for the project that will be used in the \`new\` command to create a new project based on this configuration
404
+ */
405
+ packageName?: string;
406
+ };
407
+ type CleanInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
408
+ /**
409
+ * A string identifier for the Powerlines command being executed
410
+ */
411
+ command: "clean";
412
+ };
413
+ type PrepareInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
414
+ /**
415
+ * A string identifier for the Powerlines command being executed
416
+ */
417
+ command: "prepare";
418
+ };
419
+ type BuildInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
420
+ /**
421
+ * A string identifier for the Powerlines command being executed
422
+ */
423
+ command: "build";
424
+ };
425
+ type LintInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
426
+ /**
427
+ * A string identifier for the Powerlines command being executed
428
+ */
429
+ command: "lint";
430
+ };
431
+ type DocsInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
432
+ /**
433
+ * A string identifier for the Powerlines command being executed
434
+ */
435
+ command: "docs";
436
+ };
437
+ type DeployInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
438
+ /**
439
+ * A string identifier for the Powerlines command being executed
440
+ */
441
+ command: "deploy";
442
+ };
387
443
  //#endregion
388
- export { BabelUserConfig, EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, UserConfig, WorkspaceConfig };
444
+ export { BabelUserConfig, BuildInlineConfig, CleanInlineConfig, DeployInlineConfig, DocsInlineConfig, ESBuildUserConfig, EnvironmentConfig, FarmUserConfig, InlineConfig, LintInlineConfig, LogFn, NewInlineConfig, OutputConfig, PluginConfig, PrepareInlineConfig, RolldownUserConfig, RollupUserConfig, RspackUserConfig, TsdownUserConfig, TsupUserConfig, UnbuildUserConfig, UserConfig$1 as UserConfig, ViteUserConfig, WebpackUserConfig, WorkspaceConfig };
@@ -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";
@@ -60,6 +62,9 @@ interface TransformResult$1 {
60
62
  code: string;
61
63
  map: SourceMap | null;
62
64
  }
65
+ interface SelectHooksOptions {
66
+ order?: "pre" | "post" | "normal";
67
+ }
63
68
  /**
64
69
  * Options for initializing or updating the context with new configuration values
65
70
  */
@@ -396,6 +401,112 @@ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<Unr
396
401
  */
397
402
  config: TResolvedConfig;
398
403
  };
404
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
405
+ /**
406
+ * The expected plugins options for the Powerlines project.
407
+ *
408
+ * @remarks
409
+ * 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.
410
+ */
411
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
412
+ /**
413
+ * A function to add a plugin to the context and update the configuration options
414
+ */
415
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
416
+ /**
417
+ * A table for storing the current context for each configured environment
418
+ */
419
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
420
+ /**
421
+ * Retrieves the context for a specific environment by name
422
+ *
423
+ * @throws Will throw an error if the environment does not exist
424
+ *
425
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
426
+ * @returns A promise that resolves to the environment context.
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * const devEnv = await apiContext.getEnvironment("development");
431
+ * const defaultEnv = await apiContext.getEnvironment();
432
+ * ```
433
+ */
434
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
435
+ /**
436
+ * Safely retrieves the context for a specific environment by name
437
+ *
438
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
439
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
440
+ *
441
+ * @example
442
+ * ```ts
443
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
444
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
445
+ * ```
446
+ *
447
+ * @remarks
448
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
449
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
450
+ *
451
+ * ```ts
452
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
453
+ * if (testEnv) {
454
+ * // Environment exists, safe to use it
455
+ * } else {
456
+ * // Environment does not exist, handle accordingly
457
+ * }
458
+ * ```
459
+ *
460
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
461
+ */
462
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
463
+ /**
464
+ * A function to copy the context and update the fields for a specific environment
465
+ *
466
+ * @param environment - The environment configuration to use.
467
+ * @returns A new context instance with the updated environment.
468
+ */
469
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
470
+ /**
471
+ * A function to merge all configured environments into a single context
472
+ *
473
+ * @returns A promise that resolves to the merged environment context.
474
+ */
475
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
476
+ }
477
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
478
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
479
+ context: PluginContext<TResolvedConfig>;
480
+ }
481
+ type SelectHookResultItem<TContext extends PluginContext, TKey extends string> = InferHooksListItem<TContext, TKey> & {
482
+ context: TContext;
483
+ };
484
+ type SelectHookResult<TContext extends PluginContext, TKey extends string> = SelectHookResultItem<TContext, TKey>[];
485
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
486
+ /**
487
+ * The expected plugins options for the Powerlines project.
488
+ *
489
+ * @remarks
490
+ * 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.
491
+ */
492
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
493
+ /**
494
+ * A function to add a plugin to the context and update the configuration options
495
+ */
496
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
497
+ /**
498
+ * The environment specific resolved configuration
499
+ */
500
+ environment: EnvironmentResolvedConfig;
501
+ /**
502
+ * A table holding references to hook functions registered by plugins
503
+ */
504
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
505
+ /**
506
+ * Retrieves the hook handlers for a specific hook name
507
+ */
508
+ selectHooks: <TKey extends string>(key: TKey, options?: SelectHooksOptions) => SelectHookResult<PluginContext<TResolvedConfig>, TKey>;
509
+ }
399
510
  interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
400
511
  /**
401
512
  * The environment specific resolved configuration
@@ -410,5 +521,6 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
410
521
  logger: LogFn;
411
522
  }
412
523
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
524
+ type WithUnpluginBuildContext<TContext extends PluginContext> = UnpluginBuildContext & TContext;
413
525
  //#endregion
414
- export { BuildPluginContext, Context, LogLevel, PluginContext, UnresolvedContext };
526
+ export { APIContext, BuildPluginContext, Context, EnvironmentContext, LogLevel, 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";
@@ -62,6 +62,9 @@ interface TransformResult$1 {
62
62
  code: string;
63
63
  map: SourceMap | null;
64
64
  }
65
+ interface SelectHooksOptions {
66
+ order?: "pre" | "post" | "normal";
67
+ }
65
68
  /**
66
69
  * Options for initializing or updating the context with new configuration values
67
70
  */
@@ -398,6 +401,112 @@ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<Unr
398
401
  */
399
402
  config: TResolvedConfig;
400
403
  };
404
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
405
+ /**
406
+ * The expected plugins options for the Powerlines project.
407
+ *
408
+ * @remarks
409
+ * 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.
410
+ */
411
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
412
+ /**
413
+ * A function to add a plugin to the context and update the configuration options
414
+ */
415
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
416
+ /**
417
+ * A table for storing the current context for each configured environment
418
+ */
419
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
420
+ /**
421
+ * Retrieves the context for a specific environment by name
422
+ *
423
+ * @throws Will throw an error if the environment does not exist
424
+ *
425
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
426
+ * @returns A promise that resolves to the environment context.
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * const devEnv = await apiContext.getEnvironment("development");
431
+ * const defaultEnv = await apiContext.getEnvironment();
432
+ * ```
433
+ */
434
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
435
+ /**
436
+ * Safely retrieves the context for a specific environment by name
437
+ *
438
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
439
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
440
+ *
441
+ * @example
442
+ * ```ts
443
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
444
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
445
+ * ```
446
+ *
447
+ * @remarks
448
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
449
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
450
+ *
451
+ * ```ts
452
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
453
+ * if (testEnv) {
454
+ * // Environment exists, safe to use it
455
+ * } else {
456
+ * // Environment does not exist, handle accordingly
457
+ * }
458
+ * ```
459
+ *
460
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
461
+ */
462
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
463
+ /**
464
+ * A function to copy the context and update the fields for a specific environment
465
+ *
466
+ * @param environment - The environment configuration to use.
467
+ * @returns A new context instance with the updated environment.
468
+ */
469
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
470
+ /**
471
+ * A function to merge all configured environments into a single context
472
+ *
473
+ * @returns A promise that resolves to the merged environment context.
474
+ */
475
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
476
+ }
477
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
478
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
479
+ context: PluginContext<TResolvedConfig>;
480
+ }
481
+ type SelectHookResultItem<TContext extends PluginContext, TKey extends string> = InferHooksListItem<TContext, TKey> & {
482
+ context: TContext;
483
+ };
484
+ type SelectHookResult<TContext extends PluginContext, TKey extends string> = SelectHookResultItem<TContext, TKey>[];
485
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
486
+ /**
487
+ * The expected plugins options for the Powerlines project.
488
+ *
489
+ * @remarks
490
+ * 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.
491
+ */
492
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
493
+ /**
494
+ * A function to add a plugin to the context and update the configuration options
495
+ */
496
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
497
+ /**
498
+ * The environment specific resolved configuration
499
+ */
500
+ environment: EnvironmentResolvedConfig;
501
+ /**
502
+ * A table holding references to hook functions registered by plugins
503
+ */
504
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
505
+ /**
506
+ * Retrieves the hook handlers for a specific hook name
507
+ */
508
+ selectHooks: <TKey extends string>(key: TKey, options?: SelectHooksOptions) => SelectHookResult<PluginContext<TResolvedConfig>, TKey>;
509
+ }
401
510
  interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
402
511
  /**
403
512
  * The environment specific resolved configuration
@@ -412,5 +521,6 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
412
521
  logger: LogFn;
413
522
  }
414
523
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
524
+ type WithUnpluginBuildContext<TContext extends PluginContext> = UnpluginBuildContext & TContext;
415
525
  //#endregion
416
- export { BuildPluginContext, Context, LogLevel, PluginContext, UnresolvedContext };
526
+ export { APIContext, BuildPluginContext, Context, EnvironmentContext, LogLevel, 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 };