codify-plugin-lib 1.0.112 → 1.0.114
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.
|
@@ -2,12 +2,11 @@ import { nanoid } from 'nanoid';
|
|
|
2
2
|
import * as cp from 'node:child_process';
|
|
3
3
|
import { EventEmitter } from 'node:events';
|
|
4
4
|
import * as fs from 'node:fs/promises';
|
|
5
|
-
import * as net from 'node:net';
|
|
6
5
|
import pty from 'node-pty';
|
|
7
6
|
import stripAnsi from 'strip-ansi';
|
|
7
|
+
import { debugLog } from '../utils/debug.js';
|
|
8
8
|
import { SpawnError } from './index.js';
|
|
9
9
|
import { PromiseQueue } from './promise-queue.js';
|
|
10
|
-
import { debugLog } from '../utils/debug.js';
|
|
11
10
|
EventEmitter.defaultMaxListeners = 1000;
|
|
12
11
|
/**
|
|
13
12
|
* The background pty is a specialized pty designed for speed. It can launch multiple tasks
|
|
@@ -43,14 +42,11 @@ export class BackgroundPty {
|
|
|
43
42
|
resolve(null);
|
|
44
43
|
});
|
|
45
44
|
});
|
|
46
|
-
// Use read and write so that the pipe doesn't close
|
|
47
|
-
const fileHandle = await fs.open(`/tmp/${cid}`, fs.constants.O_RDWR | fs.constants.O_NONBLOCK);
|
|
48
|
-
let pipe;
|
|
49
45
|
return new Promise((resolve) => {
|
|
50
|
-
|
|
51
|
-
|
|
46
|
+
const cat = cp.spawn('cat', [`/tmp/${cid}`]);
|
|
47
|
+
cat.stdout.pipe(process.stdout);
|
|
52
48
|
let output = '';
|
|
53
|
-
|
|
49
|
+
cat.stdout.on('data', (data) => {
|
|
54
50
|
output += data.toString();
|
|
55
51
|
if (output.includes('%%%done%%%"')) {
|
|
56
52
|
const truncOutput = output.replace('%%%done%%%"\n', '');
|
|
@@ -67,6 +63,9 @@ export class BackgroundPty {
|
|
|
67
63
|
});
|
|
68
64
|
}
|
|
69
65
|
});
|
|
66
|
+
cat.on('close', () => {
|
|
67
|
+
console.log('close');
|
|
68
|
+
});
|
|
70
69
|
this.promiseQueue.run(async () => new Promise((resolve) => {
|
|
71
70
|
const cdCommand = options?.cwd ? `cd ${options.cwd}; ` : '';
|
|
72
71
|
// Redirecting everything to the pipe and running in theb background avoids most if not all back-pressure problems
|
|
@@ -81,7 +80,7 @@ export class BackgroundPty {
|
|
|
81
80
|
resolve(null);
|
|
82
81
|
}
|
|
83
82
|
});
|
|
84
|
-
|
|
83
|
+
console.log(`Running command ${cmd}`);
|
|
85
84
|
this.basePty.write(`${command}\r`);
|
|
86
85
|
}));
|
|
87
86
|
}).finally(async () => {
|
package/package.json
CHANGED
package/src/plugin/plugin.ts
CHANGED
|
@@ -123,7 +123,7 @@ export class Plugin {
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
const plan = await ptyLocalStorage.run(this.planPty, async () => {
|
|
126
|
-
|
|
126
|
+
return this.resourceControllers.get(type)!.plan(
|
|
127
127
|
data.desired ?? null,
|
|
128
128
|
data.state ?? null,
|
|
129
129
|
data.isStateful
|
|
@@ -2,13 +2,12 @@ import { nanoid } from 'nanoid';
|
|
|
2
2
|
import * as cp from 'node:child_process';
|
|
3
3
|
import { EventEmitter } from 'node:events';
|
|
4
4
|
import * as fs from 'node:fs/promises';
|
|
5
|
-
import * as net from 'node:net';
|
|
6
5
|
import pty from 'node-pty';
|
|
7
6
|
import stripAnsi from 'strip-ansi';
|
|
8
7
|
|
|
8
|
+
import { debugLog } from '../utils/debug.js';
|
|
9
9
|
import { IPty, SpawnError, SpawnOptions, SpawnResult } from './index.js';
|
|
10
10
|
import { PromiseQueue } from './promise-queue.js';
|
|
11
|
-
import { debugLog } from '../utils/debug.js';
|
|
12
11
|
|
|
13
12
|
EventEmitter.defaultMaxListeners = 1000;
|
|
14
13
|
|
|
@@ -54,17 +53,12 @@ export class BackgroundPty implements IPty {
|
|
|
54
53
|
})
|
|
55
54
|
})
|
|
56
55
|
|
|
57
|
-
// Use read and write so that the pipe doesn't close
|
|
58
|
-
const fileHandle = await fs.open(`/tmp/${cid}`, fs.constants.O_RDWR | fs.constants.O_NONBLOCK);
|
|
59
|
-
let pipe: net.Socket;
|
|
60
|
-
|
|
61
56
|
return new Promise<SpawnResult>((resolve) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// pipe.pipe(process.stdout);
|
|
57
|
+
const cat = cp.spawn('cat', [`/tmp/${cid}`])
|
|
58
|
+
cat.stdout.pipe(process.stdout);
|
|
65
59
|
|
|
66
60
|
let output = '';
|
|
67
|
-
|
|
61
|
+
cat.stdout.on('data', (data) => {
|
|
68
62
|
output += data.toString();
|
|
69
63
|
|
|
70
64
|
if (output.includes('%%%done%%%"')) {
|
|
@@ -85,6 +79,10 @@ export class BackgroundPty implements IPty {
|
|
|
85
79
|
}
|
|
86
80
|
})
|
|
87
81
|
|
|
82
|
+
cat.on('close', () => {
|
|
83
|
+
console.log('close');
|
|
84
|
+
})
|
|
85
|
+
|
|
88
86
|
this.promiseQueue.run(async () => new Promise((resolve) => {
|
|
89
87
|
const cdCommand = options?.cwd ? `cd ${options.cwd}; ` : '';
|
|
90
88
|
// Redirecting everything to the pipe and running in theb background avoids most if not all back-pressure problems
|
|
@@ -102,7 +100,7 @@ export class BackgroundPty implements IPty {
|
|
|
102
100
|
}
|
|
103
101
|
});
|
|
104
102
|
|
|
105
|
-
|
|
103
|
+
console.log(`Running command ${cmd}`)
|
|
106
104
|
this.basePty.write(`${command}\r`);
|
|
107
105
|
|
|
108
106
|
}));
|