@dmsdc-ai/aterm 0.1.2 → 0.1.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dmsdc-ai/aterm",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "description": "Native aterm launcher package",
5
5
  "type": "module",
6
6
  "main": "./bin/aterm.js",
@@ -17,7 +17,7 @@
17
17
  "package.json"
18
18
  ],
19
19
  "optionalDependencies": {
20
- "@dmsdc-ai/aterm-darwin-arm64": "0.1.2"
20
+ "@dmsdc-ai/aterm-darwin-arm64": "0.1.3"
21
21
  },
22
22
  "dependencies": {
23
23
  "@dmsdc-ai/aigentry-brain": "latest",
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import fs from 'node:fs';
3
3
  import path from 'node:path';
4
+ import { spawnSync } from 'node:child_process';
4
5
  import { fileURLToPath } from 'node:url';
5
6
  import { createRequire } from 'node:module';
6
7
  import {
@@ -20,6 +21,9 @@ const require = createRequire(import.meta.url);
20
21
  const packageJson = JSON.parse(
21
22
  fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'),
22
23
  );
24
+ const TTY_REATTACH_FLAG = 'ATERM_POSTINSTALL_TTY_ATTACHED';
25
+
26
+ console.log(`[aterm] postinstall start (${packageJson.version})`);
23
27
 
24
28
  const PLATFORM_PACKAGES = {
25
29
  darwin: {
@@ -31,6 +35,63 @@ function resolvePlatformPackage() {
31
35
  return PLATFORM_PACKAGES[process.platform]?.[process.arch] ?? null;
32
36
  }
33
37
 
38
+ function canUseInteractiveInstaller() {
39
+ if (process.env.CI) {
40
+ return false;
41
+ }
42
+ if (process.env.npm_config_yes === 'true') {
43
+ return false;
44
+ }
45
+ return true;
46
+ }
47
+
48
+ function maybeReattachTTY() {
49
+ if (!canUseInteractiveInstaller()) {
50
+ return;
51
+ }
52
+ if (process.env[TTY_REATTACH_FLAG] === '1') {
53
+ return;
54
+ }
55
+ if (process.stdin.isTTY && process.stdout.isTTY) {
56
+ return;
57
+ }
58
+ if (process.platform === 'win32') {
59
+ return;
60
+ }
61
+
62
+ let ttyIn;
63
+ let ttyOut;
64
+ let ttyErr;
65
+
66
+ try {
67
+ ttyIn = fs.openSync('/dev/tty', 'r');
68
+ ttyOut = fs.openSync('/dev/tty', 'w');
69
+ ttyErr = fs.openSync('/dev/tty', 'w');
70
+ } catch {
71
+ return;
72
+ }
73
+
74
+ console.log('[aterm] reattaching postinstall to /dev/tty for interactive installer');
75
+ const result = spawnSync(process.execPath, [__filename], {
76
+ cwd: process.cwd(),
77
+ env: {
78
+ ...process.env,
79
+ [TTY_REATTACH_FLAG]: '1',
80
+ },
81
+ stdio: [ttyIn, ttyOut, ttyErr],
82
+ });
83
+
84
+ fs.closeSync(ttyIn);
85
+ fs.closeSync(ttyOut);
86
+ fs.closeSync(ttyErr);
87
+
88
+ if (result.status !== 0) {
89
+ process.exit(result.status ?? 1);
90
+ }
91
+
92
+ process.exit(0);
93
+ }
94
+
34
95
  async function collectInstallerPlan() {
35
96
  const mode = isGlobalInstall() ? 'global' : 'local';
36
97
  const installRoot = process.env.INIT_CWD ? path.resolve(process.env.INIT_CWD) : process.cwd();
@@ -167,6 +228,7 @@ function installNativeBundle() {
167
228
  }
168
229
 
169
230
  async function main() {
231
+ maybeReattachTTY();
170
232
  const plan = await collectInstallerPlan();
171
233
 
172
234
  let tuiModule = null;