@akala/pm 7.1.4 → 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.
- package/changelog.md +16 -1
- package/dist/cjs/cli-commands/start-self.d.ts +25 -0
- package/dist/cjs/cli-commands/start-self.js +62 -0
- package/dist/cjs/cli-commands/start-self.js.map +1 -0
- package/dist/cjs/cli-helper.js +2 -29
- package/dist/cjs/cli-helper.js.map +1 -1
- package/dist/cjs/commands/bridge.js +1 -4
- package/dist/cjs/commands/bridge.js.map +1 -1
- package/dist/cjs/commands/config.js +2 -28
- package/dist/cjs/commands/config.js.map +1 -1
- package/dist/cjs/commands/connect.js +12 -13
- package/dist/cjs/commands/connect.js.map +1 -1
- package/dist/cjs/commands/discover.js +17 -20
- package/dist/cjs/commands/discover.js.map +1 -1
- package/dist/cjs/commands/install.js +6 -35
- package/dist/cjs/commands/install.js.map +1 -1
- package/dist/cjs/commands/link.js +6 -35
- package/dist/cjs/commands/link.js.map +1 -1
- package/dist/cjs/commands/log.js +4 -7
- package/dist/cjs/commands/log.js.map +1 -1
- package/dist/cjs/commands/ls.js +1 -4
- package/dist/cjs/commands/ls.js.map +1 -1
- package/dist/cjs/commands/map.js +4 -7
- package/dist/cjs/commands/map.js.map +1 -1
- package/dist/cjs/commands/name.js +1 -4
- package/dist/cjs/commands/name.js.map +1 -1
- package/dist/cjs/commands/plugin/add.js +1 -4
- package/dist/cjs/commands/plugin/add.js.map +1 -1
- package/dist/cjs/commands/plugin/remove.js +1 -4
- package/dist/cjs/commands/plugin/remove.js.map +1 -1
- package/dist/cjs/commands/proxy.js +5 -8
- package/dist/cjs/commands/proxy.js.map +1 -1
- package/dist/cjs/commands/ready.js +4 -7
- package/dist/cjs/commands/ready.js.map +1 -1
- package/dist/cjs/commands/reload-metadata.js +3 -6
- package/dist/cjs/commands/reload-metadata.js.map +1 -1
- package/dist/cjs/commands/restart.js +1 -4
- package/dist/cjs/commands/restart.js.map +1 -1
- package/dist/cjs/commands/start.js +34 -40
- package/dist/cjs/commands/start.js.map +1 -1
- package/dist/cjs/commands/status.js +1 -4
- package/dist/cjs/commands/status.js.map +1 -1
- package/dist/cjs/commands/stop.js +1 -4
- package/dist/cjs/commands/stop.js.map +1 -1
- package/dist/cjs/commands/update.js +6 -35
- package/dist/cjs/commands/update.js.map +1 -1
- package/dist/cjs/commands/version.js +4 -7
- package/dist/cjs/commands/version.js.map +1 -1
- package/dist/cjs/container.js +1 -2
- package/dist/cjs/index.js +19 -54
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/ipc-adapter.js +1 -5
- package/dist/cjs/ipc-adapter.js.map +1 -1
- package/dist/cjs/new-line-prefixer.js +2 -6
- package/dist/cjs/new-line-prefixer.js.map +1 -1
- package/dist/cjs/npm-helper.js +7 -9
- package/dist/cjs/npm-helper.js.map +1 -1
- package/dist/cjs/sidecar.js +11 -39
- package/dist/cjs/sidecar.js.map +1 -1
- package/dist/cjs/standalone.js +16 -44
- package/dist/cjs/standalone.js.map +1 -1
- package/dist/cjs/state.js +1 -2
- package/dist/cjs/test/pwet.js +3 -9
- package/dist/cjs/test/pwet.js.map +1 -1
- package/dist/cjs/yarn-helper.js +12 -16
- package/dist/cjs/yarn-helper.js.map +1 -1
- package/dist/esm/akala.mjs.map +1 -1
- package/dist/esm/cli-commands/start-self.d.ts +25 -0
- package/dist/esm/cli-commands/start-self.js +51 -0
- package/dist/esm/cli-commands/start-self.js.map +1 -0
- package/dist/esm/cli.js +13 -13
- package/dist/esm/cli.js.map +1 -1
- package/dist/esm/commands/$init.js +4 -4
- package/dist/esm/commands/$init.js.map +1 -1
- package/dist/esm/commands/config.js.map +1 -1
- package/dist/esm/commands/connect.js +5 -4
- package/dist/esm/commands/connect.js.map +1 -1
- package/dist/esm/commands/discover.js.map +1 -1
- package/dist/esm/commands/install.js.map +1 -1
- package/dist/esm/commands/log.js.map +1 -1
- package/dist/esm/commands/proxy.js.map +1 -1
- package/dist/esm/commands/ready.js.map +1 -1
- package/dist/esm/commands/start.js.map +1 -1
- package/dist/esm/commands/stop.js.map +1 -1
- package/dist/esm/commands/update.js.map +1 -1
- package/dist/esm/commands/version.js.map +1 -1
- package/dist/esm/fork.js +12 -0
- package/dist/esm/fork.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/ipc-adapter.js.map +1 -1
- package/dist/esm/new-line-prefixer.js.map +1 -1
- package/dist/esm/sidecar.js.map +1 -1
- package/dist/esm/standalone.js.map +1 -1
- package/dist/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/package.json +19 -14
- package/src/cli-commands/start-self.json +66 -0
- package/src/cli-commands/start-self.ts +74 -0
- package/src/cli.ts +15 -15
- package/src/commands/$init.ts +6 -2
- package/src/commands/connect.ts +5 -4
- 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
|
-
|
85
|
+
open('./.pm.config.json').then(d =>
|
85
86
|
{
|
86
|
-
|
87
|
-
|
88
|
-
netsocket.connect(config.
|
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
|
94
|
-
|
93
|
+
if (e.code === 'ENOENT' && e.path === './.pm.config.json')
|
94
|
+
socket.destroy(e);
|
95
95
|
else
|
96
96
|
{
|
97
|
-
e
|
98
|
-
|
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) });
|
package/src/commands/$init.ts
CHANGED
@@ -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 ||
|
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)
|
package/src/commands/connect.ts
CHANGED
@@ -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(
|
18
|
-
|
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
|
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
|
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
|
}
|