Skip to content

Commit 4392169

Browse files
committed
Copy conpty.dll and openconsole.exe depending on arch in postinstall
1 parent ddcd0b0 commit 4392169

4 files changed

Lines changed: 46 additions & 14 deletions

File tree

.eslintrc.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ module.exports = {
99
"project": "src/tsconfig.json",
1010
"sourceType": "module"
1111
},
12-
"ignorePatterns": "**/typings/*.d.ts",
12+
"ignorePatterns": [
13+
"**/typings/*.d.ts",
14+
"scripts/**/*"
15+
],
1316
"plugins": [
1417
"@typescript-eslint"
1518
],

examples/fork/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const ptyProcess = pty.spawn(shell, [], {
1010
rows: 26,
1111
cwd: isWindows ? process.env.USERPROFILE : process.env.HOME,
1212
env: Object.assign({ TEST: "Environment vars work" }, process.env),
13-
useConpty: true
13+
useConpty: true,
14+
useConptyDll: true
1415
});
1516

1617
ptyProcess.onData(data => process.stdout.write(data));

scripts/post-install.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
var fs = require('fs');
2-
var path = require('path');
1+
//@ts-check
32

4-
var RELEASE_DIR = path.join(__dirname, '..', 'build', 'Release');
5-
var BUILD_FILES = [
3+
const fs = require('fs');
4+
const os = require('os');
5+
const path = require('path');
6+
7+
const RELEASE_DIR = path.join(__dirname, '../build/Release');
8+
const BUILD_FILES = [
69
path.join(RELEASE_DIR, 'conpty.node'),
710
path.join(RELEASE_DIR, 'conpty.pdb'),
811
path.join(RELEASE_DIR, 'conpty_console_list.node'),
@@ -15,14 +18,18 @@ var BUILD_FILES = [
1518
path.join(RELEASE_DIR, 'winpty.dll'),
1619
path.join(RELEASE_DIR, 'winpty.pdb')
1720
];
21+
const CONPTY_DIR = path.join(__dirname, '../third_party/conpty');
22+
const CONPTY_SUPPORTED_ARCH = ['x64', 'arm64'];
23+
24+
console.log('\x1b[32m> Cleaning release folder...\x1b[0m');
1825

19-
cleanFolderRecursive = function(folder) {
26+
function cleanFolderRecursive(folder) {
2027
var files = [];
21-
if( fs.existsSync(folder) ) {
28+
if (fs.existsSync(folder)) {
2229
files = fs.readdirSync(folder);
2330
files.forEach(function(file,index) {
2431
var curPath = path.join(folder, file);
25-
if(fs.lstatSync(curPath).isDirectory()) { // recurse
32+
if (fs.lstatSync(curPath).isDirectory()) { // recurse
2633
cleanFolderRecursive(curPath);
2734
fs.rmdirSync(curPath);
2835
} else if (BUILD_FILES.indexOf(curPath) < 0){ // delete file
@@ -36,7 +43,29 @@ try {
3643
cleanFolderRecursive(RELEASE_DIR);
3744
} catch(e) {
3845
console.log(e);
39-
//process.exit(1);
40-
} finally {
41-
process.exit(0);
46+
process.exit(1);
47+
}
48+
49+
console.log(`\x1b[32m> Moving conpty.dll...\x1b[0m`);
50+
if (os.platform() !== 'win32') {
51+
console.log(' SKIPPED (not Windows)');
52+
} else {
53+
const windowsArch = os.arch();
54+
if (!CONPTY_SUPPORTED_ARCH.includes(windowsArch)) {
55+
console.log(` SKIPPED (unsupported architecture ${windowsArch})`);
56+
} else {
57+
const versionFolder = fs.readdirSync(CONPTY_DIR)[0];
58+
console.log(` Found version ${versionFolder}`);
59+
const sourceFolder = path.join(CONPTY_DIR, versionFolder, `win10-${windowsArch}`);
60+
const destFolder = path.join(RELEASE_DIR, 'conpty');
61+
fs.mkdirSync(destFolder, { recursive: true });
62+
for (const file of ['conpty.dll', 'OpenConsole.exe']) {
63+
const sourceFile = path.join(sourceFolder, file);
64+
const destFile = path.join(destFolder, file);
65+
console.log(` Copying ${sourceFile} -> ${destFile}`);
66+
fs.copyFileSync(sourceFile, destFile);
67+
}
68+
}
4269
}
70+
71+
process.exit(0);

src/win/conpty.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ HANDLE LoadConptyDll(const Napi::CallbackInfo& info,
177177
}
178178
std::wstring currentDirStr(currentDir);
179179

180-
// TODO: Support arm64
181-
std::wstring conptyDllPath = currentDirStr + L"\\third_party\\conpty\\1.19.240130002\\win10-x64\\conpty.dll";
180+
std::wstring conptyDllPath = currentDirStr + L"\\build\\Release\\conpty\\conpty.dll";
182181
if (!path_util::file_exists(conptyDllPath)) {
183182
throw errorWithCode(info, "Cannot find conpty.dll");
184183
}

0 commit comments

Comments
 (0)