@powerlines/plugin-vite 0.14.126 → 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.
Files changed (40) hide show
  1. package/dist/powerlines/src/internal/helpers/hooks.cjs +15 -12
  2. package/dist/powerlines/src/internal/helpers/hooks.d.cts +0 -1
  3. package/dist/powerlines/src/internal/helpers/hooks.d.mts +0 -1
  4. package/dist/powerlines/src/internal/helpers/hooks.mjs +15 -12
  5. package/dist/powerlines/src/lib/contexts/environment-context.cjs +108 -73
  6. package/dist/powerlines/src/lib/contexts/environment-context.mjs +109 -74
  7. package/dist/powerlines/src/lib/unplugin/helpers.cjs +13 -1
  8. package/dist/powerlines/src/lib/unplugin/helpers.mjs +12 -1
  9. package/dist/powerlines/src/lib/unplugin/index.cjs +1 -1
  10. package/dist/powerlines/src/lib/unplugin/index.mjs +1 -1
  11. package/dist/powerlines/src/lib/unplugin/plugin.cjs +3 -3
  12. package/dist/powerlines/src/lib/unplugin/plugin.mjs +3 -3
  13. package/dist/powerlines/src/plugin-utils/helpers.cjs +34 -15
  14. package/dist/powerlines/src/plugin-utils/helpers.mjs +33 -15
  15. package/dist/powerlines/src/types/api.d.cts +4 -4
  16. package/dist/powerlines/src/types/api.d.mts +4 -4
  17. package/dist/powerlines/src/types/babel.d.mts +1 -1
  18. package/dist/powerlines/src/types/build.cjs +11 -3
  19. package/dist/powerlines/src/types/build.d.cts +34 -3
  20. package/dist/powerlines/src/types/build.d.mts +34 -3
  21. package/dist/powerlines/src/types/build.mjs +10 -3
  22. package/dist/powerlines/src/types/config.d.cts +14 -4
  23. package/dist/powerlines/src/types/config.d.mts +15 -5
  24. package/dist/powerlines/src/types/context.d.cts +9 -8
  25. package/dist/powerlines/src/types/context.d.mts +8 -7
  26. package/dist/powerlines/src/types/hooks.d.cts +25 -23
  27. package/dist/powerlines/src/types/hooks.d.mts +25 -23
  28. package/dist/powerlines/src/types/internal.d.cts +6 -4
  29. package/dist/powerlines/src/types/internal.d.mts +6 -4
  30. package/dist/powerlines/src/types/plugin.cjs +5 -4
  31. package/dist/powerlines/src/types/plugin.d.cts +36 -65
  32. package/dist/powerlines/src/types/plugin.d.mts +36 -65
  33. package/dist/powerlines/src/types/plugin.mjs +6 -5
  34. package/dist/powerlines/src/types/resolved.d.cts +16 -5
  35. package/dist/powerlines/src/types/resolved.d.mts +16 -6
  36. package/dist/powerlines/src/types/unplugin.d.cts +22 -0
  37. package/dist/powerlines/src/types/unplugin.d.mts +23 -0
  38. package/dist/types/plugin.d.cts +5 -1
  39. package/dist/types/plugin.d.mts +5 -1
  40. 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 hook - The hook to call.
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, hook, options, ...args) {
29
- const handlers = context.selectHooks(hook, options);
30
- if (handlers.length > 0) {
31
- context.log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.default.bold.cyanBright(`${hook}${options?.order ? ` (${options.order})` : ""}`)}`);
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(handlers.map(async (handler) => {
34
- if (!(0, __stryke_type_checks_is_function.isFunction)(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
35
- return Promise.resolve(handler.handle.apply(handler.context, [...args]));
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 handler of handlers) {
38
- if (!(0, __stryke_type_checks_is_function.isFunction)(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
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(handler.handle.apply(handler.context, [...args])));
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(handler.handle.apply(handler.context, [...sequenceArgs]));
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 hook - The hook to call.
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, hook, options, ...args) {
27
- const handlers = context.selectHooks(hook, options);
28
- if (handlers.length > 0) {
29
- context.log(LogLevelLabel.DEBUG, ` 🧩 Calling plugin hook: ${chalk.bold.cyanBright(`${hook}${options?.order ? ` (${options.order})` : ""}`)}`);
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(handlers.map(async (handler) => {
32
- if (!isFunction(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
33
- return Promise.resolve(handler.handle.apply(handler.context, [...args]));
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 handler of handlers) {
36
- if (!isFunction(handler.handle)) throw new Error(`Plugin hook handler for hook "${hook}" is not a function.`);
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(handler.handle.apply(handler.context, [...args])));
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(handler.handle.apply(handler.context, [...sequenceArgs]));
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
- const pluginHook = resolvedPlugin[hook];
64
- if (!require_helpers.isPluginHook(pluginHook)) return ret;
65
- if (!require_helpers.isHookExternal(hook)) {
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
- ret[hook][`${resolvedPlugin.enforce}Enforced`] ??= [];
69
- require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${resolvedPlugin.enforce}Enforced`]);
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
- require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook].normal);
84
+ const bucket = ret[hook].normal;
85
+ require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, bucket);
75
86
  return ret;
76
87
  }
77
- ret[hook][`${pluginHook.order}Ordered`] ??= [];
78
- require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${pluginHook.order}Ordered`]);
79
- } else {
80
- ret[hook] ??= [];
81
- ret[hook].push({
82
- plugin: resolvedPlugin,
83
- hook: require_helpers.getHookHandler(pluginHook).bind(context)
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(hook, options) {
124
+ selectHooks(key, options) {
93
125
  const result = [];
94
- if (this.hooks[hook]) if (!require_helpers.isHookExternal(hook)) {
95
- const hooks = this.hooks[hook];
96
- if (options?.order) if (options?.order === "pre") {
97
- result.push(...(hooks.preOrdered ?? []).map((h) => {
98
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
99
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
100
- return {
101
- handle: h.handler,
102
- context: plugin.context
103
- };
104
- }));
105
- result.push(...(hooks.preEnforced ?? []).map((h) => {
106
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
107
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
108
- return {
109
- handle: h.handler,
110
- context: plugin.context
111
- };
112
- }));
113
- } else if (options?.order === "post") {
114
- result.push(...(hooks.postOrdered ?? []).map((h) => {
115
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
116
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
117
- return {
118
- handle: h.handler,
119
- context: plugin.context
120
- };
121
- }));
122
- result.push(...(hooks.postEnforced ?? []).map((h) => {
123
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
124
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
125
- return {
126
- handle: h.handler,
127
- context: plugin.context
128
- };
129
- }));
130
- } else result.push(...(hooks.normal ?? []).map((h) => {
131
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
132
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
133
- return {
134
- handle: h.handler,
135
- context: plugin.context
136
- };
137
- }));
138
- else {
139
- result.push(...this.selectHooks(hook, { order: "pre" }));
140
- result.push(...this.selectHooks(hook, { order: "normal" }));
141
- result.push(...this.selectHooks(hook, { order: "post" }));
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 result.push(...this.hooks[hook].map((h) => {
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, getHookHandler, isHookExternal, isPlugin, isPluginConfig, isPluginHook } from "../../plugin-utils/helpers.mjs";
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
- const pluginHook = resolvedPlugin[hook];
63
- if (!isPluginHook(pluginHook)) return ret;
64
- if (!isHookExternal(hook)) {
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
- ret[hook][`${resolvedPlugin.enforce}Enforced`] ??= [];
68
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${resolvedPlugin.enforce}Enforced`]);
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
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook].normal);
83
+ const bucket = ret[hook].normal;
84
+ addPluginHook(context, resolvedPlugin, pluginHook, bucket);
74
85
  return ret;
75
86
  }
76
- ret[hook][`${pluginHook.order}Ordered`] ??= [];
77
- addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${pluginHook.order}Ordered`]);
78
- } else {
79
- ret[hook] ??= [];
80
- ret[hook].push({
81
- plugin: resolvedPlugin,
82
- hook: getHookHandler(pluginHook).bind(context)
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(hook, options) {
123
+ selectHooks(key, options) {
92
124
  const result = [];
93
- if (this.hooks[hook]) if (!isHookExternal(hook)) {
94
- const hooks = this.hooks[hook];
95
- if (options?.order) if (options?.order === "pre") {
96
- result.push(...(hooks.preOrdered ?? []).map((h) => {
97
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
98
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
99
- return {
100
- handle: h.handler,
101
- context: plugin.context
102
- };
103
- }));
104
- result.push(...(hooks.preEnforced ?? []).map((h) => {
105
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
106
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
107
- return {
108
- handle: h.handler,
109
- context: plugin.context
110
- };
111
- }));
112
- } else if (options?.order === "post") {
113
- result.push(...(hooks.postOrdered ?? []).map((h) => {
114
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
115
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
116
- return {
117
- handle: h.handler,
118
- context: plugin.context
119
- };
120
- }));
121
- result.push(...(hooks.postEnforced ?? []).map((h) => {
122
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
123
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
124
- return {
125
- handle: h.handler,
126
- context: plugin.context
127
- };
128
- }));
129
- } else result.push(...(hooks.normal ?? []).map((h) => {
130
- const plugin = this.plugins.find((p) => p.plugin.name === h.plugin.name);
131
- if (!plugin) throw new Error(`Could not find plugin context for plugin "${h.plugin.name}".`);
132
- return {
133
- handle: h.handler,
134
- context: plugin.context
135
- };
136
- }));
137
- else {
138
- result.push(...this.selectHooks(hook, { order: "pre" }));
139
- result.push(...this.selectHooks(hook, { order: "normal" }));
140
- result.push(...this.selectHooks(hook, { order: "post" }));
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 result.push(...this.hooks[hook].map((h) => {
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,3 +1,3 @@
1
- require('./factory.cjs');
2
1
  const require_helpers = require('./helpers.cjs');
2
+ require('./factory.cjs');
3
3
  const require_plugin = require('./plugin.cjs');
@@ -1,5 +1,5 @@
1
+ import { combineContexts, isUnpluginBuilderVariant } from "./helpers.mjs";
1
2
  import "./factory.mjs";
2
- import { combineContexts } from "./helpers.mjs";
3
3
  import { createUnplugin } from "./plugin.mjs";
4
4
 
5
5
  export { };
@@ -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 handler of ctx.$$internal.environment.selectHooks("transform")) {
90
- const result = await handler.handle.apply(require_helpers.combineContexts(ctx, this), [require_source_file.getString(transformed), id]);
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;