@akala/pm 15.0.1 → 15.2.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.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "pm": "dist/esm/cli.js",
5
5
  "pm-fork": "dist/esm/fork.js"
6
6
  },
7
- "version": "15.0.1",
7
+ "version": "15.2.0",
8
8
  "scripts": {
9
9
  "test": "echo 1",
10
10
  "generate": "ac generate dist/esm/commands commands.json --name pm && ac generate dist/esm/cli-commands cli-commands.json --name pm",
package/src/akala.mts CHANGED
@@ -116,7 +116,9 @@ export default async function (_config, program: NamespaceMiddleware<{ configFil
116
116
  {
117
117
  remotePm.processor.useMiddleware(20, result.processor);
118
118
 
119
- registerCommands(metaContainer.commands.filter(c => !['run', 'connect', Cli.Metadata.name].includes(c.name)), null, remotePm);
119
+ const remoteMeta = await result.getMetadata();
120
+
121
+ registerCommands(remoteMeta.commands.filter(c => !['run', 'connect', Cli.Metadata.name].includes(c.name)), null, remotePm);
120
122
  remotePm.unregister(Cli.Metadata.name);
121
123
  remotePm.register(Metadata.extractCommandMetadata(Cli.Metadata));
122
124
 
@@ -50,9 +50,6 @@
50
50
  "inspect": {
51
51
  "needsValue": false,
52
52
  "doc": "starts the process with --inspect-brk parameter to help debugging"
53
- },
54
- "program": {
55
- "doc": "program to start"
56
53
  }
57
54
  },
58
55
  "inject": [
@@ -38,7 +38,7 @@ namespace cliCommands
38
38
  '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>
39
39
  '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>
40
40
  }
41
- export const meta={"name":"pm","commands":[{"name":"$init","config":{"fs":{"path":"dist/esm/cli-commands/$init.js","source":"src/cli-commands/$init.ts","inject":["param.0"]},"cli":{"inject":["context"],"options":{"pmSock":{"aliases":["pm-sock"],"needsValue":true}}},"":{"inject":["param.0"]}}},{"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":"start","config":{"fs":{"path":"dist/esm/cli-commands/start.js","source":"src/cli-commands/start.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"},"program":{"doc":"program to start"}},"inject":["options.program","context"],"usage":"start pm"}}},{"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"}}}}}],"$schema":"https://raw.githubusercontent.com/npenin/akala/main/packages/commands/container-schema.json"} as Metadata.Container;
41
+ export const meta={"name":"pm","commands":[{"name":"$init","config":{"fs":{"path":"dist/esm/cli-commands/$init.js","source":"src/cli-commands/$init.ts","inject":["param.0"]},"cli":{"inject":["context"],"options":{"pmSock":{"aliases":["pm-sock"],"needsValue":true}}},"":{"inject":["param.0"]}}},{"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":"start","config":{"fs":{"path":"dist/esm/cli-commands/start.js","source":"src/cli-commands/start.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"}},"inject":["options.program","context"],"usage":"start pm"}}},{"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"}}}}}],"$schema":"https://raw.githubusercontent.com/npenin/akala/main/packages/commands/container-schema.json"} as Metadata.Container;
42
42
 
43
43
  export function connect(processor?:ICommandProcessor) {
44
44
  const container = new Container<void>("cliCommands", void 0);
@@ -138,15 +138,6 @@ export default async function start(this: State, pm: pmContainer.container & Con
138
138
  container.running = true;
139
139
  let buffer = [];
140
140
 
141
- cp.on('exit', function ()
142
- {
143
- container.running = false;
144
- if (!container.stateless)
145
- {
146
- pm.unregister(container.name);
147
- console.log(new Error('program stopped: ' + buffer?.join('')));
148
- }
149
- });
150
141
  if (options.wait && container.commandable)
151
142
  {
152
143
  //eslint-disable-next-line no-inner-declarations
@@ -155,12 +146,27 @@ export default async function start(this: State, pm: pmContainer.container & Con
155
146
  buffer.push(chunk);
156
147
  }
157
148
  cp.stderr.on('data', gather);
158
- cp.on('exit', () =>
149
+ cp.on('exit', (code) =>
159
150
  {
160
- buffer = null;
161
151
  cp.stderr.off('data', gather);
162
- });
152
+
153
+ if (code && buffer?.length > 0)
154
+ console.error(buffer.join(''));
155
+ buffer = null;
156
+ })
163
157
  }
158
+
159
+ cp.on('exit', function ()
160
+ {
161
+ container.running = false;
162
+ if (!container.stateless)
163
+ {
164
+ pm.unregister(container.name);
165
+ if (buffer?.length > 0)
166
+ console.log(new Error('program stopped: ' + buffer?.join('')));
167
+ }
168
+ });
169
+
164
170
  if (options.wait)
165
171
  await new Promise<void>(resolve => container.ready?.addListener(resolve));
166
172
  return { execPath: process.execPath, args: args, cwd: process.cwd(), shell: false, windowsHide: true };
@@ -24,6 +24,8 @@ export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> i
24
24
  public static readonly name = 'nodejs';
25
25
  private readonly cp: ChildProcess;
26
26
  public readonly adapter: IpcAdapter;
27
+ private readonly stderrPrefixer: NewLinePrefixer;
28
+ private readonly stdoutPrefixer: NewLinePrefixer;
27
29
  constructor(args: string[], options: ChildProcessRuntimeOptions, signal?: AbortSignal)
28
30
  {
29
31
  super();
@@ -33,25 +35,25 @@ export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> i
33
35
  this.cp = spawn(process.execPath, args, { cwd: process.cwd(), detached: !options.keepAttached, env: Object.assign({ DEBUG_COLORS: process.stdout.isTTY }, process.env), stdio: ['ignore', options.inheritStdio ? 'inherit' : 'pipe', options.inheritStdio ? 'inherit' : 'pipe', 'ipc'], shell: false, windowsHide: true });
34
36
  if (options.keepAttached && !options.inheritStdio)
35
37
  {
36
- const stderrPrefixer = this.cp.stderr?.pipe(new NewLinePrefixer(options.name + ' ', { useColors: process.stderr.isTTY }), { end: true });
37
- stderrPrefixer.pipe(process.stderr);
38
- const stdoutPrefixer = this.cp.stdout?.pipe(new NewLinePrefixer(options.name + ' ', { useColors: process.stdout.isTTY }), { end: true });
39
- stdoutPrefixer.pipe(process.stdout);
38
+ this.stderrPrefixer = this.cp.stderr?.pipe(new NewLinePrefixer(options.name + ' ', { useColors: process.stderr.isTTY }), { end: true });
39
+ this.stderrPrefixer.pipe(process.stderr);
40
+ this.stdoutPrefixer = this.cp.stdout?.pipe(new NewLinePrefixer(options.name + ' ', { useColors: process.stdout.isTTY }), { end: true });
41
+ this.stdoutPrefixer.pipe(process.stdout);
40
42
  this.on('disconnect', () =>
41
43
  {
42
44
  this.cp.stderr?.unpipe();
43
45
  this.cp.stdout?.unpipe();
44
- stderrPrefixer?.unpipe();
45
- stdoutPrefixer?.unpipe();
46
+ this.stderrPrefixer?.unpipe();
47
+ this.stdoutPrefixer?.unpipe();
46
48
  });
47
49
  }
48
50
  this.adapter = new IpcAdapter(this.cp);
49
- this.cp.on('close', (code, signal) => { this.emit('close', code, signal); this.emit('exit') });
51
+ this.cp.on('exit', (code, signal) => { this.emit('exit', code, signal) });
50
52
  this.cp.on('message', (message, sendHandle) => this.emit('message', message, sendHandle));
51
53
 
52
54
  this.cp.on('disconnect', () => this.emit('disconnect'));
53
55
  if (options.keepAttached)
54
- this.cp.on('disconnect', () => this.emit('exit'));
56
+ this.cp.on('disconnect', () => this.emit('exit', this.cp.exitCode, this.cp.signalCode));
55
57
 
56
58
  signal?.addEventListener('abort', () =>
57
59
  {
@@ -65,7 +67,7 @@ export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> i
65
67
  }
66
68
  })
67
69
  }
68
- stop(timeoutInMs?: number, signal?: 'SIGINT' | 'SIGTERM'): Promise<number>
70
+ stop(timeoutInMs?: number, signal?: 'SIGINT' | 'SIGTERM' | 'SIGKILL'): Promise<number>
69
71
  {
70
72
  return new Promise((resolve) =>
71
73
  {
@@ -75,7 +77,12 @@ export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> i
75
77
  resolve(code);
76
78
  })
77
79
  this.cp.kill(signal);
78
- const timeout = setTimeout(() => { this.cp.kill('SIGKILL') }, timeoutInMs || 5000)
80
+ if (signal == 'SIGTERM')
81
+ {
82
+ this.stderrPrefixer?.unpipe();
83
+ this.stdoutPrefixer?.unpipe();
84
+ }
85
+ const timeout = setTimeout(() => { this.stop(timeoutInMs, signal == 'SIGINT' ? 'SIGTERM' : 'SIGKILL') }, timeoutInMs || 5000)
79
86
  })
80
87
  }
81
88
 
@@ -10,7 +10,7 @@ export interface Runtime
10
10
 
11
11
  export type RuntimeEventMap = {
12
12
  runningChanged: IEvent<[], void>;
13
- exit: IEvent<[], void>;
13
+ exit: IEvent<[number, NodeJS.Signals], void>;
14
14
  }
15
15
 
16
16
  export interface RuntimeInstance<T extends RuntimeEventMap = RuntimeEventMap> extends EventEmitter<T>