aem-ext-daemon 0.4.0 → 0.4.1
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/dist/capabilities/shell.js +23 -7
- package/package.json +1 -1
|
@@ -152,6 +152,13 @@ export function runAio(args, cwd, requestId, connection) {
|
|
|
152
152
|
let activeProcess = null;
|
|
153
153
|
/** How long to wait for more output before assuming the process is waiting for input. */
|
|
154
154
|
const SILENCE_TIMEOUT = 3_000;
|
|
155
|
+
/** Strip ANSI escape codes from PTY output for clean text. */
|
|
156
|
+
function stripAnsi(text) {
|
|
157
|
+
// eslint-disable-next-line no-control-regex
|
|
158
|
+
return text.replace(/\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])/g, "")
|
|
159
|
+
.replace(/\r\n/g, "\n")
|
|
160
|
+
.replace(/\r/g, "\n");
|
|
161
|
+
}
|
|
155
162
|
/**
|
|
156
163
|
* Start an interactive command. Collects output until the process goes
|
|
157
164
|
* quiet (waiting for user input) or exits, then returns what it has.
|
|
@@ -167,14 +174,23 @@ export function spawnInteractive(command, cwd) {
|
|
|
167
174
|
fs.mkdirSync(cwd, { recursive: true });
|
|
168
175
|
}
|
|
169
176
|
return new Promise((resolve) => {
|
|
170
|
-
|
|
177
|
+
// Use `script` to create a pseudo-TTY so inquirer-based CLIs
|
|
178
|
+
// (like aio app create) render their prompts properly.
|
|
179
|
+
// macOS: script -q /dev/null sh -c "<command>"
|
|
180
|
+
// Linux: script -qec "<command>" /dev/null
|
|
181
|
+
const isMac = os.platform() === "darwin";
|
|
182
|
+
const spawnCmd = isMac ? "script" : "script";
|
|
183
|
+
const spawnArgs = isMac
|
|
184
|
+
? ["-q", "/dev/null", "sh", "-c", command]
|
|
185
|
+
: ["-qec", command, "/dev/null"];
|
|
186
|
+
const child = spawn(spawnCmd, spawnArgs, {
|
|
171
187
|
cwd,
|
|
172
|
-
shell: getUserShell(),
|
|
173
188
|
env: {
|
|
174
189
|
...getEnhancedEnv(),
|
|
175
190
|
// Do NOT set CI or TERM=dumb — we want interactive prompts
|
|
176
|
-
|
|
177
|
-
|
|
191
|
+
TERM: "xterm-256color",
|
|
192
|
+
COLUMNS: "120",
|
|
193
|
+
LINES: "40",
|
|
178
194
|
},
|
|
179
195
|
stdio: ["pipe", "pipe", "pipe"],
|
|
180
196
|
});
|
|
@@ -182,7 +198,7 @@ export function spawnInteractive(command, cwd) {
|
|
|
182
198
|
activeProcess = proc;
|
|
183
199
|
let silenceTimer;
|
|
184
200
|
const flushAndReturn = () => {
|
|
185
|
-
const output = proc.buffer;
|
|
201
|
+
const output = stripAnsi(proc.buffer);
|
|
186
202
|
proc.buffer = "";
|
|
187
203
|
resolve(output || "(no output)");
|
|
188
204
|
};
|
|
@@ -257,7 +273,7 @@ export function writeToProcess(input) {
|
|
|
257
273
|
clearTimeout(silenceTimer);
|
|
258
274
|
silenceTimer = setTimeout(() => {
|
|
259
275
|
if (!proc.done) {
|
|
260
|
-
const output = proc.buffer;
|
|
276
|
+
const output = stripAnsi(proc.buffer);
|
|
261
277
|
proc.buffer = "";
|
|
262
278
|
finish(output || "(waiting for input...)");
|
|
263
279
|
}
|
|
@@ -267,7 +283,7 @@ export function writeToProcess(input) {
|
|
|
267
283
|
const onClose = () => {
|
|
268
284
|
// Small delay to capture any final output
|
|
269
285
|
setTimeout(() => {
|
|
270
|
-
const output = proc.buffer;
|
|
286
|
+
const output = stripAnsi(proc.buffer);
|
|
271
287
|
proc.buffer = "";
|
|
272
288
|
finish(output || "(no output)");
|
|
273
289
|
}, 200);
|