diff --git a/.eslintrc.js b/.eslintrc.js index 97dd675ca..cc1855154 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -9,7 +9,10 @@ module.exports = { "project": "src/tsconfig.json", "sourceType": "module" }, - "ignorePatterns": "**/typings/*.d.ts", + "ignorePatterns": [ + "**/typings/*.d.ts", + "scripts/**/*" + ], "plugins": [ "@typescript-eslint" ], diff --git a/examples/fork/index.js b/examples/fork/index.js index 81f0543ce..1ab8db41b 100644 --- a/examples/fork/index.js +++ b/examples/fork/index.js @@ -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)); diff --git a/scripts/post-install.js b/scripts/post-install.js index 745fbdbef..3bf4066cb 100644 --- a/scripts/post-install.js +++ b/scripts/post-install.js @@ -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'), @@ -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 @@ -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); diff --git a/src/win/conpty.cc b/src/win/conpty.cc index 41f24c818..20993d8c0 100644 --- a/src/win/conpty.cc +++ b/src/win/conpty.cc @@ -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"); }