@kanian77/choux 0.2.1 → 0.2.2
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/README.md +85 -53
- package/bun.lock +5 -3
- package/dist/core/ChouxModule.d.ts +1 -1
- package/dist/core/ChouxModule.d.ts.map +1 -1
- package/dist/core/ChouxModule.js +1 -1
- package/dist/core/ChouxModule.js.map +1 -1
- package/dist/core/HookRegistry.js +121 -59
- package/dist/core/HookRegistry.js.map +1 -1
- package/dist/core/HookRegistry.spec.js +28 -19
- package/dist/core/HookRegistry.spec.js.map +1 -1
- package/dist/core/Plugin.d.ts +1 -6
- package/dist/core/Plugin.d.ts.map +1 -1
- package/dist/core/Plugin.js +1 -2
- package/dist/core/Plugin.js.map +1 -1
- package/dist/core/PluginManager.d.ts +8 -4
- package/dist/core/PluginManager.d.ts.map +1 -1
- package/dist/core/PluginManager.js +168 -55
- package/dist/core/PluginManager.js.map +1 -1
- package/dist/core/PluginManager.spec.js +42 -31
- package/dist/core/PluginManager.spec.js.map +1 -1
- package/dist/decorators/enableHooksDecorator.d.ts.map +1 -1
- package/dist/decorators/enableHooksDecorator.js +4 -1
- package/dist/decorators/enableHooksDecorator.js.map +1 -1
- package/dist/decorators/hookDecorator.d.ts +5 -1
- package/dist/decorators/hookDecorator.d.ts.map +1 -1
- package/dist/decorators/hookDecorator.js +46 -9
- package/dist/decorators/hookDecorator.js.map +1 -1
- package/dist/decorators/hookDecorator.spec.js +107 -25
- package/dist/decorators/hookDecorator.spec.js.map +1 -1
- package/dist/lib/functions/index.d.ts +3 -2
- package/dist/lib/functions/index.d.ts.map +1 -1
- package/dist/lib/functions/index.js +3 -2
- package/dist/lib/functions/index.js.map +1 -1
- package/dist/lib/functions/registerHookHandler.d.ts.map +1 -1
- package/dist/lib/functions/registerHookHandler.js +1 -1
- package/dist/lib/functions/registerHookHandler.js.map +1 -1
- package/dist/lib/functions/registerHooksForInstance.d.ts.map +1 -1
- package/dist/lib/functions/registerHooksForInstance.js +2 -2
- package/dist/lib/functions/registerHooksForInstance.js.map +1 -1
- package/dist/lib/functions/registerInstanceHooks.d.ts.map +1 -1
- package/dist/lib/functions/registerInstanceHooks.js +19 -10
- package/dist/lib/functions/registerInstanceHooks.js.map +1 -1
- package/dist/lib/functions/registerStaticHooks.d.ts +2 -0
- package/dist/lib/functions/registerStaticHooks.d.ts.map +1 -0
- package/dist/lib/functions/registerStaticHooks.js +36 -0
- package/dist/lib/functions/registerStaticHooks.js.map +1 -0
- package/dist/lib/test-related/plugins/plugin-a/module.d.ts +5 -2
- package/dist/lib/test-related/plugins/plugin-a/module.d.ts.map +1 -1
- package/dist/lib/test-related/plugins/plugin-a/module.js +156 -77
- package/dist/lib/test-related/plugins/plugin-a/module.js.map +1 -1
- package/dist/lib/test-related/plugins/plugin-b/module.d.ts +5 -2
- package/dist/lib/test-related/plugins/plugin-b/module.d.ts.map +1 -1
- package/dist/lib/test-related/plugins/plugin-b/module.js +158 -77
- package/dist/lib/test-related/plugins/plugin-b/module.js.map +1 -1
- package/dist/lib/test-related/services.d.ts +17 -0
- package/dist/lib/test-related/services.d.ts.map +1 -0
- package/dist/lib/test-related/services.js +104 -0
- package/dist/lib/test-related/services.js.map +1 -0
- package/dist/lib/types/IHookMetadata.d.ts +6 -0
- package/dist/lib/types/IHookMetadata.d.ts.map +1 -0
- package/dist/lib/types/IHookMetadata.js +2 -0
- package/dist/lib/types/IHookMetadata.js.map +1 -0
- package/dist/lib/types/IHookRegistry.js +1 -0
- package/dist/lib/types/IPluginManager.d.ts +3 -1
- package/dist/lib/types/IPluginManager.d.ts.map +1 -1
- package/dist/lib/types/IPluginManager.js +1 -0
- package/dist/lib/types/LoadedPlugin.d.ts +2 -2
- package/dist/lib/types/LoadedPlugin.d.ts.map +1 -1
- package/dist/lib/types/LoadedPlugin.js +1 -0
- package/dist/lib/types/PluginMetadata.js +1 -0
- package/dist/lib/types/PluginModule.d.ts +10 -0
- package/dist/lib/types/PluginModule.d.ts.map +1 -0
- package/dist/lib/types/PluginModule.js +14 -0
- package/dist/lib/types/PluginModule.js.map +1 -0
- package/dist/lib/types/index.d.ts +1 -1
- package/dist/lib/types/index.d.ts.map +1 -1
- package/dist/lib/types/index.js +1 -1
- package/dist/lib/types/index.js.map +1 -1
- package/package.json +2 -2
- package/tsconfig.json +15 -9
- package/dist/core/PluginLoader.d.ts +0 -13
- package/dist/core/PluginLoader.d.ts.map +0 -1
- package/dist/core/PluginLoader.js +0 -147
- package/dist/core/PluginLoader.js.map +0 -1
- package/dist/core/PluginLoader.spec.d.ts +0 -2
- package/dist/core/PluginLoader.spec.d.ts.map +0 -1
- package/dist/core/PluginLoader.spec.js +0 -114
- package/dist/core/PluginLoader.spec.js.map +0 -1
- package/dist/example-plugin/module.d.ts +0 -20
- package/dist/example-plugin/module.d.ts.map +0 -1
- package/dist/example-plugin/module.js +0 -90
- package/dist/example-plugin/module.js.map +0 -1
- package/dist/example-plugin/services.d.ts +0 -9
- package/dist/example-plugin/services.d.ts.map +0 -1
- package/dist/example-plugin/services.js +0 -29
- package/dist/example-plugin/services.js.map +0 -1
- package/dist/example-plugin/tokens.d.ts +0 -2
- package/dist/example-plugin/tokens.d.ts.map +0 -1
- package/dist/example-plugin/tokens.js +0 -2
- package/dist/example-plugin/tokens.js.map +0 -1
- package/dist/lib/types/HookMetadata.d.ts +0 -5
- package/dist/lib/types/HookMetadata.d.ts.map +0 -1
- package/dist/lib/types/HookMetadata.js +0 -1
- package/dist/lib/types/HookMetadata.js.map +0 -1
package/tsconfig.json
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
3
|
+
"strict": true,
|
|
4
|
+
"jsx": "react-jsx",
|
|
5
|
+
"jsxImportSource": "hono/jsx",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"composite": true,
|
|
9
|
+
// CHANGE THIS: Lower the target to force decorator transpilation
|
|
10
|
+
"target": "ES2015",
|
|
11
|
+
// "target": "ESNext",
|
|
12
|
+
// KEEP THESE: Enable decorators
|
|
13
|
+
"experimentalDecorators": false,
|
|
14
|
+
"emitDecoratorMetadata": false,
|
|
15
|
+
"useDefineForClassFields": true,
|
|
16
|
+
"module": "ESNEXT",
|
|
9
17
|
"moduleResolution": "bundler",
|
|
10
|
-
|
|
11
18
|
"esModuleInterop": true,
|
|
12
|
-
"strict": true,
|
|
13
19
|
"skipLibCheck": true,
|
|
14
20
|
"forceConsistentCasingInFileNames": true,
|
|
21
|
+
"isolatedModules": true,
|
|
15
22
|
"resolveJsonModule": true,
|
|
16
|
-
"emitDeclarationOnly": false,
|
|
17
23
|
"declaration": true,
|
|
18
24
|
"declarationMap": true, // Optional: creates sourcemap for .d.ts files
|
|
19
25
|
"sourceMap": true // Optional: creates sourcemaps for .js files
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { LoadedPlugin } from '../lib/types';
|
|
2
|
-
export declare class PluginLoader {
|
|
3
|
-
private loadedPlugins;
|
|
4
|
-
findPlugins(pluginsDir: string): Promise<string[]>;
|
|
5
|
-
loadPlugin(pluginPath: string): Promise<LoadedPlugin>;
|
|
6
|
-
loadPlugins(pluginsDir: string): Promise<LoadedPlugin[]>;
|
|
7
|
-
private resolveDependencyOrder;
|
|
8
|
-
private initializePlugin;
|
|
9
|
-
unloadPlugin(pluginName: string): Promise<void>;
|
|
10
|
-
getPlugin(name: string): LoadedPlugin | undefined;
|
|
11
|
-
getAllPlugins(): LoadedPlugin[];
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=PluginLoader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginLoader.d.ts","sourceRoot":"","sources":["../../src/core/PluginLoader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAkB,YAAY,EAAiB,MAAM,cAAc,CAAC;AAQhF,qBAAa,YAAY;IACvB,OAAO,CAAC,aAAa,CAAwC;IAEvD,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IA0BlD,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IA8CrD,WAAW,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;IAwB9D,OAAO,CAAC,sBAAsB;YA4ChB,gBAAgB;IAYxB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBrD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIjD,aAAa,IAAI,YAAY,EAAE;CAGhC"}
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { inject } from '@kanian77/simple-di';
|
|
2
|
-
import { LIFECYCLE_HOOKS } from './HookRegistry';
|
|
3
|
-
import { HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
|
|
4
|
-
import * as fs from 'fs/promises';
|
|
5
|
-
import * as path from 'path';
|
|
6
|
-
// LoadedPlugin now imported from types
|
|
7
|
-
export class PluginLoader {
|
|
8
|
-
loadedPlugins = new Map();
|
|
9
|
-
async findPlugins(pluginsDir) {
|
|
10
|
-
try {
|
|
11
|
-
const entries = await fs.readdir(pluginsDir, { withFileTypes: true });
|
|
12
|
-
const pluginDirs = [];
|
|
13
|
-
for (const entry of entries) {
|
|
14
|
-
if (entry.isDirectory()) {
|
|
15
|
-
const pluginPath = path.join(pluginsDir, entry.name);
|
|
16
|
-
const modulePath = path.join(pluginPath, 'module.ts');
|
|
17
|
-
try {
|
|
18
|
-
await fs.access(modulePath);
|
|
19
|
-
pluginDirs.push(pluginPath);
|
|
20
|
-
}
|
|
21
|
-
catch {
|
|
22
|
-
// Skip directories without module.ts
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return pluginDirs;
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.warn(`Could not read plugins directory: ${pluginsDir}`, error);
|
|
30
|
-
return [];
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async loadPlugin(pluginPath) {
|
|
34
|
-
const modulePath = path.join(pluginPath, 'module.ts');
|
|
35
|
-
console.log(`Loading plugin from ${modulePath}`);
|
|
36
|
-
const hookRegistry = inject(HOOK_REGISTRY_TOKEN);
|
|
37
|
-
await hookRegistry.trigger(LIFECYCLE_HOOKS.BEFORE_PLUGIN_LOAD, pluginPath);
|
|
38
|
-
// Dynamic import of the plugin module
|
|
39
|
-
const module = await import(modulePath);
|
|
40
|
-
const PluginClass = module.default;
|
|
41
|
-
if (!PluginClass || !PluginClass.prototype) {
|
|
42
|
-
throw new Error(`Invalid plugin at ${pluginPath}: must export a Plugin class as default`);
|
|
43
|
-
}
|
|
44
|
-
// Create plugin instance (which is also a Module)
|
|
45
|
-
const plugin = new PluginClass();
|
|
46
|
-
if (!plugin.metadata) {
|
|
47
|
-
throw new Error(`Plugin at ${pluginPath} must have metadata property`);
|
|
48
|
-
}
|
|
49
|
-
// Call plugin's onLoad lifecycle method
|
|
50
|
-
if (plugin.onLoad) {
|
|
51
|
-
await plugin.onLoad();
|
|
52
|
-
}
|
|
53
|
-
// Register custom hooks if defined
|
|
54
|
-
if (plugin.registerCustomHooks) {
|
|
55
|
-
plugin.registerCustomHooks();
|
|
56
|
-
}
|
|
57
|
-
const loadedPlugin = {
|
|
58
|
-
plugin, // plugin is already a Module
|
|
59
|
-
metadata: plugin.metadata,
|
|
60
|
-
pluginClass: PluginClass,
|
|
61
|
-
};
|
|
62
|
-
this.loadedPlugins.set(plugin.metadata.name, loadedPlugin);
|
|
63
|
-
await hookRegistry.trigger(LIFECYCLE_HOOKS.AFTER_PLUGIN_LOAD, loadedPlugin);
|
|
64
|
-
return loadedPlugin;
|
|
65
|
-
}
|
|
66
|
-
async loadPlugins(pluginsDir) {
|
|
67
|
-
const pluginDirs = await this.findPlugins(pluginsDir);
|
|
68
|
-
const loadedPlugins = [];
|
|
69
|
-
// Load all plugins first
|
|
70
|
-
for (const dir of pluginDirs) {
|
|
71
|
-
try {
|
|
72
|
-
const loaded = await this.loadPlugin(dir);
|
|
73
|
-
loadedPlugins.push(loaded);
|
|
74
|
-
}
|
|
75
|
-
catch (error) {
|
|
76
|
-
console.error(`Failed to load plugin from ${dir}:`, error);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
// Resolve dependencies and initialize
|
|
80
|
-
const sortedPlugins = this.resolveDependencyOrder(loadedPlugins);
|
|
81
|
-
for (const loaded of sortedPlugins) {
|
|
82
|
-
await this.initializePlugin(loaded);
|
|
83
|
-
}
|
|
84
|
-
return sortedPlugins;
|
|
85
|
-
}
|
|
86
|
-
resolveDependencyOrder(plugins) {
|
|
87
|
-
const sorted = [];
|
|
88
|
-
const visited = new Set();
|
|
89
|
-
const visiting = new Set();
|
|
90
|
-
const visit = (plugin) => {
|
|
91
|
-
const name = plugin.metadata.name;
|
|
92
|
-
if (visiting.has(name)) {
|
|
93
|
-
throw new Error(`Circular dependency detected involving plugin: ${name}`);
|
|
94
|
-
}
|
|
95
|
-
if (visited.has(name)) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
visiting.add(name);
|
|
99
|
-
// Visit dependencies first
|
|
100
|
-
const dependencies = plugin.metadata.dependencies || [];
|
|
101
|
-
for (const depName of dependencies) {
|
|
102
|
-
const dep = plugins.find((p) => p.metadata.name === depName);
|
|
103
|
-
if (!dep) {
|
|
104
|
-
throw new Error(`Plugin ${name} depends on ${depName}, but it's not loaded`);
|
|
105
|
-
}
|
|
106
|
-
visit(dep);
|
|
107
|
-
}
|
|
108
|
-
visiting.delete(name);
|
|
109
|
-
visited.add(name);
|
|
110
|
-
sorted.push(plugin);
|
|
111
|
-
};
|
|
112
|
-
for (const plugin of plugins) {
|
|
113
|
-
visit(plugin);
|
|
114
|
-
}
|
|
115
|
-
return sorted;
|
|
116
|
-
}
|
|
117
|
-
async initializePlugin(loaded) {
|
|
118
|
-
const hookRegistry = inject(HOOK_REGISTRY_TOKEN);
|
|
119
|
-
await hookRegistry.trigger(LIFECYCLE_HOOKS.BEFORE_PLUGIN_INIT, loaded);
|
|
120
|
-
// Call plugin's onInit lifecycle method
|
|
121
|
-
if (loaded.plugin.onInit) {
|
|
122
|
-
await loaded.plugin.onInit();
|
|
123
|
-
}
|
|
124
|
-
await hookRegistry.trigger(LIFECYCLE_HOOKS.AFTER_PLUGIN_INIT, loaded);
|
|
125
|
-
}
|
|
126
|
-
async unloadPlugin(pluginName) {
|
|
127
|
-
const loaded = this.loadedPlugins.get(pluginName);
|
|
128
|
-
if (!loaded) {
|
|
129
|
-
throw new Error(`Plugin ${pluginName} is not loaded`);
|
|
130
|
-
}
|
|
131
|
-
const hookRegistry = inject(HOOK_REGISTRY_TOKEN);
|
|
132
|
-
await hookRegistry.trigger(LIFECYCLE_HOOKS.BEFORE_PLUGIN_DESTROY, loaded);
|
|
133
|
-
// Call plugin's onDestroy lifecycle method
|
|
134
|
-
if (loaded.plugin.onDestroy) {
|
|
135
|
-
await loaded.plugin.onDestroy();
|
|
136
|
-
}
|
|
137
|
-
this.loadedPlugins.delete(pluginName);
|
|
138
|
-
await hookRegistry.trigger(LIFECYCLE_HOOKS.AFTER_PLUGIN_DESTROY, loaded);
|
|
139
|
-
}
|
|
140
|
-
getPlugin(name) {
|
|
141
|
-
return this.loadedPlugins.get(name);
|
|
142
|
-
}
|
|
143
|
-
getAllPlugins() {
|
|
144
|
-
return Array.from(this.loadedPlugins.values());
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
//# sourceMappingURL=PluginLoader.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginLoader.js","sourceRoot":"","sources":["../../src/core/PluginLoader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,MA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CAAC,YAAY,CAAC,UAAkB;QACnC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,UAAU,UAAU,gBAAgB,CAAC,CAAC;QACxD,CAAC;QAED,MAAM,YAAY,GAAG,MAAM,CAAgB,mBAAmB,CAAC,CAAC;QAChE,MAAM,YAAY,CAAC,OAAO,CAAC,eAAe,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;QAE1E,2CAA2C;QAC3C,IAAI,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;YAC5B,MAAM,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;QAClC,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;QAEtC,MAAM,YAAY,CAAC,OAAO,CAAC,eAAe,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED,aAAa;QACX,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC;IACjD,CAAC;CACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginLoader.spec.d.ts","sourceRoot":"","sources":["../../src/core/PluginLoader.spec.ts"],"names":[],"mappings":""}
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, beforeEach, afterEach } from 'bun:test';
|
|
2
|
-
import { PluginLoader } from './PluginLoader';
|
|
3
|
-
import { Plugin } from './Plugin';
|
|
4
|
-
import { tmpdir } from 'os';
|
|
5
|
-
import { mkdtempSync } from 'fs';
|
|
6
|
-
// Minimal IHookRegistry mock
|
|
7
|
-
const mockHookRegistry = {
|
|
8
|
-
trigger: async () => { },
|
|
9
|
-
register: () => { },
|
|
10
|
-
unregister: () => { },
|
|
11
|
-
getHooks: () => [],
|
|
12
|
-
clear: () => { },
|
|
13
|
-
};
|
|
14
|
-
// // Patch inject to return our mock
|
|
15
|
-
// import * as simpleDi from "@kanian77/simple-di";
|
|
16
|
-
// (simpleDi as any).inject = () => mockHookRegistry;
|
|
17
|
-
// Patch fs.promises for plugin discovery
|
|
18
|
-
import { mkdir, writeFile, rm } from 'fs/promises';
|
|
19
|
-
import { join, resolve } from 'path';
|
|
20
|
-
// Helper for plugin mocks
|
|
21
|
-
class PluginMock extends Plugin {
|
|
22
|
-
metadata = { name: 'pluginA', version: '1.0.0' };
|
|
23
|
-
imports = [];
|
|
24
|
-
providers = [];
|
|
25
|
-
async onLoad() { }
|
|
26
|
-
async onInit() { }
|
|
27
|
-
async onDestroy() { }
|
|
28
|
-
registerCustomHooks() { }
|
|
29
|
-
}
|
|
30
|
-
class PluginMockA extends Plugin {
|
|
31
|
-
metadata = { name: 'A', version: '1.0.0', dependencies: ['B'] };
|
|
32
|
-
imports = [];
|
|
33
|
-
providers = [];
|
|
34
|
-
}
|
|
35
|
-
class PluginMockB extends Plugin {
|
|
36
|
-
metadata = { name: 'B', version: '1.0.0', dependencies: ['A'] };
|
|
37
|
-
imports = [];
|
|
38
|
-
providers = [];
|
|
39
|
-
}
|
|
40
|
-
describe('PluginLoader', () => {
|
|
41
|
-
let loader;
|
|
42
|
-
let tempRoot;
|
|
43
|
-
beforeEach(async () => {
|
|
44
|
-
loader = new PluginLoader();
|
|
45
|
-
tempRoot = mkdtempSync(join(tmpdir(), 'plugin-test-'));
|
|
46
|
-
// Create pluginA with module.ts
|
|
47
|
-
const pluginADir = join(tempRoot, 'pluginA');
|
|
48
|
-
await mkdir(pluginADir);
|
|
49
|
-
await writeFile(join(pluginADir, 'module.ts'), '// pluginA module');
|
|
50
|
-
// Create pluginB without module.ts
|
|
51
|
-
const pluginBDir = join(tempRoot, 'pluginB');
|
|
52
|
-
await mkdir(pluginBDir);
|
|
53
|
-
// Create a non-directory file
|
|
54
|
-
await writeFile(join(tempRoot, 'file.txt'), 'not a directory');
|
|
55
|
-
});
|
|
56
|
-
afterEach(async () => {
|
|
57
|
-
await rm(tempRoot, { recursive: true, force: true });
|
|
58
|
-
});
|
|
59
|
-
it('findPlugins returns only directories with module.ts', async () => {
|
|
60
|
-
const plugins = await loader.findPlugins('./src/lib/test-related/plugins');
|
|
61
|
-
expect(plugins).toEqual([
|
|
62
|
-
'src/lib/test-related/plugins/plugin-a',
|
|
63
|
-
'src/lib/test-related/plugins/plugin-b',
|
|
64
|
-
]);
|
|
65
|
-
});
|
|
66
|
-
it('loadPlugin throws if no default export', async () => {
|
|
67
|
-
const origJoin = require('path').join;
|
|
68
|
-
require('path').join = (...args) => args.join('/');
|
|
69
|
-
const origImport = global.import;
|
|
70
|
-
global.import = async (_) => ({});
|
|
71
|
-
await expect(loader.loadPlugin('./src/lib/test-related/plugins/plugin-a')).rejects.toThrow();
|
|
72
|
-
global.import = origImport;
|
|
73
|
-
require('path').join = origJoin;
|
|
74
|
-
});
|
|
75
|
-
it('loadPlugin loads valid plugin and triggers hooks', async () => {
|
|
76
|
-
const modulePath = resolve('src/lib/test-related/plugins/plugin-a');
|
|
77
|
-
const loaded = await loader.loadPlugin(modulePath);
|
|
78
|
-
expect(loaded.plugin).toBeInstanceOf(await import(join(modulePath, 'module.ts')).then((m) => m.default));
|
|
79
|
-
expect(loaded.metadata.name).toBe('pluginA');
|
|
80
|
-
});
|
|
81
|
-
it('unloadPlugin triggers destroy hooks and removes plugin', async () => {
|
|
82
|
-
const loaded = {
|
|
83
|
-
plugin: new PluginMock({}),
|
|
84
|
-
metadata: { name: 'pluginA', version: '1.0.0' },
|
|
85
|
-
pluginClass: PluginMock,
|
|
86
|
-
};
|
|
87
|
-
loader['loadedPlugins'].set('pluginA', loaded);
|
|
88
|
-
await loader.unloadPlugin('pluginA');
|
|
89
|
-
expect(loader.getPlugin('pluginA')).toBeUndefined();
|
|
90
|
-
});
|
|
91
|
-
it('getAllPlugins returns all loaded plugins', () => {
|
|
92
|
-
const loaded = {
|
|
93
|
-
plugin: new PluginMock({}),
|
|
94
|
-
metadata: { name: 'pluginA', version: '1.0.0' },
|
|
95
|
-
pluginClass: PluginMock,
|
|
96
|
-
};
|
|
97
|
-
loader['loadedPlugins'].set('pluginA', loaded);
|
|
98
|
-
expect(loader.getAllPlugins()).toEqual([loaded]);
|
|
99
|
-
});
|
|
100
|
-
it('resolveDependencyOrder throws on circular dependency', () => {
|
|
101
|
-
const pluginA = {
|
|
102
|
-
plugin: new PluginMockA({}),
|
|
103
|
-
metadata: { name: 'A', version: '1.0.0', dependencies: ['B'] },
|
|
104
|
-
pluginClass: PluginMockA,
|
|
105
|
-
};
|
|
106
|
-
const pluginB = {
|
|
107
|
-
plugin: new PluginMockB({}),
|
|
108
|
-
metadata: { name: 'B', version: '1.0.0', dependencies: ['A'] },
|
|
109
|
-
pluginClass: PluginMockB,
|
|
110
|
-
};
|
|
111
|
-
expect(() => loader['resolveDependencyOrder']([pluginA, pluginB])).toThrow();
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
//# sourceMappingURL=PluginLoader.spec.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PluginLoader.spec.js","sourceRoot":"","sources":["../../src/core/PluginLoader.spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACvE,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAI9C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AACjC,6BAA6B;AAC7B,MAAM,gBAAgB,GAAkB;I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AO,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Plugin } from '../core/Plugin';
|
|
2
|
-
export default class ExamplePlugin extends Plugin {
|
|
3
|
-
readonly metadata: {
|
|
4
|
-
name: string;
|
|
5
|
-
version: string;
|
|
6
|
-
description: string;
|
|
7
|
-
dependencies: never[];
|
|
8
|
-
};
|
|
9
|
-
constructor();
|
|
10
|
-
onLoad(): Promise<void>;
|
|
11
|
-
onInit(): Promise<void>;
|
|
12
|
-
onDestroy(): Promise<void>;
|
|
13
|
-
protected registerCustomHooks(): void;
|
|
14
|
-
private handleExampleEvent;
|
|
15
|
-
private onApplicationStart;
|
|
16
|
-
private onBeforePluginLoad;
|
|
17
|
-
private registerAdditionalHooks;
|
|
18
|
-
private handleDynamicHook;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=module.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/example-plugin/module.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAIxC,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,MAAM;IAC/C,QAAQ,CAAC,QAAQ;;;;;MAKf;;IAgBa,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAIvB,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAOvB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;cAItB,mBAAmB,IAAI,IAAI;YAQhC,kBAAkB;YAKlB,kBAAkB;YAKlB,kBAAkB;IAKhC,OAAO,CAAC,uBAAuB;YAOjB,iBAAiB;CAGhC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { ExampleService } from './services';
|
|
11
|
-
import { EXAMPLE_SERVICE_TOKEN } from './tokens';
|
|
12
|
-
import { Hook } from '../decorators/hookDecorator';
|
|
13
|
-
import { inject } from '@kanian77/simple-di';
|
|
14
|
-
import { Plugin } from '../core/Plugin';
|
|
15
|
-
import { HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
|
|
16
|
-
export default class ExamplePlugin extends Plugin {
|
|
17
|
-
metadata = {
|
|
18
|
-
name: 'example-plugin',
|
|
19
|
-
version: '1.0.0',
|
|
20
|
-
description: 'An example plugin',
|
|
21
|
-
dependencies: [], // other plugin names this depends on
|
|
22
|
-
};
|
|
23
|
-
constructor() {
|
|
24
|
-
// Call parent Module constructor with plugin configuration
|
|
25
|
-
super({
|
|
26
|
-
providers: [
|
|
27
|
-
{
|
|
28
|
-
provide: EXAMPLE_SERVICE_TOKEN,
|
|
29
|
-
useClass: ExampleService,
|
|
30
|
-
},
|
|
31
|
-
],
|
|
32
|
-
// Can also import other modules if needed
|
|
33
|
-
// imports: [SomeOtherModule],
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
async onLoad() {
|
|
37
|
-
console.log('ExamplePlugin loading...');
|
|
38
|
-
}
|
|
39
|
-
async onInit() {
|
|
40
|
-
console.log('ExamplePlugin initialized!');
|
|
41
|
-
// Additional manual hook registration if needed
|
|
42
|
-
this.registerAdditionalHooks();
|
|
43
|
-
}
|
|
44
|
-
async onDestroy() {
|
|
45
|
-
console.log('ExamplePlugin destroyed!');
|
|
46
|
-
}
|
|
47
|
-
registerCustomHooks() {
|
|
48
|
-
// Define custom hooks that this plugin provides
|
|
49
|
-
// Other plugins can listen to these hooks
|
|
50
|
-
console.log('Registering custom hooks for ExamplePlugin');
|
|
51
|
-
}
|
|
52
|
-
// These methods will be automatically registered as hook handlers
|
|
53
|
-
async handleExampleEvent(data) {
|
|
54
|
-
console.log('Handling example event via decorator:', data);
|
|
55
|
-
}
|
|
56
|
-
async onApplicationStart() {
|
|
57
|
-
console.log('ExamplePlugin responding to application start via decorator');
|
|
58
|
-
}
|
|
59
|
-
async onBeforePluginLoad(pluginPath) {
|
|
60
|
-
console.log('Another plugin is about to load:', pluginPath);
|
|
61
|
-
}
|
|
62
|
-
// Manual hook registration for dynamic scenarios
|
|
63
|
-
registerAdditionalHooks() {
|
|
64
|
-
const hookRegistry = inject(HOOK_REGISTRY_TOKEN);
|
|
65
|
-
// Register additional hooks manually if needed
|
|
66
|
-
hookRegistry.register('dynamic:custom-hook', this.handleDynamicHook.bind(this));
|
|
67
|
-
}
|
|
68
|
-
async handleDynamicHook(data) {
|
|
69
|
-
console.log('Handling dynamic hook:', data);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
__decorate([
|
|
73
|
-
Hook('custom:example-event'),
|
|
74
|
-
__metadata("design:type", Function),
|
|
75
|
-
__metadata("design:paramtypes", [Object]),
|
|
76
|
-
__metadata("design:returntype", Promise)
|
|
77
|
-
], ExamplePlugin.prototype, "handleExampleEvent", null);
|
|
78
|
-
__decorate([
|
|
79
|
-
Hook('core:application-start'),
|
|
80
|
-
__metadata("design:type", Function),
|
|
81
|
-
__metadata("design:paramtypes", []),
|
|
82
|
-
__metadata("design:returntype", Promise)
|
|
83
|
-
], ExamplePlugin.prototype, "onApplicationStart", null);
|
|
84
|
-
__decorate([
|
|
85
|
-
Hook('core:before-plugin-load'),
|
|
86
|
-
__metadata("design:type", Function),
|
|
87
|
-
__metadata("design:paramtypes", [String]),
|
|
88
|
-
__metadata("design:returntype", Promise)
|
|
89
|
-
], ExamplePlugin.prototype, "onBeforePluginLoad", null);
|
|
90
|
-
//# sourceMappingURL=module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/example-plugin/module.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,MAAM;IACtC,QAAQ,GAAG;QAClB,IAAI,EAAE,gBAAgB;QACtB,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,mBAAmB;QAChC,YAAY,EAAE,EAAE,EAAE,qCAAqC;KACxD,CAAC;IAEF;QACE,2DAA2D;QAC3D,KAAK,CAAC;YACJ,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,qBAAqB;oBAC9B,QAAQ,EAAE,cAAc;iBACzB;aACF;YACD,0CAA0C;YAC1C,8BAA8B;SAC/B,CAAC,CAAC;IACL,CAAC;IAEQ,KAAK,CAAC,MAAM;QACnB,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;IAC1C,CAAC;IAEQ,KAAK,CAAC,MAAM;QACnB,OAAO,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAE1C,gDAAgD;QAChD,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAEQ,KAAK,CAAC,SAAS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AC,YAAY,CAAgB;;IAKpC,WAAW,IAAI,IAAI;CAKpB"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { Service, inject } from '@kanian77/simple-di';
|
|
11
|
-
import { EXAMPLE_SERVICE_TOKEN } from './tokens';
|
|
12
|
-
import { HOOK_REGISTRY_TOKEN } from '../lib/types/tokens';
|
|
13
|
-
let ExampleService = class ExampleService {
|
|
14
|
-
hookRegistry;
|
|
15
|
-
constructor() {
|
|
16
|
-
this.hookRegistry = inject(HOOK_REGISTRY_TOKEN);
|
|
17
|
-
}
|
|
18
|
-
doSomething() {
|
|
19
|
-
console.log('ExampleService doing something...');
|
|
20
|
-
// Can trigger custom hooks
|
|
21
|
-
this.hookRegistry.trigger('example:something-done', { data: 'example' });
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
ExampleService = __decorate([
|
|
25
|
-
Service({ token: EXAMPLE_SERVICE_TOKEN }),
|
|
26
|
-
__metadata("design:paramtypes", [])
|
|
27
|
-
], ExampleService);
|
|
28
|
-
export { ExampleService };
|
|
29
|
-
//# sourceMappingURL=services.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"services.js","sourceRoot":"","sources":["../../src/example-plugin/services.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAU,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAQnD,IAAM,cAAc,GAApB,MAAM,cAAc;IACjB,YAAY,CAAgB;IACpC;QACE,IAAI,CAAC,YAAY,GAAG,MAAM,CAAgB,mBAAmB,CAAC,CAAC;IACjE,CAAC;IAED,WAAW;QACT,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACjD,2BAA2B;QAC3B,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,wBAAwB,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAC3E,CAAC;CACF,CAAA;AAXY,cAAc;IAD1B,OAAO,CAAC,EAAE,KAAK,EAAE,qBAAqB,EAAE,CAAC;;GAC7B,cAAc,CAW1B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/example-plugin/tokens.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,eAA2B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tokens.js","sourceRoot":"","sources":["../../src/example-plugin/tokens.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CAAC,gBAAgB,CAAC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HookMetadata.d.ts","sourceRoot":"","sources":["../../../src/lib/types/HookMetadata.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=HookMetadata.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HookMetadata.js","sourceRoot":"","sources":["../../../src/lib/types/HookMetadata.ts"],"names":[],"mappings":""}
|