@powerlines/plugin-deepkit 0.11.1 → 0.11.2

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,8 +1,17 @@
1
1
  import "node:module";
2
2
  import { ArrayValues } from "@stryke/types/array";
3
- import { FunctionLike, MaybePromise, NonUndefined } from "@stryke/types/base";
3
+ import { AnyFunction, MaybePromise, NonUndefined } from "@stryke/types/base";
4
+ import { LoadResult, OutputOptions, RollupOptions } from "rollup";
4
5
  import { ExternalIdResult, HookFilter, TransformResult, UnpluginBuildContext, UnpluginContext, UnpluginMessage, UnpluginOptions } from "unplugin";
5
- import { PreviewOptions, ResolvedPreviewOptions } from "vite";
6
+ import { UserConfig } from "@farmfe/core";
7
+ import { Configuration } from "@rspack/core";
8
+ import { BuildOptions } from "@storm-software/tsup/types";
9
+ import { UnbuildOptions } from "@storm-software/unbuild/types";
10
+ import { BuildOptions as BuildOptions$1 } from "esbuild";
11
+ import { RolldownOptions } from "rolldown";
12
+ import { UserConfig as UserConfig$1 } from "tsdown";
13
+ import { DepOptimizationOptions, PreviewOptions, ResolvedPreviewOptions, UserConfig as UserConfig$2 } from "vite";
14
+ import { Configuration as Configuration$1 } from "webpack";
6
15
  import { EnvPaths } from "@stryke/env/get-env-paths";
7
16
  import { FetchRequestOptions } from "@stryke/http/fetch";
8
17
  import { PackageJson } from "@stryke/types/package-json";
@@ -25,7 +34,9 @@ import ts from "typescript";
25
34
  //#region rolldown:runtime
26
35
  //#endregion
27
36
  //#region ../powerlines/src/types/build.d.ts
28
- type UnpluginBuildVariant = "rollup" | "webpack" | "rspack" | "vite" | "esbuild" | "farm" | "unloader" | "rolldown";
37
+ type UnpluginBuilderVariant = "rollup" | "webpack" | "rspack" | "vite" | "esbuild" | "farm" | "unloader" | "rolldown" | "bun";
38
+ type BuilderVariant = UnpluginBuilderVariant | "tsup" | "tsdown" | "unbuild";
39
+ type InferUnpluginVariant<TBuildVariant extends BuilderVariant> = TBuildVariant extends "tsup" ? "esbuild" : TBuildVariant extends "tsdown" ? "rolldown" : TBuildVariant extends "unbuild" ? "rollup" : TBuildVariant;
29
40
  interface BuildConfig {
30
41
  /**
31
42
  * The platform to build the project for
@@ -166,6 +177,34 @@ interface BuildConfig {
166
177
  override?: Record<string, any>;
167
178
  }
168
179
  type BuildResolvedConfig = Omit<BuildConfig, "override">;
180
+ type ESBuildBuildConfig = Omit<BuildOptions$1, "entryPoints" | "sourceRoot" | "platform" | "outdir" | "env" | "assets" | "external" | "inject" | "tsconfig" | "tsconfigRaw" | "logLevel"> & BuildConfig;
181
+ type ESBuildResolvedBuildConfig = Omit<BuildOptions$1, "inject"> & BuildResolvedConfig;
182
+ type ViteBuildConfig = Omit<UserConfig$2, "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw" | "environments" | "output"> & BuildConfig & {
183
+ /**
184
+ * Optimize deps config
185
+ */
186
+ optimizeDeps?: Omit<DepOptimizationOptions, "extensions">;
187
+ };
188
+ type ViteResolvedBuildConfig = UserConfig$2 & BuildResolvedConfig;
189
+ type WebpackBuildConfig = Omit<Configuration$1, "name" | "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw"> & BuildConfig;
190
+ type WebpackResolvedBuildConfig = Configuration$1 & BuildResolvedConfig;
191
+ type RspackBuildConfig = Omit<Configuration, "name" | "entry" | "entryPoints" | "tsconfig" | "tsconfigRaw"> & BuildConfig;
192
+ type RspackResolvedBuildConfig = Configuration & BuildResolvedConfig;
193
+ type RollupBuildOutputConfig = Omit<OutputOptions, "dir" | "format">;
194
+ type RollupBuildConfig = Omit<RollupOptions, "entry" | "external" | "input" | "output" | "logLevel"> & {
195
+ output: RollupBuildOutputConfig | RollupBuildOutputConfig[];
196
+ } & BuildConfig;
197
+ type RollupResolvedBuildConfig = RollupOptions & BuildResolvedConfig;
198
+ type RolldownBuildConfig = Omit<RolldownOptions, "input" | "external" | "tsconfig" | "logLevel" | "output"> & BuildConfig;
199
+ type RolldownResolvedBuildConfig = RolldownOptions & BuildResolvedConfig;
200
+ type TsupBuildConfig = Partial<Omit<BuildOptions, "userOptions" | "tsconfig" | "tsconfigRaw" | "assets" | "outputPath" | "mode" | "format" | "platform" | "projectRoot" | "clean" | "env" | "entry" | "entryPoints" | "external" | "noExternal" | "skipNodeModulesBundle">> & BuildConfig;
201
+ type TsupResolvedBuildConfig = BuildOptions & BuildResolvedConfig;
202
+ type TsdownBuildConfig = Partial<Omit<UserConfig$1, "name" | "outDir" | "clean" | "cwd" | "tsconfig" | "publicDir" | "copy" | "alias" | "format" | "platform" | "env" | "define" | "entry" | "external" | "noExternal" | "skipNodeModulesBundle">> & BuildConfig;
203
+ type TsdownResolvedBuildConfig = UserConfig$1 & BuildResolvedConfig;
204
+ type UnbuildBuildConfig = Partial<Omit<UnbuildOptions, "tsconfig" | "tsconfigRaw" | "assets" | "outputPath" | "mode" | "format" | "platform" | "projectRoot" | "env" | "entry" | "entryPoints">> & BuildConfig;
205
+ type UnbuildResolvedBuildConfig = UnbuildOptions & BuildResolvedConfig;
206
+ type FarmBuildConfig = Partial<Omit<UserConfig, "tsconfig" | "tsconfigRaw" | "assets" | "outputPath" | "mode" | "format" | "platform" | "projectRoot" | "env" | "entry" | "entryPoints">> & BuildConfig;
207
+ type FarmResolvedBuildConfig = UserConfig & BuildResolvedConfig;
169
208
  //#endregion
170
209
  //#region ../powerlines/src/types/fs.d.ts
171
210
  type StoragePreset = "fs" | "virtual";
@@ -1040,7 +1079,7 @@ interface CommonUserConfig extends BaseConfig {
1040
1079
  */
1041
1080
  framework?: string;
1042
1081
  }
1043
- interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant$1 extends string = any> extends Omit<CommonUserConfig, "build"> {
1082
+ interface UserConfig$3<TBuildConfig extends BuildConfig = BuildConfig, TBuildResolvedConfig extends BuildResolvedConfig = BuildResolvedConfig, TBuildVariant extends string = any> extends Omit<CommonUserConfig, "build"> {
1044
1083
  /**
1045
1084
  * Configuration provided to build processes
1046
1085
  *
@@ -1051,7 +1090,7 @@ interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResol
1051
1090
  /**
1052
1091
  * The build variant being used by the Powerlines engine.
1053
1092
  */
1054
- variant?: TBuildVariant$1;
1093
+ variant?: TBuildVariant;
1055
1094
  /**
1056
1095
  * An optional set of override options to apply to the selected build variant.
1057
1096
  *
@@ -1061,16 +1100,98 @@ interface UserConfig<TBuildConfig extends BuildConfig = BuildConfig, TBuildResol
1061
1100
  override?: Partial<TBuildResolvedConfig>;
1062
1101
  };
1063
1102
  }
1103
+ type WebpackUserConfig = UserConfig$3<WebpackBuildConfig, WebpackResolvedBuildConfig, "webpack">;
1104
+ type RspackUserConfig = UserConfig$3<RspackBuildConfig, RspackResolvedBuildConfig, "rspack">;
1105
+ type RollupUserConfig = UserConfig$3<RollupBuildConfig, RollupResolvedBuildConfig, "rollup">;
1106
+ type RolldownUserConfig = UserConfig$3<RolldownBuildConfig, RolldownResolvedBuildConfig, "rolldown">;
1107
+ type ViteUserConfig = UserConfig$3<ViteBuildConfig, ViteResolvedBuildConfig, "vite">;
1108
+ type ESBuildUserConfig = UserConfig$3<ESBuildBuildConfig, ESBuildResolvedBuildConfig, "esbuild">;
1109
+ type UnbuildUserConfig = UserConfig$3<UnbuildBuildConfig, UnbuildResolvedBuildConfig, "unbuild">;
1110
+ type TsupUserConfig = UserConfig$3<TsupBuildConfig, TsupResolvedBuildConfig, "tsup">;
1111
+ type TsdownUserConfig = UserConfig$3<TsdownBuildConfig, TsdownResolvedBuildConfig, "tsdown">;
1112
+ type FarmUserConfig = UserConfig$3<FarmBuildConfig, FarmResolvedBuildConfig, "farm">;
1064
1113
  type PowerlinesCommand = "new" | "prepare" | "build" | "lint" | "test" | "docs" | "deploy" | "clean";
1065
1114
  /**
1066
1115
  * The configuration provided while executing Powerlines commands.
1067
1116
  */
1068
- type InlineConfig<TUserConfig extends UserConfig = UserConfig> = Partial<TUserConfig> & {
1117
+ type InlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = Partial<TUserConfig> & {
1069
1118
  /**
1070
1119
  * A string identifier for the Powerlines command being executed
1071
1120
  */
1072
1121
  command: PowerlinesCommand;
1073
1122
  };
1123
+ type NewInlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = InlineConfig<TUserConfig> & Required<Pick<InlineConfig<TUserConfig>, "root">> & {
1124
+ /**
1125
+ * A string identifier for the Powerlines command being executed
1126
+ */
1127
+ command: "new";
1128
+ /**
1129
+ * 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
1130
+ */
1131
+ packageName?: string;
1132
+ };
1133
+ type CleanInlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = InlineConfig<TUserConfig> & {
1134
+ /**
1135
+ * A string identifier for the Powerlines command being executed
1136
+ */
1137
+ command: "clean";
1138
+ };
1139
+ type PrepareInlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = InlineConfig<TUserConfig> & {
1140
+ /**
1141
+ * A string identifier for the Powerlines command being executed
1142
+ */
1143
+ command: "prepare";
1144
+ };
1145
+ type BuildInlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = InlineConfig<TUserConfig> & {
1146
+ /**
1147
+ * A string identifier for the Powerlines command being executed
1148
+ */
1149
+ command: "build";
1150
+ };
1151
+ type LintInlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = InlineConfig<TUserConfig> & {
1152
+ /**
1153
+ * A string identifier for the Powerlines command being executed
1154
+ */
1155
+ command: "lint";
1156
+ };
1157
+ type DocsInlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = InlineConfig<TUserConfig> & {
1158
+ /**
1159
+ * A string identifier for the Powerlines command being executed
1160
+ */
1161
+ command: "docs";
1162
+ };
1163
+ type DeployInlineConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = InlineConfig<TUserConfig> & {
1164
+ /**
1165
+ * A string identifier for the Powerlines command being executed
1166
+ */
1167
+ command: "deploy";
1168
+ };
1169
+ //#endregion
1170
+ //#region ../powerlines/src/types/hooks.d.ts
1171
+ type HookListOrders = "preOrdered" | "preEnforced" | "normal" | "postEnforced" | "postOrdered";
1172
+ 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 | {
1173
+ handler: infer THandler;
1174
+ } ? THandler extends ((this: infer THandlerOriginalContext, ...args: infer THandlerArgs) => infer THandlerReturn) ? (this: THandlerOriginalContext & WithUnpluginBuildContext<TContext>, ...args: THandlerArgs) => THandlerReturn : THandler extends {
1175
+ handler: infer THandlerFunction;
1176
+ } ? THandlerFunction extends ((this: infer THandlerFunctionOriginalContext, ...args: infer THandlerFunctionArgs) => infer THandlerFunctionReturn) ? (this: THandlerFunctionOriginalContext & WithUnpluginBuildContext<TContext>, ...args: THandlerFunctionArgs) => THandlerFunctionReturn : never : never : never;
1177
+ interface PluginHooksListItem<TContext extends PluginContext = PluginContext, TFields extends PluginHookFields<TContext> = PluginHookFields<TContext>> {
1178
+ plugin: Plugin<TContext>;
1179
+ handler: PluginHookFunctions<TContext>[TFields];
1180
+ }
1181
+ type PluginHooksList<TContext extends PluginContext = PluginContext, TFields extends PluginHookFields<TContext> = PluginHookFields<TContext>> = { [TKey in HookListOrders]?: PluginHooksListItem<TContext, TFields>[] | undefined };
1182
+ interface UnpluginHooksListItem<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant, TField$1 extends keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1] = keyof Required<UnpluginOptions>[TUnpluginBuilderVariant$1]> {
1183
+ plugin: Plugin<TContext>;
1184
+ handler: UnpluginHookFunctions<TContext, TUnpluginBuilderVariant$1, TField$1>;
1185
+ }
1186
+ 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 };
1187
+ type UnpluginHookVariantField<TContext extends PluginContext = PluginContext, TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant> = { [TKey in keyof UnpluginOptions[TUnpluginBuilderVariant$1]]?: UnpluginHookList<TContext, TUnpluginBuilderVariant$1, TKey> };
1188
+ type UnpluginHookVariant<TContext extends PluginContext = PluginContext> = { [TKey in UnpluginBuilderVariant]?: UnpluginHookVariantField<TContext, TKey> };
1189
+ type HookFields<TContext extends PluginContext = PluginContext> = PluginHookFields<TContext> | UnpluginBuilderVariant;
1190
+ type HooksList<TContext extends PluginContext = PluginContext> = { [TField in HookFields<TContext>]?: TField extends PluginHookFields<TContext> ? PluginHooksList<TContext, TField> : TField extends UnpluginBuilderVariant ? UnpluginHookVariant<TContext>[TField] : never };
1191
+ 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;
1192
+ 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;
1193
+ type InferHookReturnType<TContext extends PluginContext, TKey$1 extends string> = ReturnType<InferHookFunction<TContext, TKey$1>>;
1194
+ type InferHookParameters<TContext extends PluginContext, TKey$1 extends string> = Parameters<InferHookFunction<TContext, TKey$1>>;
1074
1195
  //#endregion
1075
1196
  //#region ../powerlines/src/types/resolved.d.ts
1076
1197
  interface ResolvedEntryTypeDefinition extends TypeDefinition {
@@ -1100,7 +1221,7 @@ type OutputResolvedConfig = Required<Omit<OutputConfig, "assets" | "storage"> &
1100
1221
  /**
1101
1222
  * The resolved options for the Powerlines project configuration.
1102
1223
  */
1103
- type ResolvedConfig<TUserConfig extends UserConfig = UserConfig> = Omit<TUserConfig, "name" | "title" | "organization" | "compatibilityDate" | "plugins" | "mode" | "environments" | "platform" | "tsconfig" | "lint" | "test" | "build" | "transform" | "deploy" | "variant" | "type" | "output" | "logLevel" | "framework" | "sourceRoot"> & Required<Pick<TUserConfig, "name" | "title" | "organization" | "compatibilityDate" | "plugins" | "mode" | "environments" | "tsconfig" | "lint" | "test" | "build" | "transform" | "deploy" | "framework" | "sourceRoot">> & {
1224
+ type ResolvedConfig<TUserConfig extends UserConfig$3 = UserConfig$3> = Omit<TUserConfig, "name" | "title" | "organization" | "compatibilityDate" | "plugins" | "mode" | "environments" | "platform" | "tsconfig" | "lint" | "test" | "build" | "transform" | "deploy" | "variant" | "type" | "output" | "logLevel" | "framework" | "sourceRoot"> & Required<Pick<TUserConfig, "name" | "title" | "organization" | "compatibilityDate" | "plugins" | "mode" | "environments" | "tsconfig" | "lint" | "test" | "build" | "transform" | "deploy" | "framework" | "sourceRoot">> & {
1104
1225
  /**
1105
1226
  * The configuration options that were provided inline to the Powerlines CLI.
1106
1227
  */
@@ -1135,7 +1256,7 @@ type ResolvedConfig<TUserConfig extends UserConfig = UserConfig> = Omit<TUserCon
1135
1256
  * Configuration provided to build processes
1136
1257
  *
1137
1258
  * @remarks
1138
- * This configuration can be used by plugins during the `build` command. It will generally contain options specific to the selected {@link BuildVariant | build variant}.
1259
+ * This configuration can be used by plugins during the `build` command. It will generally contain options specific to the selected {@link BuilderVariant | build variant}.
1139
1260
  */
1140
1261
  build: Omit<TUserConfig["build"], "override"> & Required<Pick<Required<TUserConfig["build"]>, "override">>;
1141
1262
  /**
@@ -1145,6 +1266,17 @@ type ResolvedConfig<TUserConfig extends UserConfig = UserConfig> = Omit<TUserCon
1145
1266
  */
1146
1267
  logLevel: "error" | "warn" | "info" | "debug" | "trace" | null;
1147
1268
  };
1269
+ type ViteResolvedConfig = ResolvedConfig<ViteUserConfig>;
1270
+ type WebpackResolvedConfig = ResolvedConfig<WebpackUserConfig>;
1271
+ type RspackResolvedConfig = ResolvedConfig<RspackUserConfig>;
1272
+ type ESBuildResolvedConfig = ResolvedConfig<ESBuildUserConfig>;
1273
+ type RollupResolvedConfig = ResolvedConfig<RollupUserConfig>;
1274
+ type RolldownResolvedConfig = ResolvedConfig<RolldownUserConfig>;
1275
+ type TsupResolvedConfig = ResolvedConfig<TsupUserConfig>;
1276
+ type TsdownResolvedConfig = ResolvedConfig<TsdownUserConfig>;
1277
+ type UnbuildResolvedConfig = ResolvedConfig<UnbuildUserConfig>;
1278
+ type FarmResolvedConfig = ResolvedConfig<FarmUserConfig>;
1279
+ type InferResolvedConfig<TBuildVariant extends BuilderVariant | undefined> = TBuildVariant extends undefined ? ResolvedConfig : TBuildVariant extends "webpack" ? WebpackResolvedConfig : TBuildVariant extends "rspack" ? RspackResolvedConfig : TBuildVariant extends "vite" ? ViteResolvedConfig : TBuildVariant extends "esbuild" ? ESBuildResolvedConfig : TBuildVariant extends "unbuild" ? UnbuildResolvedConfig : TBuildVariant extends "tsup" ? TsupResolvedConfig : TBuildVariant extends "tsdown" ? TsdownResolvedConfig : TBuildVariant extends "rolldown" ? RolldownResolvedConfig : TBuildVariant extends "rollup" ? RollupResolvedConfig : TBuildVariant extends "farm" ? FarmResolvedConfig : ResolvedConfig;
1148
1280
  //#endregion
1149
1281
  //#region ../powerlines/src/types/context.d.ts
1150
1282
  interface MetaInfo {
@@ -1180,6 +1312,9 @@ interface TransformResult$1 {
1180
1312
  code: string;
1181
1313
  map: SourceMap | null;
1182
1314
  }
1315
+ interface SelectHooksOptions {
1316
+ order?: "pre" | "post" | "normal";
1317
+ }
1183
1318
  /**
1184
1319
  * Options for initializing or updating the context with new configuration values
1185
1320
  */
@@ -1484,7 +1619,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
1484
1619
  /**
1485
1620
  * A function to update the context fields using a new user configuration options
1486
1621
  */
1487
- withUserConfig: (userConfig: UserConfig, options?: InitContextOptions) => Promise<void>;
1622
+ withUserConfig: (userConfig: UserConfig$3, options?: InitContextOptions) => Promise<void>;
1488
1623
  /**
1489
1624
  * A function to update the context fields using inline configuration options
1490
1625
  */
@@ -1516,6 +1651,112 @@ type Context<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = Omit<Unr
1516
1651
  */
1517
1652
  config: TResolvedConfig;
1518
1653
  };
1654
+ interface APIContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
1655
+ /**
1656
+ * The expected plugins options for the Powerlines project.
1657
+ *
1658
+ * @remarks
1659
+ * 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.
1660
+ */
1661
+ plugins: Plugin<PluginContext<TResolvedConfig>>[];
1662
+ /**
1663
+ * A function to add a plugin to the context and update the configuration options
1664
+ */
1665
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
1666
+ /**
1667
+ * A table for storing the current context for each configured environment
1668
+ */
1669
+ environments: Record<string, EnvironmentContext<TResolvedConfig>>;
1670
+ /**
1671
+ * Retrieves the context for a specific environment by name
1672
+ *
1673
+ * @throws Will throw an error if the environment does not exist
1674
+ *
1675
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
1676
+ * @returns A promise that resolves to the environment context.
1677
+ *
1678
+ * @example
1679
+ * ```ts
1680
+ * const devEnv = await apiContext.getEnvironment("development");
1681
+ * const defaultEnv = await apiContext.getEnvironment();
1682
+ * ```
1683
+ */
1684
+ getEnvironment: (name?: string) => Promise<EnvironmentContext<TResolvedConfig>>;
1685
+ /**
1686
+ * Safely retrieves the context for a specific environment by name
1687
+ *
1688
+ * @param name - The name of the environment to retrieve. If not provided, the default environment is returned.
1689
+ * @returns A promise that resolves to the environment context, or undefined if the environment does not exist.
1690
+ *
1691
+ * @example
1692
+ * ```ts
1693
+ * const devEnv = await apiContext.getEnvironmentSafe("development");
1694
+ * const defaultEnv = await apiContext.getEnvironmentSafe();
1695
+ * ```
1696
+ *
1697
+ * @remarks
1698
+ * This method is similar to `getEnvironment`, but it returns `undefined` instead of throwing an error if the specified environment does not exist.
1699
+ * This can be useful in scenarios where the existence of an environment is optional or uncertain.
1700
+ *
1701
+ * ```ts
1702
+ * const testEnv = await apiContext.getEnvironmentSafe("test");
1703
+ * if (testEnv) {
1704
+ * // Environment exists, safe to use it
1705
+ * } else {
1706
+ * // Environment does not exist, handle accordingly
1707
+ * }
1708
+ * ```
1709
+ *
1710
+ * Using this method helps avoid unhandled exceptions in cases where an environment might not be defined.
1711
+ */
1712
+ getEnvironmentSafe: (name?: string) => Promise<EnvironmentContext<TResolvedConfig> | undefined>;
1713
+ /**
1714
+ * A function to copy the context and update the fields for a specific environment
1715
+ *
1716
+ * @param environment - The environment configuration to use.
1717
+ * @returns A new context instance with the updated environment.
1718
+ */
1719
+ in: (environment: EnvironmentResolvedConfig) => Promise<EnvironmentContext<TResolvedConfig>>;
1720
+ /**
1721
+ * A function to merge all configured environments into a single context
1722
+ *
1723
+ * @returns A promise that resolves to the merged environment context.
1724
+ */
1725
+ toEnvironment: () => Promise<EnvironmentContext<TResolvedConfig>>;
1726
+ }
1727
+ interface EnvironmentContextPlugin<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
1728
+ plugin: Plugin<PluginContext<TResolvedConfig>>;
1729
+ context: PluginContext<TResolvedConfig>;
1730
+ }
1731
+ type SelectHookResultItem<TContext extends PluginContext, TKey$1 extends string> = InferHooksListItem<TContext, TKey$1> & {
1732
+ context: TContext;
1733
+ };
1734
+ type SelectHookResult<TContext extends PluginContext, TKey$1 extends string> = SelectHookResultItem<TContext, TKey$1>[];
1735
+ interface EnvironmentContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig> {
1736
+ /**
1737
+ * The expected plugins options for the Powerlines project.
1738
+ *
1739
+ * @remarks
1740
+ * 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.
1741
+ */
1742
+ plugins: EnvironmentContextPlugin<TResolvedConfig>[];
1743
+ /**
1744
+ * A function to add a plugin to the context and update the configuration options
1745
+ */
1746
+ addPlugin: (plugin: Plugin<PluginContext<TResolvedConfig>>) => Promise<void>;
1747
+ /**
1748
+ * The environment specific resolved configuration
1749
+ */
1750
+ environment: EnvironmentResolvedConfig;
1751
+ /**
1752
+ * A table holding references to hook functions registered by plugins
1753
+ */
1754
+ hooks: HooksList<PluginContext<TResolvedConfig>>;
1755
+ /**
1756
+ * Retrieves the hook handlers for a specific hook name
1757
+ */
1758
+ selectHooks: <TKey$1 extends string>(key: TKey$1, options?: SelectHooksOptions) => SelectHookResult<PluginContext<TResolvedConfig>, TKey$1>;
1759
+ }
1519
1760
  interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedConfig> extends Context<TResolvedConfig>, UnpluginContext {
1520
1761
  /**
1521
1762
  * The environment specific resolved configuration
@@ -1530,13 +1771,166 @@ interface PluginContext<out TResolvedConfig extends ResolvedConfig = ResolvedCon
1530
1771
  logger: LogFn;
1531
1772
  }
1532
1773
  type BuildPluginContext<TResolvedConfig extends ResolvedConfig = ResolvedConfig> = UnpluginBuildContext & PluginContext<TResolvedConfig>;
1774
+ type WithUnpluginBuildContext<TContext extends PluginContext> = UnpluginBuildContext & TContext;
1533
1775
  //#endregion
1534
1776
  //#region ../powerlines/src/types/commands.d.ts
1535
1777
  declare const SUPPORTED_COMMANDS: readonly ["new", "clean", "prepare", "lint", "test", "build", "docs", "deploy", "finalize"];
1536
1778
  type CommandType = ArrayValues<typeof SUPPORTED_COMMANDS>;
1537
1779
  //#endregion
1780
+ //#region ../powerlines/src/internal/helpers/hooks.d.ts
1781
+ type CallHookOptions = SelectHooksOptions & (({
1782
+ /**
1783
+ * Whether to call the hooks sequentially or in parallel.
1784
+ *
1785
+ * @defaultValue true
1786
+ */
1787
+ sequential?: true;
1788
+ } & ({
1789
+ /**
1790
+ * How to handle multiple return values from hooks.
1791
+ * - "merge": Merge all non-undefined return values (if they are objects).
1792
+ * - "first": Return the first non-undefined value.
1793
+ *
1794
+ * @remarks
1795
+ * Merging only works if the return values are objects.
1796
+ *
1797
+ * @defaultValue "merge"
1798
+ */
1799
+ result: "first";
1800
+ } | {
1801
+ /**
1802
+ * How to handle multiple return values from hooks.
1803
+ * - "merge": Merge all non-undefined return values (if they are objects).
1804
+ * - "first": Return the first non-undefined value.
1805
+ *
1806
+ * @remarks
1807
+ * Merging only works if the return values are objects.
1808
+ *
1809
+ * @defaultValue "merge"
1810
+ */
1811
+ result?: "merge" | "last";
1812
+ /**
1813
+ * An indicator specifying if the results of the previous hook should be provided as the **first** parameter of the next hook function, or a function to process the result of the previous hook function and pass the returned value as the next hook's **first** parameter
1814
+ */
1815
+ asNextParam?: false | ((previousResult: any) => MaybePromise<any>);
1816
+ })) | {
1817
+ /**
1818
+ * Whether to call the hooks sequentially or in parallel.
1819
+ */
1820
+ sequential: false;
1821
+ });
1822
+ //#endregion
1823
+ //#region ../powerlines/src/types/api.d.ts
1824
+ /**
1825
+ * Powerlines API Interface
1826
+ */
1827
+ interface API<TResolvedConfig extends ResolvedConfig = ResolvedConfig> {
1828
+ /**
1829
+ * The Powerlines shared API context
1830
+ */
1831
+ context: APIContext<TResolvedConfig>;
1832
+ /**
1833
+ * Prepare the Powerlines API
1834
+ *
1835
+ * @remarks
1836
+ * This method will prepare the Powerlines API for use, initializing any necessary resources.
1837
+ *
1838
+ * @param inlineConfig - The inline configuration for the prepare command
1839
+ */
1840
+ prepare: (inlineConfig: PrepareInlineConfig | NewInlineConfig | CleanInlineConfig | BuildInlineConfig | LintInlineConfig | DocsInlineConfig | DeployInlineConfig) => Promise<void>;
1841
+ /**
1842
+ * Create a new Powerlines project
1843
+ *
1844
+ * @remarks
1845
+ * This method will create a new Powerlines project in the current directory.
1846
+ *
1847
+ * @param inlineConfig - The inline configuration for the new command
1848
+ * @returns A promise that resolves when the project has been created
1849
+ */
1850
+ new: (inlineConfig: NewInlineConfig) => Promise<void>;
1851
+ /**
1852
+ * Clean any previously prepared artifacts
1853
+ *
1854
+ * @remarks
1855
+ * This method will remove the previous Powerlines artifacts from the project.
1856
+ *
1857
+ * @param inlineConfig - The inline configuration for the clean command
1858
+ * @returns A promise that resolves when the clean command has completed
1859
+ */
1860
+ clean: (inlineConfig: CleanInlineConfig | PrepareInlineConfig) => Promise<void>;
1861
+ /**
1862
+ * Lint the project source code
1863
+ *
1864
+ * @param inlineConfig - The inline configuration for the lint command
1865
+ * @returns A promise that resolves when the lint command has completed
1866
+ */
1867
+ lint: (inlineConfig: LintInlineConfig) => Promise<void>;
1868
+ /**
1869
+ * Build the project
1870
+ *
1871
+ * @remarks
1872
+ * This method will build the Powerlines project, generating the necessary artifacts.
1873
+ *
1874
+ * @param inlineConfig - The inline configuration for the build command
1875
+ * @returns A promise that resolves when the build command has completed
1876
+ */
1877
+ build: (inlineConfig: BuildInlineConfig) => Promise<void>;
1878
+ /**
1879
+ * Prepare the documentation for the project
1880
+ *
1881
+ * @param inlineConfig - The inline configuration for the docs command
1882
+ * @returns A promise that resolves when the documentation generation has completed
1883
+ */
1884
+ docs: (inlineConfig: DocsInlineConfig) => Promise<void>;
1885
+ /**
1886
+ * Deploy the project source code
1887
+ *
1888
+ * @remarks
1889
+ * This method will prepare and build the Powerlines project, generating the necessary artifacts for the deployment.
1890
+ *
1891
+ * @param inlineConfig - The inline configuration for the deploy command
1892
+ */
1893
+ deploy: (inlineConfig: DeployInlineConfig) => Promise<void>;
1894
+ /**
1895
+ * Finalization process
1896
+ *
1897
+ * @remarks
1898
+ * This step includes any final processes or clean up required by Powerlines. It will be run after each Powerlines command.
1899
+ *
1900
+ * @returns A promise that resolves when the finalization process has completed
1901
+ */
1902
+ finalize: () => Promise<void>;
1903
+ /**
1904
+ * Invokes the configured plugin hooks
1905
+ *
1906
+ * @remarks
1907
+ * By default, it will call the `"pre"`, `"normal"`, and `"post"` ordered hooks in sequence
1908
+ *
1909
+ * @param hook - The hook to call
1910
+ * @param options - The options to provide to the hook
1911
+ * @param args - The arguments to pass to the hook
1912
+ * @returns The result of the hook call
1913
+ */
1914
+ callHook: <TKey$1 extends string>(hook: TKey$1, options: CallHookOptions & {
1915
+ environment?: string | EnvironmentContext<TResolvedConfig>;
1916
+ }, ...args: InferHookParameters<PluginContext<TResolvedConfig>, TKey$1>) => Promise<InferHookReturnType<PluginContext<TResolvedConfig>, TKey$1> | undefined>;
1917
+ }
1918
+ //#endregion
1919
+ //#region ../powerlines/src/types/unplugin.d.ts
1920
+ interface UnpluginOptions$1<TUnpluginBuilderVariant$1 extends UnpluginBuilderVariant = UnpluginBuilderVariant> extends UnpluginOptions {
1921
+ /**
1922
+ * An API object that can be used for inter-plugin communication.
1923
+ *
1924
+ * @see https://rollupjs.org/plugin-development/#direct-plugin-communication
1925
+ */
1926
+ api: API<InferResolvedConfig<TUnpluginBuilderVariant$1>>;
1927
+ }
1928
+ type InferUnpluginOptions<TContext extends Context = Context, TBuilderVariant$1 extends BuilderVariant = BuilderVariant, TUnpluginVariant extends InferUnpluginVariant<TBuilderVariant$1> = InferUnpluginVariant<TBuilderVariant$1>> = { [TKey in keyof Required<UnpluginOptions$1<TUnpluginVariant>>[TUnpluginVariant]]?: Required<UnpluginOptions$1<TUnpluginVariant>>[TUnpluginVariant][TKey] extends infer THandler | {
1929
+ handler: infer THandler;
1930
+ } ? THandler extends ((this: infer TOriginalContext, ...args: infer TArgs) => infer TReturn) ? PluginHook<(this: TOriginalContext & TContext, ...args: TArgs) => MaybePromise<TReturn>, keyof HookFilter> : Required<UnpluginOptions$1<TUnpluginVariant>>[TUnpluginVariant][TKey] : Required<UnpluginOptions$1<TUnpluginVariant>>[TUnpluginVariant][TKey] };
1931
+ //#endregion
1538
1932
  //#region ../powerlines/src/types/plugin.d.ts
1539
- interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> {
1933
+ interface PluginHookObject<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> {
1540
1934
  /**
1541
1935
  * The order in which the plugin should be applied.
1542
1936
  */
@@ -1550,7 +1944,7 @@ interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends k
1550
1944
  */
1551
1945
  handler: THookFunction;
1552
1946
  }
1553
- type PluginHook<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
1947
+ type PluginHook<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
1554
1948
  /**
1555
1949
  * A result returned by the plugin from the `types` hook that describes the declaration types output file.
1556
1950
  */
@@ -1558,9 +1952,7 @@ interface TypesResult {
1558
1952
  directives?: string[];
1559
1953
  code: string;
1560
1954
  }
1561
- type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
1562
- type ConfigResult<TContext extends PluginContext = PluginContext> = DeepPartial<TContext["config"]> & Record<string, any>;
1563
- interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext> extends Record<CommandType, (this: TContext) => MaybePromise<void>> {
1955
+ type PluginHookFunctions<TContext extends PluginContext> = { [TCommandType in CommandType]: (this: TContext) => MaybePromise<void> } & {
1564
1956
  /**
1565
1957
  * A function that returns configuration options to be merged with the build context's options.
1566
1958
  *
@@ -1575,7 +1967,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
1575
1967
  * @param config - The partial configuration object to be modified.
1576
1968
  * @returns A promise that resolves to a partial configuration object.
1577
1969
  */
1578
- config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>;
1970
+ config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>;
1579
1971
  /**
1580
1972
  * 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.
1581
1973
  *
@@ -1637,7 +2029,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
1637
2029
  * @param id - The identifier of the source code.
1638
2030
  * @returns A promise that resolves when the hook is complete.
1639
2031
  */
1640
- load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>;
2032
+ load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<LoadResult>;
1641
2033
  /**
1642
2034
  * A hook that is called to resolve the identifier of the source code.
1643
2035
  *
@@ -1657,56 +2049,14 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
1657
2049
  * @returns A promise that resolves when the hook is complete.
1658
2050
  */
1659
2051
  writeBundle: (this: TContext) => MaybePromise<void>;
1660
- }
1661
- 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] };
1662
- type PluginHooks<TContext extends PluginContext = PluginContext> = { [TKey in keyof BasePluginHookFunctions<TContext>]: PluginHook<BasePluginHookFunctions<TContext>[TKey]> } & {
1663
- /**
1664
- * A function that returns configuration options to be merged with the build context's options.
1665
- *
1666
- * @remarks
1667
- * 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.
1668
- *
1669
- * @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.
1670
- *
1671
- * @see https://vitejs.dev/guide/api-plugin#config
1672
- *
1673
- * @param this - The build context.
1674
- * @param config - The partial configuration object to be modified.
1675
- * @returns A promise that resolves to a partial configuration object.
1676
- */
1677
- config: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>> | ConfigResult<TContext>;
1678
- /**
1679
- * A hook that is called to transform the source code.
1680
- *
1681
- * @param this - The build context, unplugin build context, and unplugin context.
1682
- * @param code - The source code to transform.
1683
- * @param id - The identifier of the source code.
1684
- * @returns A promise that resolves when the hook is complete.
1685
- */
1686
- transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>, "code" | "id">;
1687
- /**
1688
- * A hook that is called to load the source code.
1689
- *
1690
- * @param this - The build context, unplugin build context, and unplugin context.
1691
- * @param id - The identifier of the source code.
1692
- * @returns A promise that resolves when the hook is complete.
1693
- */
1694
- load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>, "id">;
1695
- /**
1696
- * A hook that is called to resolve the identifier of the source code.
1697
- *
1698
- * @param this - The build context, unplugin build context, and unplugin context.
1699
- * @param id - The identifier of the source code.
1700
- * @param importer - The importer of the source code.
1701
- * @param options - The options for resolving the identifier.
1702
- * @returns A promise that resolves when the hook is complete.
1703
- */
1704
- resolveId: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
1705
- isEntry: boolean;
1706
- }) => MaybePromise<string | ExternalIdResult | null | undefined>, "id">;
1707
2052
  };
1708
- type PluginBuildPlugins<TContext extends PluginContext = PluginContext> = { [TBuildVariant in UnpluginBuildVariant]?: BuildPlugin<TContext, TBuildVariant> };
1709
- interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> extends Partial<PluginHooks<TContext>>, PluginBuildPlugins<TContext> {
2053
+ type PluginHooks<TContext extends PluginContext> = { [TPluginHook in keyof PluginHookFunctions<TContext>]?: PluginHook<PluginHookFunctions<TContext>[TPluginHook]> } & {
2054
+ transform: PluginHook<PluginHookFunctions<TContext>["transform"], "code" | "id">;
2055
+ load: PluginHook<PluginHookFunctions<TContext>["load"], "id">;
2056
+ resolveId: PluginHook<PluginHookFunctions<TContext>["resolveId"], "id">;
2057
+ };
2058
+ type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
2059
+ type Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> = Partial<PluginHooks<TContext>> & {
1710
2060
  /**
1711
2061
  * The name of the plugin, for use in deduplication, error messages and logs.
1712
2062
  */
@@ -1754,7 +2104,23 @@ interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<
1754
2104
  * @returns `true` if the plugin should be active in the specified environment, `false` otherwise.
1755
2105
  */
1756
2106
  applyToEnvironment?: (environment: EnvironmentResolvedConfig) => boolean | PluginConfig<TContext>;
1757
- }
2107
+ /**
2108
+ * A function that returns configuration options to be merged with the build context's options.
2109
+ *
2110
+ * @remarks
2111
+ * 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.
2112
+ *
2113
+ * @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.
2114
+ *
2115
+ * @see https://vitejs.dev/guide/api-plugin#config
2116
+ *
2117
+ * @param this - The build context.
2118
+ * @param config - The partial configuration object to be modified.
2119
+ * @returns A promise that resolves to a partial configuration object.
2120
+ */
2121
+ config?: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>> | (DeepPartial<TContext["config"]> & Record<string, any>);
2122
+ } & { [TBuilderVariant in BuilderVariant]?: InferUnpluginOptions<TContext, TBuilderVariant> };
2123
+ type PluginHookFields<TContext extends PluginContext = PluginContext> = keyof PluginHookFunctions<TContext>;
1758
2124
  import * as import___deepkit_type_compiler_config from "@deepkit/type-compiler/config";
1759
2125
  //#endregion
1760
2126
  //#region ../plugin-tsc/src/types/plugin.d.ts
@@ -1766,7 +2132,7 @@ type TypeScriptCompilerPluginOptions = Partial<Omit<ts.TranspileOptions, "fileNa
1766
2132
  */
1767
2133
  typeCheck?: boolean;
1768
2134
  };
1769
- interface TypeScriptCompilerPluginUserConfig extends UserConfig {
2135
+ interface TypeScriptCompilerPluginUserConfig extends UserConfig$3 {
1770
2136
  transform: {
1771
2137
  /**
1772
2138
  * TypeScript Compiler transformation options