fix(ssh): modernize filesystem handling and package exports for NodeNext compatibility

This commit is contained in:
2026-05-01 18:44:22 +00:00
parent a9820a9e98
commit d8ab8a8d73
14 changed files with 7100 additions and 4960 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
/**
* autocreated commitinfo by @pushrocks/commitinfo
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartssh',
version: '2.0.2',
description: 'setups SSH quickly and in a painless manner'
version: '2.0.3',
description: 'A library for setting up SSH configuration quickly and painlessly.'
}
+1 -1
View File
@@ -2,6 +2,6 @@ import * as plugins from './smartssh.plugins.js';
import { SshKey } from './smartssh.classes.sshkey.js';
export let sshKeyArrayFromDir = function (dirArg: string): SshKey[] {
let sshKeyArray = []; // TODO
let sshKeyArray: SshKey[] = []; // TODO
return sshKeyArray;
};
+8 -14
View File
@@ -12,11 +12,10 @@ export class SshConfig {
* stores a config file
*/
store(dirPathArg: string) {
let done = plugins.smartpromise.defer();
plugins.fs.ensureDirSync(dirPathArg);
let configArray: configObject[] = [];
let configString;
for (let key in this._sshKeyArray) {
let sshKey = this._sshKeyArray[key];
for (const sshKey of this._sshKeyArray) {
let configString = '';
if (sshKey.host) {
configString =
'Host ' +
@@ -38,18 +37,13 @@ export class SshConfig {
});
}
let configFile: string = '';
for (let key in configArray) {
configFile = configFile + configArray[key].configString + '\n';
for (const config of configArray) {
configFile = configFile + config.configString + '\n';
}
plugins.smartfile.memory.toFsSync(configFile, plugins.path.join(dirPathArg, 'config'));
return done.promise;
plugins.fs.writeFileSync(plugins.path.join(dirPathArg, 'config'), configFile);
}
read(dirPathArg) {
let done = plugins.smartpromise.defer();
let configArray: configObject[];
plugins.smartfile.fs.toStringSync(plugins.path.join(dirPathArg, 'config'));
return done.promise;
read(dirPathArg: string) {
return plugins.fs.readFileSync(plugins.path.join(dirPathArg, 'config'), 'utf8');
}
}
+2 -2
View File
@@ -18,7 +18,7 @@ export class SshInstance {
this._sshKeyArray = [];
this._sshConfig = new SshConfig(this._sshKeyArray);
this._sshDir = new SshDir(this._sshKeyArray, this._sshConfig, optionsArg.sshDirPath);
this._sshSync = optionsArg.sshSync;
this._sshSync = optionsArg.sshSync ?? false;
}
// altering methods
@@ -43,7 +43,7 @@ export class SshInstance {
}
// non altering methods
getKey(hostArg: string): SshKey {
getKey(hostArg: string): SshKey | undefined {
this._syncAuto('from');
let filteredArray = this._sshKeyArray.filter(function (keyArg) {
return keyArg.host === hostArg;
+9 -13
View File
@@ -7,20 +7,16 @@ export class SshKey {
private _hostVar: string;
private _authorized: boolean;
private _smarthshellInstance = new plugins.smartshell.Smartshell({
executor: 'bash',
});
/**
* the constructor for class SshKey
*/
constructor(
optionsArg: { private?: string; public?: string; host?: string; authorized?: boolean } = {}
) {
this._privKey = optionsArg.private;
this._pubKey = optionsArg.public;
this._hostVar = optionsArg.host;
this._authorized = optionsArg.authorized;
this._privKey = optionsArg.private ?? '';
this._pubKey = optionsArg.public ?? '';
this._hostVar = optionsArg.host ?? '';
this._authorized = optionsArg.authorized ?? false;
}
// this.host
@@ -87,20 +83,20 @@ export class SshKey {
}
// methods
read(filePathArg) {}
read(filePathArg: string) {}
async store(dirPathArg: string) {
plugins.fs.ensureDirSync(dirPathArg);
let fileNameBase = this.host;
if (this._privKey) {
let filePath = plugins.path.join(dirPathArg, fileNameBase);
plugins.smartfile.memory.toFsSync(this._privKey, filePath);
await this._smarthshellInstance.exec(`chmod 0600 ${filePath}`);
plugins.fs.writeFileSync(filePath, this._privKey);
plugins.fs.chmodSync(filePath, 0o600);
}
if (this._pubKey) {
let filePath = plugins.path.join(dirPathArg, fileNameBase + '.pub');
plugins.smartfile.memory.toFsSync(this._pubKey, filePath);
await this._smarthshellInstance.exec(`chmod 0600 ${filePath}`);
plugins.fs.writeFileSync(filePath, this._pubKey);
plugins.fs.chmodSync(filePath, 0o600);
}
}
}
+1 -7
View File
@@ -1,25 +1,19 @@
// node native
import * as fs from 'fs-extra';
import fs from 'fs-extra';
import * as path from 'path';
export { fs, path };
// @push.rocks scope
import * as smartjson from '@push.rocks/smartjson';
import * as smartfile from '@push.rocks/smartfile';
import * as smartcrypto from '@push.rocks/smartcrypto';
import * as smartpath from '@push.rocks/smartpath';
import * as smartpromise from '@push.rocks/smartpromise';
import * as smartshell from '@push.rocks/smartshell';
import * as smartstring from '@push.rocks/smartstring';
export {
smartjson,
smartfile,
smartcrypto,
smartpath,
smartpromise,
smartshell,
smartstring,
};