@akala/pm 14.5.0 → 14.5.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/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": "14.5.0",
7
+ "version": "14.5.1",
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",
@@ -29,9 +29,9 @@
29
29
  "src/fork.ts"
30
30
  ],
31
31
  "dependencies": {
32
- "@akala/cli": "^5.5.32",
33
- "@akala/commands": "^13.0.3",
34
- "@akala/config": "^6.0.57",
32
+ "@akala/cli": "^5.6.0",
33
+ "@akala/commands": "^13.0.4",
34
+ "@akala/config": "^6.0.58",
35
35
  "@akala/core": "^39.0.0",
36
36
  "@akala/json-rpc-ws": "^11.0.75",
37
37
  "reflect-metadata": "^0.2.2",
package/src/akala.mts CHANGED
@@ -81,29 +81,30 @@ export default async function (_config, program: NamespaceMiddleware<{ configFil
81
81
  if (connectMapping)
82
82
  if (connectMapping instanceof Configuration)
83
83
  connectMapping = connectMapping.extract();
84
- await eachAsync(connectMapping, async (config, connectionString) =>
85
- {
86
- if (container)
87
- return;
88
- try
89
- {
90
- log.verbose('trying to connect to ' + connectionString);
91
- const url = new URL(connectionString);
92
- if (url.hostname == '0.0.0.0')
93
- url.hostname = 'localhost';
94
- container = await connect(url, c.abort.signal, metaContainer);
95
- }
96
- catch (e)
84
+ if (connectMapping)
85
+ await eachAsync(connectMapping, async (config, connectionString) =>
97
86
  {
98
- log.silly('failed to connect to ' + connectionString);
99
- log.silly(e)
100
- if (e.code == 'ENOENT' || e.code == 'ECONNREFUSED')
87
+ if (container)
101
88
  return;
102
- log.error(e);
103
- throw e;
104
- }
89
+ try
90
+ {
91
+ log.verbose('trying to connect to ' + connectionString);
92
+ const url = new URL(connectionString);
93
+ if (url.hostname == '0.0.0.0')
94
+ url.hostname = 'localhost';
95
+ container = await connect(url, c.abort.signal, metaContainer);
96
+ }
97
+ catch (e)
98
+ {
99
+ log.silly('failed to connect to ' + connectionString);
100
+ log.silly(e)
101
+ if (e.code == 'ENOENT' || e.code == 'ECONNREFUSED')
102
+ return;
103
+ log.error(e);
104
+ throw e;
105
+ }
105
106
 
106
- })
107
+ })
107
108
  }
108
109
  if (container)
109
110
  {
@@ -10,7 +10,7 @@ export default async function start(this: State, name: string, context?: CliCont
10
10
  configFile: context.options.configFile + '#pm',
11
11
  name: 'pm',
12
12
  program: new URL('../../../commands.json', import.meta.url).toString(),
13
- inspect: undefined, keepAttached: undefined, new: undefined, wait: undefined
13
+ inspect: undefined, new: undefined, wait: undefined
14
14
  })];
15
15
 
16
16
  const cp = ChildProcess.build(args, { ...context.options, inheritStdio: context.options.keepAttached }, context.abort.signal);
@@ -21,8 +21,8 @@ export default async function start(this: State, name: string, context?: CliCont
21
21
  cp.on('message', function (message)
22
22
  {
23
23
  console.log(message);
24
- // cp.disconnect();
25
24
  });
25
+
26
26
  return new Promise<void>((resolve) =>
27
27
  {
28
28
  cp.on('disconnect', function ()
@@ -23,8 +23,19 @@
23
23
  ]
24
24
  },
25
25
  "keepAttached": {
26
- "needsValue": true
26
+ "aliases": [
27
+ "keep-attached"
28
+ ],
29
+ "needsValue": false,
30
+ "doc": "keeps the process attached to the current terminal"
31
+ },
32
+ "wait": {
33
+ "aliases": [
34
+ "w"
35
+ ],
36
+ "needsValue": false,
37
+ "doc": "waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"
27
38
  }
28
39
  }
29
40
  }
30
- }
41
+ }
@@ -150,8 +150,13 @@ export default async function (this: State, container: RunningContainer & pmCont
150
150
  if (!context.options.keepAttached)
151
151
  {
152
152
  if (process.send)
153
- process.send('disconnecting daemon');
153
+ await new Promise<void>((resolve, reject) => process.send('disconnecting daemon', err => err ? reject(err) : resolve()));
154
154
  process.disconnect();
155
155
  }
156
156
  }
157
+
158
+ context.abort.signal.addEventListener('abort', async () =>
159
+ {
160
+ await container.dispatch('stop', { param: ['pm'] });
161
+ });
157
162
  }
package/src/fork.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import sms from 'source-map-support'
3
3
  sms.install();
4
- import * as path from 'path'
4
+ import path from 'path'
5
5
  import { lstat } from 'fs/promises';
6
6
  import pmDef from './container.js';
7
7
  import { IpcAdapter } from "./ipc-adapter.js";
@@ -23,14 +23,15 @@ let log: Logger;
23
23
  const logMiddleware = new NamespaceMiddleware<{ program: string, name: string, tls: boolean }>(null).option<string>()('verbose', { aliases: ['v',] });
24
24
  logMiddleware.preAction(async c =>
25
25
  {
26
+ const fs: Processors.FileSystem = new Processors.FileSystem(path.dirname(c.options.program));
26
27
  if (c.options.verbose)
27
- processor = new Processors.LogProcessor((_c, cmd, params) =>
28
+ processor = new Processors.LogEventProcessor(fs, c.abort.signal, (_c, cmd, params) =>
28
29
  {
29
30
  log.verbose({ cmd, params });
30
- return undefined;
31
31
  });
32
32
 
33
- await Processors.FileSystem.discoverCommands(c.options.program, cliContainer, { processor: processor, isDirectory: folderOrFile.isDirectory() });
33
+ const options: Processors.DiscoveryOptions = { processor: processor, isDirectory: folderOrFile.isDirectory() };
34
+ await Processors.FileSystem.discoverCommands(c.options.program, cliContainer, options);
34
35
  });
35
36
  let initMiddleware = new NamespaceMiddleware<{ program: string, name: string, tls: boolean }>(null);
36
37
  const controller = new AbortController();
@@ -36,9 +36,11 @@ export default class Runtime extends EventEmitter<ChildProcessRuntimeEventMap> i
36
36
  }
37
37
  this.adapter = new IpcAdapter(this.cp);
38
38
  this.cp.on('close', (code, signal) => { this.emit('close', code, signal); this.emit('exit') });
39
+ this.cp.on('message', (message, sendHandle) => this.emit('message', message, sendHandle));
39
40
 
41
+ this.cp.on('disconnect', () => { this.emit('disconnect'); });
40
42
  if (options.keepAttached)
41
- this.cp.on('disconnect', () => { this.emit('disconnect'); this.emit('exit') });
43
+ this.cp.on('disconnect', () => { this.emit('exit') });
42
44
 
43
45
  signal?.addEventListener('abort', () =>
44
46
  {