Skip to content

Commit

Permalink
Copy conpty.dll and openconsole.exe depending on arch in postinstall
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyriar committed Aug 1, 2024
1 parent ddcd0b0 commit 4392169
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ module.exports = {
"project": "src/tsconfig.json",
"sourceType": "module"
},
"ignorePatterns": "**/typings/*.d.ts",
"ignorePatterns": [
"**/typings/*.d.ts",
"scripts/**/*"
],
"plugins": [
"@typescript-eslint"
],
Expand Down
3 changes: 2 additions & 1 deletion examples/fork/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const ptyProcess = pty.spawn(shell, [], {
rows: 26,
cwd: isWindows ? process.env.USERPROFILE : process.env.HOME,
env: Object.assign({ TEST: "Environment vars work" }, process.env),
useConpty: true
useConpty: true,
useConptyDll: true
});

ptyProcess.onData(data => process.stdout.write(data));
Expand Down
49 changes: 39 additions & 10 deletions scripts/post-install.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
var fs = require('fs');
var path = require('path');
//@ts-check

var RELEASE_DIR = path.join(__dirname, '..', 'build', 'Release');
var BUILD_FILES = [
const fs = require('fs');
const os = require('os');
const path = require('path');

const RELEASE_DIR = path.join(__dirname, '../build/Release');
const BUILD_FILES = [
path.join(RELEASE_DIR, 'conpty.node'),
path.join(RELEASE_DIR, 'conpty.pdb'),
path.join(RELEASE_DIR, 'conpty_console_list.node'),
Expand All @@ -15,14 +18,18 @@ var BUILD_FILES = [
path.join(RELEASE_DIR, 'winpty.dll'),
path.join(RELEASE_DIR, 'winpty.pdb')
];
const CONPTY_DIR = path.join(__dirname, '../third_party/conpty');
const CONPTY_SUPPORTED_ARCH = ['x64', 'arm64'];

console.log('\x1b[32m> Cleaning release folder...\x1b[0m');

cleanFolderRecursive = function(folder) {
function cleanFolderRecursive(folder) {
var files = [];
if( fs.existsSync(folder) ) {
if (fs.existsSync(folder)) {
files = fs.readdirSync(folder);
files.forEach(function(file,index) {
var curPath = path.join(folder, file);
if(fs.lstatSync(curPath).isDirectory()) { // recurse
if (fs.lstatSync(curPath).isDirectory()) { // recurse
cleanFolderRecursive(curPath);
fs.rmdirSync(curPath);
} else if (BUILD_FILES.indexOf(curPath) < 0){ // delete file
Expand All @@ -36,7 +43,29 @@ try {
cleanFolderRecursive(RELEASE_DIR);
} catch(e) {
console.log(e);
//process.exit(1);
} finally {
process.exit(0);
process.exit(1);
}

console.log(`\x1b[32m> Moving conpty.dll...\x1b[0m`);
if (os.platform() !== 'win32') {
console.log(' SKIPPED (not Windows)');
} else {
const windowsArch = os.arch();
if (!CONPTY_SUPPORTED_ARCH.includes(windowsArch)) {
console.log(` SKIPPED (unsupported architecture ${windowsArch})`);
} else {
const versionFolder = fs.readdirSync(CONPTY_DIR)[0];
console.log(` Found version ${versionFolder}`);
const sourceFolder = path.join(CONPTY_DIR, versionFolder, `win10-${windowsArch}`);
const destFolder = path.join(RELEASE_DIR, 'conpty');
fs.mkdirSync(destFolder, { recursive: true });
for (const file of ['conpty.dll', 'OpenConsole.exe']) {
const sourceFile = path.join(sourceFolder, file);
const destFile = path.join(destFolder, file);
console.log(` Copying ${sourceFile} -> ${destFile}`);
fs.copyFileSync(sourceFile, destFile);
}
}
}

process.exit(0);
3 changes: 1 addition & 2 deletions src/win/conpty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ HANDLE LoadConptyDll(const Napi::CallbackInfo& info,
}
std::wstring currentDirStr(currentDir);

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

0 comments on commit 4392169

Please sign in to comment.