@lvce-editor/pty-host 8.11.1 → 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 +60 -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
|
*
|
|
@@ -1670,7 +1697,8 @@ const toPath = pathOrUri => {
|
|
|
1670
1697
|
const create$1 = async ({
|
|
1671
1698
|
args,
|
|
1672
1699
|
command,
|
|
1673
|
-
cwd
|
|
1700
|
+
cwd,
|
|
1701
|
+
env
|
|
1674
1702
|
} = {}) => {
|
|
1675
1703
|
try {
|
|
1676
1704
|
string(cwd);
|
|
@@ -1680,9 +1708,28 @@ const create$1 = async ({
|
|
|
1680
1708
|
spawn
|
|
1681
1709
|
} = await import('node-pty');
|
|
1682
1710
|
const cwdPath = toPath(cwd);
|
|
1683
|
-
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, {
|
|
1684
1730
|
cwd: cwdPath,
|
|
1685
|
-
encoding: null
|
|
1731
|
+
encoding: null,
|
|
1732
|
+
env: childEnv
|
|
1686
1733
|
// cols: 10,
|
|
1687
1734
|
// rows: 10,
|
|
1688
1735
|
});
|
|
@@ -1713,7 +1760,7 @@ const disposeConnection = ipc => {
|
|
|
1713
1760
|
};
|
|
1714
1761
|
|
|
1715
1762
|
// TODO maybe merge pty and pty controller
|
|
1716
|
-
const createWithDependencies = async (ipc, id, cwd, command, args, createPty) => {
|
|
1763
|
+
const createWithDependencies = async (ipc, id, cwd, command, args, createPty, options = {}) => {
|
|
1717
1764
|
number(id);
|
|
1718
1765
|
string(cwd);
|
|
1719
1766
|
string(command);
|
|
@@ -1734,7 +1781,10 @@ const createWithDependencies = async (ipc, id, cwd, command, args, createPty) =>
|
|
|
1734
1781
|
pty = await createPty({
|
|
1735
1782
|
args,
|
|
1736
1783
|
command,
|
|
1737
|
-
cwd
|
|
1784
|
+
cwd,
|
|
1785
|
+
...(options.env && {
|
|
1786
|
+
env: options.env
|
|
1787
|
+
})
|
|
1738
1788
|
});
|
|
1739
1789
|
} catch (error) {
|
|
1740
1790
|
entries.delete(entry);
|
|
@@ -1787,10 +1837,13 @@ const create = (ipc, id, cwd, command, args, options) => {
|
|
|
1787
1837
|
return create$2(ipc, id, options.sessionToken, options.restoreOnly === true, () => create$1({
|
|
1788
1838
|
args,
|
|
1789
1839
|
command,
|
|
1790
|
-
cwd
|
|
1840
|
+
cwd,
|
|
1841
|
+
...(options.env && {
|
|
1842
|
+
env: options.env
|
|
1843
|
+
})
|
|
1791
1844
|
}));
|
|
1792
1845
|
}
|
|
1793
|
-
return createWithDependencies(ipc, id, cwd, command, args, create$1);
|
|
1846
|
+
return createWithDependencies(ipc, id, cwd, command, args, create$1, options);
|
|
1794
1847
|
};
|
|
1795
1848
|
const write = (ipc, id, data) => {
|
|
1796
1849
|
const pty = get(ipc, id);
|