@powerlines/plugin-webpack 0.5.134 → 0.5.135

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 (35) hide show
  1. package/dist/powerlines/src/internal/helpers/hooks.cjs +15 -12
  2. package/dist/powerlines/src/internal/helpers/hooks.d.cts +47 -0
  3. package/dist/powerlines/src/internal/helpers/hooks.d.mts +49 -0
  4. package/dist/powerlines/src/internal/helpers/hooks.mjs +15 -12
  5. package/dist/powerlines/src/lib/contexts/environment-context.cjs +108 -73
  6. package/dist/powerlines/src/lib/contexts/environment-context.mjs +109 -74
  7. package/dist/powerlines/src/lib/unplugin/helpers.cjs +13 -1
  8. package/dist/powerlines/src/lib/unplugin/helpers.mjs +12 -1
  9. package/dist/powerlines/src/lib/unplugin/index.cjs +1 -1
  10. package/dist/powerlines/src/lib/unplugin/index.mjs +1 -1
  11. package/dist/powerlines/src/lib/unplugin/plugin.cjs +3 -3
  12. package/dist/powerlines/src/lib/unplugin/plugin.mjs +3 -3
  13. package/dist/powerlines/src/plugin-utils/helpers.cjs +34 -15
  14. package/dist/powerlines/src/plugin-utils/helpers.mjs +33 -15
  15. package/dist/powerlines/src/types/api.d.cts +104 -0
  16. package/dist/powerlines/src/types/api.d.mts +104 -0
  17. package/dist/powerlines/src/types/build.cjs +11 -3
  18. package/dist/powerlines/src/types/build.d.cts +39 -3
  19. package/dist/powerlines/src/types/build.d.mts +39 -3
  20. package/dist/powerlines/src/types/build.mjs +10 -3
  21. package/dist/powerlines/src/types/config.d.cts +60 -5
  22. package/dist/powerlines/src/types/config.d.mts +60 -6
  23. package/dist/powerlines/src/types/context.d.cts +113 -1
  24. package/dist/powerlines/src/types/context.d.mts +113 -3
  25. package/dist/powerlines/src/types/hooks.d.cts +32 -0
  26. package/dist/powerlines/src/types/hooks.d.mts +32 -2
  27. package/dist/powerlines/src/types/plugin.cjs +5 -4
  28. package/dist/powerlines/src/types/plugin.d.cts +35 -61
  29. package/dist/powerlines/src/types/plugin.d.mts +35 -61
  30. package/dist/powerlines/src/types/plugin.mjs +6 -5
  31. package/dist/powerlines/src/types/resolved.d.cts +15 -4
  32. package/dist/powerlines/src/types/resolved.d.mts +15 -5
  33. package/dist/powerlines/src/types/unplugin.d.cts +22 -0
  34. package/dist/powerlines/src/types/unplugin.d.mts +23 -0
  35. package/package.json +5 -5
@@ -1,4 +1,4 @@
1
- import { BuildConfig, BuildResolvedConfig, WebpackBuildConfig, WebpackResolvedBuildConfig } from "./build.cjs";
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.cjs";
2
2
  import { StoragePort, StoragePreset } from "./fs.cjs";
3
3
  import { Plugin } from "./plugin.cjs";
4
4
  import { TSConfig } from "./tsconfig.cjs";
@@ -341,7 +341,7 @@ interface CommonUserConfig extends BaseConfig {
341
341
  */
342
342
  framework?: string;
343
343
  }
344
- interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
344
+ interface UserConfig$1<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
345
345
  /**
346
346
  * Configuration provided to build processes
347
347
  *
@@ -362,16 +362,71 @@ interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResol
362
362
  override?: Partial<TBuildResolvedConfig>;
363
363
  };
364
364
  }
365
- type WebpackUserConfig = UserConfig<WebpackBuildConfig, WebpackResolvedBuildConfig, "webpack">;
365
+ type WebpackUserConfig = UserConfig$1<WebpackBuildConfig, WebpackResolvedBuildConfig, "webpack">;
366
+ type RspackUserConfig = UserConfig$1<RspackBuildConfig, RspackResolvedBuildConfig, "rspack">;
367
+ type RollupUserConfig = UserConfig$1<RollupBuildConfig, RollupResolvedBuildConfig, "rollup">;
368
+ type RolldownUserConfig = UserConfig$1<RolldownBuildConfig, RolldownResolvedBuildConfig, "rolldown">;
369
+ type ViteUserConfig = UserConfig$1<ViteBuildConfig, ViteResolvedBuildConfig, "vite">;
370
+ type ESBuildUserConfig = UserConfig$1<ESBuildBuildConfig, ESBuildResolvedBuildConfig, "esbuild">;
371
+ type UnbuildUserConfig = UserConfig$1<UnbuildBuildConfig, UnbuildResolvedBuildConfig, "unbuild">;
372
+ type TsupUserConfig = UserConfig$1<TsupBuildConfig, TsupResolvedBuildConfig, "tsup">;
373
+ type TsdownUserConfig = UserConfig$1<TsdownBuildConfig, TsdownResolvedBuildConfig, "tsdown">;
374
+ type FarmUserConfig = UserConfig$1<FarmBuildConfig, FarmResolvedBuildConfig, "farm">;
366
375
  type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "deploy" | "clean";
367
376
  /**
368
377
  * The configuration provided while executing Powerlines commands.
369
378
  */
370
- type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
379
+ type InlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = Partial<TUserConfig> & {
371
380
  /**
372
381
  * A string identifier for the Powerlines command being executed
373
382
  */
374
383
  command: PowerlinesCommand;
375
384
  };
385
+ type NewInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & Required<Pick<InlineConfig<TUserConfig>, "root">> & {
386
+ /**
387
+ * A string identifier for the Powerlines command being executed
388
+ */
389
+ command: "new";
390
+ /**
391
+ * 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
392
+ */
393
+ packageName?: string;
394
+ };
395
+ type CleanInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
396
+ /**
397
+ * A string identifier for the Powerlines command being executed
398
+ */
399
+ command: "clean";
400
+ };
401
+ type PrepareInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
402
+ /**
403
+ * A string identifier for the Powerlines command being executed
404
+ */
405
+ command: "prepare";
406
+ };
407
+ type BuildInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
408
+ /**
409
+ * A string identifier for the Powerlines command being executed
410
+ */
411
+ command: "build";
412
+ };
413
+ type LintInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
414
+ /**
415
+ * A string identifier for the Powerlines command being executed
416
+ */
417
+ command: "lint";
418
+ };
419
+ type DocsInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
420
+ /**
421
+ * A string identifier for the Powerlines command being executed
422
+ */
423
+ command: "docs";
424
+ };
425
+ type DeployInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
426
+ /**
427
+ * A string identifier for the Powerlines command being executed
428
+ */
429
+ command: "deploy";
430
+ };
376
431
  //#endregion
377
- export { EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, UserConfig, WebpackUserConfig, WorkspaceConfig };
432
+ export { 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,4 @@
1
- import { BuildConfig, BuildResolvedConfig, WebpackBuildConfig, WebpackResolvedBuildConfig } 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 "./babel.mjs";
3
3
  import { StoragePort, StoragePreset } from "./fs.mjs";
4
4
  import { Plugin } from "./plugin.mjs";
@@ -6,7 +6,6 @@ import { TSConfig } from "./tsconfig.mjs";
6
6
  import { PluginContext } from "./context.mjs";
7
7
  import { LogLevelLabel } from "@storm-software/config-tools/types";
8
8
  import { transformAsync } from "@babel/core";
9
- import "c12";
10
9
  import { PreviewOptions } from "vite";
11
10
  import { MaybePromise } from "@stryke/types/base";
12
11
  import { Format } from "@storm-software/build-tools/types";
@@ -343,7 +342,7 @@ interface CommonUserConfig extends BaseConfig {
343
342
  */
344
343
  framework?: string;
345
344
  }
346
- interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
345
+ interface UserConfig$1<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
347
346
  /**
348
347
  * Configuration provided to build processes
349
348
  *
@@ -364,16 +363,71 @@ interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResol
364
363
  override?: Partial<TBuildResolvedConfig>;
365
364
  };
366
365
  }
367
- type WebpackUserConfig = UserConfig<WebpackBuildConfig, WebpackResolvedBuildConfig, "webpack">;
366
+ type WebpackUserConfig = UserConfig$1<WebpackBuildConfig, WebpackResolvedBuildConfig, "webpack">;
367
+ type RspackUserConfig = UserConfig$1<RspackBuildConfig, RspackResolvedBuildConfig, "rspack">;
368
+ type RollupUserConfig = UserConfig$1<RollupBuildConfig, RollupResolvedBuildConfig, "rollup">;
369
+ type RolldownUserConfig = UserConfig$1<RolldownBuildConfig, RolldownResolvedBuildConfig, "rolldown">;
370
+ type ViteUserConfig = UserConfig$1<ViteBuildConfig, ViteResolvedBuildConfig, "vite">;
371
+ type ESBuildUserConfig = UserConfig$1<ESBuildBuildConfig, ESBuildResolvedBuildConfig, "esbuild">;
372
+ type UnbuildUserConfig = UserConfig$1<UnbuildBuildConfig, UnbuildResolvedBuildConfig, "unbuild">;
373
+ type TsupUserConfig = UserConfig$1<TsupBuildConfig, TsupResolvedBuildConfig, "tsup">;
374
+ type TsdownUserConfig = UserConfig$1<TsdownBuildConfig, TsdownResolvedBuildConfig, "tsdown">;
375
+ type FarmUserConfig = UserConfig$1<FarmBuildConfig, FarmResolvedBuildConfig, "farm">;
368
376
  type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "deploy" | "clean";
369
377
  /**
370
378
  * The configuration provided while executing Powerlines commands.
371
379
  */
372
- type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
380
+ type InlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = Partial<TUserConfig> & {
373
381
  /**
374
382
  * A string identifier for the Powerlines command being executed
375
383
  */
376
384
  command: PowerlinesCommand;
377
385
  };
386
+ type NewInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & Required<Pick<InlineConfig<TUserConfig>, "root">> & {
387
+ /**
388
+ * A string identifier for the Powerlines command being executed
389
+ */
390
+ command: "new";
391
+ /**
392
+ * 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
393
+ */
394
+ packageName?: string;
395
+ };
396
+ type CleanInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
397
+ /**
398
+ * A string identifier for the Powerlines command being executed
399
+ */
400
+ command: "clean";
401
+ };
402
+ type PrepareInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
403
+ /**
404
+ * A string identifier for the Powerlines command being executed
405
+ */
406
+ command: "prepare";
407
+ };
408
+ type BuildInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
409
+ /**
410
+ * A string identifier for the Powerlines command being executed
411
+ */
412
+ command: "build";
413
+ };
414
+ type LintInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
415
+ /**
416
+ * A string identifier for the Powerlines command being executed
417
+ */
418
+ command: "lint";
419
+ };
420
+ type DocsInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
421
+ /**
422
+ * A string identifier for the Powerlines command being executed
423
+ */
424
+ command: "docs";
425
+ };
426
+ type DeployInlineConfig<TUserConfig extends UserConfig$1 = UserConfig$1> = InlineConfig<TUserConfig> & {
427
+ /**
428
+ * A string identifier for the Powerlines command being executed
429
+ */
430
+ command: "deploy";
431
+ };
378
432
  //#endregion
379
- export { EnvironmentConfig, InlineConfig, LogFn, OutputConfig, PluginConfig, UserConfig, WebpackUserConfig, WorkspaceConfig };
433
+ export { 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,7 @@
1
1
  import { ResolveOptions, VirtualFile, VirtualFileSystemInterface, WriteOptions } from "./fs.cjs";
2
2
  import { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.cjs";
3
+ import { HooksList, InferHooksListItem } from "./hooks.cjs";
4
+ import { Plugin } from "./plugin.cjs";
3
5
  import { ParsedTypeScriptConfig } from "./tsconfig.cjs";
4
6
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.cjs";
5
7
  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 { EnvironmentResolvedConfig, ResolvedConfig, ResolvedEntryTypeDefinition } from "./resolved.mjs";
3
- import "./plugin.mjs";
3
+ import { HooksList, InferHooksListItem } from "./hooks.mjs";
4
+ import { Plugin } from "./plugin.mjs";
4
5
  import { ParsedTypeScriptConfig } from "./tsconfig.mjs";
5
6
  import { InlineConfig, LogFn, UserConfig, WorkspaceConfig } from "./config.mjs";
6
- import "./hooks.mjs";
7
7
  import { ExternalIdResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage } from "unplugin";
8
8
  import { Project } from "ts-morph";
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 { 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 };
@@ -9,11 +9,12 @@ const PLUGIN_NON_HOOK_FIELDS = [
9
9
  "dedupe",
10
10
  "applyToEnvironment"
11
11
  ];
12
- const KNOWN_HOOKS = [
12
+ const PLUGIN_HOOKS_FIELDS = [
13
13
  ...require_commands.SUPPORTED_COMMANDS,
14
14
  "config",
15
15
  "configEnvironment",
16
16
  "configResolved",
17
+ "types",
17
18
  "buildStart",
18
19
  "buildEnd",
19
20
  "transform",
@@ -23,10 +24,10 @@ const KNOWN_HOOKS = [
23
24
  ];
24
25
  const KNOWN_PLUGIN_FIELDS = [
25
26
  ...PLUGIN_NON_HOOK_FIELDS,
26
- ...KNOWN_HOOKS,
27
- ...require_build.UNPLUGIN_BUILD_VARIANTS
27
+ ...PLUGIN_HOOKS_FIELDS,
28
+ ...require_build.BUILDER_VARIANTS
28
29
  ];
29
30
 
30
31
  //#endregion
31
- exports.KNOWN_HOOKS = KNOWN_HOOKS;
32
+ exports.PLUGIN_HOOKS_FIELDS = PLUGIN_HOOKS_FIELDS;
32
33
  exports.PLUGIN_NON_HOOK_FIELDS = PLUGIN_NON_HOOK_FIELDS;