@akala/pm 7.1.5 → 8.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 (102) hide show
  1. package/changelog.md +16 -1
  2. package/dist/cjs/cli-commands/start-self.d.ts +25 -0
  3. package/dist/cjs/cli-commands/start-self.js +62 -0
  4. package/dist/cjs/cli-commands/start-self.js.map +1 -0
  5. package/dist/cjs/cli-helper.js +2 -29
  6. package/dist/cjs/cli-helper.js.map +1 -1
  7. package/dist/cjs/commands/bridge.js +1 -4
  8. package/dist/cjs/commands/bridge.js.map +1 -1
  9. package/dist/cjs/commands/config.js +2 -28
  10. package/dist/cjs/commands/config.js.map +1 -1
  11. package/dist/cjs/commands/connect.js +12 -13
  12. package/dist/cjs/commands/connect.js.map +1 -1
  13. package/dist/cjs/commands/discover.js +17 -20
  14. package/dist/cjs/commands/discover.js.map +1 -1
  15. package/dist/cjs/commands/install.js +6 -35
  16. package/dist/cjs/commands/install.js.map +1 -1
  17. package/dist/cjs/commands/link.js +6 -35
  18. package/dist/cjs/commands/link.js.map +1 -1
  19. package/dist/cjs/commands/log.js +4 -7
  20. package/dist/cjs/commands/log.js.map +1 -1
  21. package/dist/cjs/commands/ls.js +1 -4
  22. package/dist/cjs/commands/ls.js.map +1 -1
  23. package/dist/cjs/commands/map.js +4 -7
  24. package/dist/cjs/commands/map.js.map +1 -1
  25. package/dist/cjs/commands/name.js +1 -4
  26. package/dist/cjs/commands/name.js.map +1 -1
  27. package/dist/cjs/commands/plugin/add.js +1 -4
  28. package/dist/cjs/commands/plugin/add.js.map +1 -1
  29. package/dist/cjs/commands/plugin/remove.js +1 -4
  30. package/dist/cjs/commands/plugin/remove.js.map +1 -1
  31. package/dist/cjs/commands/proxy.js +5 -8
  32. package/dist/cjs/commands/proxy.js.map +1 -1
  33. package/dist/cjs/commands/ready.js +4 -7
  34. package/dist/cjs/commands/ready.js.map +1 -1
  35. package/dist/cjs/commands/reload-metadata.js +3 -6
  36. package/dist/cjs/commands/reload-metadata.js.map +1 -1
  37. package/dist/cjs/commands/restart.js +1 -4
  38. package/dist/cjs/commands/restart.js.map +1 -1
  39. package/dist/cjs/commands/start.js +34 -40
  40. package/dist/cjs/commands/start.js.map +1 -1
  41. package/dist/cjs/commands/status.js +1 -4
  42. package/dist/cjs/commands/status.js.map +1 -1
  43. package/dist/cjs/commands/stop.js +1 -4
  44. package/dist/cjs/commands/stop.js.map +1 -1
  45. package/dist/cjs/commands/update.js +6 -35
  46. package/dist/cjs/commands/update.js.map +1 -1
  47. package/dist/cjs/commands/version.js +4 -7
  48. package/dist/cjs/commands/version.js.map +1 -1
  49. package/dist/cjs/container.js +1 -2
  50. package/dist/cjs/index.js +19 -54
  51. package/dist/cjs/index.js.map +1 -1
  52. package/dist/cjs/ipc-adapter.js +1 -5
  53. package/dist/cjs/ipc-adapter.js.map +1 -1
  54. package/dist/cjs/new-line-prefixer.js +2 -6
  55. package/dist/cjs/new-line-prefixer.js.map +1 -1
  56. package/dist/cjs/npm-helper.js +7 -9
  57. package/dist/cjs/npm-helper.js.map +1 -1
  58. package/dist/cjs/sidecar.js +11 -39
  59. package/dist/cjs/sidecar.js.map +1 -1
  60. package/dist/cjs/standalone.js +16 -44
  61. package/dist/cjs/standalone.js.map +1 -1
  62. package/dist/cjs/state.js +1 -2
  63. package/dist/cjs/test/pwet.js +3 -9
  64. package/dist/cjs/test/pwet.js.map +1 -1
  65. package/dist/cjs/yarn-helper.js +12 -16
  66. package/dist/cjs/yarn-helper.js.map +1 -1
  67. package/dist/esm/akala.mjs.map +1 -1
  68. package/dist/esm/cli-commands/start-self.d.ts +25 -0
  69. package/dist/esm/cli-commands/start-self.js +51 -0
  70. package/dist/esm/cli-commands/start-self.js.map +1 -0
  71. package/dist/esm/cli.js +13 -13
  72. package/dist/esm/cli.js.map +1 -1
  73. package/dist/esm/commands/$init.js +4 -4
  74. package/dist/esm/commands/$init.js.map +1 -1
  75. package/dist/esm/commands/config.js.map +1 -1
  76. package/dist/esm/commands/connect.js +5 -4
  77. package/dist/esm/commands/connect.js.map +1 -1
  78. package/dist/esm/commands/discover.js.map +1 -1
  79. package/dist/esm/commands/install.js.map +1 -1
  80. package/dist/esm/commands/log.js.map +1 -1
  81. package/dist/esm/commands/proxy.js.map +1 -1
  82. package/dist/esm/commands/ready.js.map +1 -1
  83. package/dist/esm/commands/start.js.map +1 -1
  84. package/dist/esm/commands/stop.js.map +1 -1
  85. package/dist/esm/commands/update.js.map +1 -1
  86. package/dist/esm/commands/version.js.map +1 -1
  87. package/dist/esm/fork.js +12 -0
  88. package/dist/esm/fork.js.map +1 -1
  89. package/dist/esm/index.js.map +1 -1
  90. package/dist/esm/ipc-adapter.js.map +1 -1
  91. package/dist/esm/new-line-prefixer.js.map +1 -1
  92. package/dist/esm/sidecar.js.map +1 -1
  93. package/dist/esm/standalone.js.map +1 -1
  94. package/dist/tsconfig.cjs.tsbuildinfo +1 -1
  95. package/dist/tsconfig.esm.tsbuildinfo +1 -1
  96. package/package.json +19 -14
  97. package/src/cli-commands/start-self.json +66 -0
  98. package/src/cli-commands/start-self.ts +74 -0
  99. package/src/cli.ts +15 -15
  100. package/src/commands/$init.ts +6 -2
  101. package/src/commands/connect.ts +5 -4
  102. package/src/fork.ts +14 -0
@@ -0,0 +1,66 @@
1
+ {
2
+ "$schema": "https://raw.githubusercontent.com/npenin/akala/master/packages/commands/command-schema.json",
3
+ "": {
4
+ "inject": [
5
+ "$container",
6
+ "param.0",
7
+ "param.1"
8
+ ]
9
+ },
10
+ "cli": {
11
+ "options": {
12
+ "output": {
13
+ "aliases": [
14
+ "o"
15
+ ],
16
+ "needsValue": true,
17
+ "doc": "output as `table` if array otherwise falls back to standard node output"
18
+ },
19
+ "verbose": {
20
+ "aliases": [
21
+ "v"
22
+ ]
23
+ },
24
+ "tls": {
25
+ "doc": "enables tls connection to the `pmSock`"
26
+ },
27
+ "pmSock": {
28
+ "aliases": [
29
+ "pm-sock"
30
+ ],
31
+ "needsValue": true,
32
+ "doc": "path to the unix socket or destination in the form host:port"
33
+ },
34
+ "help": {
35
+ "doc": "displays this help message"
36
+ },
37
+ "wait": {
38
+ "aliases": [
39
+ "w"
40
+ ],
41
+ "needsValue": false,
42
+ "doc": "waits for the program to be started before returning, otherwise, returns after the start command is sent to the pm daemon"
43
+ },
44
+ "inspect": {
45
+ "needsValue": false,
46
+ "doc": "starts the process with --inspect-brk parameter to help debugging"
47
+ },
48
+ "new": {
49
+ "needsValue": false
50
+ },
51
+ "name": {
52
+ "doc": "name to assign to the process",
53
+ "needsValue": true
54
+ },
55
+ "program": {
56
+ "doc": "program to start"
57
+ }
58
+ },
59
+ "inject": [
60
+ "$container",
61
+ "options.program",
62
+ "context"
63
+ ],
64
+ "usage": "start pm"
65
+ }
66
+ }
@@ -0,0 +1,74 @@
1
+ import { Container, Processors, Metadata, Cli, updateCommands } from "@akala/commands";
2
+ import State, { RunningContainer, SidecarMetadata } from '../state.js';
3
+ import { spawn, ChildProcess, StdioOptions } from "child_process";
4
+ import pmContainer from '../container.js';
5
+ import { Deferred, eachAsync } from "@akala/core";
6
+ import { NewLinePrefixer } from "../new-line-prefixer.js";
7
+ import { CliContext, unparseOptions } from "@akala/cli";
8
+ import { ErrorWithStatus } from "@akala/core";
9
+ import getRandomName from "../commands/name.js";
10
+ import { ProxyConfiguration } from "@akala/config";
11
+ import { IpcAdapter } from "../ipc-adapter.js";
12
+ import path from 'path'
13
+ import { fileURLToPath } from 'url'
14
+
15
+ //eslint-disable-next-line @typescript-eslint/ban-ts-comment
16
+ //@ts-ignore
17
+ const _dirname = typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url))
18
+
19
+ export default async function start(this: State, pm: pmContainer.container & Container<State>, name: string, context?: CliContext<{ new?: boolean, name: string, keepAttached?: boolean, inspect?: boolean, verbose?: boolean, wait?: boolean }>): Promise<void | { execPath: string, args: string[], cwd: string, stdio: StdioOptions, shell: boolean, windowsHide: boolean }>
20
+ {
21
+ let args: string[];
22
+
23
+ if (!context.options.name && context.options.new)
24
+ context.options.name = getRandomName();
25
+ else if (!context.options.name)
26
+ context.options.name = name;
27
+
28
+ if (this.isDaemon)
29
+ throw new ErrorWithStatus(40, 'pm is already running');
30
+ else
31
+ {
32
+ if (name != 'pm')
33
+ throw new ErrorWithStatus(40, 'this command needs to run through daemon process');
34
+
35
+ args = [...context.args, ...unparseOptions({ ...context.options, inspect: undefined })];
36
+ }
37
+
38
+ args.unshift(path.resolve(_dirname, '../fork'))
39
+
40
+ if (context.options && context.options.inspect)
41
+ args.unshift('--inspect-brk');
42
+
43
+ args.unshift(...process.execArgv);
44
+
45
+ if (context.options && context.options.verbose)
46
+ args.push('-v')
47
+
48
+ let cp: ChildProcess;
49
+ if (context.options.keepAttached)
50
+ cp = spawn(process.execPath, args, { cwd: process.cwd(), stdio: ['inherit', 'inherit', 'inherit', 'ipc'] });
51
+ else
52
+ cp = spawn(process.execPath, args, { cwd: process.cwd(), detached: true, stdio: ['ignore', 'ignore', 'ignore', 'ipc'] });
53
+ cp.on('exit', function (...args: unknown[])
54
+ {
55
+ console.log(args);
56
+ })
57
+ cp.on('message', function (message)
58
+ {
59
+ console.log(message);
60
+ // cp.disconnect();
61
+ });
62
+ return new Promise<void>((resolve) =>
63
+ {
64
+ cp.on('disconnect', function ()
65
+ {
66
+ if (!context.options.keepAttached)
67
+ cp.unref();
68
+ console.log('pm started');
69
+ resolve();
70
+ })
71
+ })
72
+ }
73
+
74
+ start.$inject = ['$container', 'param.0', 'options']
package/src/cli.ts CHANGED
@@ -4,13 +4,14 @@ import { Processors, NetSocketAdapter, Metadata, Container, proxy, Triggers, Cli
4
4
  import { Socket } from 'net';
5
5
  import { TLSSocket } from 'tls';
6
6
  import { platform, homedir } from 'os';
7
- import start from './commands/start.js'
7
+ import start from './cli-commands/start-self.js'
8
8
  import { Readable } from 'stream';
9
9
 
10
- import State from './state.js';
10
+ import State, { StateConfiguration } from './state.js';
11
11
  import { program, buildCliContextFromProcess, ErrorMessage } from '@akala/cli';
12
12
  import { InteractError } from './index.js';
13
13
  import { Binding } from '@akala/core';
14
+ import { open } from 'fs/promises';
14
15
 
15
16
  const tableChars = {
16
17
  'top': '─'
@@ -81,25 +82,24 @@ cli.preAction(async c =>
81
82
  netsocket.connect('\\\\?\\pipe\\pm')
82
83
  else
83
84
  {
84
- try
85
+ open('./.pm.config.json').then(d =>
85
86
  {
86
- // eslint-disable-next-line @typescript-eslint/no-var-requires
87
- import(path.join(homedir(), './.pm.config.json'), { assert: { type: 'json' } }).then(config =>
88
- netsocket.connect(config.default.mapping.pm.connect.socket[0])
89
- );
90
- }
91
- catch (e)
87
+ d.readFile({ encoding: 'utf-8' }).then(d => JSON.parse(d)).then((config: StateConfiguration) =>
88
+ {
89
+ netsocket.connect(config.mapping.pm.connect.socket[0]);
90
+ }).finally(() => d.close());
91
+ }, e =>
92
92
  {
93
- if (e.code != 'MODULE_NOT_FOUND')
94
- reject(e);
93
+ if (e.code === 'ENOENT' && e.path === './.pm.config.json')
94
+ socket.destroy(e);
95
95
  else
96
96
  {
97
- e.code = 'ENOENT';
98
- socket.destroy(e);
97
+ reject(e);
98
+ throw e;
99
99
  }
100
-
101
- }
100
+ });
102
101
  }
102
+
103
103
  if (c.options.tls)
104
104
  {
105
105
  // socket.on('data', function (e) { console.log(e) });
@@ -83,10 +83,14 @@ export default async function (this: State, container: RunningContainer & pmCont
83
83
  , disconnect: null
84
84
  , unref: null
85
85
  , ref: null
86
- , killed: false
86
+ , killed: false,
87
+ [Symbol.dispose]()
88
+ {
89
+
90
+ }
87
91
  });
88
92
 
89
- const configPath = context.options.configFile || join(homedir(), './.pm.config.json');
93
+ const configPath = context.options.configFile || './.pm.config.json';
90
94
  this.config = await Configuration.load<StateConfiguration>(configPath, true);
91
95
 
92
96
  if (this.config?.mapping?.pm)
@@ -14,13 +14,14 @@ export default async function connect(this: State, name: string, context?: Serve
14
14
  mapping = Configuration.new(null, this.processes[name] as SidecarConfiguration);
15
15
  // console.log(name);
16
16
  // console.log(mapping);
17
- // console.log(options);
18
- if (context && context.args.length > 0)
17
+ // console.log(mapping.connect);
18
+ // console.log(context);
19
+ if (context?.args?.length > 0)
19
20
  {
20
21
  if (!mapping)
21
- this.config.mapping.set(`${name}.connect`, serveMetadata({ args: context.args, options: { ...context.options, socketName: context.options.socketName || name } }));
22
+ this.config.mapping.set(`${name}.connect`, serveMetadata({ args: context.args, options: { ...context.options, socketName: context.options?.socketName || name } }));
22
23
  else
23
- mapping.set('connect', serveMetadata({ args: context.args, options: { ...context.options, socketName: context.options.socketName || name } }));
24
+ mapping.set('connect', serveMetadata({ args: context.args, options: { ...context.options, socketName: context.options?.socketName || name } }));
24
25
  }
25
26
  else
26
27
  {
package/src/fork.ts CHANGED
@@ -10,6 +10,7 @@ import { logger, Logger, MiddlewareComposite, module as coreModule } from '@akal
10
10
  import { program, buildCliContextFromProcess, ErrorMessage, NamespaceMiddleware } from '@akala/cli';
11
11
  import { Stats } from 'fs';
12
12
  import { registerCommands, SelfDefinedCommand, parseMetadata, StructuredParameters } from '@akala/commands';
13
+ import { fileURLToPath } from 'url';
13
14
 
14
15
  var isPm = false;
15
16
 
@@ -50,6 +51,18 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
50
51
  }).
51
52
  preAction(async c => //If pure js file
52
53
  {
54
+ try
55
+ {
56
+ const url = new URL(c.options.program);
57
+ if (url.protocol == 'file:')
58
+ c.options.program = fileURLToPath(url);
59
+ else
60
+ throw new Error('remote commands are not yet supported');
61
+ }
62
+ catch (e)
63
+ {
64
+ console.log(e);
65
+ }
53
66
  folderOrFile = await lstat(c.options.program);
54
67
  if (folderOrFile.isFile() && path.extname(c.options.program) === '.js')
55
68
  return require(c.options.program);
@@ -158,6 +171,7 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
158
171
  try
159
172
  {
160
173
  const serveArgs: ac.ServeMetadataWithSignal = await pm.dispatch('connect', c.options.name);
174
+ // console.log(serveArgs)
161
175
  serveArgs.signal = controller.signal;
162
176
  await cliContainer.dispatch('$serve', serveArgs);
163
177
  }