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