@powerlines/plugin-env 0.15.9 → 0.15.10

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 (68) hide show
  1. package/dist/babel/plugin.cjs +1 -1
  2. package/dist/babel/plugin.mjs +1 -1
  3. package/dist/helpers/load.cjs +2 -2
  4. package/dist/helpers/load.mjs +1 -1
  5. package/dist/index.cjs +2 -2
  6. package/dist/index.mjs +2 -2
  7. package/dist/plugin-alloy/src/core/components/source-file.cjs +1 -1
  8. package/dist/plugin-alloy/src/core/components/source-file.mjs +1 -1
  9. package/dist/plugin-alloy/src/index.cjs +12 -5
  10. package/dist/plugin-alloy/src/index.mjs +12 -5
  11. package/dist/plugin-alloy/src/types/components.d.cts +1 -3
  12. package/dist/plugin-alloy/src/types/components.d.mts +2 -3
  13. package/dist/plugin-alloy/src/typescript/components/builtin-file.cjs +1 -1
  14. package/dist/plugin-alloy/src/typescript/components/builtin-file.mjs +1 -1
  15. package/dist/plugin-alloy/src/typescript/components/typescript-file.cjs +17 -11
  16. package/dist/plugin-alloy/src/typescript/components/typescript-file.d.cts +1 -0
  17. package/dist/plugin-alloy/src/typescript/components/typescript-file.d.mts +1 -0
  18. package/dist/plugin-alloy/src/typescript/components/typescript-file.mjs +17 -11
  19. package/dist/plugin-automd/src/index.cjs +2 -2
  20. package/dist/plugin-automd/src/index.mjs +1 -1
  21. package/dist/plugin-babel/src/helpers/module-helpers.cjs +1 -1
  22. package/dist/plugin-babel/src/helpers/module-helpers.mjs +1 -1
  23. package/dist/plugin-babel/src/index.cjs +4 -7
  24. package/dist/plugin-babel/src/index.mjs +2 -5
  25. package/dist/powerlines/src/api.d.mts +2 -2
  26. package/dist/powerlines/src/index.d.mts +8 -5
  27. package/dist/powerlines/src/internal/helpers/hooks.cjs +37 -19
  28. package/dist/powerlines/src/internal/helpers/hooks.d.cts +47 -0
  29. package/dist/powerlines/src/internal/helpers/hooks.d.mts +46 -2
  30. package/dist/powerlines/src/internal/helpers/hooks.mjs +37 -20
  31. package/dist/powerlines/src/lib/build/esbuild.cjs +2 -2
  32. package/dist/powerlines/src/lib/build/esbuild.mjs +2 -2
  33. package/dist/powerlines/src/lib/entry.cjs +1 -1
  34. package/dist/powerlines/src/lib/entry.mjs +1 -1
  35. package/dist/powerlines/src/types/api.cjs +62 -1
  36. package/dist/powerlines/src/types/api.d.cts +104 -0
  37. package/dist/powerlines/src/types/api.d.mts +104 -5
  38. package/dist/powerlines/src/types/api.mjs +61 -2
  39. package/dist/powerlines/src/types/build.cjs +26 -4
  40. package/dist/powerlines/src/types/build.d.cts +43 -3
  41. package/dist/powerlines/src/types/build.d.mts +42 -4
  42. package/dist/powerlines/src/types/build.mjs +23 -3
  43. package/dist/powerlines/src/types/config.cjs +107 -0
  44. package/dist/powerlines/src/types/config.d.cts +60 -4
  45. package/dist/powerlines/src/types/config.d.mts +61 -5
  46. package/dist/powerlines/src/types/config.mjs +99 -1
  47. package/dist/powerlines/src/types/context.cjs +57 -0
  48. package/dist/powerlines/src/types/context.d.cts +113 -1
  49. package/dist/powerlines/src/types/context.d.mts +113 -3
  50. package/dist/powerlines/src/types/context.mjs +54 -1
  51. package/dist/powerlines/src/types/hooks.cjs +33 -14
  52. package/dist/powerlines/src/types/hooks.d.cts +32 -0
  53. package/dist/powerlines/src/types/hooks.d.mts +32 -2
  54. package/dist/powerlines/src/types/hooks.mjs +32 -12
  55. package/dist/powerlines/src/types/index.cjs +3 -3
  56. package/dist/powerlines/src/types/index.d.mts +8 -8
  57. package/dist/powerlines/src/types/index.mjs +7 -7
  58. package/dist/powerlines/src/types/plugin.cjs +40 -105
  59. package/dist/powerlines/src/types/plugin.d.cts +35 -61
  60. package/dist/powerlines/src/types/plugin.d.mts +35 -61
  61. package/dist/powerlines/src/types/plugin.mjs +40 -102
  62. package/dist/powerlines/src/types/resolved.d.cts +16 -4
  63. package/dist/powerlines/src/types/resolved.d.mts +16 -5
  64. package/dist/powerlines/src/types/unplugin.cjs +47 -1
  65. package/dist/powerlines/src/types/unplugin.d.cts +22 -0
  66. package/dist/powerlines/src/types/unplugin.d.mts +22 -6
  67. package/dist/powerlines/src/types/unplugin.mjs +45 -2
  68. package/package.json +9 -9
@@ -1,4 +1,5 @@
1
1
  const require_build = require('./build.cjs');
2
+ const require_unplugin = require('./unplugin.cjs');
2
3
  const require_commands = require('./commands.cjs');
3
4
 
4
5
  //#region ../powerlines/src/types/plugin.ts
@@ -8,44 +9,17 @@ const __ΩPick = [
8
9
  "Pick",
9
10
  "l+e#!e\"!fRb!b\"Pde\"\"N#!w#y"
10
11
  ];
12
+ const __ΩPartial = [
13
+ "T",
14
+ "Partial",
15
+ "l+e#!e\"!fRb!Pde\"!gN#\"w\"y"
16
+ ];
11
17
  const __ΩRecord = [
12
18
  "K",
13
19
  "T",
14
20
  "Record",
15
21
  "l'e#\"Rb!b\"Pde\"!N#!w#y"
16
22
  ];
17
- const __ΩRequired = [
18
- "T",
19
- "Required",
20
- "l+e#!e\"!fRb!Pde\"!gN##w\"y"
21
- ];
22
- const __ΩThisParameterType = [
23
- "T",
24
- "this",
25
- "args",
26
- "",
27
- "ThisParameterType",
28
- "lAe\"!R#RPde#!Ph\"!2\"!@2#\"/$qk#'QRb!Pde\"!p)w%y"
29
- ];
30
- const __ΩParameters = [
31
- "T",
32
- "args",
33
- "",
34
- "Parameters",
35
- "l>e\"!R!RPde#!Ph\"!@2\"\"/#qk#'QRb!Pde\"!p)w$y"
36
- ];
37
- const __ΩReturnType = [
38
- "T",
39
- "args",
40
- "",
41
- "ReturnType",
42
- "l>e\"!R\"RPde#!P\"@2\"h\"!/#qk#'QRb!Pde\"!p)w$y"
43
- ];
44
- const __ΩPartial = [
45
- "T",
46
- "Partial",
47
- "l+e#!e\"!fRb!Pde\"!gN#\"w\"y"
48
- ];
49
23
  const __ΩPluginHookObject = [
50
24
  "THookFunction",
51
25
  "TFilter",
@@ -68,25 +42,8 @@ const __ΩPluginHook = [
68
42
  "PluginHook",
69
43
  "b!!c\"Pe\"!e\"!e\"\"o##Jw$y"
70
44
  ];
71
- const __ΩDeepPartial = [
72
- "T",
73
- 0,
74
- "DeepPartial",
75
- "l.e#!e\"!fo\"\"Rb!Pde\"!gN#\"w#y"
76
- ];
77
- const __ΩConfigResult = [
78
- "PluginContext",
45
+ const __ΩPluginHookFunctions = [
79
46
  "TContext",
80
- () => __ΩDeepPartial,
81
- "config",
82
- () => __ΩRecord,
83
- "ConfigResult",
84
- "\"w!c\"Pe\"!.$fo#\"&\"o%#Kw&y"
85
- ];
86
- const __ΩBasePluginHookFunctions = [
87
- "PluginContext",
88
- "TContext",
89
- () => __ΩRecord,
90
47
  "CommandType",
91
48
  "this",
92
49
  "",
@@ -120,74 +77,44 @@ const __ΩBasePluginHookFunctions = [
120
77
  "A hook that is called to resolve the identifier of the source code.",
121
78
  "writeBundle",
122
79
  "A hook that is called to write the bundle to disk.",
123
- "BasePluginHookFunctions",
124
- "\"w!c\"P\"w$Pe#!2%!/&o##P\"w'2%!/&4(?)Pe#!2%&2*\"w+2,!/&4-?.Pe#!2%!/&4/?0Pe#!2%&21!/&42?3PP\"w4e$!K2%!/&45?6PP\"w4e$!K2%!/&47?8PP\"w4e$!K2%&21&29!/&4:?;PP\"w4e$!K2%&29!/&4<?=PP\"w4e$!K2%&29P&-J2>P)4?M2@!/&4A?BPe#!2%!/&4C?DMwEy"
125
- ];
126
- const __ΩBuildPlugin = [
127
- "PluginContext",
128
- "TContext",
129
- "UnpluginBuildVariant",
130
- "TBuildVariant",
131
- () => __ΩRequired,
132
- "TOptions",
133
- () => __ΩThisParameterType,
134
- "this",
135
- () => __ΩParameters,
136
- "args",
137
- () => __ΩReturnType,
138
- "",
139
- "BuildPlugin",
140
- "liPPe'#e&!fo'\"e'!K2(e&#e%!fo)\"@2*Pe'#e&!fo+\"!J/,Re%#e$!fRPe$#e#!f!qk#RQR\"w!c\"\"w#c$!o%\"e!\"fc&Pde\"#gNZ!w-y"
80
+ "PluginHookFunctions",
81
+ "l-Pe%!2#!/$Rb!PPd\"w\"N#!PP\"w%2#!/$4&?'Pe$!2#&2(\"w)2*!/$4+?,Pe$!2#!/$4-?.Pe$!2#&2/!/$40?1PP\"w2e%!K2#!/$43?4PP\"w2e%!K2#!/$45?6PP\"w2e%!K2#&2/&27!/$48?9PP\"w2e%!K2#&27!/$4:?;PP\"w2e%!K2#&27P&-J2<P)4=M2>!/$4??@Pe$!2#!/$4A?BMKwCy"
141
82
  ];
142
83
  const __ΩPluginHooks = [
143
- "PluginContext",
144
84
  "TContext",
145
- () => __ΩBasePluginHookFunctions,
146
- () => __ΩPluginHook,
147
- () => __ΩBasePluginHookFunctions,
85
+ () => __ΩPluginHookFunctions,
148
86
  () => __ΩPluginHook,
149
- "UnresolvedContext",
150
- "this",
151
- "",
152
- () => __ΩConfigResult,
153
- "config",
154
- "A function that returns configuration options to be merged with the build context's options.",
87
+ () => __ΩPluginHookFunctions,
155
88
  () => __ΩPluginHook,
156
- "BuildPluginContext",
157
- "code",
158
- "id",
89
+ () => __ΩPluginHookFunctions,
90
+ "transform",
159
91
  "code",
160
92
  "id",
161
93
  "transform",
162
- "A hook that is called to transform the source code.",
163
94
  () => __ΩPluginHook,
95
+ () => __ΩPluginHookFunctions,
96
+ "load",
164
97
  "id",
165
98
  "load",
166
- "A hook that is called to load the source code.",
167
99
  () => __ΩPluginHook,
168
- "importer",
169
- "isEntry",
170
- "options",
100
+ () => __ΩPluginHookFunctions,
101
+ "resolveId",
171
102
  "id",
172
103
  "resolveId",
173
- "A hook that is called to resolve the identifier of the source code.",
174
104
  "PluginHooks",
175
- "l1e$!o%\"e\"!fo$\"R\"w!c\"PPde#!o#\"gN#!PPP\"w'2(!/)o&\"e$!o*\"J4+?,PP\"w.e%!K2(&2/&20!/)P.1.2Jo-#43?4PP\"w.e%!K2(&20!/).6o5#47?8PP\"w.e%!K2(&20P&-J2:P)4;M2<!/).=o9#4>??MKw@y"
105
+ "l1e$!o$\"e\"!fo#\"Rb!PPde#!o\"\"gN#\"Pe#!o&\".'fP.(.)Jo%#4*e#!o,\".-f..o+#4/e#!o1\".2f.3o0#44MKw5y"
176
106
  ];
177
- const __ΩPluginBuildPlugins = [
178
- "PluginContext",
179
- "TContext",
180
- "UnpluginBuildVariant",
181
- () => __ΩBuildPlugin,
182
- "PluginBuildPlugins",
183
- "l-e#!e\"!o$#R\"w!c\"Pd\"w#N#\"w%y"
107
+ const __ΩDeepPartial = [
108
+ "T",
109
+ 0,
110
+ "DeepPartial",
111
+ "l.e#!e\"!fo\"\"Rb!Pde\"!gN#\"w#y"
184
112
  ];
185
113
  const __ΩPlugin = [
186
114
  "PluginContext",
187
115
  "TContext",
188
116
  () => __ΩPartial,
189
117
  () => __ΩPluginHooks,
190
- () => __ΩPluginBuildPlugins,
191
118
  "name",
192
119
  "The name of the plugin, for use in deduplication, error messages and logs.",
193
120
  () => __ΩRecord,
@@ -208,8 +135,18 @@ const __ΩPlugin = [
208
135
  "PluginConfig",
209
136
  "applyToEnvironment",
210
137
  "Define environments where this plugin should be active. By default, the plugin is active in all environments.",
138
+ () => __ΩPluginHook,
139
+ "UnresolvedContext",
140
+ "this",
141
+ () => __ΩDeepPartial,
142
+ "config",
143
+ () => __ΩRecord,
144
+ "config",
145
+ "A function that returns configuration options to be merged with the build context's options.",
146
+ "BuilderVariant",
147
+ () => require_unplugin.__ΩInferUnpluginOptions,
211
148
  "Plugin",
212
- "\"w!c\"Pe\"!o$\"o#\"e\"!o%\"&4&?'&\"o(#4)8?*P.+.,J4-8?.P./P\"o0\"21)/2J438?4P\"w526P)\"w7J/2488?9Mw:y"
149
+ "l-e$!e\"!oB#R\"w!c\"Pe\"!o$\"o#\"P&4%?&&\"o'#4(8?)P.*.+J4,8?-P..P\"o/\"20)/1J428?3P\"w425P)\"w6J/1478?8PP\"w:2;!/1o9\"Pe%!.=fo<\"&\"o>#KJ4?8?@MPd\"wAN#\"KwCy"
213
150
  ];
214
151
  const PLUGIN_NON_HOOK_FIELDS = [
215
152
  "name",
@@ -218,11 +155,12 @@ const PLUGIN_NON_HOOK_FIELDS = [
218
155
  "dedupe",
219
156
  "applyToEnvironment"
220
157
  ];
221
- const KNOWN_HOOKS = [
158
+ const PLUGIN_HOOKS_FIELDS = [
222
159
  ...require_commands.SUPPORTED_COMMANDS,
223
160
  "config",
224
161
  "configEnvironment",
225
162
  "configResolved",
163
+ "types",
226
164
  "buildStart",
227
165
  "buildEnd",
228
166
  "transform",
@@ -232,18 +170,15 @@ const KNOWN_HOOKS = [
232
170
  ];
233
171
  const KNOWN_PLUGIN_FIELDS = [
234
172
  ...PLUGIN_NON_HOOK_FIELDS,
235
- ...KNOWN_HOOKS,
236
- ...require_build.UNPLUGIN_BUILD_VARIANTS
173
+ ...PLUGIN_HOOKS_FIELDS,
174
+ ...require_build.BUILDER_VARIANTS
237
175
  ];
238
176
 
239
177
  //#endregion
240
- exports.KNOWN_HOOKS = KNOWN_HOOKS;
178
+ exports.PLUGIN_HOOKS_FIELDS = PLUGIN_HOOKS_FIELDS;
241
179
  exports.PLUGIN_NON_HOOK_FIELDS = PLUGIN_NON_HOOK_FIELDS;
242
- exports.__ΩBasePluginHookFunctions = __ΩBasePluginHookFunctions;
243
- exports.__ΩBuildPlugin = __ΩBuildPlugin;
244
- exports.__ΩConfigResult = __ΩConfigResult;
245
180
  exports.__ΩPlugin = __ΩPlugin;
246
- exports.__ΩPluginBuildPlugins = __ΩPluginBuildPlugins;
247
181
  exports.__ΩPluginHook = __ΩPluginHook;
182
+ exports.__ΩPluginHookFunctions = __ΩPluginHookFunctions;
248
183
  exports.__ΩPluginHookObject = __ΩPluginHookObject;
249
184
  exports.__ΩPluginHooks = __ΩPluginHooks;
@@ -1,14 +1,16 @@
1
- import { UnpluginBuildVariant } from "./build.cjs";
1
+ import { BuilderVariant } from "./build.cjs";
2
2
  import { CommandType } from "./commands.cjs";
3
+ import { InferUnpluginOptions } from "./unplugin.cjs";
3
4
  import { BuildPluginContext, PluginContext, UnresolvedContext } from "./context.cjs";
4
5
  import { EnvironmentConfig, PluginConfig } from "./config.cjs";
5
6
  import { EnvironmentResolvedConfig, ResolvedConfig } from "./resolved.cjs";
6
- import { FunctionLike, MaybePromise } from "@stryke/types/base";
7
- import { ExternalIdResult, HookFilter, TransformResult, UnpluginOptions } from "unplugin";
7
+ import { AnyFunction, MaybePromise } from "@stryke/types/base";
8
+ import { LoadResult } from "rollup";
9
+ import { ExternalIdResult, HookFilter, TransformResult } from "unplugin";
8
10
  import { ArrayValues } from "@stryke/types/array";
9
11
 
10
12
  //#region ../powerlines/src/types/plugin.d.ts
11
- interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> {
13
+ interface PluginHookObject<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> {
12
14
  /**
13
15
  * The order in which the plugin should be applied.
14
16
  */
@@ -22,7 +24,7 @@ interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends k
22
24
  */
23
25
  handler: THookFunction;
24
26
  }
25
- type PluginHook<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
27
+ type PluginHook<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
26
28
  /**
27
29
  * A result returned by the plugin from the `types` hook that describes the declaration types output file.
28
30
  */
@@ -30,9 +32,7 @@ interface TypesResult {
30
32
  directives?: string[];
31
33
  code: string;
32
34
  }
33
- type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
34
- type ConfigResult<TContext extends PluginContext = PluginContext> = DeepPartial<TContext["config"]> & Record<string, any>;
35
- interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext> extends Record<CommandType, (this: TContext) => MaybePromise<void>> {
35
+ type PluginHookFunctions<TContext extends PluginContext> = { [TCommandType in CommandType]: (this: TContext) => MaybePromise<void> } & {
36
36
  /**
37
37
  * A function that returns configuration options to be merged with the build context's options.
38
38
  *
@@ -47,7 +47,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
47
47
  * @param config - The partial configuration object to be modified.
48
48
  * @returns A promise that resolves to a partial configuration object.
49
49
  */
50
- config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>;
50
+ config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>;
51
51
  /**
52
52
  * Modify environment configs before it's resolved. The hook can either mutate the passed-in environment config directly, or return a partial config object that will be deeply merged into existing config.
53
53
  *
@@ -109,7 +109,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
109
109
  * @param id - The identifier of the source code.
110
110
  * @returns A promise that resolves when the hook is complete.
111
111
  */
112
- load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>;
112
+ load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<LoadResult>;
113
113
  /**
114
114
  * A hook that is called to resolve the identifier of the source code.
115
115
  *
@@ -129,56 +129,14 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
129
129
  * @returns A promise that resolves when the hook is complete.
130
130
  */
131
131
  writeBundle: (this: TContext) => MaybePromise<void>;
132
- }
133
- type BuildPlugin<TContext extends PluginContext = PluginContext, TBuildVariant$1 extends UnpluginBuildVariant = UnpluginBuildVariant, TOptions extends Required<UnpluginOptions>[TBuildVariant$1] = Required<UnpluginOptions>[TBuildVariant$1]> = { [TKey in keyof TOptions]: TOptions[TKey] extends FunctionLike ? (this: ThisParameterType<TOptions[TKey]> & TContext, ...args: Parameters<TOptions[TKey]>) => ReturnType<TOptions[TKey]> | MaybePromise<ReturnType<TOptions[TKey]>> : TOptions[TKey] };
134
- type PluginHooks<TContext extends PluginContext = PluginContext> = { [TKey in keyof BasePluginHookFunctions<TContext>]: PluginHook<BasePluginHookFunctions<TContext>[TKey]> } & {
135
- /**
136
- * A function that returns configuration options to be merged with the build context's options.
137
- *
138
- * @remarks
139
- * Modify config before it's resolved. The hook can either mutate {@link Context.config} on the passed-in context directly, or return a partial config object that will be deeply merged into existing config.
140
- *
141
- * @warning User plugins are resolved before running this hook so injecting other plugins inside the config hook will have no effect. If you want to add plugins, consider doing so in the {@link Plugin.dependsOn} property instead.
142
- *
143
- * @see https://vitejs.dev/guide/api-plugin#config
144
- *
145
- * @param this - The build context.
146
- * @param config - The partial configuration object to be modified.
147
- * @returns A promise that resolves to a partial configuration object.
148
- */
149
- config: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>> | ConfigResult<TContext>;
150
- /**
151
- * A hook that is called to transform the source code.
152
- *
153
- * @param this - The build context, unplugin build context, and unplugin context.
154
- * @param code - The source code to transform.
155
- * @param id - The identifier of the source code.
156
- * @returns A promise that resolves when the hook is complete.
157
- */
158
- transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>, "code" | "id">;
159
- /**
160
- * A hook that is called to load the source code.
161
- *
162
- * @param this - The build context, unplugin build context, and unplugin context.
163
- * @param id - The identifier of the source code.
164
- * @returns A promise that resolves when the hook is complete.
165
- */
166
- load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>, "id">;
167
- /**
168
- * A hook that is called to resolve the identifier of the source code.
169
- *
170
- * @param this - The build context, unplugin build context, and unplugin context.
171
- * @param id - The identifier of the source code.
172
- * @param importer - The importer of the source code.
173
- * @param options - The options for resolving the identifier.
174
- * @returns A promise that resolves when the hook is complete.
175
- */
176
- resolveId: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
177
- isEntry: boolean;
178
- }) => MaybePromise<string | ExternalIdResult | null | undefined>, "id">;
179
132
  };
180
- type PluginBuildPlugins<TContext extends PluginContext = PluginContext> = { [TBuildVariant in UnpluginBuildVariant]?: BuildPlugin<TContext, TBuildVariant> };
181
- interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> extends Partial<PluginHooks<TContext>>, PluginBuildPlugins<TContext> {
133
+ type PluginHooks<TContext extends PluginContext> = { [TPluginHook in keyof PluginHookFunctions<TContext>]?: PluginHook<PluginHookFunctions<TContext>[TPluginHook]> } & {
134
+ transform: PluginHook<PluginHookFunctions<TContext>["transform"], "code" | "id">;
135
+ load: PluginHook<PluginHookFunctions<TContext>["load"], "id">;
136
+ resolveId: PluginHook<PluginHookFunctions<TContext>["resolveId"], "id">;
137
+ };
138
+ type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
139
+ type Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> = Partial<PluginHooks<TContext>> & {
182
140
  /**
183
141
  * The name of the plugin, for use in deduplication, error messages and logs.
184
142
  */
@@ -226,6 +184,22 @@ interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<
226
184
  * @returns `true` if the plugin should be active in the specified environment, `false` otherwise.
227
185
  */
228
186
  applyToEnvironment?: (environment: EnvironmentResolvedConfig) => boolean | PluginConfig<TContext>;
229
- }
187
+ /**
188
+ * A function that returns configuration options to be merged with the build context's options.
189
+ *
190
+ * @remarks
191
+ * Modify config before it's resolved. The hook can either mutate {@link Context.config} on the passed-in context directly, or return a partial config object that will be deeply merged into existing config.
192
+ *
193
+ * @warning User plugins are resolved before running this hook so injecting other plugins inside the config hook will have no effect. If you want to add plugins, consider doing so in the {@link Plugin.dependsOn} property instead.
194
+ *
195
+ * @see https://vitejs.dev/guide/api-plugin#config
196
+ *
197
+ * @param this - The build context.
198
+ * @param config - The partial configuration object to be modified.
199
+ * @returns A promise that resolves to a partial configuration object.
200
+ */
201
+ config?: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>> | (DeepPartial<TContext["config"]> & Record<string, any>);
202
+ } & { [TBuilderVariant in BuilderVariant]?: InferUnpluginOptions<TContext, TBuilderVariant> };
203
+ type PluginHookFields<TContext extends PluginContext = PluginContext> = keyof PluginHookFunctions<TContext>;
230
204
  //#endregion
231
- export { Plugin };
205
+ export { Plugin, PluginHook, PluginHookFields, PluginHookFunctions };
@@ -1,14 +1,16 @@
1
- import { UnpluginBuildVariant } from "./build.mjs";
1
+ import { BuilderVariant } from "./build.mjs";
2
2
  import { CommandType } from "./commands.mjs";
3
+ import { InferUnpluginOptions } from "./unplugin.mjs";
3
4
  import { BuildPluginContext, PluginContext, UnresolvedContext } from "./context.mjs";
4
5
  import { EnvironmentConfig, PluginConfig } from "./config.mjs";
5
6
  import { EnvironmentResolvedConfig, ResolvedConfig } from "./resolved.mjs";
6
- import { FunctionLike, MaybePromise } from "@stryke/types/base";
7
- import { ExternalIdResult, HookFilter, TransformResult, UnpluginOptions } from "unplugin";
7
+ import { AnyFunction, MaybePromise } from "@stryke/types/base";
8
+ import { LoadResult } from "rollup";
9
+ import { ExternalIdResult, HookFilter, TransformResult } from "unplugin";
8
10
  import { ArrayValues } from "@stryke/types/array";
9
11
 
10
12
  //#region ../powerlines/src/types/plugin.d.ts
11
- interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> {
13
+ interface PluginHookObject<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> {
12
14
  /**
13
15
  * The order in which the plugin should be applied.
14
16
  */
@@ -22,7 +24,7 @@ interface PluginHookObject<THookFunction extends FunctionLike, TFilter extends k
22
24
  */
23
25
  handler: THookFunction;
24
26
  }
25
- type PluginHook<THookFunction extends FunctionLike, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
27
+ type PluginHook<THookFunction extends AnyFunction, TFilter extends keyof HookFilter = never> = THookFunction | PluginHookObject<THookFunction, TFilter>;
26
28
  /**
27
29
  * A result returned by the plugin from the `types` hook that describes the declaration types output file.
28
30
  */
@@ -30,9 +32,7 @@ interface TypesResult {
30
32
  directives?: string[];
31
33
  code: string;
32
34
  }
33
- type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
34
- type ConfigResult<TContext extends PluginContext = PluginContext> = DeepPartial<TContext["config"]> & Record<string, any>;
35
- interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext> extends Record<CommandType, (this: TContext) => MaybePromise<void>> {
35
+ type PluginHookFunctions<TContext extends PluginContext> = { [TCommandType in CommandType]: (this: TContext) => MaybePromise<void> } & {
36
36
  /**
37
37
  * A function that returns configuration options to be merged with the build context's options.
38
38
  *
@@ -47,7 +47,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
47
47
  * @param config - The partial configuration object to be modified.
48
48
  * @returns A promise that resolves to a partial configuration object.
49
49
  */
50
- config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>;
50
+ config: (this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>;
51
51
  /**
52
52
  * Modify environment configs before it's resolved. The hook can either mutate the passed-in environment config directly, or return a partial config object that will be deeply merged into existing config.
53
53
  *
@@ -109,7 +109,7 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
109
109
  * @param id - The identifier of the source code.
110
110
  * @returns A promise that resolves when the hook is complete.
111
111
  */
112
- load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>;
112
+ load: (this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<LoadResult>;
113
113
  /**
114
114
  * A hook that is called to resolve the identifier of the source code.
115
115
  *
@@ -129,56 +129,14 @@ interface BasePluginHookFunctions<TContext extends PluginContext = PluginContext
129
129
  * @returns A promise that resolves when the hook is complete.
130
130
  */
131
131
  writeBundle: (this: TContext) => MaybePromise<void>;
132
- }
133
- type BuildPlugin<TContext extends PluginContext = PluginContext, TBuildVariant$1 extends UnpluginBuildVariant = UnpluginBuildVariant, TOptions extends Required<UnpluginOptions>[TBuildVariant$1] = Required<UnpluginOptions>[TBuildVariant$1]> = { [TKey in keyof TOptions]: TOptions[TKey] extends FunctionLike ? (this: ThisParameterType<TOptions[TKey]> & TContext, ...args: Parameters<TOptions[TKey]>) => ReturnType<TOptions[TKey]> | MaybePromise<ReturnType<TOptions[TKey]>> : TOptions[TKey] };
134
- type PluginHooks<TContext extends PluginContext = PluginContext> = { [TKey in keyof BasePluginHookFunctions<TContext>]: PluginHook<BasePluginHookFunctions<TContext>[TKey]> } & {
135
- /**
136
- * A function that returns configuration options to be merged with the build context's options.
137
- *
138
- * @remarks
139
- * Modify config before it's resolved. The hook can either mutate {@link Context.config} on the passed-in context directly, or return a partial config object that will be deeply merged into existing config.
140
- *
141
- * @warning User plugins are resolved before running this hook so injecting other plugins inside the config hook will have no effect. If you want to add plugins, consider doing so in the {@link Plugin.dependsOn} property instead.
142
- *
143
- * @see https://vitejs.dev/guide/api-plugin#config
144
- *
145
- * @param this - The build context.
146
- * @param config - The partial configuration object to be modified.
147
- * @returns A promise that resolves to a partial configuration object.
148
- */
149
- config: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<ConfigResult<TContext>>> | ConfigResult<TContext>;
150
- /**
151
- * A hook that is called to transform the source code.
152
- *
153
- * @param this - The build context, unplugin build context, and unplugin context.
154
- * @param code - The source code to transform.
155
- * @param id - The identifier of the source code.
156
- * @returns A promise that resolves when the hook is complete.
157
- */
158
- transform: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, code: string, id: string) => MaybePromise<TransformResult>, "code" | "id">;
159
- /**
160
- * A hook that is called to load the source code.
161
- *
162
- * @param this - The build context, unplugin build context, and unplugin context.
163
- * @param id - The identifier of the source code.
164
- * @returns A promise that resolves when the hook is complete.
165
- */
166
- load: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string) => MaybePromise<TransformResult>, "id">;
167
- /**
168
- * A hook that is called to resolve the identifier of the source code.
169
- *
170
- * @param this - The build context, unplugin build context, and unplugin context.
171
- * @param id - The identifier of the source code.
172
- * @param importer - The importer of the source code.
173
- * @param options - The options for resolving the identifier.
174
- * @returns A promise that resolves when the hook is complete.
175
- */
176
- resolveId: PluginHook<(this: BuildPluginContext<TContext["config"]> & TContext, id: string, importer: string | undefined, options: {
177
- isEntry: boolean;
178
- }) => MaybePromise<string | ExternalIdResult | null | undefined>, "id">;
179
132
  };
180
- type PluginBuildPlugins<TContext extends PluginContext = PluginContext> = { [TBuildVariant in UnpluginBuildVariant]?: BuildPlugin<TContext, TBuildVariant> };
181
- interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> extends Partial<PluginHooks<TContext>>, PluginBuildPlugins<TContext> {
133
+ type PluginHooks<TContext extends PluginContext> = { [TPluginHook in keyof PluginHookFunctions<TContext>]?: PluginHook<PluginHookFunctions<TContext>[TPluginHook]> } & {
134
+ transform: PluginHook<PluginHookFunctions<TContext>["transform"], "code" | "id">;
135
+ load: PluginHook<PluginHookFunctions<TContext>["load"], "id">;
136
+ resolveId: PluginHook<PluginHookFunctions<TContext>["resolveId"], "id">;
137
+ };
138
+ type DeepPartial<T> = { [K in keyof T]?: DeepPartial<T[K]> };
139
+ type Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<ResolvedConfig>> = Partial<PluginHooks<TContext>> & {
182
140
  /**
183
141
  * The name of the plugin, for use in deduplication, error messages and logs.
184
142
  */
@@ -226,6 +184,22 @@ interface Plugin<TContext extends PluginContext<ResolvedConfig> = PluginContext<
226
184
  * @returns `true` if the plugin should be active in the specified environment, `false` otherwise.
227
185
  */
228
186
  applyToEnvironment?: (environment: EnvironmentResolvedConfig) => boolean | PluginConfig<TContext>;
229
- }
187
+ /**
188
+ * A function that returns configuration options to be merged with the build context's options.
189
+ *
190
+ * @remarks
191
+ * Modify config before it's resolved. The hook can either mutate {@link Context.config} on the passed-in context directly, or return a partial config object that will be deeply merged into existing config.
192
+ *
193
+ * @warning User plugins are resolved before running this hook so injecting other plugins inside the config hook will have no effect. If you want to add plugins, consider doing so in the {@link Plugin.dependsOn} property instead.
194
+ *
195
+ * @see https://vitejs.dev/guide/api-plugin#config
196
+ *
197
+ * @param this - The build context.
198
+ * @param config - The partial configuration object to be modified.
199
+ * @returns A promise that resolves to a partial configuration object.
200
+ */
201
+ config?: PluginHook<(this: UnresolvedContext<TContext["config"]>) => MaybePromise<DeepPartial<TContext["config"]> & Record<string, any>>> | (DeepPartial<TContext["config"]> & Record<string, any>);
202
+ } & { [TBuilderVariant in BuilderVariant]?: InferUnpluginOptions<TContext, TBuilderVariant> };
203
+ type PluginHookFields<TContext extends PluginContext = PluginContext> = keyof PluginHookFunctions<TContext>;
230
204
  //#endregion
231
- export { BasePluginHookFunctions, BuildPlugin, ConfigResult, Plugin, PluginBuildPlugins, PluginHook, PluginHookObject, PluginHooks, TypesResult };
205
+ export { Plugin, PluginHook, PluginHookFields, PluginHookFunctions, PluginHookObject, PluginHooks, TypesResult };