conduithub 0.1.0 → 1.0.1
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/core/conduit-hub/index.cjs +188 -0
- package/dist/core/conduit-hub/index.d.cts +44 -0
- package/dist/core/conduit-hub/index.d.mts +44 -0
- package/dist/core/conduit-hub/index.d.ts +44 -0
- package/dist/core/conduit-hub/index.mjs +186 -0
- package/dist/core/config-manager/index.cjs +216 -0
- package/dist/core/config-manager/index.d.cts +7 -0
- package/dist/core/config-manager/index.d.mts +7 -0
- package/dist/core/config-manager/index.d.ts +7 -0
- package/dist/core/config-manager/index.mjs +214 -0
- package/dist/core/event-bus/index.cjs +154 -53
- package/dist/core/event-bus/index.d.cts +2 -42
- package/dist/core/event-bus/index.d.mts +2 -42
- package/dist/core/event-bus/index.d.ts +2 -42
- package/dist/core/event-bus/index.mjs +153 -52
- package/dist/core/hook/index.cjs +185 -148
- package/dist/core/hook/index.d.cts +28 -16
- package/dist/core/hook/index.d.mts +28 -16
- package/dist/core/hook/index.d.ts +28 -16
- package/dist/core/hook/index.mjs +183 -146
- package/dist/core/index.cjs +17 -1
- package/dist/core/index.d.cts +184 -3
- package/dist/core/index.d.mts +184 -3
- package/dist/core/index.d.ts +184 -3
- package/dist/core/index.mjs +12 -1
- package/dist/core/plugin/index.cjs +271 -0
- package/dist/core/plugin/index.d.cts +7 -0
- package/dist/core/plugin/index.d.mts +7 -0
- package/dist/core/plugin/index.d.ts +7 -0
- package/dist/core/plugin/index.mjs +268 -0
- package/dist/core/service-container/index.cjs +306 -0
- package/dist/core/service-container/index.d.cts +51 -0
- package/dist/core/service-container/index.d.mts +51 -0
- package/dist/core/service-container/index.d.ts +51 -0
- package/dist/core/service-container/index.mjs +304 -0
- package/dist/core/state-manager/index.cjs +195 -0
- package/dist/core/state-manager/index.d.cts +39 -0
- package/dist/core/state-manager/index.d.mts +39 -0
- package/dist/core/state-manager/index.d.ts +39 -0
- package/dist/core/state-manager/index.mjs +193 -0
- package/dist/error/index.cjs +71 -0
- package/dist/error/index.d.cts +47 -0
- package/dist/error/index.d.mts +47 -0
- package/dist/error/index.d.ts +47 -0
- package/dist/error/index.mjs +65 -0
- package/dist/index.cjs +38 -5
- package/dist/index.d.cts +8 -2
- package/dist/index.d.mts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.mjs +16 -1
- package/dist/plugins/index.cjs +12 -0
- package/dist/plugins/index.d.cts +8 -0
- package/dist/plugins/index.d.mts +8 -0
- package/dist/plugins/index.d.ts +8 -0
- package/dist/plugins/index.mjs +6 -0
- package/dist/plugins/redis/index.cjs +12 -0
- package/dist/plugins/redis/index.d.cts +109 -0
- package/dist/plugins/redis/index.d.mts +109 -0
- package/dist/plugins/redis/index.d.ts +109 -0
- package/dist/plugins/redis/index.mjs +6 -0
- package/dist/shared/conduithub.-bZD30_I.mjs +769 -0
- package/dist/shared/{conduithub.CvMLTa-R.cjs → conduithub.BNQsddJO.cjs} +2 -9
- package/dist/shared/{conduithub.74V0wiLi.mjs → conduithub.BNefRQsK.mjs} +3 -9
- package/dist/shared/conduithub.BZQmkQy7.d.cts +52 -0
- package/dist/shared/conduithub.Bq_7Xj0J.cjs +18 -0
- package/dist/shared/conduithub.BzLwccre.d.mts +52 -0
- package/dist/shared/conduithub.CkOQG3cD.mjs +14 -0
- package/dist/shared/conduithub.CmZo_Vuc.cjs +38 -0
- package/dist/shared/conduithub.DQO1dRnn.cjs +33 -0
- package/dist/shared/conduithub.DQOWQ-Bx.d.ts +52 -0
- package/dist/shared/conduithub.Dlvl2xGE.cjs +76 -0
- package/dist/shared/conduithub.DsOOeNwU.cjs +269 -0
- package/dist/shared/conduithub.DyQQrHW9.mjs +267 -0
- package/dist/shared/conduithub.G7ICpZIy.mjs +36 -0
- package/dist/shared/conduithub.Up0QYVao.mjs +59 -0
- package/dist/shared/conduithub.alPiaJax.mjs +29 -0
- package/dist/shared/conduithub.cvEjE62V.cjs +775 -0
- package/dist/utils/index.cjs +19 -5
- package/dist/utils/index.d.cts +33 -2
- package/dist/utils/index.d.mts +33 -2
- package/dist/utils/index.d.ts +33 -2
- package/dist/utils/index.mjs +8 -1
- package/package.json +55 -7
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
class PluginManager {
|
|
2
|
+
constructor(eventBus, logger, serviceContainer, stateManager, hookSystem, configManager) {
|
|
3
|
+
this.eventBus = eventBus;
|
|
4
|
+
this.logger = logger;
|
|
5
|
+
this.serviceContainer = serviceContainer;
|
|
6
|
+
this.stateManager = stateManager;
|
|
7
|
+
this.hookSystem = hookSystem;
|
|
8
|
+
this.configManager = configManager;
|
|
9
|
+
}
|
|
10
|
+
plugins = /* @__PURE__ */ new Map();
|
|
11
|
+
pluginStatuses = /* @__PURE__ */ new Map();
|
|
12
|
+
pluginConfigs = /* @__PURE__ */ new Map();
|
|
13
|
+
log(level, message, ...args) {
|
|
14
|
+
const l = this.logger;
|
|
15
|
+
if (l && typeof l.log === "function") {
|
|
16
|
+
l.log(level, message, ...args);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
const anyLogger = l;
|
|
20
|
+
const fn = anyLogger?.[level];
|
|
21
|
+
if (typeof fn === "function") fn(message, ...args);
|
|
22
|
+
}
|
|
23
|
+
async registerPlugin(plugin, config) {
|
|
24
|
+
const pluginName = plugin.constructor.name;
|
|
25
|
+
if (this.plugins.has(pluginName)) {
|
|
26
|
+
throw new Error(`Plugin ${pluginName} already registered`);
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const existing = this.pluginConfigs.get(pluginName) ?? await this.configManager.getPluginConfig(pluginName);
|
|
30
|
+
const metaVersion = plugin.getMetadata().version;
|
|
31
|
+
const pluginConfig = {
|
|
32
|
+
name: pluginName,
|
|
33
|
+
version: config?.version ?? existing?.version ?? metaVersion,
|
|
34
|
+
enabled: config?.enabled ?? existing?.enabled ?? true,
|
|
35
|
+
dependencies: config?.dependencies ?? existing?.dependencies ?? [],
|
|
36
|
+
config: { ...existing?.config ?? {}, ...config?.config ?? {} }
|
|
37
|
+
};
|
|
38
|
+
plugin.updateConfig(pluginConfig);
|
|
39
|
+
this.plugins.set(pluginName, plugin);
|
|
40
|
+
this.pluginConfigs.set(pluginName, pluginConfig);
|
|
41
|
+
this.pluginStatuses.set(pluginName, {
|
|
42
|
+
name: pluginName,
|
|
43
|
+
version: pluginConfig.version,
|
|
44
|
+
status: "registered",
|
|
45
|
+
config: pluginConfig,
|
|
46
|
+
lastActivity: Date.now()
|
|
47
|
+
});
|
|
48
|
+
this.log("info", `Plugin ${pluginName} registered successfully`);
|
|
49
|
+
await this.hookSystem.executeHook("plugin:registered", {
|
|
50
|
+
plugin: pluginName,
|
|
51
|
+
config: pluginConfig
|
|
52
|
+
});
|
|
53
|
+
await this.eventBus.emit("plugin:registered", {
|
|
54
|
+
plugin: pluginName,
|
|
55
|
+
config: pluginConfig
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
this.log("error", `Failed to register plugin ${pluginName}`, error);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
async unregisterPlugin(pluginName) {
|
|
63
|
+
const plugin = this.plugins.get(pluginName);
|
|
64
|
+
if (!plugin) {
|
|
65
|
+
throw new Error(`Plugin ${pluginName} is not registered`);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
if (plugin.isPluginRunning()) {
|
|
69
|
+
await this.stopPlugin(pluginName);
|
|
70
|
+
}
|
|
71
|
+
if (plugin.isPluginInitialized()) {
|
|
72
|
+
await plugin.destroy();
|
|
73
|
+
}
|
|
74
|
+
this.plugins.delete(pluginName);
|
|
75
|
+
this.pluginConfigs.delete(pluginName);
|
|
76
|
+
this.pluginStatuses.delete(pluginName);
|
|
77
|
+
this.log("info", `Plugin ${pluginName} unregistered successfully`);
|
|
78
|
+
await this.eventBus.emit("plugin:unregistered", {
|
|
79
|
+
plugin: pluginName
|
|
80
|
+
});
|
|
81
|
+
await this.hookSystem.executeHook("plugin:unregistered", {
|
|
82
|
+
plugin: pluginName
|
|
83
|
+
});
|
|
84
|
+
} catch (error) {
|
|
85
|
+
this.log("error", `Failed to unregister plugin ${pluginName}`, error);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async initializePlugin(pluginName) {
|
|
90
|
+
const plugin = this.plugins.get(pluginName);
|
|
91
|
+
if (!plugin) {
|
|
92
|
+
throw new Error(`Plugin ${pluginName} is not registered`);
|
|
93
|
+
}
|
|
94
|
+
const status = this.pluginStatuses.get(pluginName);
|
|
95
|
+
if (status?.status === "initialized" || status?.status === "running") {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const context = {
|
|
100
|
+
eventBus: this.eventBus,
|
|
101
|
+
logger: this.logger,
|
|
102
|
+
config: this.pluginConfigs.get(pluginName),
|
|
103
|
+
serviceContainer: this.serviceContainer,
|
|
104
|
+
stateManager: this.stateManager,
|
|
105
|
+
hookSystem: this.hookSystem
|
|
106
|
+
};
|
|
107
|
+
await plugin.initialize(context);
|
|
108
|
+
this.pluginStatuses.set(pluginName, {
|
|
109
|
+
...status,
|
|
110
|
+
status: "initialized",
|
|
111
|
+
lastActivity: Date.now()
|
|
112
|
+
});
|
|
113
|
+
this.log("info", `Plugin ${pluginName} initialized successfully`);
|
|
114
|
+
await this.eventBus.emit("plugin:initialized", { plugin: pluginName });
|
|
115
|
+
await this.hookSystem.executeHook("plugin:initialized", {
|
|
116
|
+
plugin: pluginName
|
|
117
|
+
});
|
|
118
|
+
} catch (error) {
|
|
119
|
+
this.log("error", `Failed to initialize plugin ${pluginName}`, error);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async startPlugin(pluginName) {
|
|
124
|
+
const plugin = this.plugins.get(pluginName);
|
|
125
|
+
if (!plugin) {
|
|
126
|
+
throw new Error(`Plugin ${pluginName} is not registered`);
|
|
127
|
+
}
|
|
128
|
+
const status = this.pluginStatuses.get(pluginName);
|
|
129
|
+
if (status?.status === "running") {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
try {
|
|
133
|
+
if (!plugin.isPluginInitialized()) {
|
|
134
|
+
await this.initializePlugin(pluginName);
|
|
135
|
+
}
|
|
136
|
+
await plugin.start();
|
|
137
|
+
this.pluginStatuses.set(pluginName, {
|
|
138
|
+
...status,
|
|
139
|
+
status: "running",
|
|
140
|
+
lastActivity: Date.now()
|
|
141
|
+
});
|
|
142
|
+
this.log("info", `Plugin ${pluginName} started successfully`);
|
|
143
|
+
await this.eventBus.emit("plugin:started", { plugin: pluginName });
|
|
144
|
+
await this.hookSystem.executeHook("plugin:started", {
|
|
145
|
+
plugin: pluginName
|
|
146
|
+
});
|
|
147
|
+
} catch (error) {
|
|
148
|
+
this.pluginStatuses.set(pluginName, {
|
|
149
|
+
...this.pluginStatuses.get(pluginName),
|
|
150
|
+
status: "error",
|
|
151
|
+
error: error instanceof Error ? error.message : String(error),
|
|
152
|
+
lastActivity: Date.now()
|
|
153
|
+
});
|
|
154
|
+
this.log("error", `Failed to start plugin ${pluginName}`, error);
|
|
155
|
+
throw error;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async stopPlugin(pluginName) {
|
|
159
|
+
const plugin = this.plugins.get(pluginName);
|
|
160
|
+
if (!plugin) {
|
|
161
|
+
throw new Error(`Plugin ${pluginName} is not registered`);
|
|
162
|
+
}
|
|
163
|
+
const status = this.pluginStatuses.get(pluginName);
|
|
164
|
+
if (status?.status !== "running") {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
await plugin.stop();
|
|
169
|
+
this.pluginStatuses.set(pluginName, {
|
|
170
|
+
...status,
|
|
171
|
+
status: "stopped",
|
|
172
|
+
lastActivity: Date.now()
|
|
173
|
+
});
|
|
174
|
+
this.log("info", `Plugin ${pluginName} stopped successfully`);
|
|
175
|
+
await this.eventBus.emit("plugin:stopped", { plugin: pluginName });
|
|
176
|
+
await this.hookSystem.executeHook("plugin:stopped", {
|
|
177
|
+
plugin: pluginName
|
|
178
|
+
});
|
|
179
|
+
} catch (error) {
|
|
180
|
+
this.pluginStatuses.set(pluginName, {
|
|
181
|
+
...this.pluginStatuses.get(pluginName),
|
|
182
|
+
status: "error",
|
|
183
|
+
error: error instanceof Error ? error.message : String(error),
|
|
184
|
+
lastActivity: Date.now()
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
async shutdownAll() {
|
|
189
|
+
this.log("info", "Shutting down all plugins...");
|
|
190
|
+
const shutdownPromises = Array.from(this.plugins.keys()).map(
|
|
191
|
+
async (pluginName) => {
|
|
192
|
+
try {
|
|
193
|
+
await this.unregisterPlugin(pluginName);
|
|
194
|
+
} catch (error) {
|
|
195
|
+
this.log("error", `Failed to shutdown plugin ${pluginName}`, error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
);
|
|
199
|
+
await Promise.all(shutdownPromises);
|
|
200
|
+
this.log("info", "All plugins shutdown successfully");
|
|
201
|
+
}
|
|
202
|
+
isPluginRegistered(pluginName) {
|
|
203
|
+
return this.plugins.has(pluginName);
|
|
204
|
+
}
|
|
205
|
+
isPluginRunning(pluginName) {
|
|
206
|
+
const status = this.pluginStatuses.get(pluginName);
|
|
207
|
+
return status?.status === "running";
|
|
208
|
+
}
|
|
209
|
+
getPluginStatus(pluginName) {
|
|
210
|
+
return this.pluginStatuses.get(pluginName);
|
|
211
|
+
}
|
|
212
|
+
listPlugins() {
|
|
213
|
+
return Array.from(this.plugins.keys());
|
|
214
|
+
}
|
|
215
|
+
getAllPluginStatuses() {
|
|
216
|
+
return Array.from(this.pluginStatuses.values());
|
|
217
|
+
}
|
|
218
|
+
getPlugin(pluginName) {
|
|
219
|
+
return this.plugins.get(pluginName);
|
|
220
|
+
}
|
|
221
|
+
getPluginConfig(pluginName) {
|
|
222
|
+
return this.pluginConfigs.get(pluginName);
|
|
223
|
+
}
|
|
224
|
+
async updatePluginConfig(pluginName, config) {
|
|
225
|
+
const plugin = this.plugins.get(pluginName);
|
|
226
|
+
if (!plugin) {
|
|
227
|
+
throw new Error(`Plugin ${pluginName} is not registered`);
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
const currentConfig = this.pluginConfigs.get(pluginName);
|
|
231
|
+
if (!currentConfig) {
|
|
232
|
+
throw new Error(`Plugin config not found for ${pluginName}`);
|
|
233
|
+
}
|
|
234
|
+
const newConfig = {
|
|
235
|
+
name: currentConfig.name,
|
|
236
|
+
version: config?.version ?? currentConfig.version,
|
|
237
|
+
enabled: config?.enabled ?? currentConfig.enabled,
|
|
238
|
+
dependencies: config?.dependencies ?? currentConfig.dependencies ?? [],
|
|
239
|
+
config: { ...currentConfig.config ?? {}, ...config?.config ?? {} }
|
|
240
|
+
};
|
|
241
|
+
this.pluginConfigs.set(pluginName, newConfig);
|
|
242
|
+
plugin.updateConfig(newConfig);
|
|
243
|
+
const status = this.pluginStatuses.get(pluginName);
|
|
244
|
+
if (status) {
|
|
245
|
+
this.pluginStatuses.set(pluginName, {
|
|
246
|
+
...status,
|
|
247
|
+
config: newConfig,
|
|
248
|
+
lastActivity: Date.now()
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
this.log("info", `Plugin ${pluginName} config updated successfully`);
|
|
252
|
+
await this.eventBus.emit("plugin:configUpdated", {
|
|
253
|
+
plugin: pluginName,
|
|
254
|
+
config: newConfig
|
|
255
|
+
});
|
|
256
|
+
await this.hookSystem.executeHook("plugin:configUpdated", {
|
|
257
|
+
plugin: pluginName,
|
|
258
|
+
config: newConfig
|
|
259
|
+
});
|
|
260
|
+
} catch (error) {
|
|
261
|
+
this.log("error", `Failed to update plugin ${pluginName} config`, error);
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export { PluginManager as P };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const ERROR_CODE = {
|
|
2
|
+
// Configuration errors
|
|
3
|
+
INVALID_JSON: "Invalid JSON format",
|
|
4
|
+
INVALID_CONFIG: "Configuration validation failed",
|
|
5
|
+
UNSUPPORTED_CONFIG_FORMAT: "JavaScript config files are not supported. Use JSON format.",
|
|
6
|
+
// Initialization errors
|
|
7
|
+
STATE_MANAGER_NOT_INITIALIZED: "StateManager is not initialized",
|
|
8
|
+
SERVICE_CONTAINER_NOT_INITIALIZED: "Service Container is not initialized",
|
|
9
|
+
EVENT_BUS_NOT_INITIALIZED: "EventBus is not initialized",
|
|
10
|
+
HOOK_SYSTEM_NOT_INITIALIZED: "Hook system is not initialized",
|
|
11
|
+
// Handler limit errors
|
|
12
|
+
EVENT_HANDLER_LIMIT_EXCEEDED: "Handler limit exceeded for event",
|
|
13
|
+
HOOK_HANDLER_LIMIT_EXCEEDED: "Handler limit exceeded for hook",
|
|
14
|
+
// Duplicate ID errors
|
|
15
|
+
DUPLICATE_EVENT_HANDLER_ID: "Duplicate custom ID for event",
|
|
16
|
+
DUPLICATE_HOOK_HANDLER_ID: "Duplicate custom ID for hook",
|
|
17
|
+
// State management errors
|
|
18
|
+
INVALID_STATE_JSON_FORMAT: "Invalid state JSON format",
|
|
19
|
+
// Execution errors
|
|
20
|
+
HOOK_EXECUTION_FAILED: "Hook execution failed",
|
|
21
|
+
UNKNOWN_ERROR: "Unknown error",
|
|
22
|
+
// Service container errors
|
|
23
|
+
CIRCULAR_DEPENDENCY_DETECTED: "Circular dependency detected",
|
|
24
|
+
SERVICE_NOT_FOUND: "Service not found",
|
|
25
|
+
SERVICE_CREATION_FAILED: "Service creation failed",
|
|
26
|
+
SERVICE_IS_SINGLETON: "Service is a singleton and cannot be registered again",
|
|
27
|
+
// Plugin errors
|
|
28
|
+
PLUGIN_NOT_INITIALIZED: "Plugin is not initialized",
|
|
29
|
+
PLUGIN_ALREADY_INITIALIZED: "Plugin is already initialized",
|
|
30
|
+
PLUGIN_NOT_RUNNING: "Plugin is not running",
|
|
31
|
+
// ConfigManager errors
|
|
32
|
+
CONFIG_MANAGER_NOT_INITIALIZED: "ConfigManager is not initialized",
|
|
33
|
+
CONFIG_MANAGER_ALREADY_INITIALIZED: "ConfigManager is already initialized"
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export { ERROR_CODE as E };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { stdout, stdin } from 'process';
|
|
2
|
+
import * as readline from 'readline';
|
|
3
|
+
import { setPkgManager, MissingDependencyError } from '../error/index.mjs';
|
|
4
|
+
import { c as createLogger } from './conduithub.BNefRQsK.mjs';
|
|
5
|
+
import 'uuid';
|
|
6
|
+
|
|
7
|
+
class PackageManagerUtil {
|
|
8
|
+
logger = createLogger();
|
|
9
|
+
/**
|
|
10
|
+
* Prompts the user to select their package manager and saves the choice.
|
|
11
|
+
* This is a standalone utility that can be used anywhere in your app.
|
|
12
|
+
*
|
|
13
|
+
* @returns Promise that resolves with the selected package manager
|
|
14
|
+
* @throws MissingDependencyError if there's an issue with the selection process
|
|
15
|
+
*/
|
|
16
|
+
async promptAndSetPackageManager() {
|
|
17
|
+
try {
|
|
18
|
+
const rl = readline.createInterface({ input: stdin, output: stdout });
|
|
19
|
+
const manager = await new Promise((resolve) => {
|
|
20
|
+
rl.question(
|
|
21
|
+
"Which package manager are you using? (npm/pnpm/yarn): ",
|
|
22
|
+
(answer) => {
|
|
23
|
+
rl.close();
|
|
24
|
+
resolve(answer.trim().toLowerCase());
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
const validManagers = ["npm", "pnpm", "yarn"];
|
|
29
|
+
if (!validManagers.includes(manager)) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
`Invalid package manager: ${manager}. Supported: ${validManagers.join(", ")}`
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
setPkgManager(manager);
|
|
35
|
+
this.logger.info(`Package manager set to: ${manager}`);
|
|
36
|
+
return manager;
|
|
37
|
+
} catch (err) {
|
|
38
|
+
this.logger.error(
|
|
39
|
+
`Package manager setup failed: ${err instanceof Error ? err.message : String(err)}`
|
|
40
|
+
);
|
|
41
|
+
throw new MissingDependencyError("package-manager");
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a handler function that can be used with Hook or EventBus systems.
|
|
46
|
+
* This allows you to integrate package manager setup into your event/hook workflows
|
|
47
|
+
* without duplicating the logic.
|
|
48
|
+
*
|
|
49
|
+
* @returns A handler function that sets up the package manager
|
|
50
|
+
*/
|
|
51
|
+
createHandler() {
|
|
52
|
+
return async () => {
|
|
53
|
+
await this.promptAndSetPackageManager();
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const packageManagerUtil = new PackageManagerUtil();
|
|
58
|
+
|
|
59
|
+
export { PackageManagerUtil as P, packageManagerUtil as p };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const ISO8601_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
|
|
2
|
+
function parseJson(data) {
|
|
3
|
+
try {
|
|
4
|
+
return JSON.parse(data, dateReviver);
|
|
5
|
+
} catch {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function stringifyJson(value, replacer, space) {
|
|
10
|
+
return JSON.stringify(value, replacer, space);
|
|
11
|
+
}
|
|
12
|
+
function safeStringifyJson(value) {
|
|
13
|
+
try {
|
|
14
|
+
return JSON.stringify(value);
|
|
15
|
+
} catch {
|
|
16
|
+
return "[Circular or Non-Serializable Object]";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function dateReviver(_, value) {
|
|
20
|
+
if (typeof value === "string" && ISO8601_REGEX.test(value)) {
|
|
21
|
+
const date = new Date(value);
|
|
22
|
+
if (!Number.isNaN(date.getTime())) {
|
|
23
|
+
return date;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { safeStringifyJson as a, parseJson as p, stringifyJson as s };
|