@powerlines/plugin-vite 0.14.125 → 0.14.127
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/powerlines/src/internal/helpers/hooks.cjs +15 -12
- package/dist/powerlines/src/internal/helpers/hooks.d.cts +0 -1
- package/dist/powerlines/src/internal/helpers/hooks.d.mts +0 -1
- package/dist/powerlines/src/internal/helpers/hooks.mjs +15 -12
- package/dist/powerlines/src/lib/contexts/environment-context.cjs +108 -73
- package/dist/powerlines/src/lib/contexts/environment-context.mjs +109 -74
- package/dist/powerlines/src/lib/unplugin/helpers.cjs +13 -1
- package/dist/powerlines/src/lib/unplugin/helpers.mjs +12 -1
- package/dist/powerlines/src/lib/unplugin/index.cjs +1 -1
- package/dist/powerlines/src/lib/unplugin/index.mjs +1 -1
- package/dist/powerlines/src/lib/unplugin/plugin.cjs +3 -3
- package/dist/powerlines/src/lib/unplugin/plugin.mjs +3 -3
- package/dist/powerlines/src/lib/utilities/source-file.mjs +1 -0
- package/dist/powerlines/src/plugin-utils/helpers.cjs +34 -15
- package/dist/powerlines/src/plugin-utils/helpers.mjs +33 -15
- package/dist/powerlines/src/types/api.d.cts +4 -4
- package/dist/powerlines/src/types/api.d.mts +4 -4
- package/dist/powerlines/src/types/babel.d.mts +1 -1
- package/dist/powerlines/src/types/build.cjs +11 -3
- package/dist/powerlines/src/types/build.d.cts +34 -3
- package/dist/powerlines/src/types/build.d.mts +34 -3
- package/dist/powerlines/src/types/build.mjs +10 -3
- package/dist/powerlines/src/types/config.d.cts +14 -4
- package/dist/powerlines/src/types/config.d.mts +16 -5
- package/dist/powerlines/src/types/context.d.cts +9 -8
- package/dist/powerlines/src/types/context.d.mts +8 -7
- package/dist/powerlines/src/types/hooks.d.cts +25 -23
- package/dist/powerlines/src/types/hooks.d.mts +25 -23
- package/dist/powerlines/src/types/internal.d.cts +6 -4
- package/dist/powerlines/src/types/internal.d.mts +6 -4
- package/dist/powerlines/src/types/plugin.cjs +5 -4
- package/dist/powerlines/src/types/plugin.d.cts +36 -65
- package/dist/powerlines/src/types/plugin.d.mts +36 -65
- package/dist/powerlines/src/types/plugin.mjs +6 -5
- package/dist/powerlines/src/types/resolved.d.cts +16 -5
- package/dist/powerlines/src/types/resolved.d.mts +16 -6
- package/dist/powerlines/src/types/unplugin.d.cts +22 -0
- package/dist/powerlines/src/types/unplugin.d.mts +23 -0
- package/dist/types/plugin.d.cts +5 -1
- package/dist/types/plugin.d.mts +5 -1
- package/package.json +5 -5
|
@@ -20,29 +20,32 @@ const mergeResults = (0, defu.createDefu)((obj, key, value) => {
|
|
|
20
20
|
* Calls a hook with the given context, options, and arguments.
|
|
21
21
|
*
|
|
22
22
|
* @param context - The context to use when calling the hook.
|
|
23
|
-
* @param
|
|
23
|
+
* @param key - The hook to call.
|
|
24
24
|
* @param options - Options for calling the hook.
|
|
25
25
|
* @param args - Arguments to pass to the hook.
|
|
26
26
|
* @returns The return value of the hook.
|
|
27
27
|
*/
|
|
28
|
-
async function callHook(context,
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
31
|
-
context.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.default.bold.cyanBright(`${
|
|
28
|
+
async function callHook(context, key, options, ...args) {
|
|
29
|
+
const hooks = context.selectHooks(key, options);
|
|
30
|
+
if (hooks.length > 0) {
|
|
31
|
+
context.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.default.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)}`);
|
|
32
|
+
const invokeHook = async (hook, hookArgs) => {
|
|
33
|
+
return Reflect.apply(hook.handler, hook.context, hookArgs);
|
|
34
|
+
};
|
|
32
35
|
let results = [];
|
|
33
|
-
if (options?.sequential === false) results = await Promise.all(
|
|
34
|
-
if (!(0, __stryke_type_checks_is_function.isFunction)(handler
|
|
35
|
-
return
|
|
36
|
+
if (options?.sequential === false) results = await Promise.all(hooks.map(async (hook) => {
|
|
37
|
+
if (!(0, __stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
38
|
+
return invokeHook(hook, [...args]);
|
|
36
39
|
}));
|
|
37
|
-
else for (const
|
|
38
|
-
if (!(0, __stryke_type_checks_is_function.isFunction)(handler
|
|
40
|
+
else for (const hook of hooks) {
|
|
41
|
+
if (!(0, __stryke_type_checks_is_function.isFunction)(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
39
42
|
if (options?.result === "first" || options?.asNextParam === false) {
|
|
40
|
-
results.push(await Promise.resolve(
|
|
43
|
+
results.push(await Promise.resolve(invokeHook(hook, [...args])));
|
|
41
44
|
if (options?.result === "first" && (0, __stryke_type_checks_is_set.isSet)(results[results.length - 1])) break;
|
|
42
45
|
} else {
|
|
43
46
|
const sequenceArgs = [...args];
|
|
44
47
|
if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = (0, __stryke_type_checks_is_function.isFunction)(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
|
|
45
|
-
const result = await Promise.resolve(
|
|
48
|
+
const result = await Promise.resolve(invokeHook(hook, [...sequenceArgs]));
|
|
46
49
|
if (result) {
|
|
47
50
|
if (options?.result === "last") results = [result];
|
|
48
51
|
else if ((0, __stryke_type_checks_is_string.isString)(result)) results = [`${(0, __stryke_type_checks_is_string.isString)(results[0]) ? results[0] || "" : ""}\n${result || ""}`.trim()];
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SelectHooksOptions } from "../../types/context.cjs";
|
|
2
2
|
import { MaybePromise } from "@stryke/types/base";
|
|
3
|
-
import { ArrayValues } from "@stryke/types/array";
|
|
4
3
|
|
|
5
4
|
//#region ../powerlines/src/internal/helpers/hooks.d.ts
|
|
6
5
|
type CallHookOptions = SelectHooksOptions & (({
|
|
@@ -2,7 +2,6 @@ import "../../types/resolved.mjs";
|
|
|
2
2
|
import "../../types/hooks.mjs";
|
|
3
3
|
import { SelectHooksOptions } from "../../types/context.mjs";
|
|
4
4
|
import { MaybePromise } from "@stryke/types/base";
|
|
5
|
-
import { ArrayValues } from "@stryke/types/array";
|
|
6
5
|
|
|
7
6
|
//#region ../powerlines/src/internal/helpers/hooks.d.ts
|
|
8
7
|
type CallHookOptions = SelectHooksOptions & (({
|
|
@@ -18,29 +18,32 @@ const mergeResults = createDefu((obj, key, value) => {
|
|
|
18
18
|
* Calls a hook with the given context, options, and arguments.
|
|
19
19
|
*
|
|
20
20
|
* @param context - The context to use when calling the hook.
|
|
21
|
-
* @param
|
|
21
|
+
* @param key - The hook to call.
|
|
22
22
|
* @param options - Options for calling the hook.
|
|
23
23
|
* @param args - Arguments to pass to the hook.
|
|
24
24
|
* @returns The return value of the hook.
|
|
25
25
|
*/
|
|
26
|
-
async function callHook(context,
|
|
27
|
-
const
|
|
28
|
-
if (
|
|
29
|
-
context.log(LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.bold.cyanBright(`${
|
|
26
|
+
async function callHook(context, key, options, ...args) {
|
|
27
|
+
const hooks = context.selectHooks(key, options);
|
|
28
|
+
if (hooks.length > 0) {
|
|
29
|
+
context.log(LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.bold.cyanBright(`${key}${options?.order ? ` (${options.order})` : ""}`)}`);
|
|
30
|
+
const invokeHook = async (hook, hookArgs) => {
|
|
31
|
+
return Reflect.apply(hook.handler, hook.context, hookArgs);
|
|
32
|
+
};
|
|
30
33
|
let results = [];
|
|
31
|
-
if (options?.sequential === false) results = await Promise.all(
|
|
32
|
-
if (!isFunction(handler
|
|
33
|
-
return
|
|
34
|
+
if (options?.sequential === false) results = await Promise.all(hooks.map(async (hook) => {
|
|
35
|
+
if (!isFunction(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
36
|
+
return invokeHook(hook, [...args]);
|
|
34
37
|
}));
|
|
35
|
-
else for (const
|
|
36
|
-
if (!isFunction(handler
|
|
38
|
+
else for (const hook of hooks) {
|
|
39
|
+
if (!isFunction(hook.handler)) throw new Error(`Plugin hook handler for hook "${key}" is not a function.`);
|
|
37
40
|
if (options?.result === "first" || options?.asNextParam === false) {
|
|
38
|
-
results.push(await Promise.resolve(
|
|
41
|
+
results.push(await Promise.resolve(invokeHook(hook, [...args])));
|
|
39
42
|
if (options?.result === "first" && isSet(results[results.length - 1])) break;
|
|
40
43
|
} else {
|
|
41
44
|
const sequenceArgs = [...args];
|
|
42
45
|
if (results.length > 0 && sequenceArgs.length > 0) sequenceArgs[0] = isFunction(options.asNextParam) ? await Promise.resolve(options.asNextParam(results[0])) : results[0];
|
|
43
|
-
const result = await Promise.resolve(
|
|
46
|
+
const result = await Promise.resolve(invokeHook(hook, [...sequenceArgs]));
|
|
44
47
|
if (result) {
|
|
45
48
|
if (options?.result === "last") results = [result];
|
|
46
49
|
else if (isString(result)) results = [`${isString(results[0]) ? results[0] || "" : ""}\n${result || ""}`.trim()];
|
|
@@ -2,10 +2,12 @@ const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.
|
|
|
2
2
|
const require_plugin = require('../../types/plugin.cjs');
|
|
3
3
|
const require_helpers = require('../../plugin-utils/helpers.cjs');
|
|
4
4
|
const require_context = require('./context.cjs');
|
|
5
|
+
const require_helpers$1 = require('../unplugin/helpers.cjs');
|
|
5
6
|
const require_plugin_context = require('./plugin-context.cjs');
|
|
6
7
|
let __stryke_fs_resolve = require("@stryke/fs/resolve");
|
|
7
8
|
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
8
9
|
let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
10
|
+
let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-object");
|
|
9
11
|
|
|
10
12
|
//#region ../powerlines/src/lib/contexts/environment-context.ts
|
|
11
13
|
var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends require_context.PowerlinesContext {
|
|
@@ -60,94 +62,127 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends re
|
|
|
60
62
|
});
|
|
61
63
|
this.#hooks = Object.keys(resolvedPlugin).filter((key) => !require_plugin.PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
|
|
62
64
|
const hook = key;
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
ret[hook] ??= {
|
|
65
|
+
if (require_helpers.isPluginHookField(hook)) {
|
|
66
|
+
const pluginHook = resolvedPlugin[hook];
|
|
67
|
+
if (!require_helpers.isPluginHook(pluginHook)) return ret;
|
|
68
|
+
ret[hook] ??= {
|
|
69
|
+
preEnforced: [],
|
|
70
|
+
preOrdered: [],
|
|
71
|
+
normal: [],
|
|
72
|
+
postEnforced: [],
|
|
73
|
+
postOrdered: []
|
|
74
|
+
};
|
|
67
75
|
if (resolvedPlugin.enforce) {
|
|
68
|
-
|
|
69
|
-
|
|
76
|
+
const hookListOrder$1 = `${resolvedPlugin.enforce}Enforced`;
|
|
77
|
+
ret[hook][hookListOrder$1] ??= [];
|
|
78
|
+
const bucket = ret[hook][hookListOrder$1];
|
|
79
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, bucket);
|
|
70
80
|
return ret;
|
|
71
81
|
}
|
|
72
82
|
if ((0, __stryke_type_checks_is_function.isFunction)(pluginHook) || !pluginHook.order) {
|
|
73
83
|
ret[hook].normal ??= [];
|
|
74
|
-
|
|
84
|
+
const bucket = ret[hook].normal;
|
|
85
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, bucket);
|
|
75
86
|
return ret;
|
|
76
87
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
ret
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
const hookListOrder = `${pluginHook.order}Ordered`;
|
|
89
|
+
ret[hook][hookListOrder] ??= [];
|
|
90
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][hookListOrder]);
|
|
91
|
+
return ret;
|
|
92
|
+
} else if (require_helpers.isUnpluginHookField(hook)) {
|
|
93
|
+
const unpluginPlugin = resolvedPlugin[hook];
|
|
94
|
+
if (!(0, __stryke_type_checks_is_set_object.isSetObject)(unpluginPlugin)) return ret;
|
|
95
|
+
for (const field of Object.keys(unpluginPlugin)) {
|
|
96
|
+
const variantField = field;
|
|
97
|
+
const pluginHook = unpluginPlugin[variantField];
|
|
98
|
+
if (!require_helpers.isPluginHook(pluginHook)) continue;
|
|
99
|
+
ret[hook] ??= {};
|
|
100
|
+
ret[hook][variantField] ??= {
|
|
101
|
+
preEnforced: [],
|
|
102
|
+
preOrdered: [],
|
|
103
|
+
normal: [],
|
|
104
|
+
postEnforced: [],
|
|
105
|
+
postOrdered: []
|
|
106
|
+
};
|
|
107
|
+
if (resolvedPlugin.enforce) {
|
|
108
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField][`${resolvedPlugin.enforce}Enforced`]);
|
|
109
|
+
return ret;
|
|
110
|
+
}
|
|
111
|
+
if ((0, __stryke_type_checks_is_function.isFunction)(pluginHook) || !pluginHook.order) {
|
|
112
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField].normal);
|
|
113
|
+
return ret;
|
|
114
|
+
}
|
|
115
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField][`${pluginHook.order}Ordered`]);
|
|
116
|
+
}
|
|
117
|
+
} else this.warn(`Unknown plugin hook field: ${String(hook)}`);
|
|
86
118
|
return ret;
|
|
87
119
|
}, this.hooks);
|
|
88
120
|
}
|
|
89
121
|
/**
|
|
90
122
|
* Retrieves the hook handlers for a specific hook name
|
|
91
123
|
*/
|
|
92
|
-
selectHooks(
|
|
124
|
+
selectHooks(key, options) {
|
|
93
125
|
const result = [];
|
|
94
|
-
if (
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
126
|
+
if (require_helpers.isUnpluginHookKey(key)) {
|
|
127
|
+
const variant = String(key).split(":")[0];
|
|
128
|
+
if (require_helpers$1.isUnpluginBuilderVariant(variant)) {
|
|
129
|
+
const hooks = this.hooks[variant];
|
|
130
|
+
if (hooks) {
|
|
131
|
+
const field = String(key).split(":")[1];
|
|
132
|
+
if (field && hooks[field]) {
|
|
133
|
+
const fieldHooks = hooks[field];
|
|
134
|
+
if (options?.order) {
|
|
135
|
+
const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
|
|
136
|
+
const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
|
|
137
|
+
if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
|
|
138
|
+
return {
|
|
139
|
+
handler: hook.handler,
|
|
140
|
+
plugin: hook.plugin,
|
|
141
|
+
context: plugin.context
|
|
142
|
+
};
|
|
143
|
+
});
|
|
144
|
+
if (options?.order === "pre") {
|
|
145
|
+
result.push(...mapHooksToResult(fieldHooks.preOrdered ?? []));
|
|
146
|
+
result.push(...mapHooksToResult(fieldHooks.preEnforced ?? []));
|
|
147
|
+
} else if (options?.order === "post") {
|
|
148
|
+
result.push(...mapHooksToResult(fieldHooks.postOrdered ?? []));
|
|
149
|
+
result.push(...mapHooksToResult(fieldHooks.postEnforced ?? []));
|
|
150
|
+
} else result.push(...mapHooksToResult(fieldHooks.normal ?? []));
|
|
151
|
+
} else {
|
|
152
|
+
result.push(...this.selectHooks(key, { order: "pre" }));
|
|
153
|
+
result.push(...this.selectHooks(key, { order: "normal" }));
|
|
154
|
+
result.push(...this.selectHooks(key, { order: "post" }));
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
} else if (require_helpers.isPluginHookField(key)) {
|
|
160
|
+
if (this.hooks[key]) {
|
|
161
|
+
const fieldHooks = this.hooks[key];
|
|
162
|
+
if (options?.order) {
|
|
163
|
+
const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
|
|
164
|
+
const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
|
|
165
|
+
if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
|
|
166
|
+
return {
|
|
167
|
+
handler: hook.handler,
|
|
168
|
+
plugin: hook.plugin,
|
|
169
|
+
context: plugin.context
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
if (options?.order === "pre") {
|
|
173
|
+
result.push(...mapHooksToResult(fieldHooks.preOrdered ?? []));
|
|
174
|
+
result.push(...mapHooksToResult(fieldHooks.preEnforced ?? []));
|
|
175
|
+
} else if (options?.order === "post") {
|
|
176
|
+
result.push(...mapHooksToResult(fieldHooks.postOrdered ?? []));
|
|
177
|
+
result.push(...mapHooksToResult(fieldHooks.postEnforced ?? []));
|
|
178
|
+
} else result.push(...mapHooksToResult(fieldHooks.normal ?? []));
|
|
179
|
+
} else {
|
|
180
|
+
result.push(...this.selectHooks(key, { order: "pre" }));
|
|
181
|
+
result.push(...this.selectHooks(key, { order: "normal" }));
|
|
182
|
+
result.push(...this.selectHooks(key, { order: "post" }));
|
|
183
|
+
}
|
|
142
184
|
}
|
|
143
|
-
} else
|
|
144
|
-
const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
|
|
145
|
-
if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
|
|
146
|
-
return {
|
|
147
|
-
handle: h.handler,
|
|
148
|
-
context: plugin.context
|
|
149
|
-
};
|
|
150
|
-
}));
|
|
185
|
+
} else throw new Error(`Unknown plugin hook key: ${String(key)}`);
|
|
151
186
|
return result;
|
|
152
187
|
}
|
|
153
188
|
constructor(config, workspaceConfig) {
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { PLUGIN_NON_HOOK_FIELDS } from "../../types/plugin.mjs";
|
|
2
|
-
import { addPluginHook,
|
|
2
|
+
import { addPluginHook, isPlugin, isPluginConfig, isPluginHook, isPluginHookField, isUnpluginHookField, isUnpluginHookKey } from "../../plugin-utils/helpers.mjs";
|
|
3
3
|
import { PowerlinesContext } from "./context.mjs";
|
|
4
|
+
import { isUnpluginBuilderVariant } from "../unplugin/helpers.mjs";
|
|
4
5
|
import { createPluginContext } from "./plugin-context.mjs";
|
|
5
6
|
import { resolvePackage } from "@stryke/fs/resolve";
|
|
6
7
|
import { isFunction } from "@stryke/type-checks/is-function";
|
|
7
8
|
import { isObject } from "@stryke/type-checks/is-object";
|
|
9
|
+
import { isSetObject } from "@stryke/type-checks/is-set-object";
|
|
8
10
|
|
|
9
11
|
//#region ../powerlines/src/lib/contexts/environment-context.ts
|
|
10
12
|
var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends PowerlinesContext {
|
|
@@ -59,94 +61,127 @@ var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends Po
|
|
|
59
61
|
});
|
|
60
62
|
this.#hooks = Object.keys(resolvedPlugin).filter((key) => !PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
|
|
61
63
|
const hook = key;
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
ret[hook] ??= {
|
|
64
|
+
if (isPluginHookField(hook)) {
|
|
65
|
+
const pluginHook = resolvedPlugin[hook];
|
|
66
|
+
if (!isPluginHook(pluginHook)) return ret;
|
|
67
|
+
ret[hook] ??= {
|
|
68
|
+
preEnforced: [],
|
|
69
|
+
preOrdered: [],
|
|
70
|
+
normal: [],
|
|
71
|
+
postEnforced: [],
|
|
72
|
+
postOrdered: []
|
|
73
|
+
};
|
|
66
74
|
if (resolvedPlugin.enforce) {
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
const hookListOrder$1 = `${resolvedPlugin.enforce}Enforced`;
|
|
76
|
+
ret[hook][hookListOrder$1] ??= [];
|
|
77
|
+
const bucket = ret[hook][hookListOrder$1];
|
|
78
|
+
addPluginHook(context, resolvedPlugin, pluginHook, bucket);
|
|
69
79
|
return ret;
|
|
70
80
|
}
|
|
71
81
|
if (isFunction(pluginHook) || !pluginHook.order) {
|
|
72
82
|
ret[hook].normal ??= [];
|
|
73
|
-
|
|
83
|
+
const bucket = ret[hook].normal;
|
|
84
|
+
addPluginHook(context, resolvedPlugin, pluginHook, bucket);
|
|
74
85
|
return ret;
|
|
75
86
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
ret
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
const hookListOrder = `${pluginHook.order}Ordered`;
|
|
88
|
+
ret[hook][hookListOrder] ??= [];
|
|
89
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][hookListOrder]);
|
|
90
|
+
return ret;
|
|
91
|
+
} else if (isUnpluginHookField(hook)) {
|
|
92
|
+
const unpluginPlugin = resolvedPlugin[hook];
|
|
93
|
+
if (!isSetObject(unpluginPlugin)) return ret;
|
|
94
|
+
for (const field of Object.keys(unpluginPlugin)) {
|
|
95
|
+
const variantField = field;
|
|
96
|
+
const pluginHook = unpluginPlugin[variantField];
|
|
97
|
+
if (!isPluginHook(pluginHook)) continue;
|
|
98
|
+
ret[hook] ??= {};
|
|
99
|
+
ret[hook][variantField] ??= {
|
|
100
|
+
preEnforced: [],
|
|
101
|
+
preOrdered: [],
|
|
102
|
+
normal: [],
|
|
103
|
+
postEnforced: [],
|
|
104
|
+
postOrdered: []
|
|
105
|
+
};
|
|
106
|
+
if (resolvedPlugin.enforce) {
|
|
107
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField][`${resolvedPlugin.enforce}Enforced`]);
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
if (isFunction(pluginHook) || !pluginHook.order) {
|
|
111
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField].normal);
|
|
112
|
+
return ret;
|
|
113
|
+
}
|
|
114
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][variantField][`${pluginHook.order}Ordered`]);
|
|
115
|
+
}
|
|
116
|
+
} else this.warn(`Unknown plugin hook field: ${String(hook)}`);
|
|
85
117
|
return ret;
|
|
86
118
|
}, this.hooks);
|
|
87
119
|
}
|
|
88
120
|
/**
|
|
89
121
|
* Retrieves the hook handlers for a specific hook name
|
|
90
122
|
*/
|
|
91
|
-
selectHooks(
|
|
123
|
+
selectHooks(key, options) {
|
|
92
124
|
const result = [];
|
|
93
|
-
if (
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
125
|
+
if (isUnpluginHookKey(key)) {
|
|
126
|
+
const variant = String(key).split(":")[0];
|
|
127
|
+
if (isUnpluginBuilderVariant(variant)) {
|
|
128
|
+
const hooks = this.hooks[variant];
|
|
129
|
+
if (hooks) {
|
|
130
|
+
const field = String(key).split(":")[1];
|
|
131
|
+
if (field && hooks[field]) {
|
|
132
|
+
const fieldHooks = hooks[field];
|
|
133
|
+
if (options?.order) {
|
|
134
|
+
const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
|
|
135
|
+
const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
|
|
136
|
+
if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
|
|
137
|
+
return {
|
|
138
|
+
handler: hook.handler,
|
|
139
|
+
plugin: hook.plugin,
|
|
140
|
+
context: plugin.context
|
|
141
|
+
};
|
|
142
|
+
});
|
|
143
|
+
if (options?.order === "pre") {
|
|
144
|
+
result.push(...mapHooksToResult(fieldHooks.preOrdered ?? []));
|
|
145
|
+
result.push(...mapHooksToResult(fieldHooks.preEnforced ?? []));
|
|
146
|
+
} else if (options?.order === "post") {
|
|
147
|
+
result.push(...mapHooksToResult(fieldHooks.postOrdered ?? []));
|
|
148
|
+
result.push(...mapHooksToResult(fieldHooks.postEnforced ?? []));
|
|
149
|
+
} else result.push(...mapHooksToResult(fieldHooks.normal ?? []));
|
|
150
|
+
} else {
|
|
151
|
+
result.push(...this.selectHooks(key, { order: "pre" }));
|
|
152
|
+
result.push(...this.selectHooks(key, { order: "normal" }));
|
|
153
|
+
result.push(...this.selectHooks(key, { order: "post" }));
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} else if (isPluginHookField(key)) {
|
|
159
|
+
if (this.hooks[key]) {
|
|
160
|
+
const fieldHooks = this.hooks[key];
|
|
161
|
+
if (options?.order) {
|
|
162
|
+
const mapHooksToResult = (hooksList) => hooksList.map((hook) => {
|
|
163
|
+
const plugin = this.plugins.find((p) => p.plugin.name === hook.plugin.name);
|
|
164
|
+
if (!plugin) throw new Error(`Could not find plugin context for plugin "${hook.plugin.name}".`);
|
|
165
|
+
return {
|
|
166
|
+
handler: hook.handler,
|
|
167
|
+
plugin: hook.plugin,
|
|
168
|
+
context: plugin.context
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
if (options?.order === "pre") {
|
|
172
|
+
result.push(...mapHooksToResult(fieldHooks.preOrdered ?? []));
|
|
173
|
+
result.push(...mapHooksToResult(fieldHooks.preEnforced ?? []));
|
|
174
|
+
} else if (options?.order === "post") {
|
|
175
|
+
result.push(...mapHooksToResult(fieldHooks.postOrdered ?? []));
|
|
176
|
+
result.push(...mapHooksToResult(fieldHooks.postEnforced ?? []));
|
|
177
|
+
} else result.push(...mapHooksToResult(fieldHooks.normal ?? []));
|
|
178
|
+
} else {
|
|
179
|
+
result.push(...this.selectHooks(key, { order: "pre" }));
|
|
180
|
+
result.push(...this.selectHooks(key, { order: "normal" }));
|
|
181
|
+
result.push(...this.selectHooks(key, { order: "post" }));
|
|
182
|
+
}
|
|
141
183
|
}
|
|
142
|
-
} else
|
|
143
|
-
const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
|
|
144
|
-
if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
|
|
145
|
-
return {
|
|
146
|
-
handle: h.handler,
|
|
147
|
-
context: plugin.context
|
|
148
|
-
};
|
|
149
|
-
}));
|
|
184
|
+
} else throw new Error(`Unknown plugin hook key: ${String(key)}`);
|
|
150
185
|
return result;
|
|
151
186
|
}
|
|
152
187
|
constructor(config, workspaceConfig) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_build = require('../../types/build.cjs');
|
|
2
3
|
let defu = require("defu");
|
|
4
|
+
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
3
5
|
|
|
4
6
|
//#region ../powerlines/src/lib/unplugin/helpers.ts
|
|
5
7
|
/**
|
|
@@ -12,6 +14,16 @@ let defu = require("defu");
|
|
|
12
14
|
function combineContexts(context, unplugin) {
|
|
13
15
|
return (0, defu.defu)(context, unplugin);
|
|
14
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* Checks if a value is a valid UnpluginBuilderVariant.
|
|
19
|
+
*
|
|
20
|
+
* @param str - The value to check.
|
|
21
|
+
* @returns True if the value is a UnpluginBuilderVariant, false otherwise.
|
|
22
|
+
*/
|
|
23
|
+
function isUnpluginBuilderVariant(str) {
|
|
24
|
+
return (0, __stryke_type_checks_is_set_string.isSetString)(str) && require_build.UNPLUGIN_BUILDER_VARIANTS.includes(str);
|
|
25
|
+
}
|
|
15
26
|
|
|
16
27
|
//#endregion
|
|
17
|
-
exports.combineContexts = combineContexts;
|
|
28
|
+
exports.combineContexts = combineContexts;
|
|
29
|
+
exports.isUnpluginBuilderVariant = isUnpluginBuilderVariant;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { UNPLUGIN_BUILDER_VARIANTS } from "../../types/build.mjs";
|
|
1
2
|
import { defu } from "defu";
|
|
3
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
2
4
|
|
|
3
5
|
//#region ../powerlines/src/lib/unplugin/helpers.ts
|
|
4
6
|
/**
|
|
@@ -11,6 +13,15 @@ import { defu } from "defu";
|
|
|
11
13
|
function combineContexts(context, unplugin) {
|
|
12
14
|
return defu(context, unplugin);
|
|
13
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* Checks if a value is a valid UnpluginBuilderVariant.
|
|
18
|
+
*
|
|
19
|
+
* @param str - The value to check.
|
|
20
|
+
* @returns True if the value is a UnpluginBuilderVariant, false otherwise.
|
|
21
|
+
*/
|
|
22
|
+
function isUnpluginBuilderVariant(str) {
|
|
23
|
+
return isSetString(str) && UNPLUGIN_BUILDER_VARIANTS.includes(str);
|
|
24
|
+
}
|
|
14
25
|
|
|
15
26
|
//#endregion
|
|
16
|
-
export { combineContexts };
|
|
27
|
+
export { combineContexts, isUnpluginBuilderVariant };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_logger = require('../logger.cjs');
|
|
3
|
-
const require_source_file = require('../utilities/source-file.cjs');
|
|
4
3
|
const require_helpers = require('./helpers.cjs');
|
|
4
|
+
const require_source_file = require('../utilities/source-file.cjs');
|
|
5
5
|
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
6
6
|
let __stryke_path_replace = require("@stryke/path/replace");
|
|
7
7
|
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
@@ -86,8 +86,8 @@ export * from "${(0, __stryke_type_checks_is_string.isString)(resolved) ? resolv
|
|
|
86
86
|
}
|
|
87
87
|
async function transform(code, id) {
|
|
88
88
|
let transformed = code;
|
|
89
|
-
for (const
|
|
90
|
-
const result = await handler.
|
|
89
|
+
for (const hook of ctx.$$internal.environment.selectHooks("transform")) {
|
|
90
|
+
const result = await hook.handler.apply(require_helpers.combineContexts(ctx, this), [require_source_file.getString(transformed), id]);
|
|
91
91
|
if (result) transformed = result;
|
|
92
92
|
}
|
|
93
93
|
return transformed;
|