@akala/pm 5.2.19 → 5.2.21

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
@@ -40,7 +40,7 @@ cli.command('start pm')
40
40
  .action(c =>
41
41
  {
42
42
  c.options['name'] = 'pm'
43
- c.options['program'] = require.resolve('../commands.json');
43
+ c.options['program'] = new URL('../../commands.json', import.meta.url).toString();
44
44
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
45
45
  return start.call({} as unknown as State, null, 'pm', c as any);
46
46
  });
@@ -59,7 +59,7 @@ cli.preAction(async c =>
59
59
  const netsocket = socket = new Socket();
60
60
  if (c.options.tls)
61
61
  {
62
- socket = new TLSSocket(socket, {});
62
+ socket = new TLSSocket(netsocket, {});
63
63
  }
64
64
 
65
65
  await new Promise<void>((resolve, reject) =>
@@ -84,9 +84,9 @@ cli.preAction(async c =>
84
84
  try
85
85
  {
86
86
  // eslint-disable-next-line @typescript-eslint/no-var-requires
87
- const config = require(path.join(homedir(), './.pm.config.json'));
88
-
89
- netsocket.connect(config.mapping.pm.connect.socket[0]);
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
90
  }
91
91
  catch (e)
92
92
  {
@@ -144,7 +144,7 @@ cli.preAction(async c =>
144
144
  if (!processor)
145
145
  processor = new Processors.JsonRpc(Processors.JsonRpc.getConnection(new NetSocketAdapter(socket)));
146
146
  if (!metaContainer)
147
- metaContainer = require('../commands.json');
147
+ metaContainer = (await import(new URL('../../commands.json', import.meta.url).toString(), { assert: { type: 'json' } })).default;
148
148
  if (!container)
149
149
  {
150
150
  container = proxy(metaContainer, processor);
@@ -95,7 +95,7 @@ export default async function (this: State, container: RunningContainer & pmCont
95
95
  }
96
96
  else
97
97
  this.config = Configuration.new<StateConfiguration>(configPath, {
98
- containers: { pm: { commandable: true, stateless: false, path: require.resolve('../../commands.json') } },
98
+ containers: { pm: { commandable: true, stateless: false, path: await import(new URL('../../../commands.json', import.meta.url).toString(), { assert: { type: 'json' } }) } },
99
99
  mapping: { pm: { cwd: process.cwd(), container: 'pm' } },
100
100
  plugins: []
101
101
  }) as State['config'];
package/src/fork.ts CHANGED
@@ -11,9 +11,9 @@ 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'
14
+ // import module from 'module'
15
15
 
16
- const require = module.createRequire(import.meta.url.substring('file://'.length));
16
+ // const require = module.createRequire(import.meta.url.substring('file://'.length));
17
17
 
18
18
  var isPm = false;
19
19
 
@@ -37,8 +37,8 @@ logMiddleware.preAction(async c =>
37
37
  let initMiddleware = new NamespaceMiddleware<{ program: string, name: string, tls: boolean }>(null);
38
38
  const controller = new AbortController();
39
39
 
40
- program.option<string, 'program'>('program', { needsValue: true, normalize: true }).
41
- option<string, 'name'>('name', { needsValue: true }).
40
+ program.option<string, 'program'>('program', { needsValue: true, normalize: true, positional: true, position: 0 }).
41
+ option<string, 'name'>('name', { needsValue: true, positional: true, position: 1, optional: true }).
42
42
  option<boolean, 'tls'>('tls', { needsValue: false }).
43
43
  options<{
44
44
  port?: number,
@@ -71,16 +71,19 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
71
71
  handle: async c =>
72
72
  {
73
73
  cliContainer.name = c.options.name;
74
- isPm = c.options.name === 'pm' && c.options.program === require.resolve('../commands.json');
74
+ isPm = c.options.name === 'pm' && 'file://' + c.options.program === new URL('../../commands.json', import.meta.url).toString();
75
75
  const init = cliContainer.resolve('$init');
76
76
  if (init && init.config && init.config.cli && init.config.cli.options)
77
77
  {
78
78
  if (init.config.cli.usage)
79
+ {
79
80
  initMiddleware = initMiddleware.command(init.config.cli.usage, init.config?.doc?.description)
81
+ c.args.unshift('$init');
82
+ }
80
83
  ac.Triggers.addCliOptions(init, initMiddleware);
81
84
  }
82
85
 
83
- process.on('unhandledRejection', (x) =>
86
+ process.on('unhandledRejection', (x, p) =>
84
87
  {
85
88
  controller.abort(x)
86
89
  return false;
@@ -100,7 +103,7 @@ program.option<string, 'program'>('program', { needsValue: true, normalize: true
100
103
  if (!isPm)
101
104
  {
102
105
  //eslint-disable-next-line @typescript-eslint/no-var-requires
103
- const pmMeta = require('../commands.json');
106
+ const pmMeta = await import(new URL('../../commands.json', import.meta.url).toString());
104
107
  if (process.connected)
105
108
  {
106
109
  pm = new ac.Container('pm', null, new ac.Processors.JsonRpc(ac.Processors.JsonRpc.getConnection(new IpcAdapter(process), cliContainer), true)) as ac.Container<unknown> & pmDef.container;