@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.
- package/dist/babel/plugin.cjs +1 -1
- package/dist/babel/plugin.mjs +1 -1
- package/dist/helpers/load.cjs +2 -2
- package/dist/helpers/load.mjs +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +2 -2
- package/dist/plugin-alloy/src/core/components/source-file.cjs +1 -1
- package/dist/plugin-alloy/src/core/components/source-file.mjs +1 -1
- package/dist/plugin-alloy/src/index.cjs +12 -5
- package/dist/plugin-alloy/src/index.mjs +12 -5
- package/dist/plugin-alloy/src/types/components.d.cts +1 -3
- package/dist/plugin-alloy/src/types/components.d.mts +2 -3
- package/dist/plugin-alloy/src/typescript/components/builtin-file.cjs +1 -1
- package/dist/plugin-alloy/src/typescript/components/builtin-file.mjs +1 -1
- package/dist/plugin-alloy/src/typescript/components/typescript-file.cjs +17 -11
- package/dist/plugin-alloy/src/typescript/components/typescript-file.d.cts +1 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-file.d.mts +1 -0
- package/dist/plugin-alloy/src/typescript/components/typescript-file.mjs +17 -11
- package/dist/plugin-automd/src/index.cjs +2 -2
- package/dist/plugin-automd/src/index.mjs +1 -1
- package/dist/plugin-babel/src/helpers/module-helpers.cjs +1 -1
- package/dist/plugin-babel/src/helpers/module-helpers.mjs +1 -1
- package/dist/plugin-babel/src/index.cjs +4 -7
- package/dist/plugin-babel/src/index.mjs +2 -5
- package/dist/powerlines/src/api.d.mts +2 -2
- package/dist/powerlines/src/index.d.mts +8 -5
- package/dist/powerlines/src/internal/helpers/hooks.cjs +37 -19
- package/dist/powerlines/src/internal/helpers/hooks.d.cts +47 -0
- package/dist/powerlines/src/internal/helpers/hooks.d.mts +46 -2
- package/dist/powerlines/src/internal/helpers/hooks.mjs +37 -20
- package/dist/powerlines/src/lib/build/esbuild.cjs +2 -2
- package/dist/powerlines/src/lib/build/esbuild.mjs +2 -2
- package/dist/powerlines/src/lib/entry.cjs +1 -1
- package/dist/powerlines/src/lib/entry.mjs +1 -1
- package/dist/powerlines/src/types/api.cjs +62 -1
- package/dist/powerlines/src/types/api.d.cts +104 -0
- package/dist/powerlines/src/types/api.d.mts +104 -5
- package/dist/powerlines/src/types/api.mjs +61 -2
- package/dist/powerlines/src/types/build.cjs +26 -4
- package/dist/powerlines/src/types/build.d.cts +43 -3
- package/dist/powerlines/src/types/build.d.mts +42 -4
- package/dist/powerlines/src/types/build.mjs +23 -3
- package/dist/powerlines/src/types/config.cjs +107 -0
- package/dist/powerlines/src/types/config.d.cts +60 -4
- package/dist/powerlines/src/types/config.d.mts +61 -5
- package/dist/powerlines/src/types/config.mjs +99 -1
- package/dist/powerlines/src/types/context.cjs +57 -0
- package/dist/powerlines/src/types/context.d.cts +113 -1
- package/dist/powerlines/src/types/context.d.mts +113 -3
- package/dist/powerlines/src/types/context.mjs +54 -1
- package/dist/powerlines/src/types/hooks.cjs +33 -14
- package/dist/powerlines/src/types/hooks.d.cts +32 -0
- package/dist/powerlines/src/types/hooks.d.mts +32 -2
- package/dist/powerlines/src/types/hooks.mjs +32 -12
- package/dist/powerlines/src/types/index.cjs +3 -3
- package/dist/powerlines/src/types/index.d.mts +8 -8
- package/dist/powerlines/src/types/index.mjs +7 -7
- package/dist/powerlines/src/types/plugin.cjs +40 -105
- package/dist/powerlines/src/types/plugin.d.cts +35 -61
- package/dist/powerlines/src/types/plugin.d.mts +35 -61
- package/dist/powerlines/src/types/plugin.mjs +40 -102
- package/dist/powerlines/src/types/resolved.d.cts +16 -4
- package/dist/powerlines/src/types/resolved.d.mts +16 -5
- package/dist/powerlines/src/types/unplugin.cjs +47 -1
- package/dist/powerlines/src/types/unplugin.d.cts +22 -0
- package/dist/powerlines/src/types/unplugin.d.mts +22 -6
- package/dist/powerlines/src/types/unplugin.mjs +45 -2
- 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 __Ω
|
|
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
|
-
"
|
|
124
|
-
"\"w
|
|
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
|
-
() => __Ω
|
|
146
|
-
() => __ΩPluginHook,
|
|
147
|
-
() => __ΩBasePluginHookFunctions,
|
|
85
|
+
() => __ΩPluginHookFunctions,
|
|
148
86
|
() => __ΩPluginHook,
|
|
149
|
-
|
|
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
|
-
|
|
157
|
-
"
|
|
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
|
-
|
|
169
|
-
"
|
|
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
|
|
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 __Ω
|
|
178
|
-
"
|
|
179
|
-
|
|
180
|
-
"
|
|
181
|
-
|
|
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#\"
|
|
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
|
|
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
|
-
...
|
|
236
|
-
...require_build.
|
|
173
|
+
...PLUGIN_HOOKS_FIELDS,
|
|
174
|
+
...require_build.BUILDER_VARIANTS
|
|
237
175
|
];
|
|
238
176
|
|
|
239
177
|
//#endregion
|
|
240
|
-
exports.
|
|
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 {
|
|
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 {
|
|
7
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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<
|
|
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<
|
|
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
|
|
181
|
-
|
|
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 {
|
|
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 {
|
|
7
|
-
import {
|
|
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
|
|
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
|
|
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
|
|
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<
|
|
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<
|
|
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
|
|
181
|
-
|
|
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 {
|
|
205
|
+
export { Plugin, PluginHook, PluginHookFields, PluginHookFunctions, PluginHookObject, PluginHooks, TypesResult };
|