@powerlines/plugin-nodejs 0.1.4 → 0.1.5

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.
Files changed (29) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.mjs +1 -1
  3. package/dist/plugin-alloy/src/index.cjs +12 -5
  4. package/dist/plugin-alloy/src/index.mjs +12 -5
  5. package/dist/plugin-alloy/src/types/components.d.cts +1 -3
  6. package/dist/plugin-alloy/src/types/components.d.mts +1 -3
  7. package/dist/plugin-alloy/src/typescript/components/typescript-file.cjs +16 -10
  8. package/dist/plugin-alloy/src/typescript/components/typescript-file.d.cts +1 -0
  9. package/dist/plugin-alloy/src/typescript/components/typescript-file.d.mts +1 -0
  10. package/dist/plugin-alloy/src/typescript/components/typescript-file.mjs +16 -10
  11. package/dist/powerlines/src/internal/helpers/hooks.d.cts +47 -0
  12. package/dist/powerlines/src/internal/helpers/hooks.d.mts +49 -0
  13. package/dist/powerlines/src/types/api.d.cts +104 -0
  14. package/dist/powerlines/src/types/api.d.mts +104 -0
  15. package/dist/powerlines/src/types/build.d.cts +43 -3
  16. package/dist/powerlines/src/types/build.d.mts +42 -4
  17. package/dist/powerlines/src/types/config.d.cts +60 -4
  18. package/dist/powerlines/src/types/config.d.mts +60 -4
  19. package/dist/powerlines/src/types/context.d.cts +113 -1
  20. package/dist/powerlines/src/types/context.d.mts +113 -3
  21. package/dist/powerlines/src/types/hooks.d.cts +32 -0
  22. package/dist/powerlines/src/types/hooks.d.mts +32 -2
  23. package/dist/powerlines/src/types/plugin.d.cts +35 -61
  24. package/dist/powerlines/src/types/plugin.d.mts +35 -61
  25. package/dist/powerlines/src/types/resolved.d.cts +16 -4
  26. package/dist/powerlines/src/types/resolved.d.mts +16 -5
  27. package/dist/powerlines/src/types/unplugin.d.cts +22 -0
  28. package/dist/powerlines/src/types/unplugin.d.mts +23 -0
  29. package/package.json +6 -6
@@ -1,5 +1,5 @@
1
1
  import { StoragePort, StoragePreset } from "./fs.cjs";
2
- import { BuildConfig, BuildResolvedConfig } from "./build.cjs";
2
+ 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.cjs";
3
3
  import { Plugin } from "./plugin.cjs";
4
4
  import { TSConfig } from "./tsconfig.cjs";
5
5
  import { PluginContext } from "./context.cjs";
@@ -352,7 +352,7 @@ interface CommonUserConfig extends BaseConfig {
352
352
  */
353
353
  framework?: string;
354
354
  }
355
- interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
355
+ interface UserConfig$1<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
356
356
  /**
357
357
  * Configuration provided to build processes
358
358
  *
@@ -373,15 +373,71 @@ interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResol
373
373
  override?: Partial<TBuildResolvedConfig>;
374
374
  };
375
375
  }
376
+ type WebpackUserConfig = UserConfig$1<WebpackBuildConfig, WebpackResolvedBuildConfig, "webpack">;
377
+ type RspackUserConfig = UserConfig$1<RspackBuildConfig, RspackResolvedBuildConfig, "rspack">;
378
+ type RollupUserConfig = UserConfig$1<RollupBuildConfig, RollupResolvedBuildConfig, "rollup">;
379
+ type RolldownUserConfig = UserConfig$1<RolldownBuildConfig, RolldownResolvedBuildConfig, "rolldown">;
380
+ type ViteUserConfig = UserConfig$1<ViteBuildConfig, ViteResolvedBuildConfig, "vite">;
381
+ type ESBuildUserConfig = UserConfig$1<ESBuildBuildConfig, ESBuildResolvedBuildConfig, "esbuild">;
382
+ type UnbuildUserConfig = UserConfig$1<UnbuildBuildConfig, UnbuildResolvedBuildConfig, "unbuild">;
383
+ type TsupUserConfig = UserConfig$1<TsupBuildConfig, TsupResolvedBuildConfig, "tsup">;
384
+ type TsdownUserConfig = UserConfig$1<TsdownBuildConfig, TsdownResolvedBuildConfig, "tsdown">;
385
+ type FarmUserConfig = UserConfig$1<FarmBuildConfig, FarmResolvedBuildConfig, "farm">;
376
386
  type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "deploy" | "clean";
377
387
  /**
378
388
  * The configuration provided while executing Powerlines commands.
379
389
  */
380
- type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
390
+ type InlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = Partial<TUserConfig> & {
381
391
  /**
382
392
  * A string identifier for the Powerlines command being executed
383
393
  */
384
394
  command: PowerlinesCommand;
385
395
  };
396
+ type NewInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & Required<Pick<InlineConfig<TUserConfig>, "root">> & {
397
+ /**
398
+ * A string identifier for the Powerlines command being executed
399
+ */
400
+ command: "new";
401
+ /**
402
+ * 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
403
+ */
404
+ packageName?: string;
405
+ };
406
+ type CleanInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
407
+ /**
408
+ * A string identifier for the Powerlines command being executed
409
+ */
410
+ command: "clean";
411
+ };
412
+ type PrepareInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
413
+ /**
414
+ * A string identifier for the Powerlines command being executed
415
+ */
416
+ command: "prepare";
417
+ };
418
+ type BuildInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
419
+ /**
420
+ * A string identifier for the Powerlines command being executed
421
+ */
422
+ command: "build";
423
+ };
424
+ type LintInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
425
+ /**
426
+ * A string identifier for the Powerlines command being executed
427
+ */
428
+ command: "lint";
429
+ };
430
+ type DocsInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
431
+ /**
432
+ * A string identifier for the Powerlines command being executed
433
+ */
434
+ command: "docs";
435
+ };
436
+ type DeployInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
437
+ /**
438
+ * A string identifier for the Powerlines command being executed
439
+ */
440
+ command: "deploy";
441
+ };
386
442
  //#endregion
387
- export { BabelUserConfig, EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, UserConfig, WorkspaceConfig };
443
+ 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,5 +1,5 @@
1
1
  import { StoragePort, StoragePreset } from "./fs.mjs";
2
- import { BuildConfig, BuildResolvedConfig } from "./build.mjs";
2
+ 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";
3
3
  import { Plugin } from "./plugin.mjs";
4
4
  import { TSConfig } from "./tsconfig.mjs";
5
5
  import { PluginContext } from "./context.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,4 +1,6 @@
1
1
  import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.cjs";
2
+ import { Plugin } from "./plugin.cjs";
3
+ import { HooksList, InferHooksListItem } from "./hooks.cjs";
2
4
  import { ParsedTypeScriptConfig } from "./tsconfig.cjs";
3
5
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.cjs";
4
6
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.cjs";
@@ -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,6 +1,6 @@
1
1
  import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.mjs";
2
- import "./plugin.mjs";
3
- import "./hooks.mjs";
2
+ import { Plugin } from "./plugin.mjs";
3
+ import { HooksList, InferHooksListItem } from "./hooks.mjs";
4
4
  import { ParsedTypeScriptConfig } from "./tsconfig.mjs";
5
5
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.mjs";
6
6
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.mjs";
@@ -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 { Plugin, PluginHookFields, PluginHookFunctions } from "./plugin.cjs";
3
+ import { PluginContext, WithUnpluginBuildContext } from "./context.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 "./plugin.mjs";
2
- import "./context.mjs";
1
+ import { UnpluginBuilderVariant } from "./build.mjs";
2
+ import { Plugin, PluginHookFields, PluginHookFunctions } from "./plugin.mjs";
3
+ import { PluginContext, WithUnpluginBuildContext } from "./context.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 };