@akala/pm 5.2.17 → 5.2.19

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/src/cli.ts CHANGED
@@ -1,15 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  import * as path from 'path'
3
- import { Processors, NetSocketAdapter, Metadata, Container, ICommandProcessor, proxy, Triggers, Cli } from '@akala/commands';
3
+ import { Processors, NetSocketAdapter, Metadata, Container, proxy, Triggers, Cli } from '@akala/commands';
4
4
  import { Socket } from 'net';
5
5
  import { TLSSocket } from 'tls';
6
6
  import { platform, homedir } from 'os';
7
7
  import start from './commands/start.js'
8
8
  import { Readable } from 'stream';
9
9
 
10
- import { spawnAsync } from './cli-helper.js';
11
- import State, { StateConfiguration } from './state.js';
12
- import program, { buildCliContextFromProcess, CliContext, ErrorMessage, NamespaceMiddleware, unparse } from '@akala/cli';
10
+ import State from './state.js';
11
+ import program, { buildCliContextFromProcess, ErrorMessage } from '@akala/cli';
13
12
  import { InteractError } from './index.js';
14
13
  import { Binding } from '@akala/core';
15
14
 
@@ -35,14 +34,14 @@ const truncate = '…';
35
34
  type CliOptions = { output: string, verbose: boolean, pmSock: string | number, tls: boolean, help: boolean };
36
35
 
37
36
  const cli = program.options<CliOptions>({ 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" } });
38
- const startpm = cli.command('start pm')
37
+ cli.command('start pm')
39
38
  .option('inspect', { doc: "starts the process with --inspect-brk parameter to help debugging" })
40
39
  .option('keepAttached', { doc: "keeps the process attached" })
41
40
  .action(c =>
42
41
  {
43
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
42
  c.options['name'] = 'pm'
45
43
  c.options['program'] = require.resolve('../commands.json');
44
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
46
45
  return start.call({} as unknown as State, null, 'pm', c as any);
47
46
  });
48
47
 
@@ -50,7 +49,7 @@ let socket: Socket;
50
49
  let processor: Processors.JsonRpc;
51
50
  let metaContainer: Metadata.Container;
52
51
  let container: Container<unknown>;
53
- const handle = new NamespaceMiddleware(null);
52
+
54
53
  cli.preAction(async c =>
55
54
  {
56
55
  process.stdin.pause();
@@ -104,6 +103,7 @@ cli.preAction(async c =>
104
103
  if (c.options.tls)
105
104
  {
106
105
  // socket.on('data', function (e) { console.log(e) });
106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
107
  socket.connect({} as any);
108
108
  netsocket.on('error', function (e)
109
109
  {
@@ -412,93 +412,6 @@ function formatResult(result: unknown, outputFormat: string)
412
412
  }
413
413
  }
414
414
 
415
- function prepareParam(cmd: Metadata.Command, args: CliContext, standalone?: boolean)
416
- {
417
- if (!cmd)
418
- return false;
419
-
420
- if (!cmd.config || !cmd.config.cli || (standalone && !cmd.config.cli.standalone))
421
- return false;
422
-
423
- delete args.options.pmSock;
424
- return {
425
- options: args.options, param: args.args.slice(1), _trigger: 'cli', cwd: args.currentWorkingDirectory, context: args, get stdin()
426
- {
427
- return new Promise<string>((resolve) =>
428
- {
429
- const buffers = [];
430
- process.stdin.on('data', data => buffers.push(data));
431
- process.stdin.on('end', () => resolve(Buffer.concat(buffers).toString('utf8')));
432
- })
433
- }
434
- };
435
- }
436
-
437
- async function tryRun(processor: ICommandProcessor, cmd: Metadata.Command, args: CliContext, localProcessing: boolean)
438
- {
439
- const params = prepareParam(cmd, args, localProcessing);
440
- if (!params)
441
- throw new Error('Either command does not exist or it is not standalone');
442
-
443
- try
444
- {
445
- const result = await processor.handle(null, cmd, params).then(err => { throw err }, res => res);
446
- if (result instanceof Readable)
447
- result.pipe(process.stdout);
448
- else
449
- formatResult(result, args.options.output as string);
450
- }
451
-
452
- catch (e)
453
- {
454
- if (e.code == 'INTERACT')
455
- {
456
- console.log(e.message);
457
- let value = await readLine();
458
- value = value.trim();
459
- if (e.as)
460
- args.options[e] = value;
461
- else
462
- args.args.push(value);
463
- args.args.unshift(cmd.name);
464
- return await tryRun(processor, cmd, args, localProcessing);
465
- }
466
- if (args.options.verbose)
467
- console.log(e);
468
- else
469
- console.log(e.message);
470
- }
471
-
472
- }
473
-
474
- async function tryLocalProcessing(args: CliContext)
475
- {
476
- // eslint-disable-next-line @typescript-eslint/no-var-requires
477
- const config: StateConfiguration = require(path.join(homedir(), './.pm.config.json'));
478
- let cmdName = args.args.shift();
479
- if (!cmdName)
480
- throw undefined;
481
- const indexOfDot = cmdName.indexOf('.');
482
- if (indexOfDot > -1)
483
- {
484
- const containerName = cmdName.substring(0, indexOfDot);
485
- if (config.containers[containerName] && config.containers[containerName].commandable)
486
- {
487
- cmdName = cmdName.substring(indexOfDot + 1);
488
- const container = new Container('cli-temp', {});
489
- const options: Processors.DiscoveryOptions = {};
490
- await Processors.FileSystem.discoverCommands(config.containers[containerName].path, container, options);
491
- const cmd = container.resolve(cmdName);
492
- return tryRun(options.processor, cmd, args, true);
493
- }
494
- }
495
- else
496
- {
497
- if (!config.containers[cmdName].commandable)
498
- return spawnAsync(config.containers[cmdName].path, null, ...unparse(args));
499
- }
500
- }
501
-
502
415
  let stdinBuffer = '';
503
416
  function readLine()
504
417
  {
@@ -8,7 +8,6 @@ import { PassThrough } from 'stream';
8
8
  import { EventEmitter } from 'events';
9
9
  import { CliContext } from '@akala/cli';
10
10
  import Configuration from '@akala/config';
11
- import { each, grep } from '@akala/core';
12
11
 
13
12
  export async function metadata(container: Container<unknown>, deep?: boolean): Promise<Metadata.Container>
14
13
  {
@@ -160,6 +160,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
160
160
 
161
161
  container.running = true;
162
162
  let buffer = [];
163
+
163
164
  cp.on('exit', function ()
164
165
  {
165
166
  (container as RunningContainer).running = false;
@@ -171,6 +172,7 @@ export default async function start(this: State, pm: pmContainer.container & Con
171
172
  });
172
173
  if (context.options.wait && container.commandable)
173
174
  {
175
+ //eslint-disable-next-line no-inner-declarations
174
176
  function gather(chunk: string)
175
177
  {
176
178
  buffer.push(chunk);
package/src/container.ts CHANGED
@@ -1,34 +1,37 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { Arguments, Argument0, Argument1, Argument2, Argument3, Argument4, Argument5, Argument6, Argument7, Argument8, Argument9, Argument10, Argument11, Argument12, Argument13, Argument14, Argument15, Argument16, Argument17 } from '@akala/core';
1
+ //eslint-disable-next-line @typescript-eslint/no-unused-vars
2
+ import {Arguments, Argument0, Argument1, Argument2, Argument3, Argument4, Argument5, Argument6, Argument7, Argument8, Argument9, Argument10, Argument11, Argument12, Argument13, Argument14, Argument15, Argument16, Argument17 } from '@akala/core';
3
3
  // eslint-disable-next-line @typescript-eslint/no-namespace
4
4
  namespace commands
5
5
  {
6
6
  export interface container
7
7
  {
8
- dispatch(cmd: '$init', ...args: [Argument1<typeof import('./commands/$init.js').default>]): ReturnType<typeof import('./commands/$init.js').default>
9
- dispatch(cmd: 'bridge', ...args: [Argument0<typeof import('./commands/bridge.js').default>, Argument1<typeof import('./commands/bridge.js').default>]): ReturnType<typeof import('./commands/bridge.js').default>
10
- dispatch(cmd: 'config', ...args: [Argument0<typeof import('./commands/config.js').default>, Argument1<typeof import('./commands/config.js').default>]): ReturnType<typeof import('./commands/config.js').default>
11
- dispatch(cmd: 'connect', ...args: [Argument0<typeof import('./commands/connect.js').default>, Argument1<typeof import('./commands/connect.js').default>]): ReturnType<typeof import('./commands/connect.js').default>
12
- dispatch(cmd: 'discover', ...args: [Argument0<typeof import('./commands/discover.js').default>, Argument1<typeof import('./commands/discover.js').default>]): ReturnType<typeof import('./commands/discover.js').default>
13
- dispatch(cmd: 'install', ...args: [Argument0<typeof import('./commands/install.js').default>]): ReturnType<typeof import('./commands/install.js').default>
14
- dispatch(cmd: 'link', ...args: [Argument0<typeof import('./commands/link.js').default>, Argument1<typeof import('./commands/link.js').default>]): ReturnType<typeof import('./commands/link.js').default>
15
- dispatch(cmd: 'log', ...args: [Argument0<typeof import('./commands/log.js').default>]): ReturnType<typeof import('./commands/log.js').default>
16
- dispatch(cmd: 'ls', ...args: []): ReturnType<typeof import('./commands/ls.js').default>
17
- dispatch(cmd: 'map', ...args: [Argument0<typeof import('./commands/map.js').default>, Argument1<typeof import('./commands/map.js').default>, Argument2<typeof import('./commands/map.js').default>, Argument3<typeof import('./commands/map.js').default>]): ReturnType<typeof import('./commands/map.js').default>
18
- dispatch(cmd: 'name', ...args: [Argument0<typeof import('./commands/name.js').default>]): ReturnType<typeof import('./commands/name.js').default>
19
- dispatch(cmd: 'proxy', ...args: [Argument0<typeof import('./commands/proxy.js').default>, Argument1<typeof import('./commands/proxy.js').default>]): ReturnType<typeof import('./commands/proxy.js').default>
20
- dispatch(cmd: 'ready', ...args: []): ReturnType<typeof import('./commands/ready.js').default>
21
- dispatch(cmd: 'reload-metadata', ...args: [Argument0<typeof import('./commands/reload-metadata.js').default>]): ReturnType<typeof import('./commands/reload-metadata.js').default>
22
- dispatch(cmd: 'restart', ...args: [Argument1<typeof import('./commands/restart.js').default>, Argument2<typeof import('./commands/restart.js').default>]): ReturnType<typeof import('./commands/restart.js').default>
23
- dispatch(cmd: 'start', ...args: [Argument1<typeof import('./commands/start.js').default>, Argument2<typeof import('./commands/start.js').default>]): ReturnType<typeof import('./commands/start.js').default>
24
- dispatch(cmd: 'status', ...args: [Argument0<typeof import('./commands/status.js').default>]): ReturnType<typeof import('./commands/status.js').default>
25
- dispatch(cmd: 'stop', ...args: [Argument0<typeof import('./commands/stop.js').default>]): ReturnType<typeof import('./commands/stop.js').default>
26
- dispatch(cmd: 'update', ...args: [Argument0<typeof import('./commands/update.js').default>, Argument1<typeof import('./commands/update.js').default>]): ReturnType<typeof import('./commands/update.js').default>
27
- dispatch(cmd: 'version', ...args: [Argument0<typeof import('./commands/version.js').default>, Argument1<typeof import('./commands/version.js').default>]): ReturnType<typeof import('./commands/version.js').default>
8
+ dispatch (cmd:'$init', ...args: [Argument1<typeof import('./commands/$init.js').default>]): ReturnType<typeof import('./commands/$init.js').default>
9
+ dispatch (cmd:'add', ...args: [Argument0<typeof import('./commands/plugin/add.js').default>]): ReturnType<typeof import('./commands/plugin/add.js').default>
10
+ dispatch (cmd:'bridge', ...args: [Argument0<typeof import('./commands/bridge.js').default>, Argument1<typeof import('./commands/bridge.js').default>]): ReturnType<typeof import('./commands/bridge.js').default>
11
+ dispatch (cmd:'config', ...args: [Argument0<typeof import('./commands/config.js').default>, Argument1<typeof import('./commands/config.js').default>]): ReturnType<typeof import('./commands/config.js').default>
12
+ dispatch (cmd:'connect', ...args: [Argument0<typeof import('./commands/connect.js').default>, Argument1<typeof import('./commands/connect.js').default>]): ReturnType<typeof import('./commands/connect.js').default>
13
+ dispatch (cmd:'discover', ...args: [Argument0<typeof import('./commands/discover.js').default>, Argument1<typeof import('./commands/discover.js').default>]): ReturnType<typeof import('./commands/discover.js').default>
14
+ dispatch (cmd:'install', ...args: [Argument0<typeof import('./commands/install.js').default>]): ReturnType<typeof import('./commands/install.js').default>
15
+ dispatch (cmd:'link', ...args: [Argument0<typeof import('./commands/link.js').default>, Argument1<typeof import('./commands/link.js').default>]): ReturnType<typeof import('./commands/link.js').default>
16
+ dispatch (cmd:'log', ...args: [Argument0<typeof import('./commands/log.js').default>]): ReturnType<typeof import('./commands/log.js').default>
17
+ dispatch (cmd:'ls', ...args: []): ReturnType<typeof import('./commands/ls.js').default>
18
+ dispatch (cmd:'map', ...args: [Argument0<typeof import('./commands/map.js').default>, Argument1<typeof import('./commands/map.js').default>, Argument2<typeof import('./commands/map.js').default>, Argument3<typeof import('./commands/map.js').default>]): ReturnType<typeof import('./commands/map.js').default>
19
+ dispatch (cmd:'name', ...args: [Argument0<typeof import('./commands/name.js').default>]): ReturnType<typeof import('./commands/name.js').default>
20
+ dispatch (cmd:'proxy', ...args: [Argument0<typeof import('./commands/proxy.js').default>, Argument1<typeof import('./commands/proxy.js').default>]): ReturnType<typeof import('./commands/proxy.js').default>
21
+ dispatch (cmd:'ready', ...args: []): ReturnType<typeof import('./commands/ready.js').default>
22
+ dispatch (cmd:'reload-metadata', ...args: [Argument0<typeof import('./commands/reload-metadata.js').default>]): ReturnType<typeof import('./commands/reload-metadata.js').default>
23
+ dispatch (cmd:'remove', ...args: [Argument0<typeof import('./commands/plugin/remove.js').default>]): ReturnType<typeof import('./commands/plugin/remove.js').default>
24
+ dispatch (cmd:'restart', ...args: [Argument1<typeof import('./commands/restart.js').default>, Argument2<typeof import('./commands/restart.js').default>]): ReturnType<typeof import('./commands/restart.js').default>
25
+ dispatch (cmd:'start', ...args: [Argument1<typeof import('./commands/start.js').default>, Argument2<typeof import('./commands/start.js').default>]): ReturnType<typeof import('./commands/start.js').default>
26
+ dispatch (cmd:'status', ...args: [Argument0<typeof import('./commands/status.js').default>]): ReturnType<typeof import('./commands/status.js').default>
27
+ dispatch (cmd:'stop', ...args: [Argument0<typeof import('./commands/stop.js').default>]): ReturnType<typeof import('./commands/stop.js').default>
28
+ dispatch (cmd:'update', ...args: [Argument0<typeof import('./commands/update.js').default>, Argument1<typeof import('./commands/update.js').default>]): ReturnType<typeof import('./commands/update.js').default>
29
+ dispatch (cmd:'version', ...args: [Argument0<typeof import('./commands/version.js').default>, Argument1<typeof import('./commands/version.js').default>]): ReturnType<typeof import('./commands/version.js').default>
28
30
  }
29
31
  export interface proxy
30
32
  {
31
33
  '$init'(...args: [Argument1<typeof import('./commands/$init.js').default>]): ReturnType<typeof import('./commands/$init.js').default>
34
+ 'add'(...args: [Argument0<typeof import('./commands/plugin/add.js').default>]): ReturnType<typeof import('./commands/plugin/add.js').default>
32
35
  'bridge'(...args: [Argument0<typeof import('./commands/bridge.js').default>, Argument1<typeof import('./commands/bridge.js').default>]): ReturnType<typeof import('./commands/bridge.js').default>
33
36
  'config'(...args: [Argument0<typeof import('./commands/config.js').default>, Argument1<typeof import('./commands/config.js').default>]): ReturnType<typeof import('./commands/config.js').default>
34
37
  'connect'(...args: [Argument0<typeof import('./commands/connect.js').default>, Argument1<typeof import('./commands/connect.js').default>]): ReturnType<typeof import('./commands/connect.js').default>
@@ -42,6 +45,7 @@ namespace commands
42
45
  'proxy'(...args: [Argument0<typeof import('./commands/proxy.js').default>, Argument1<typeof import('./commands/proxy.js').default>]): ReturnType<typeof import('./commands/proxy.js').default>
43
46
  'ready'(...args: []): ReturnType<typeof import('./commands/ready.js').default>
44
47
  'reload-metadata'(...args: [Argument0<typeof import('./commands/reload-metadata.js').default>]): ReturnType<typeof import('./commands/reload-metadata.js').default>
48
+ 'remove'(...args: [Argument0<typeof import('./commands/plugin/remove.js').default>]): ReturnType<typeof import('./commands/plugin/remove.js').default>
45
49
  'restart'(...args: [Argument1<typeof import('./commands/restart.js').default>, Argument2<typeof import('./commands/restart.js').default>]): ReturnType<typeof import('./commands/restart.js').default>
46
50
  'start'(...args: [Argument1<typeof import('./commands/start.js').default>, Argument2<typeof import('./commands/start.js').default>]): ReturnType<typeof import('./commands/start.js').default>
47
51
  'status'(...args: [Argument0<typeof import('./commands/status.js').default>]): ReturnType<typeof import('./commands/status.js').default>
package/src/fork.ts CHANGED
@@ -11,6 +11,10 @@ import program, { buildCliContextFromProcess, ErrorMessage, NamespaceMiddleware
11
11
  import { Stats } from 'fs';
12
12
  import { registerCommands, SelfDefinedCommand, parseMetadata, StructuredParameters } from '@akala/commands';
13
13
 
14
+ import module from 'module'
15
+
16
+ const require = module.createRequire(import.meta.url.substring('file://'.length));
17
+
14
18
  var isPm = false;
15
19
 
16
20
  program.option('help')
@@ -183,8 +187,7 @@ controller.signal.addEventListener('abort', function ()
183
187
  }
184
188
  })
185
189
 
186
- if (require.main == module)
187
- program.process(buildCliContextFromProcess()).catch(e =>
188
- {
189
- setImmediate(() => controller.abort(e));
190
- });
190
+ program.process(buildCliContextFromProcess()).catch(e =>
191
+ {
192
+ setImmediate(() => controller.abort(e));
193
+ });
package/src/standalone.ts CHANGED
@@ -4,7 +4,7 @@ sms.install();
4
4
  import * as path from 'path'
5
5
  import * as ac from '@akala/commands';
6
6
  import { lstat } from 'fs/promises';
7
- import { logger, Logger, MiddlewareComposite, module as coreModule } from '@akala/core';
7
+ import { logger, Logger, MiddlewareComposite } from '@akala/core';
8
8
  import program, { buildCliContextFromProcess, ErrorMessage, NamespaceMiddleware } from '@akala/cli';
9
9
  import { Stats } from 'fs';
10
10