@powerlines/plugin-webpack 0.5.132 → 0.5.134
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/_virtual/rolldown_runtime.cjs +29 -0
- package/dist/helpers/index.cjs +2 -3
- package/dist/helpers/index.d.cts +1 -3
- package/dist/helpers/index.d.mts +1 -3
- package/dist/helpers/index.mjs +1 -2
- package/dist/helpers/unplugin.cjs +11 -2
- package/dist/helpers/unplugin.d.cts +6 -2
- package/dist/helpers/unplugin.d.mts +6 -2
- package/dist/helpers/unplugin.mjs +9 -1
- package/dist/index.cjs +8 -50
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +5 -5
- package/dist/index.mjs +3 -46
- package/dist/powerlines/schemas/fs.cjs +226 -0
- package/dist/powerlines/schemas/fs.mjs +224 -0
- package/dist/powerlines/src/api.cjs +580 -0
- package/dist/powerlines/src/api.mjs +578 -0
- package/dist/powerlines/src/internal/babel/module-resolver-plugin.cjs +86 -0
- package/dist/powerlines/src/internal/babel/module-resolver-plugin.mjs +84 -0
- package/dist/powerlines/src/internal/helpers/environment.cjs +52 -0
- package/dist/powerlines/src/internal/helpers/environment.mjs +48 -0
- package/dist/powerlines/src/internal/helpers/generate-types.cjs +51 -0
- package/dist/powerlines/src/internal/helpers/generate-types.mjs +49 -0
- package/dist/powerlines/src/internal/helpers/hooks.cjs +63 -0
- package/dist/powerlines/src/internal/helpers/hooks.mjs +61 -0
- package/dist/powerlines/src/internal/helpers/install-dependencies.cjs +25 -0
- package/dist/powerlines/src/internal/helpers/install-dependencies.mjs +24 -0
- package/dist/powerlines/src/internal/helpers/install.cjs +37 -0
- package/dist/powerlines/src/internal/helpers/install.mjs +36 -0
- package/dist/powerlines/src/internal/helpers/resolve-tsconfig.cjs +98 -0
- package/dist/powerlines/src/internal/helpers/resolve-tsconfig.mjs +94 -0
- package/dist/powerlines/src/internal/helpers/resolver.cjs +43 -0
- package/dist/powerlines/src/internal/helpers/resolver.mjs +41 -0
- package/dist/powerlines/src/lib/build/webpack.cjs +47 -0
- package/dist/powerlines/src/lib/build/webpack.mjs +45 -0
- package/dist/powerlines/src/lib/config-file.cjs +79 -0
- package/dist/powerlines/src/lib/config-file.mjs +76 -0
- package/dist/powerlines/src/lib/contexts/api-context.cjs +184 -0
- package/dist/powerlines/src/lib/contexts/api-context.mjs +182 -0
- package/dist/powerlines/src/lib/contexts/context.cjs +933 -0
- package/dist/powerlines/src/lib/contexts/context.mjs +931 -0
- package/dist/powerlines/src/lib/contexts/environment-context.cjs +160 -0
- package/dist/powerlines/src/lib/contexts/environment-context.mjs +159 -0
- package/dist/powerlines/src/lib/contexts/plugin-context.cjs +75 -0
- package/dist/powerlines/src/lib/contexts/plugin-context.mjs +74 -0
- package/dist/powerlines/src/lib/entry.cjs +69 -0
- package/dist/powerlines/src/lib/entry.mjs +67 -0
- package/dist/powerlines/src/lib/fs/helpers.cjs +85 -0
- package/dist/powerlines/src/lib/fs/helpers.mjs +81 -0
- package/dist/powerlines/src/lib/fs/storage/base.cjs +196 -0
- package/dist/powerlines/src/lib/fs/storage/base.mjs +195 -0
- package/dist/powerlines/src/lib/fs/storage/file-system.cjs +170 -0
- package/dist/powerlines/src/lib/fs/storage/file-system.mjs +169 -0
- package/dist/powerlines/src/lib/fs/storage/virtual.cjs +88 -0
- package/dist/powerlines/src/lib/fs/storage/virtual.mjs +87 -0
- package/dist/powerlines/src/lib/fs/vfs.cjs +830 -0
- package/dist/powerlines/src/lib/fs/vfs.mjs +828 -0
- package/dist/powerlines/src/lib/logger.cjs +58 -0
- package/dist/powerlines/src/lib/logger.mjs +55 -0
- package/dist/powerlines/src/lib/typescript/ts-morph.cjs +104 -0
- package/dist/powerlines/src/lib/typescript/ts-morph.mjs +102 -0
- package/dist/powerlines/src/lib/typescript/tsconfig.cjs +149 -0
- package/dist/powerlines/src/lib/typescript/tsconfig.mjs +144 -0
- package/dist/powerlines/src/lib/unplugin/factory.cjs +6 -0
- package/dist/powerlines/src/lib/unplugin/factory.mjs +8 -0
- package/dist/powerlines/src/lib/unplugin/helpers.cjs +17 -0
- package/dist/powerlines/src/lib/unplugin/helpers.mjs +16 -0
- package/dist/powerlines/src/lib/unplugin/index.cjs +3 -0
- package/dist/powerlines/src/lib/unplugin/index.mjs +5 -0
- package/dist/powerlines/src/lib/unplugin/plugin.cjs +128 -0
- package/dist/powerlines/src/lib/unplugin/plugin.mjs +127 -0
- package/dist/powerlines/src/lib/utilities/file-header.cjs +22 -0
- package/dist/powerlines/src/lib/utilities/file-header.mjs +21 -0
- package/dist/powerlines/src/lib/utilities/meta.cjs +45 -0
- package/dist/powerlines/src/lib/utilities/meta.mjs +41 -0
- package/dist/powerlines/src/lib/utilities/source-file.cjs +22 -0
- package/dist/powerlines/src/lib/utilities/source-file.mjs +21 -0
- package/dist/powerlines/src/plugin-utils/helpers.cjs +148 -0
- package/dist/powerlines/src/plugin-utils/helpers.mjs +138 -0
- package/dist/powerlines/src/plugin-utils/paths.cjs +36 -0
- package/dist/powerlines/src/plugin-utils/paths.mjs +35 -0
- package/dist/powerlines/src/types/babel.d.mts +4 -0
- package/dist/powerlines/src/types/build.cjs +15 -0
- package/dist/powerlines/src/types/build.d.cts +149 -0
- package/dist/powerlines/src/types/build.d.mts +149 -0
- package/dist/powerlines/src/types/build.mjs +14 -0
- package/dist/powerlines/src/types/commands.cjs +16 -0
- package/dist/powerlines/src/types/commands.d.cts +8 -0
- package/dist/powerlines/src/types/commands.d.mts +9 -0
- package/dist/powerlines/src/types/commands.mjs +15 -0
- package/dist/powerlines/src/types/config.d.cts +377 -0
- package/dist/powerlines/src/types/config.d.mts +379 -0
- package/dist/powerlines/src/types/context.d.cts +403 -0
- package/dist/powerlines/src/types/context.d.mts +405 -0
- package/dist/powerlines/src/types/fs.d.cts +486 -0
- package/dist/powerlines/src/types/fs.d.mts +486 -0
- package/dist/powerlines/src/types/hooks.d.mts +2 -0
- package/dist/powerlines/src/types/plugin.cjs +32 -0
- package/dist/powerlines/src/types/plugin.d.cts +231 -0
- package/dist/powerlines/src/types/plugin.d.mts +231 -0
- package/dist/powerlines/src/types/plugin.mjs +31 -0
- package/dist/powerlines/src/types/resolved.d.cts +82 -0
- package/dist/powerlines/src/types/resolved.d.mts +83 -0
- package/dist/powerlines/src/types/tsconfig.d.cts +69 -0
- package/dist/powerlines/src/types/tsconfig.d.mts +69 -0
- package/dist/types/index.cjs +0 -2
- package/dist/types/index.d.cts +1 -2
- package/dist/types/index.d.mts +1 -2
- package/dist/types/index.mjs +0 -3
- package/dist/types/plugin.cjs +0 -1
- package/dist/types/plugin.d.cts +12 -1
- package/dist/types/plugin.d.mts +12 -1
- package/dist/types/plugin.mjs +0 -2
- package/package.json +5 -5
- package/dist/helpers-B15z10jN.mjs +0 -1
- package/dist/helpers-LF26RHol.cjs +0 -0
- package/dist/index-9iG2qHLe.d.mts +0 -1
- package/dist/index-D4ELpJXS.d.cts +0 -1
- package/dist/index-D6CnpA_r.d.cts +0 -1
- package/dist/index-DL0uimUT.d.mts +0 -1
- package/dist/plugin-C5bG6Zu0.d.mts +0 -1772
- package/dist/plugin-Cl1J-dKa.d.cts +0 -1769
- package/dist/plugin-ifZVa20V.mjs +0 -1
- package/dist/plugin-pBKbb5K9.cjs +0 -0
- package/dist/types-U3zd8PTP.mjs +0 -1
- package/dist/types-o3zWarRp.cjs +0 -0
- package/dist/unplugin-Bo9KoKSB.d.cts +0 -7
- package/dist/unplugin-Ct4wZxE5.d.mts +0 -7
- package/dist/unplugin-GJmHohOE.mjs +0 -4617
- package/dist/unplugin-bKYETUU8.cjs +0 -4661
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_plugin = require('../../types/plugin.cjs');
|
|
3
|
+
const require_helpers = require('../../plugin-utils/helpers.cjs');
|
|
4
|
+
const require_context = require('./context.cjs');
|
|
5
|
+
const require_plugin_context = require('./plugin-context.cjs');
|
|
6
|
+
let __stryke_fs_resolve = require("@stryke/fs/resolve");
|
|
7
|
+
let __stryke_type_checks_is_function = require("@stryke/type-checks/is-function");
|
|
8
|
+
let __stryke_type_checks_is_object = require("@stryke/type-checks/is-object");
|
|
9
|
+
|
|
10
|
+
//#region ../powerlines/src/lib/contexts/environment-context.ts
|
|
11
|
+
var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends require_context.PowerlinesContext {
|
|
12
|
+
/**
|
|
13
|
+
* The hooks registered by plugins in this environment
|
|
14
|
+
*/
|
|
15
|
+
#hooks = {};
|
|
16
|
+
/**
|
|
17
|
+
* Create a new Storm context from the workspace root and user config.
|
|
18
|
+
*
|
|
19
|
+
* @param workspaceConfig - The root directory of the workspace.
|
|
20
|
+
* @param config - The user configuration options.
|
|
21
|
+
* @returns A promise that resolves to the new context.
|
|
22
|
+
*/
|
|
23
|
+
static async fromConfig(workspaceConfig, config) {
|
|
24
|
+
const context = new PowerlinesEnvironmentContext(config, workspaceConfig);
|
|
25
|
+
await context.init();
|
|
26
|
+
const powerlinesPath = await (0, __stryke_fs_resolve.resolvePackage)("powerlines");
|
|
27
|
+
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
28
|
+
context.powerlinesPath = powerlinesPath;
|
|
29
|
+
return context;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The resolved environment configuration
|
|
33
|
+
*/
|
|
34
|
+
environment;
|
|
35
|
+
/**
|
|
36
|
+
* The list of plugins applied to this environment
|
|
37
|
+
*/
|
|
38
|
+
plugins = [];
|
|
39
|
+
/**
|
|
40
|
+
* The resolved configuration options
|
|
41
|
+
*/
|
|
42
|
+
get config() {
|
|
43
|
+
return super.config;
|
|
44
|
+
}
|
|
45
|
+
get hooks() {
|
|
46
|
+
return this.#hooks;
|
|
47
|
+
}
|
|
48
|
+
async addPlugin(plugin) {
|
|
49
|
+
let resolvedPlugin = plugin;
|
|
50
|
+
if ((0, __stryke_type_checks_is_function.isFunction)(plugin.applyToEnvironment)) {
|
|
51
|
+
const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
|
|
52
|
+
if (!result || (0, __stryke_type_checks_is_object.isObject)(result) && Object.keys(result).length === 0) return;
|
|
53
|
+
if (require_helpers.isPluginConfig(result)) return this.$$internal.addPlugin(result);
|
|
54
|
+
resolvedPlugin = require_helpers.isPlugin(result) ? result : plugin;
|
|
55
|
+
}
|
|
56
|
+
const context = require_plugin_context.createPluginContext(resolvedPlugin, this);
|
|
57
|
+
this.plugins.push({
|
|
58
|
+
plugin: resolvedPlugin,
|
|
59
|
+
context
|
|
60
|
+
});
|
|
61
|
+
this.#hooks = Object.keys(resolvedPlugin).filter((key) => !require_plugin.PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
|
|
62
|
+
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] ??= {};
|
|
67
|
+
if (resolvedPlugin.enforce) {
|
|
68
|
+
ret[hook][`${resolvedPlugin.enforce}Enforced`] ??= [];
|
|
69
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${resolvedPlugin.enforce}Enforced`]);
|
|
70
|
+
return ret;
|
|
71
|
+
}
|
|
72
|
+
if ((0, __stryke_type_checks_is_function.isFunction)(pluginHook) || !pluginHook.order) {
|
|
73
|
+
ret[hook].normal ??= [];
|
|
74
|
+
require_helpers.addPluginHook(context, resolvedPlugin, pluginHook, ret[hook].normal);
|
|
75
|
+
return ret;
|
|
76
|
+
}
|
|
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
|
+
}
|
|
86
|
+
return ret;
|
|
87
|
+
}, this.hooks);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Retrieves the hook handlers for a specific hook name
|
|
91
|
+
*/
|
|
92
|
+
selectHooks(hook, options) {
|
|
93
|
+
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" }));
|
|
142
|
+
}
|
|
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
|
+
}));
|
|
151
|
+
return result;
|
|
152
|
+
}
|
|
153
|
+
constructor(config, workspaceConfig) {
|
|
154
|
+
super(workspaceConfig);
|
|
155
|
+
this.resolvedConfig = config;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
//#endregion
|
|
160
|
+
exports.PowerlinesEnvironmentContext = PowerlinesEnvironmentContext;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { PLUGIN_NON_HOOK_FIELDS } from "../../types/plugin.mjs";
|
|
2
|
+
import { addPluginHook, getHookHandler, isHookExternal, isPlugin, isPluginConfig, isPluginHook } from "../../plugin-utils/helpers.mjs";
|
|
3
|
+
import { PowerlinesContext } from "./context.mjs";
|
|
4
|
+
import { createPluginContext } from "./plugin-context.mjs";
|
|
5
|
+
import { resolvePackage } from "@stryke/fs/resolve";
|
|
6
|
+
import { isFunction } from "@stryke/type-checks/is-function";
|
|
7
|
+
import { isObject } from "@stryke/type-checks/is-object";
|
|
8
|
+
|
|
9
|
+
//#region ../powerlines/src/lib/contexts/environment-context.ts
|
|
10
|
+
var PowerlinesEnvironmentContext = class PowerlinesEnvironmentContext extends PowerlinesContext {
|
|
11
|
+
/**
|
|
12
|
+
* The hooks registered by plugins in this environment
|
|
13
|
+
*/
|
|
14
|
+
#hooks = {};
|
|
15
|
+
/**
|
|
16
|
+
* Create a new Storm context from the workspace root and user config.
|
|
17
|
+
*
|
|
18
|
+
* @param workspaceConfig - The root directory of the workspace.
|
|
19
|
+
* @param config - The user configuration options.
|
|
20
|
+
* @returns A promise that resolves to the new context.
|
|
21
|
+
*/
|
|
22
|
+
static async fromConfig(workspaceConfig, config) {
|
|
23
|
+
const context = new PowerlinesEnvironmentContext(config, workspaceConfig);
|
|
24
|
+
await context.init();
|
|
25
|
+
const powerlinesPath = await resolvePackage("powerlines");
|
|
26
|
+
if (!powerlinesPath) throw new Error("Could not resolve `powerlines` package location.");
|
|
27
|
+
context.powerlinesPath = powerlinesPath;
|
|
28
|
+
return context;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* The resolved environment configuration
|
|
32
|
+
*/
|
|
33
|
+
environment;
|
|
34
|
+
/**
|
|
35
|
+
* The list of plugins applied to this environment
|
|
36
|
+
*/
|
|
37
|
+
plugins = [];
|
|
38
|
+
/**
|
|
39
|
+
* The resolved configuration options
|
|
40
|
+
*/
|
|
41
|
+
get config() {
|
|
42
|
+
return super.config;
|
|
43
|
+
}
|
|
44
|
+
get hooks() {
|
|
45
|
+
return this.#hooks;
|
|
46
|
+
}
|
|
47
|
+
async addPlugin(plugin) {
|
|
48
|
+
let resolvedPlugin = plugin;
|
|
49
|
+
if (isFunction(plugin.applyToEnvironment)) {
|
|
50
|
+
const result = await Promise.resolve(plugin.applyToEnvironment(this.environment));
|
|
51
|
+
if (!result || isObject(result) && Object.keys(result).length === 0) return;
|
|
52
|
+
if (isPluginConfig(result)) return this.$$internal.addPlugin(result);
|
|
53
|
+
resolvedPlugin = isPlugin(result) ? result : plugin;
|
|
54
|
+
}
|
|
55
|
+
const context = createPluginContext(resolvedPlugin, this);
|
|
56
|
+
this.plugins.push({
|
|
57
|
+
plugin: resolvedPlugin,
|
|
58
|
+
context
|
|
59
|
+
});
|
|
60
|
+
this.#hooks = Object.keys(resolvedPlugin).filter((key) => !PLUGIN_NON_HOOK_FIELDS.includes(key)).reduce((ret, key) => {
|
|
61
|
+
const hook = key;
|
|
62
|
+
const pluginHook = resolvedPlugin[hook];
|
|
63
|
+
if (!isPluginHook(pluginHook)) return ret;
|
|
64
|
+
if (!isHookExternal(hook)) {
|
|
65
|
+
ret[hook] ??= {};
|
|
66
|
+
if (resolvedPlugin.enforce) {
|
|
67
|
+
ret[hook][`${resolvedPlugin.enforce}Enforced`] ??= [];
|
|
68
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook][`${resolvedPlugin.enforce}Enforced`]);
|
|
69
|
+
return ret;
|
|
70
|
+
}
|
|
71
|
+
if (isFunction(pluginHook) || !pluginHook.order) {
|
|
72
|
+
ret[hook].normal ??= [];
|
|
73
|
+
addPluginHook(context, resolvedPlugin, pluginHook, ret[hook].normal);
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
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
|
+
}
|
|
85
|
+
return ret;
|
|
86
|
+
}, this.hooks);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Retrieves the hook handlers for a specific hook name
|
|
90
|
+
*/
|
|
91
|
+
selectHooks(hook, options) {
|
|
92
|
+
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" }));
|
|
141
|
+
}
|
|
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
|
+
}));
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
constructor(config, workspaceConfig) {
|
|
153
|
+
super(workspaceConfig);
|
|
154
|
+
this.resolvedConfig = config;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
//#endregion
|
|
159
|
+
export { PowerlinesEnvironmentContext };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
3
|
+
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
4
|
+
|
|
5
|
+
//#region ../powerlines/src/lib/contexts/plugin-context.ts
|
|
6
|
+
/**
|
|
7
|
+
* Create a Proxy-based PluginContext
|
|
8
|
+
*
|
|
9
|
+
* @param plugin - The plugin instance
|
|
10
|
+
* @param environment - The environment context
|
|
11
|
+
* @returns The proxied plugin context
|
|
12
|
+
*/
|
|
13
|
+
function createPluginContext(plugin, environment) {
|
|
14
|
+
const normalizeMessage = (message) => {
|
|
15
|
+
return (0, __stryke_type_checks_is_string.isString)(message) ? message : message.message;
|
|
16
|
+
};
|
|
17
|
+
const log = environment.extendLog(plugin.name.replaceAll(":", " - "));
|
|
18
|
+
const callHookFn = async (hook, options, ...args) => {
|
|
19
|
+
return environment.$$internal.api.callHook(hook, {
|
|
20
|
+
sequential: true,
|
|
21
|
+
result: "merge",
|
|
22
|
+
...options,
|
|
23
|
+
environment
|
|
24
|
+
}, ...args);
|
|
25
|
+
};
|
|
26
|
+
return new Proxy({}, {
|
|
27
|
+
get(_, prop) {
|
|
28
|
+
if (prop === "$$internal") return {
|
|
29
|
+
...environment.$$internal,
|
|
30
|
+
environment,
|
|
31
|
+
callHook: callHookFn
|
|
32
|
+
};
|
|
33
|
+
if (prop === "log" || prop === "logger") return log;
|
|
34
|
+
if (prop === "error") return (message) => {
|
|
35
|
+
log(__storm_software_config_tools_types.LogLevelLabel.ERROR, normalizeMessage(message));
|
|
36
|
+
};
|
|
37
|
+
if (prop === "warn") return (message) => {
|
|
38
|
+
log(__storm_software_config_tools_types.LogLevelLabel.WARN, normalizeMessage(message));
|
|
39
|
+
};
|
|
40
|
+
if (prop === "info") return (message) => {
|
|
41
|
+
log(__storm_software_config_tools_types.LogLevelLabel.INFO, normalizeMessage(message));
|
|
42
|
+
};
|
|
43
|
+
if (prop === "debug") return (message) => {
|
|
44
|
+
log(__storm_software_config_tools_types.LogLevelLabel.DEBUG, normalizeMessage(message));
|
|
45
|
+
};
|
|
46
|
+
if (prop === "trace") return (message) => {
|
|
47
|
+
log(__storm_software_config_tools_types.LogLevelLabel.TRACE, normalizeMessage(message));
|
|
48
|
+
};
|
|
49
|
+
return environment[prop];
|
|
50
|
+
},
|
|
51
|
+
set(_, prop, value) {
|
|
52
|
+
if ([
|
|
53
|
+
"$$internal",
|
|
54
|
+
"environment",
|
|
55
|
+
"config",
|
|
56
|
+
"log",
|
|
57
|
+
"logger",
|
|
58
|
+
"error",
|
|
59
|
+
"warn",
|
|
60
|
+
"plugins",
|
|
61
|
+
"hooks",
|
|
62
|
+
"addPlugin",
|
|
63
|
+
"selectHooks"
|
|
64
|
+
].includes(prop)) {
|
|
65
|
+
log(__storm_software_config_tools_types.LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
environment[prop] = value;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.createPluginContext = createPluginContext;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
2
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
3
|
+
|
|
4
|
+
//#region ../powerlines/src/lib/contexts/plugin-context.ts
|
|
5
|
+
/**
|
|
6
|
+
* Create a Proxy-based PluginContext
|
|
7
|
+
*
|
|
8
|
+
* @param plugin - The plugin instance
|
|
9
|
+
* @param environment - The environment context
|
|
10
|
+
* @returns The proxied plugin context
|
|
11
|
+
*/
|
|
12
|
+
function createPluginContext(plugin, environment) {
|
|
13
|
+
const normalizeMessage = (message) => {
|
|
14
|
+
return isString(message) ? message : message.message;
|
|
15
|
+
};
|
|
16
|
+
const log = environment.extendLog(plugin.name.replaceAll(":", " - "));
|
|
17
|
+
const callHookFn = async (hook, options, ...args) => {
|
|
18
|
+
return environment.$$internal.api.callHook(hook, {
|
|
19
|
+
sequential: true,
|
|
20
|
+
result: "merge",
|
|
21
|
+
...options,
|
|
22
|
+
environment
|
|
23
|
+
}, ...args);
|
|
24
|
+
};
|
|
25
|
+
return new Proxy({}, {
|
|
26
|
+
get(_, prop) {
|
|
27
|
+
if (prop === "$$internal") return {
|
|
28
|
+
...environment.$$internal,
|
|
29
|
+
environment,
|
|
30
|
+
callHook: callHookFn
|
|
31
|
+
};
|
|
32
|
+
if (prop === "log" || prop === "logger") return log;
|
|
33
|
+
if (prop === "error") return (message) => {
|
|
34
|
+
log(LogLevelLabel.ERROR, normalizeMessage(message));
|
|
35
|
+
};
|
|
36
|
+
if (prop === "warn") return (message) => {
|
|
37
|
+
log(LogLevelLabel.WARN, normalizeMessage(message));
|
|
38
|
+
};
|
|
39
|
+
if (prop === "info") return (message) => {
|
|
40
|
+
log(LogLevelLabel.INFO, normalizeMessage(message));
|
|
41
|
+
};
|
|
42
|
+
if (prop === "debug") return (message) => {
|
|
43
|
+
log(LogLevelLabel.DEBUG, normalizeMessage(message));
|
|
44
|
+
};
|
|
45
|
+
if (prop === "trace") return (message) => {
|
|
46
|
+
log(LogLevelLabel.TRACE, normalizeMessage(message));
|
|
47
|
+
};
|
|
48
|
+
return environment[prop];
|
|
49
|
+
},
|
|
50
|
+
set(_, prop, value) {
|
|
51
|
+
if ([
|
|
52
|
+
"$$internal",
|
|
53
|
+
"environment",
|
|
54
|
+
"config",
|
|
55
|
+
"log",
|
|
56
|
+
"logger",
|
|
57
|
+
"error",
|
|
58
|
+
"warn",
|
|
59
|
+
"plugins",
|
|
60
|
+
"hooks",
|
|
61
|
+
"addPlugin",
|
|
62
|
+
"selectHooks"
|
|
63
|
+
].includes(prop)) {
|
|
64
|
+
log(LogLevelLabel.WARN, `Cannot set read-only property "${String(prop)}"`);
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
environment[prop] = value;
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { createPluginContext };
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_paths = require('../plugin-utils/paths.cjs');
|
|
3
|
+
let __stryke_path_join_paths = require("@stryke/path/join-paths");
|
|
4
|
+
let __stryke_convert_to_array = require("@stryke/convert/to-array");
|
|
5
|
+
let __stryke_fs_list_files = require("@stryke/fs/list-files");
|
|
6
|
+
let __stryke_path_append = require("@stryke/path/append");
|
|
7
|
+
let __stryke_path_replace = require("@stryke/path/replace");
|
|
8
|
+
let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
|
|
9
|
+
let __stryke_type_checks_is_string = require("@stryke/type-checks/is-string");
|
|
10
|
+
let __stryke_hash_murmurhash = require("@stryke/hash/murmurhash");
|
|
11
|
+
let __stryke_helpers_get_unique = require("@stryke/helpers/get-unique");
|
|
12
|
+
let __stryke_convert_parse_type_definition = require("@stryke/convert/parse-type-definition");
|
|
13
|
+
let __stryke_fs_is_file = require("@stryke/fs/is-file");
|
|
14
|
+
|
|
15
|
+
//#region ../powerlines/src/lib/entry.ts
|
|
16
|
+
function resolveEntryInputFile(context, typeDefinition) {
|
|
17
|
+
return (0, __stryke_path_replace.replacePath)(typeDefinition.file, (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot));
|
|
18
|
+
}
|
|
19
|
+
function resolveEntryInput(context, typeDefinition) {
|
|
20
|
+
return {
|
|
21
|
+
file: resolveEntryInputFile(context, typeDefinition),
|
|
22
|
+
name: typeDefinition.name
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveEntryOutput(context, typeDefinition) {
|
|
26
|
+
return (0, __stryke_path_replace.replaceExtension)((0, __stryke_path_replace.replacePath)((0, __stryke_path_replace.replacePath)((0, __stryke_path_replace.replacePath)((0, __stryke_path_replace.replacePath)((0, __stryke_path_replace.replacePath)(typeDefinition.file, (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.sourceRoot)), (0, __stryke_path_join_paths.joinPaths)(context.workspaceConfig.workspaceRoot, context.config.projectRoot)), context.config.sourceRoot), context.config.projectRoot), (0, __stryke_path_replace.replacePath)(context.config.sourceRoot, context.config.projectRoot)));
|
|
27
|
+
}
|
|
28
|
+
function resolveEntry(context, typeDefinition) {
|
|
29
|
+
const input = resolveEntryInput(context, typeDefinition);
|
|
30
|
+
return {
|
|
31
|
+
...input,
|
|
32
|
+
input,
|
|
33
|
+
output: resolveEntryOutput(context, typeDefinition)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Resolves multiple type definitions into their corresponding resolved entry type definitions.
|
|
38
|
+
*
|
|
39
|
+
* @param context - The current context
|
|
40
|
+
* @param typeDefinitions - The type definitions to resolve.
|
|
41
|
+
* @returns A promise that resolves to an array of resolved entry type definitions.
|
|
42
|
+
*/
|
|
43
|
+
function resolveEntriesSync(context, typeDefinitions) {
|
|
44
|
+
return typeDefinitions.map((entry) => (0, __stryke_type_checks_is_string.isString)(entry) ? require_paths.replacePathTokens(context, entry) : require_paths.replacePathTokens(context, entry.file)).map((typeDefinition) => {
|
|
45
|
+
const parsed = (0, __stryke_convert_parse_type_definition.parseTypeDefinition)(typeDefinition);
|
|
46
|
+
const filePath = (0, __stryke_path_append.appendPath)(parsed.file, context.config.projectRoot);
|
|
47
|
+
if ((0, __stryke_fs_is_file.isFile)(filePath)) return resolveEntry(context, {
|
|
48
|
+
file: (0, __stryke_path_replace.replacePath)(filePath, context.config.projectRoot),
|
|
49
|
+
name: parsed.name
|
|
50
|
+
});
|
|
51
|
+
return (0, __stryke_fs_list_files.listFilesSync)(filePath).map((file) => resolveEntry(context, {
|
|
52
|
+
file,
|
|
53
|
+
name: parsed.name
|
|
54
|
+
}));
|
|
55
|
+
}).flat().filter(Boolean);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get unique entries from the provided list.
|
|
59
|
+
*
|
|
60
|
+
* @param entries - The entries to process.
|
|
61
|
+
* @returns An array of unique entries (by file path or content hash).
|
|
62
|
+
*/
|
|
63
|
+
function getUniqueEntries(entries = []) {
|
|
64
|
+
return (0, __stryke_helpers_get_unique.getUniqueBy)((0, __stryke_convert_to_array.toArray)(entries), (item) => (0, __stryke_type_checks_is_set_string.isSetString)(item) ? item : (0, __stryke_hash_murmurhash.murmurhash)(item ?? {}, { maxLength: 24 }));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
//#endregion
|
|
68
|
+
exports.getUniqueEntries = getUniqueEntries;
|
|
69
|
+
exports.resolveEntriesSync = resolveEntriesSync;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { replacePathTokens } from "../plugin-utils/paths.mjs";
|
|
2
|
+
import { joinPaths } from "@stryke/path/join-paths";
|
|
3
|
+
import { toArray } from "@stryke/convert/to-array";
|
|
4
|
+
import { listFiles, listFilesSync } from "@stryke/fs/list-files";
|
|
5
|
+
import { appendPath } from "@stryke/path/append";
|
|
6
|
+
import { replaceExtension, replacePath } from "@stryke/path/replace";
|
|
7
|
+
import { isSetString } from "@stryke/type-checks/is-set-string";
|
|
8
|
+
import { isString } from "@stryke/type-checks/is-string";
|
|
9
|
+
import { murmurhash } from "@stryke/hash/murmurhash";
|
|
10
|
+
import { getUniqueBy } from "@stryke/helpers/get-unique";
|
|
11
|
+
import { parseTypeDefinition } from "@stryke/convert/parse-type-definition";
|
|
12
|
+
import { isFile } from "@stryke/fs/is-file";
|
|
13
|
+
|
|
14
|
+
//#region ../powerlines/src/lib/entry.ts
|
|
15
|
+
function resolveEntryInputFile(context, typeDefinition) {
|
|
16
|
+
return replacePath(typeDefinition.file, joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot));
|
|
17
|
+
}
|
|
18
|
+
function resolveEntryInput(context, typeDefinition) {
|
|
19
|
+
return {
|
|
20
|
+
file: resolveEntryInputFile(context, typeDefinition),
|
|
21
|
+
name: typeDefinition.name
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function resolveEntryOutput(context, typeDefinition) {
|
|
25
|
+
return replaceExtension(replacePath(replacePath(replacePath(replacePath(replacePath(typeDefinition.file, joinPaths(context.workspaceConfig.workspaceRoot, context.config.sourceRoot)), joinPaths(context.workspaceConfig.workspaceRoot, context.config.projectRoot)), context.config.sourceRoot), context.config.projectRoot), replacePath(context.config.sourceRoot, context.config.projectRoot)));
|
|
26
|
+
}
|
|
27
|
+
function resolveEntry(context, typeDefinition) {
|
|
28
|
+
const input = resolveEntryInput(context, typeDefinition);
|
|
29
|
+
return {
|
|
30
|
+
...input,
|
|
31
|
+
input,
|
|
32
|
+
output: resolveEntryOutput(context, typeDefinition)
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Resolves multiple type definitions into their corresponding resolved entry type definitions.
|
|
37
|
+
*
|
|
38
|
+
* @param context - The current context
|
|
39
|
+
* @param typeDefinitions - The type definitions to resolve.
|
|
40
|
+
* @returns A promise that resolves to an array of resolved entry type definitions.
|
|
41
|
+
*/
|
|
42
|
+
function resolveEntriesSync(context, typeDefinitions) {
|
|
43
|
+
return typeDefinitions.map((entry) => isString(entry) ? replacePathTokens(context, entry) : replacePathTokens(context, entry.file)).map((typeDefinition) => {
|
|
44
|
+
const parsed = parseTypeDefinition(typeDefinition);
|
|
45
|
+
const filePath = appendPath(parsed.file, context.config.projectRoot);
|
|
46
|
+
if (isFile(filePath)) return resolveEntry(context, {
|
|
47
|
+
file: replacePath(filePath, context.config.projectRoot),
|
|
48
|
+
name: parsed.name
|
|
49
|
+
});
|
|
50
|
+
return listFilesSync(filePath).map((file) => resolveEntry(context, {
|
|
51
|
+
file,
|
|
52
|
+
name: parsed.name
|
|
53
|
+
}));
|
|
54
|
+
}).flat().filter(Boolean);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get unique entries from the provided list.
|
|
58
|
+
*
|
|
59
|
+
* @param entries - The entries to process.
|
|
60
|
+
* @returns An array of unique entries (by file path or content hash).
|
|
61
|
+
*/
|
|
62
|
+
function getUniqueEntries(entries = []) {
|
|
63
|
+
return getUniqueBy(toArray(entries), (item) => isSetString(item) ? item : murmurhash(item ?? {}, { maxLength: 24 }));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
//#endregion
|
|
67
|
+
export { getUniqueEntries, resolveEntriesSync };
|