@lvce-editor/pty-host 8.11.2 → 8.11.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.
- package/dist/ptyHostMain.js +47 -7
- package/package.json +1 -1
package/dist/ptyHostMain.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { fileURLToPath } from 'node:url';
|
|
3
3
|
import Headless from '@xterm/headless';
|
|
4
|
+
import { stat } from 'node:fs/promises';
|
|
5
|
+
import { win32 } from 'node:path';
|
|
4
6
|
import { Console } from 'node:console';
|
|
5
7
|
import { createWriteStream, readFileSync } from 'node:fs';
|
|
6
8
|
import { tmpdir } from 'node:os';
|
|
@@ -1622,6 +1624,31 @@ class ExitEvent extends Event {
|
|
|
1622
1624
|
}
|
|
1623
1625
|
}
|
|
1624
1626
|
|
|
1627
|
+
const isFile = async path => {
|
|
1628
|
+
try {
|
|
1629
|
+
const info = await stat(path);
|
|
1630
|
+
return info.isFile();
|
|
1631
|
+
} catch (error) {
|
|
1632
|
+
const {
|
|
1633
|
+
code
|
|
1634
|
+
} = error;
|
|
1635
|
+
if (code !== 'ENOENT' && code !== 'ENOTDIR') throw error;
|
|
1636
|
+
return false;
|
|
1637
|
+
}
|
|
1638
|
+
};
|
|
1639
|
+
const resolveWindowsCommand = async (command, cwd, searchPath) => {
|
|
1640
|
+
if (win32.isAbsolute(command)) return command;
|
|
1641
|
+
const directories = /[/\\]/.test(command) ? [cwd] : searchPath.split(';').filter(Boolean);
|
|
1642
|
+
const names = win32.extname(command) ? [command] : [command, `${command}.exe`];
|
|
1643
|
+
for (const directory of directories) {
|
|
1644
|
+
for (const name of names) {
|
|
1645
|
+
const candidate = win32.resolve(cwd, directory.replace(/^"(.*)"$/, '$1'), name);
|
|
1646
|
+
if (await isFile(candidate)) return candidate;
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
throw new Error(`Executable not found: ${command}`);
|
|
1650
|
+
};
|
|
1651
|
+
|
|
1625
1652
|
class Pty extends EventTarget {
|
|
1626
1653
|
/**
|
|
1627
1654
|
*
|
|
@@ -1681,15 +1708,28 @@ const create$1 = async ({
|
|
|
1681
1708
|
spawn
|
|
1682
1709
|
} = await import('node-pty');
|
|
1683
1710
|
const cwdPath = toPath(cwd);
|
|
1684
|
-
const
|
|
1711
|
+
const childEnv = env ? {
|
|
1712
|
+
...process.env,
|
|
1713
|
+
...env
|
|
1714
|
+
} : {
|
|
1715
|
+
...process.env
|
|
1716
|
+
};
|
|
1717
|
+
let executable = command;
|
|
1718
|
+
if (process.platform === 'win32') {
|
|
1719
|
+
const pathOverride = Object.entries(env || {}).find(([key]) => key.toLowerCase() === 'path');
|
|
1720
|
+
const searchPath = pathOverride ? String(pathOverride[1]) : process.env.PATH || '';
|
|
1721
|
+
// CreateProcess searches System32 before PATH for bare names, even though
|
|
1722
|
+
// node-pty validates a PATH match first. Pass that match to the spawn too.
|
|
1723
|
+
executable = await resolveWindowsCommand(command, cwdPath, searchPath);
|
|
1724
|
+
for (const key of Object.keys(childEnv)) {
|
|
1725
|
+
if (key.toLowerCase() === 'path') delete childEnv[key];
|
|
1726
|
+
}
|
|
1727
|
+
childEnv.Path = searchPath;
|
|
1728
|
+
}
|
|
1729
|
+
const pty = spawn(executable, args, {
|
|
1685
1730
|
cwd: cwdPath,
|
|
1686
1731
|
encoding: null,
|
|
1687
|
-
|
|
1688
|
-
env: {
|
|
1689
|
-
...process.env,
|
|
1690
|
-
...env
|
|
1691
|
-
}
|
|
1692
|
-
})
|
|
1732
|
+
env: childEnv
|
|
1693
1733
|
// cols: 10,
|
|
1694
1734
|
// rows: 10,
|
|
1695
1735
|
});
|