@travetto/cli 3.4.0-rc.2 → 3.4.0-rc.4

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/util.ts +30 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/cli",
3
- "version": "3.4.0-rc.2",
3
+ "version": "3.4.0-rc.4",
4
4
  "description": "CLI infrastructure for Travetto framework",
5
5
  "keywords": [
6
6
  "cli",
@@ -29,7 +29,7 @@
29
29
  "directory": "module/cli"
30
30
  },
31
31
  "dependencies": {
32
- "@travetto/schema": "^3.4.0-rc.1",
32
+ "@travetto/schema": "^3.4.0-rc.3",
33
33
  "@travetto/terminal": "^3.4.0-rc.0"
34
34
  },
35
35
  "travetto": {
package/src/util.ts CHANGED
@@ -1,7 +1,5 @@
1
- import fs from 'fs/promises';
2
-
3
- import { Env, ExecUtil } from '@travetto/base';
4
- import { path, RootIndex } from '@travetto/manifest';
1
+ import { CompilerClient, Env, ExecUtil } from '@travetto/base';
2
+ import { RootIndex } from '@travetto/manifest';
5
3
 
6
4
  import { CliCommandShape } from './types';
7
5
  import { CliCommandRegistry } from './registry';
@@ -40,23 +38,43 @@ export class CliUtil {
40
38
  * Dispatch IPC payload
41
39
  */
42
40
  static async triggerIpc<T extends CliCommandShape>(action: 'run', cmd: T): Promise<boolean> {
43
- const file = process.env.TRV_CLI_IPC;
41
+ if (!process.env.TRV_CLI_IPC) {
42
+ return false;
43
+ }
44
44
 
45
- if (!file) {
45
+ const client = new CompilerClient({});
46
+
47
+ const info = await client.getInfo(true);
48
+
49
+ if (!info) { // Server not running
46
50
  return false;
47
51
  }
48
52
 
53
+ const defaultEnvKeys = new Set(Object.keys(info.env ?? {}));
54
+ defaultEnvKeys.add('PS1').add('INIT_CWD').add('COLOR').add('LANGUAGE').add('PROFILEHOME').add('_');
55
+
56
+ const env = Object.fromEntries(
57
+ Object.entries(process.env).filter(([k]) =>
58
+ !defaultEnvKeys.has(k) && !/^(npm_|GTK|GDK|TRV|NODE|GIT|TERM_)/.test(k) && !/VSCODE/.test(k)
59
+ )
60
+ );
61
+
49
62
  const cfg = CliCommandRegistry.getConfig(cmd);
50
- const payload = JSON.stringify({
51
- type: `@travetto/cli:${action}`, data: {
63
+ const req = {
64
+ type: `@travetto/cli:${action}`,
65
+ ipc: process.env.TRV_CLI_IPC,
66
+ data: {
52
67
  name: cfg.name,
53
68
  commandModule: cfg.module,
54
69
  module: RootIndex.manifest.mainModule,
55
- args: process.argv.slice(3)
70
+ args: process.argv.slice(3),
71
+ env
56
72
  }
57
- });
58
- await fs.mkdir(path.dirname(file), { recursive: true });
59
- await fs.appendFile(file, `${payload}\n`);
73
+ }
74
+
75
+ console.log('Triggering IPC request', req);
76
+
77
+ await client.sendEvent('custom', req);
60
78
  return true;
61
79
  }
62
80