codify-plugin-lib 1.0.113 → 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
- pipe = new net.Socket({ fd: fileHandle.fd });
51
- pipe.pipe(process.stdout);
46
+ const cat = cp.spawn('cat', [`/tmp/${cid}`]);
47
+ cat.stdout.pipe(process.stdout);
52
48
  let output = '';
53
- pipe.on('data', (data) => {
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codify-plugin-lib",
3
- "version": "1.0.113",
3
+ "version": "1.0.114",
4
4
  "description": "Library plugin library",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -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
- pipe = new net.Socket({ fd: fileHandle.fd });
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
- pipe.on('data', (data) => {
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