@akala/pm 14.6.3 → 15.0.0

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 (53) hide show
  1. package/changelog.md +23 -2
  2. package/cli-commands.json +13 -3
  3. package/dist/esm/akala.d.mts +4 -0
  4. package/dist/esm/akala.mjs +37 -18
  5. package/dist/esm/akala.mjs.map +1 -1
  6. package/dist/esm/cli-commands/discover.js +6 -6
  7. package/dist/esm/cli-commands/discover.js.map +1 -1
  8. package/dist/esm/cli-commands/map.d.ts +2 -2
  9. package/dist/esm/cli-commands/map.js +2 -2
  10. package/dist/esm/cli-commands/map.js.map +1 -1
  11. package/dist/esm/cli-commands/run.js +6 -34
  12. package/dist/esm/cli-commands/run.js.map +1 -1
  13. package/dist/esm/cli-container.d.ts +3 -3
  14. package/dist/esm/cli-container.js +1 -1
  15. package/dist/esm/cli-container.js.map +1 -1
  16. package/dist/esm/commands/start.js +87 -111
  17. package/dist/esm/commands/start.js.map +1 -1
  18. package/dist/esm/commands/status.js +1 -1
  19. package/dist/esm/commands/status.js.map +1 -1
  20. package/dist/esm/commands/stop.js +1 -1
  21. package/dist/esm/commands/stop.js.map +1 -1
  22. package/dist/esm/container.d.ts +3 -3
  23. package/dist/esm/container.js +1 -1
  24. package/dist/esm/container.js.map +1 -1
  25. package/dist/esm/runtimes/child_process.d.ts +3 -1
  26. package/dist/esm/runtimes/child_process.js +14 -6
  27. package/dist/esm/runtimes/child_process.js.map +1 -1
  28. package/dist/esm/runtimes/process.d.ts +2 -0
  29. package/dist/esm/runtimes/process.js +3 -8
  30. package/dist/esm/runtimes/process.js.map +1 -1
  31. package/dist/esm/runtimes/shared.d.ts +2 -0
  32. package/dist/esm/runtimes/worker.d.ts +1 -0
  33. package/dist/esm/runtimes/worker.js +1 -0
  34. package/dist/esm/runtimes/worker.js.map +1 -1
  35. package/dist/esm/state.d.ts +2 -2
  36. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  37. package/package.json +6 -6
  38. package/src/akala.mts +48 -19
  39. package/src/cli-commands/discover.ts +7 -7
  40. package/src/cli-commands/map.json +10 -2
  41. package/src/cli-commands/map.ts +4 -4
  42. package/src/cli-commands/run.json +2 -1
  43. package/src/cli-commands/run.ts +6 -38
  44. package/src/cli-container.ts +3 -3
  45. package/src/commands/start.ts +96 -128
  46. package/src/commands/status.ts +2 -2
  47. package/src/commands/stop.ts +1 -1
  48. package/src/container.ts +3 -3
  49. package/src/runtimes/child_process.ts +15 -6
  50. package/src/runtimes/process.ts +3 -10
  51. package/src/runtimes/shared.ts +2 -0
  52. package/src/runtimes/worker.ts +1 -0
  53. package/src/state.ts +2 -2
@@ -26,48 +26,38 @@ export default async function start(this: State, pm: pmContainer.container & Con
26
26
 
27
27
  let def: ProxyConfiguration<SidecarMetadata>;
28
28
 
29
- if (this.isDaemon)
30
- {
31
- var instanceConfig = this.config.mapping[options.name || name];
32
- if (!instanceConfig?.container)
33
- def = this.config.containers[name];
34
- else
35
- def = this.config.containers[instanceConfig.container];
29
+ var instanceConfig = this.config.mapping[options.name || name];
30
+ if (!instanceConfig?.container)
31
+ def = this.config.containers[name];
32
+ else
33
+ def = this.config.containers[instanceConfig.container];
36
34
 
37
- if (typeof options.autostart !== 'undefined')
38
- if (instanceConfig)
39
- instanceConfig.autostart = options.autostart;
40
- else
41
- {
42
- this.config.mapping.set(options.name || name, { container: name, autostart: options.autostart });
43
- await this.config.commit()
44
- }
35
+ if (typeof options.autostart !== 'undefined')
36
+ if (instanceConfig)
37
+ instanceConfig.autostart = options.autostart;
38
+ else
39
+ {
40
+ this.config.mapping.set(options.name || name, { container: name, autostart: options.autostart });
41
+ await this.config.commit()
42
+ }
45
43
 
46
- var container = this.processes[options.name || name];
47
- if (container?.running)
48
- throw new Error(container.name + ' is already started');
44
+ var container = this.processes[options.name || name];
45
+ if (container?.running)
46
+ throw new Error(container.name + ' is already started');
49
47
 
50
- args = [];
48
+ args = [];
51
49
 
52
- if (!def && name != 'pm')
53
- throw new ErrorWithStatus(404, `No mapping was found for ${name}. Did you want to run \`pm install ${name}\` or maybe are you missing the folder to ${name} ?`)
50
+ if (!def && name != 'pm')
51
+ throw new ErrorWithStatus(404, `No mapping was found for ${name}. Did you want to run \`pm install ${name}\` or maybe are you missing the folder to ${name} ?`)
54
52
 
55
- // if (options.configFile)
56
- // options.configFile += '#' + options.name
53
+ // if (options.configFile)
54
+ // options.configFile += '#' + options.name
57
55
 
58
- args.unshift(...(context?.args || []), ...unparseOptions({ ...options, program: undefined, new: undefined, inspect: undefined }, { ignoreUndefined: true }));
59
- if (def && def.get('path'))
60
- args.unshift('--program=' + def.get('path'));
61
- else
62
- args.unshift('--program=' + name);
63
- }
56
+ args.unshift(...(context?.args || []), ...unparseOptions({ ...options, program: undefined, new: undefined, inspect: undefined }, { ignoreUndefined: true }));
57
+ if (def && def.get('path'))
58
+ args.unshift('--program=' + def.get('path'));
64
59
  else
65
- {
66
- if (name != 'pm')
67
- throw new ErrorWithStatus(40, 'this command needs to run through daemon process');
68
-
69
- args = [new URL('../../../commands.json', import.meta.url).toString(), ...(context?.args || []), ...unparseOptions({ ...options, inspect: undefined })];
70
- }
60
+ args.unshift('--program=' + name);
71
61
 
72
62
  if (options?.inspect)
73
63
  args.unshift('--inspect-brk');
@@ -77,80 +67,58 @@ export default async function start(this: State, pm: pmContainer.container & Con
77
67
  if (options?.verbose)
78
68
  args.push('-v')
79
69
 
80
- if (!this.isDaemon)
81
- {
82
- const cp = ChildProcess.build(args, { inheritStdio: true, name: options.name });
83
- cp.on('exit', function ()
84
- {
85
- console.log(args);
86
- })
87
70
 
88
- return new Promise<void>((resolve) =>
89
- {
90
- cp.on('runningChanged', () =>
91
- {
92
- if (!options.keepAttached)
93
- cp.unref();
94
- console.log('pm started');
95
- resolve();
96
- })
97
- })
98
- }
99
- else
71
+ let cp: RuntimeInstance;
72
+
73
+ if (!container && def.dependencies?.length)
100
74
  {
101
- let cp: RuntimeInstance;
75
+ const missingDeps = def.dependencies.filter(d => !this.config.containers[d] && !this.config.mapping[d]);
76
+ if (missingDeps.length > 0)
77
+ throw new ErrorWithStatus(404, `Some dependencies are missing to start ${options.name}:\n\t-${missingDeps.join('\n\t-')}`);
102
78
 
103
- if (!container && def.dependencies?.length)
104
- {
105
- const missingDeps = def.dependencies.filter(d => !this.config.containers[d] && !this.config.mapping[d]);
106
- if (missingDeps.length > 0)
107
- throw new ErrorWithStatus(404, `Some dependencies are missing to start ${options.name}:\n\t-${missingDeps.join('\n\t-')}`);
79
+ await eachAsync(def.dependencies, async (dep) => { await pm.dispatch('start', dep, { name: options.name + '-' + dep, wait: true }) });
80
+ }
108
81
 
109
- await eachAsync(def.dependencies, async (dep) => { await pm.dispatch('start', dep, { name: options.name + '-' + dep, wait: true }) });
110
- }
82
+ switch (def?.type)
83
+ {
84
+ case 'worker':
85
+ cp = Worker.build(args, options);
86
+ break;
87
+ case 'nodejs':
88
+ args.push('--pm-sock', 'ipc://')
89
+ cp = ChildProcess.build(args, { ...options, keepAttached: true });
90
+ break;
91
+ default:
92
+ throw new ErrorWithStatus(400, `container with type ${this.config.containers[name]?.type} are not yet supported`);
93
+ }
111
94
 
112
- switch (def?.type)
95
+ if (!container?.running)
96
+ {
97
+ container = new Container(options.name, null) as RunningContainer;
98
+ const connection = Processors.JsonRpc.getConnection(cp.adapter, pm, (params) =>
113
99
  {
114
- case 'worker':
115
- cp = Worker.build(args, options);
116
- break;
117
- case 'nodejs':
118
- cp = ChildProcess.build(args, options);
119
- break;
120
- default:
121
- throw new ErrorWithStatus(400, `container with type ${this.config.containers[name]?.type} are not yet supported`);
122
- }
100
+ params.process = cp;
101
+ Object.defineProperty(params, 'connectionAsContainer', { value: container });
102
+ });
103
+ container.processor.useMiddleware(20, new Processors.JsonRpc(connection));
123
104
 
124
- if (!container?.running)
105
+ connection.on('close', function disconnected()
125
106
  {
126
- container = new Container(options.name, null) as RunningContainer;
127
- const connection = Processors.JsonRpc.getConnection(cp.adapter, pm, (params) =>
128
- {
129
- params.process = cp;
130
- Object.defineProperty(params, 'connectionAsContainer', { value: container });
131
- });
132
- container.processor.useMiddleware(20, new Processors.JsonRpc(connection));
133
-
134
- connection.on('close', function disconnected()
135
- {
136
- console.warn(`${options.name} has disconnected`);
137
- container.running = false;
138
- });
107
+ console.warn(`${options.name} has disconnected`);
108
+ container.running = false;
109
+ });
139
110
 
140
- if (def?.commandable)
141
- pm.register(container, def?.stateless);
111
+ this.processes[options.name] = container;
112
+ }
113
+ container.process = cp;
142
114
 
143
- this.processes[options.name] = container;
144
- }
145
- container.process = cp;
115
+ Object.assign(container, def, instanceConfig);
116
+ container.ready = new Event();
117
+ if (container.commandable)// && !container.stateless)
118
+ {
119
+ container.unregister(Cli.Metadata.name);
120
+ container.register(Metadata.extractCommandMetadata(Cli.Metadata));
146
121
 
147
- Object.assign(container, def, instanceConfig);
148
- container.ready = new Event();
149
- if (container.commandable)// && !container.stateless)
150
- {
151
- container.unregister(Cli.Metadata.name);
152
- container.register(Metadata.extractCommandMetadata(Cli.Metadata));
153
- }
154
122
  container.ready.addListener(() =>
155
123
  {
156
124
  return container.dispatch('$metadata').then((metaContainer: Metadata.Container) =>
@@ -160,40 +128,40 @@ export default async function start(this: State, pm: pmContainer.container & Con
160
128
  pm.register(name, container, true);
161
129
  });
162
130
  });
163
- // , () =>
164
- // {
165
- // console.warn(`${options.name} has disconnected`);
166
- // container.running = false;
167
- // });
131
+ }
132
+ // , () =>
133
+ // {
134
+ // console.warn(`${options.name} has disconnected`);
135
+ // container.running = false;
136
+ // });
168
137
 
169
- container.running = true;
170
- let buffer = [];
138
+ container.running = true;
139
+ let buffer = [];
171
140
 
172
- cp.on('exit', function ()
141
+ cp.on('exit', function ()
142
+ {
143
+ container.running = false;
144
+ if (!container.stateless)
173
145
  {
174
- container.running = false;
175
- if (!container.stateless)
176
- {
177
- pm.unregister(container.name);
178
- console.log(new Error('program stopped: ' + buffer?.join('')));
179
- }
180
- });
181
- if (options.wait && container.commandable)
146
+ pm.unregister(container.name);
147
+ console.log(new Error('program stopped: ' + buffer?.join('')));
148
+ }
149
+ });
150
+ if (options.wait && container.commandable)
151
+ {
152
+ //eslint-disable-next-line no-inner-declarations
153
+ function gather(chunk: string)
182
154
  {
183
- //eslint-disable-next-line no-inner-declarations
184
- function gather(chunk: string)
185
- {
186
- buffer.push(chunk);
187
- }
188
- cp.stderr.on('data', gather);
189
- cp.on('exit', () =>
190
- {
191
- buffer = null;
192
- cp.stderr.off('data', gather);
193
- });
155
+ buffer.push(chunk);
194
156
  }
195
- if (options.wait)
196
- await new Promise<void>(resolve => container.ready?.addListener(resolve));
197
- return { execPath: process.execPath, args: args, cwd: process.cwd(), shell: false, windowsHide: true };
157
+ cp.stderr.on('data', gather);
158
+ cp.on('exit', () =>
159
+ {
160
+ buffer = null;
161
+ cp.stderr.off('data', gather);
162
+ });
198
163
  }
164
+ if (options.wait)
165
+ await new Promise<void>(resolve => container.ready?.addListener(resolve));
166
+ return { execPath: process.execPath, args: args, cwd: process.cwd(), shell: false, windowsHide: true };
199
167
  }
@@ -6,5 +6,5 @@ export default function status(this: State, name?: string): { name: string, filt
6
6
  if (name)
7
7
  processes = processes.filter(p => p.name == name);
8
8
 
9
- return processes.map(p => { return { name: p.name, filter: name, running: p.running, folder: p.path, stateless: p.stateless, type: p.type, cwd: p.cwd } })
10
- }
9
+ return processes.map(p => { return { name: p.name, filter: name, running: p.running, folder: p.path, stateless: p.stateless, type: p.process?.runtime.name, cwd: p.cwd } })
10
+ }
@@ -3,7 +3,7 @@ import State from '../state.js';
3
3
 
4
4
  export default async function stop(this: State, name: string, container: Container<State>): Promise<void>
5
5
  {
6
- await Promise.all(Object.values(this.processes).filter(p => p.name == name && p.process).map(cp =>
6
+ await Promise.all(Object.values(this.processes).filter(p => (p.name == name || name === 'pm') && p.process).map(cp =>
7
7
  {
8
8
  return new Promise<void>((resolve) =>
9
9
  {
package/src/container.ts CHANGED
@@ -23,7 +23,7 @@ namespace commands
23
23
  dispatch (cmd:'link', ...args: [Argument0<typeof import('./cli-commands/link.js').default>, Argument1<typeof import('./cli-commands/link.js').default>]): ReturnType<typeof import('./cli-commands/link.js').default>
24
24
  dispatch (cmd:'log', ...args: [Argument0<typeof import('./cli-commands/log.js').default>]): ReturnType<typeof import('./cli-commands/log.js').default>
25
25
  dispatch (cmd:'ls', ...args: []): ReturnType<typeof import('./cli-commands/ls.js').default>
26
- dispatch (cmd:'map', ...args: [Argument0<typeof import('./cli-commands/map.js').default>, Argument1<typeof import('./cli-commands/map.js').default>, Argument2<typeof import('./cli-commands/map.js').default>, Argument3<typeof import('./cli-commands/map.js').default>]): ReturnType<typeof import('./cli-commands/map.js').default>
26
+ dispatch (cmd:'map', ...args: [Argument0<typeof import('./cli-commands/map.js').default>, Argument1<typeof import('./cli-commands/map.js').default>, Argument2<typeof import('./cli-commands/map.js').default>, Argument3<typeof import('./cli-commands/map.js').default>, Argument4<typeof import('./cli-commands/map.js').default>]): ReturnType<typeof import('./cli-commands/map.js').default>
27
27
  dispatch (cmd:'run', ...args: [Argument0<typeof import('./cli-commands/run.js').default>, Argument1<typeof import('./cli-commands/run.js').default>]): ReturnType<typeof import('./cli-commands/run.js').default>
28
28
  dispatch (cmd:'uninstall', ...args: [Argument0<typeof import('./cli-commands/uninstall.js').default>]): ReturnType<typeof import('./cli-commands/uninstall.js').default>
29
29
  dispatch (cmd:'update', ...args: [Argument0<typeof import('./cli-commands/update.js').default>, Argument1<typeof import('./cli-commands/update.js').default>, Argument2<typeof import('./cli-commands/update.js').default>]): ReturnType<typeof import('./cli-commands/update.js').default>
@@ -46,13 +46,13 @@ namespace commands
46
46
  'link'(...args: [Argument0<typeof import('./cli-commands/link.js').default>, Argument1<typeof import('./cli-commands/link.js').default>]): ReturnType<typeof import('./cli-commands/link.js').default>
47
47
  'log'(...args: [Argument0<typeof import('./cli-commands/log.js').default>]): ReturnType<typeof import('./cli-commands/log.js').default>
48
48
  'ls'(...args: []): ReturnType<typeof import('./cli-commands/ls.js').default>
49
- 'map'(...args: [Argument0<typeof import('./cli-commands/map.js').default>, Argument1<typeof import('./cli-commands/map.js').default>, Argument2<typeof import('./cli-commands/map.js').default>, Argument3<typeof import('./cli-commands/map.js').default>]): ReturnType<typeof import('./cli-commands/map.js').default>
49
+ 'map'(...args: [Argument0<typeof import('./cli-commands/map.js').default>, Argument1<typeof import('./cli-commands/map.js').default>, Argument2<typeof import('./cli-commands/map.js').default>, Argument3<typeof import('./cli-commands/map.js').default>, Argument4<typeof import('./cli-commands/map.js').default>]): ReturnType<typeof import('./cli-commands/map.js').default>
50
50
  'run'(...args: [Argument0<typeof import('./cli-commands/run.js').default>, Argument1<typeof import('./cli-commands/run.js').default>]): ReturnType<typeof import('./cli-commands/run.js').default>
51
51
  'uninstall'(...args: [Argument0<typeof import('./cli-commands/uninstall.js').default>]): ReturnType<typeof import('./cli-commands/uninstall.js').default>
52
52
  'update'(...args: [Argument0<typeof import('./cli-commands/update.js').default>, Argument1<typeof import('./cli-commands/update.js').default>, Argument2<typeof import('./cli-commands/update.js').default>]): ReturnType<typeof import('./cli-commands/update.js').default>
53
53
  'version'(...args: [Argument0<typeof import('./cli-commands/version.js').default>, Argument1<typeof import('./cli-commands/version.js').default>]): ReturnType<typeof import('./cli-commands/version.js').default>
54
54
  }
55
- export const meta={"name":"pm","commands":[{"name":"$init","config":{"fs":{"disabled":true,"path":"dist/esm/commands/$init.js","source":"src/commands/$init.ts","inject":["$container","param.0"]},"":{"inject":["$container","param.0"]},"cli":{"inject":["$container","context"],"usage":"$init [...args]","options":{"configFile":{"needsValue":true,"aliases":["c"]},"keepAttached":{"aliases":["keep-attached"],"needsValue":false,"doc":"keeps the process attached to the current terminal"},"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"tcpPort":{"needsValue":true,"aliases":["tcp-port"]},"port":{"needsValue":true},"key":{"needsValue":true},"cert":{"needsValue":true}}}}},{"name":"bridge","config":{"fs":{"path":"dist/esm/commands/bridge.js","source":"src/commands/bridge.ts","inject":["param.0","param.1"]},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":["param.0","param.1"]}}},{"name":"name","config":{"fs":{"path":"dist/esm/commands/name.js","source":"src/commands/name.ts","inject":["param.0"]},"":{"inject":["param.0"]}}},{"name":"proxy","config":{"fs":{"path":"dist/esm/commands/proxy.js","source":"src/commands/proxy.ts","inject":["param.0","param.1"]},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":["param.0","param.1"]}}},{"name":"ready","config":{"fs":{"path":"dist/esm/commands/ready.js","source":"src/commands/ready.ts","inject":["$container","ignore"]},"jsonrpc":{"inject":["$container","dummy","connectionAsContainer"]},"":{"inject":["$container","connectionAsContainer"]}}},{"name":"reload-metadata","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/reload-metadata.js","source":"src/commands/reload-metadata.ts"},"jsonrpc":{"inject":["connectionAsContainer"]},"":{"inject":["param.0"]}}},{"name":"restart","config":{"fs":{"path":"dist/esm/commands/restart.js","source":"src/commands/restart.ts","inject":["$container","param.0","param.1"]},"":{"inject":["$container","param.0","param.1"]},"cli":{"options":{"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"}},"inject":["$container","param.0","context"],"usage":"restart <program>"},"schema":{"inject":["$container","param.0","param.1"],"$defs":{"param.0":{"type":"string"},"param.1":{"type":"object","properties":{"wait":{"type":"boolean"}}}}},"html-form":{"inject":["$container","param.0","param.1"]}}},{"name":"start","config":{"fs":{"path":"dist/esm/commands/start.js","source":"src/commands/start.ts","inject":["$container","param.0","param.1","param.2"]},"":{"inject":["$container","param.0","param.1","param.2"]},"cli":{"options":{"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"},"autostart":{"doc":"start automatically when pm starts"}},"inject":["$container","options.program","options","context"],"usage":"start <program>"},"html-form":{"inject":["$container","param.0","param.1","param.2"]},"schema":{"inject":["$container","param.0","param.1","param.2"],"$defs":{"param.0":{"type":"string"},"param.1":{"type":"object","properties":{"wait":{"type":"boolean"},"inspect":{"type":"boolean"},"new":{"type":"boolean"},"name":{"type":"string"},"program":{"type":"string"}}},"param.2":{"type":"object","properties":{"args":{"type":"array","items":{"type":"string"}}}}}}}},{"name":"status","config":{"fs":{"path":"dist/esm/commands/status.js","source":"src/commands/status.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]},"html-form":{"inject":["param.0"]},"schema":{"inject":["param.0"],"$defs":{"param.0":{"type":"string","description":"The name of the container to get the status of"}}}}},{"name":"stop","config":{"fs":{"path":"dist/esm/commands/stop.js","source":"src/commands/stop.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["options.process","$container"],"options":{"process":{"doc":"process to stop. Stops all the processes otherwise (including pm)."}},"usage":"stop [process]"},"html-form":{"inject":["param.0","$container"]},"schema":{"inject":["param.0","$container"],"$defs":{"param.0":{"type":"string"}}}}},{"name":"connect","config":{"fs":{"path":"dist/esm/cli-commands/connect.js","source":"src/cli-commands/connect.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"usage":"connect <name>","inject":["options.name","context"],"options":{"tcpPort":{"needsValue":true,"aliases":["tcp-port"]},"port":{"needsValue":true},"key":{"needsValue":true},"cert":{"needsValue":true}}}}},{"name":"discover","config":{"fs":{"path":"dist/esm/cli-commands/discover.js","source":"src/cli-commands/discover.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"usage":"discover <name> <folder>","options":{"folder":{"normalize":true}},"inject":["options.name","options.folder","$container"]}}},{"name":"install","config":{"fs":{"path":"dist/esm/cli-commands/install.js","source":"src/cli-commands/install.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["param.0","$container"]}}},{"name":"link","config":{"fs":{"path":"dist/esm/cli-commands/link.js","source":"src/cli-commands/link.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"inject":["param.0","param.1","$container"]}}},{"name":"log","config":{"fs":{"path":"dist/esm/cli-commands/log.js","source":"src/cli-commands/log.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]}}},{"name":"ls","config":{"fs":{"path":"dist/esm/cli-commands/ls.js","source":"src/cli-commands/ls.ts","inject":[]},"":{"inject":[]},"cli":{"inject":[]},"html-form":{"inject":[]}}},{"name":"map","config":{"fs":{"path":"dist/esm/cli-commands/map.js","source":"src/cli-commands/map.ts","inject":["param.0","param.1","param.2","param.3"]},"":{"inject":["param.0","param.1","param.2","param.3"]},"cli":{"inject":["options.name","options.path","cwd","options"],"options":{"commandable":{"aliases":["c"],"needsValue":false},"stateless":{"aliases":["s"],"needsValue":false}},"usage":"map <name> <path>"}}},{"name":"run","config":{"fs":{"path":"dist/esm/cli-commands/run.js","source":"src/cli-commands/run.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"options":{"output":{"aliases":["o"],"needsValue":true,"doc":"output as `table` if array otherwise falls back to standard node output"},"verbose":{"aliases":["v"]},"tls":{"doc":"enables tls connection to the `pmSock`"},"pmSock":{"aliases":["pm-sock"],"needsValue":true,"doc":"path to the unix socket or destination in the form host:port"},"help":{"doc":"displays this help message"},"keepAttached":{"aliases":["keep-attached"],"needsValue":false,"doc":"keeps the process attached to the current terminal"},"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"}},"inject":["options.program","options.name","context","options.pmSock"],"usage":"run [...args]"}}},{"name":"uninstall","config":{"fs":{"path":"dist/esm/cli-commands/uninstall.js","source":"src/cli-commands/uninstall.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["param.0","$container"]}}},{"name":"update","config":{"fs":{"path":"dist/esm/cli-commands/update.js","source":"src/cli-commands/update.ts","inject":["param.0","param.1","param.2"]},"cli":{"inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","param.2"]}}},{"name":"version","config":{"fs":{"path":"dist/esm/cli-commands/version.js","source":"src/cli-commands/version.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"inject":["options.packageName","options.folder"],"usage":"version <packageName> [folder]"},"schema":{"inject":["param.0","param.1"],"$defs":{"param.0":{"type":"string"},"param.1":{"type":"string"}}}}}],"extends":["./cli-commands.json"],"$schema":"https://raw.githubusercontent.com/npenin/akala/main/packages/commands/container-schema.json"} as Metadata.Container;
55
+ export const meta={"name":"pm","commands":[{"name":"$init","config":{"fs":{"disabled":true,"path":"dist/esm/commands/$init.js","source":"src/commands/$init.ts","inject":["$container","param.0"]},"":{"inject":["$container","param.0"]},"cli":{"inject":["$container","context"],"usage":"$init [...args]","options":{"configFile":{"needsValue":true,"aliases":["c"]},"keepAttached":{"aliases":["keep-attached"],"needsValue":false,"doc":"keeps the process attached to the current terminal"},"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"tcpPort":{"needsValue":true,"aliases":["tcp-port"]},"port":{"needsValue":true},"key":{"needsValue":true},"cert":{"needsValue":true}}}}},{"name":"bridge","config":{"fs":{"path":"dist/esm/commands/bridge.js","source":"src/commands/bridge.ts","inject":["param.0","param.1"]},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":["param.0","param.1"]}}},{"name":"name","config":{"fs":{"path":"dist/esm/commands/name.js","source":"src/commands/name.ts","inject":["param.0"]},"":{"inject":["param.0"]}}},{"name":"proxy","config":{"fs":{"path":"dist/esm/commands/proxy.js","source":"src/commands/proxy.ts","inject":["param.0","param.1"]},"jsonrpc":{"inject":["param.0","socket"]},"":{"inject":["param.0","param.1"]}}},{"name":"ready","config":{"fs":{"path":"dist/esm/commands/ready.js","source":"src/commands/ready.ts","inject":["$container","ignore"]},"jsonrpc":{"inject":["$container","dummy","connectionAsContainer"]},"":{"inject":["$container","connectionAsContainer"]}}},{"name":"reload-metadata","config":{"fs":{"inject":["param.0"],"path":"dist/esm/commands/reload-metadata.js","source":"src/commands/reload-metadata.ts"},"jsonrpc":{"inject":["connectionAsContainer"]},"":{"inject":["param.0"]}}},{"name":"restart","config":{"fs":{"path":"dist/esm/commands/restart.js","source":"src/commands/restart.ts","inject":["$container","param.0","param.1"]},"":{"inject":["$container","param.0","param.1"]},"cli":{"options":{"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"}},"inject":["$container","param.0","context"],"usage":"restart <program>"},"schema":{"inject":["$container","param.0","param.1"],"$defs":{"param.0":{"type":"string"},"param.1":{"type":"object","properties":{"wait":{"type":"boolean"}}}}},"html-form":{"inject":["$container","param.0","param.1"]}}},{"name":"start","config":{"fs":{"path":"dist/esm/commands/start.js","source":"src/commands/start.ts","inject":["$container","param.0","param.1","param.2"]},"":{"inject":["$container","param.0","param.1","param.2"]},"cli":{"options":{"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"},"autostart":{"doc":"start automatically when pm starts"}},"inject":["$container","options.program","options","context"],"usage":"start <program>"},"html-form":{"inject":["$container","param.0","param.1","param.2"]},"schema":{"inject":["$container","param.0","param.1","param.2"],"$defs":{"param.0":{"type":"string"},"param.1":{"type":"object","properties":{"wait":{"type":"boolean"},"inspect":{"type":"boolean"},"new":{"type":"boolean"},"name":{"type":"string"},"program":{"type":"string"}}},"param.2":{"type":"object","properties":{"args":{"type":"array","items":{"type":"string"}}}}}}}},{"name":"status","config":{"fs":{"path":"dist/esm/commands/status.js","source":"src/commands/status.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]},"html-form":{"inject":["param.0"]},"schema":{"inject":["param.0"],"$defs":{"param.0":{"type":"string","description":"The name of the container to get the status of"}}}}},{"name":"stop","config":{"fs":{"path":"dist/esm/commands/stop.js","source":"src/commands/stop.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["options.process","$container"],"options":{"process":{"doc":"process to stop. Stops all the processes otherwise (including pm)."}},"usage":"stop [process]"},"html-form":{"inject":["param.0","$container"]},"schema":{"inject":["param.0","$container"],"$defs":{"param.0":{"type":"string"}}}}},{"name":"connect","config":{"fs":{"path":"dist/esm/cli-commands/connect.js","source":"src/cli-commands/connect.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"usage":"connect <name>","inject":["options.name","context"],"options":{"tcpPort":{"needsValue":true,"aliases":["tcp-port"]},"port":{"needsValue":true},"key":{"needsValue":true},"cert":{"needsValue":true}}}}},{"name":"discover","config":{"fs":{"path":"dist/esm/cli-commands/discover.js","source":"src/cli-commands/discover.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"usage":"discover <name> <folder>","options":{"folder":{"normalize":true}},"inject":["options.name","options.folder","$container"]}}},{"name":"install","config":{"fs":{"path":"dist/esm/cli-commands/install.js","source":"src/cli-commands/install.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["param.0","$container"]}}},{"name":"link","config":{"fs":{"path":"dist/esm/cli-commands/link.js","source":"src/cli-commands/link.ts","inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","$container"]},"cli":{"inject":["param.0","param.1","$container"]}}},{"name":"log","config":{"fs":{"path":"dist/esm/cli-commands/log.js","source":"src/cli-commands/log.ts","inject":["param.0"]},"":{"inject":["param.0"]},"cli":{"inject":["param.0"]}}},{"name":"ls","config":{"fs":{"path":"dist/esm/cli-commands/ls.js","source":"src/cli-commands/ls.ts","inject":[]},"":{"inject":[]},"cli":{"inject":[]},"html-form":{"inject":[]}}},{"name":"map","config":{"fs":{"path":"dist/esm/cli-commands/map.js","source":"src/cli-commands/map.ts","inject":["param.0","param.1","param.2","param.3","param.4"]},"":{"inject":["param.0","param.1","param.2","param.3","param.4"]},"cli":{"inject":["options.name","options.path","options.runtime","cwd","options"],"options":{"commandable":{"aliases":["c"],"needsValue":false},"stateless":{"aliases":["s"],"needsValue":false},"runtime":{"aliases":["r"],"needsValue":true}},"usage":"map <name> <path>"}}},{"name":"run","config":{"fs":{"path":"dist/esm/cli-commands/run.js","source":"src/cli-commands/run.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"jsonrpc":false,"cli":{"options":{"output":{"aliases":["o"],"needsValue":true,"doc":"output as `table` if array otherwise falls back to standard node output"},"verbose":{"aliases":["v"]},"tls":{"doc":"enables tls connection to the `pmSock`"},"pmSock":{"aliases":["pm-sock"],"needsValue":true,"doc":"path to the unix socket or destination in the form host:port"},"help":{"doc":"displays this help message"},"keepAttached":{"aliases":["keep-attached"],"needsValue":false,"doc":"keeps the process attached to the current terminal"},"wait":{"aliases":["w"],"needsValue":false,"doc":"waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"},"inspect":{"needsValue":false,"doc":"starts the process with --inspect-brk parameter to help debugging"},"new":{"needsValue":false},"name":{"doc":"name to assign to the process","needsValue":true},"program":{"doc":"program to start"}},"inject":["options.program","options.name","context","options.pmSock"],"usage":"run <name> [...args]"}}},{"name":"uninstall","config":{"fs":{"path":"dist/esm/cli-commands/uninstall.js","source":"src/cli-commands/uninstall.ts","inject":["param.0","$container"]},"":{"inject":["param.0","$container"]},"cli":{"inject":["param.0","$container"]}}},{"name":"update","config":{"fs":{"path":"dist/esm/cli-commands/update.js","source":"src/cli-commands/update.ts","inject":["param.0","param.1","param.2"]},"cli":{"inject":["param.0","param.1","$container"]},"":{"inject":["param.0","param.1","param.2"]}}},{"name":"version","config":{"fs":{"path":"dist/esm/cli-commands/version.js","source":"src/cli-commands/version.ts","inject":["param.0","param.1"]},"":{"inject":["param.0","param.1"]},"cli":{"inject":["options.packageName","options.folder"],"usage":"version <packageName> [folder]"},"schema":{"inject":["param.0","param.1"],"$defs":{"param.0":{"type":"string"},"param.1":{"type":"string"}}}}}],"extends":["./cli-commands.json"],"$schema":"https://raw.githubusercontent.com/npenin/akala/main/packages/commands/container-schema.json"} as Metadata.Container;
56
56
 
57
57
  export function connect(processor?:ICommandProcessor) {
58
58
  const container = new Container<void>("commands", void 0);
@@ -20,6 +20,8 @@ export type ChildProcessRuntimeOptions = { new?: boolean, name: string, keepAtta
20
20
 
21
21
  export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> implements RuntimeInstance<ChildProcessRuntimeEventMap>
22
22
  {
23
+ public readonly runtime = Runtime;
24
+ public static readonly name = 'nodejs';
23
25
  private readonly cp: ChildProcess;
24
26
  public readonly adapter: IpcAdapter;
25
27
  constructor(args: string[], options: ChildProcessRuntimeOptions, signal?: AbortSignal)
@@ -47,16 +49,23 @@ export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> i
47
49
  this.cp.on('close', (code, signal) => { this.emit('close', code, signal); this.emit('exit') });
48
50
  this.cp.on('message', (message, sendHandle) => this.emit('message', message, sendHandle));
49
51
 
50
- this.cp.on('disconnect', () => { this.emit('disconnect'); });
52
+ this.cp.on('disconnect', () => this.emit('disconnect'));
51
53
  if (options.keepAttached)
52
- this.cp.on('disconnect', () => { this.emit('exit') });
54
+ this.cp.on('disconnect', () => this.emit('exit'));
53
55
 
54
56
  signal?.addEventListener('abort', () =>
55
57
  {
56
- return this.stop(5000);
58
+ switch (signal.reason)
59
+ {
60
+ case 'SIGINT':
61
+ case 'SIGTERM':
62
+ return this.stop(5000, signal.reason);
63
+ default:
64
+ return this.stop(5000);
65
+ }
57
66
  })
58
67
  }
59
- stop(timeoutInMs?: number): Promise<number>
68
+ stop(timeoutInMs?: number, signal?: 'SIGINT' | 'SIGTERM'): Promise<number>
60
69
  {
61
70
  return new Promise((resolve) =>
62
71
  {
@@ -65,8 +74,8 @@ export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> i
65
74
  clearTimeout(timeout);
66
75
  resolve(code);
67
76
  })
68
- this.cp.kill('SIGINT');
69
- const timeout = setTimeout(() => { this.cp.kill() }, timeoutInMs || 5000)
77
+ this.cp.kill(signal);
78
+ const timeout = setTimeout(() => { this.cp.kill('SIGKILL') }, timeoutInMs || 5000)
70
79
  })
71
80
  }
72
81
 
@@ -5,6 +5,8 @@ import { EventEmitter } from "@akala/core";
5
5
 
6
6
  export default class Runtime extends EventEmitter<RuntimeEventMap> implements RuntimeInstance
7
7
  {
8
+ public static readonly name = 'self'
9
+ public readonly runtime = Runtime;
8
10
  public readonly adapter: IpcAdapter;
9
11
  private stdio: { stderr: Readable, stdout: Readable, stdin: Writable }
10
12
  constructor(stdio?: { stderr: Readable, stdout: Readable, stdin: Writable })
@@ -16,16 +18,7 @@ export default class Runtime extends EventEmitter<RuntimeEventMap> implements Ru
16
18
  }
17
19
  stop(timeoutInMs?: number): Promise<number>
18
20
  {
19
- return new Promise((resolve) =>
20
- {
21
- process.on('exit', (code, signal) =>
22
- {
23
- clearTimeout(timeout);
24
- resolve(code);
25
- })
26
- process.kill(process.pid, 'SIGINT')
27
- const timeout = setTimeout(() => { process.exit() }, timeoutInMs || 5000)
28
- })
21
+ return Promise.resolve(0);
29
22
  }
30
23
  get stderr(): Readable { return this.stdio.stderr }
31
24
  get stdout(): Readable { return this.stdio.stdout }
@@ -4,6 +4,7 @@ import { Readable } from "stream";
4
4
 
5
5
  export interface Runtime
6
6
  {
7
+ name: string;
7
8
  build(args: string[], options: { new?: boolean, name: string, keepAttached?: boolean, inspect?: boolean, verbose?: boolean, wait?: boolean }): RuntimeInstance;
8
9
  }
9
10
 
@@ -14,6 +15,7 @@ export type RuntimeEventMap = {
14
15
 
15
16
  export interface RuntimeInstance<T extends RuntimeEventMap = RuntimeEventMap> extends EventEmitter<T>
16
17
  {
18
+ runtime: Omit<Runtime, 'build'>;
17
19
  stop(): Promise<number>;
18
20
  get adapter(): SocketAdapter;
19
21
 
@@ -9,6 +9,7 @@ const require = module.createRequire(import.meta.url);
9
9
 
10
10
  export default class Runtime extends EventEmitter<RuntimeEventMap> implements RuntimeInstance
11
11
  {
12
+ public readonly runtime = Runtime;
12
13
  private readonly cp: Worker;
13
14
  public readonly adapter: MessagePortAdapter;
14
15
  private _running: boolean;
package/src/state.ts CHANGED
@@ -26,7 +26,7 @@ export interface SidecarMetadata
26
26
  stateless: boolean;
27
27
  dependencies?: string[];
28
28
  commandable: boolean;
29
- type?: 'nodejs' | 'worker';
29
+ type: 'nodejs' | 'worker';
30
30
  }
31
31
 
32
32
  export interface SidecarConfiguration<T extends string | SerializableObject = SerializableObject>
@@ -40,7 +40,7 @@ export interface SidecarConfiguration<T extends string | SerializableObject = Se
40
40
  }
41
41
 
42
42
  //eslint-disable-next-line @typescript-eslint/no-explicit-any
43
- export interface RunningContainer<T extends string | SerializableObject = any> extends Container<unknown>, SidecarConfiguration<T>, SidecarMetadata
43
+ export interface RunningContainer<T extends string | SerializableObject = any> extends Container<unknown>, SidecarConfiguration<T>, Omit<SidecarMetadata, 'type'>
44
44
  {
45
45
  process: RuntimeInstance;
46
46
  running?: boolean;