fix(core): Fix interactive shell execution and update dependencies
This commit is contained in:
parent
1474fd541f
commit
6904097960
128
.gitlab-ci.yml
128
.gitlab-ci.yml
@ -1,128 +0,0 @@
|
|||||||
# gitzone ci_default
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
|
|
||||||
cache:
|
|
||||||
paths:
|
|
||||||
- .npmci_cache/
|
|
||||||
key: '$CI_BUILD_STAGE'
|
|
||||||
|
|
||||||
stages:
|
|
||||||
- security
|
|
||||||
- test
|
|
||||||
- release
|
|
||||||
- metadata
|
|
||||||
|
|
||||||
before_script:
|
|
||||||
- pnpm install -g pnpm
|
|
||||||
- pnpm install -g @shipzone/npmci
|
|
||||||
- npmci npm prepare
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
# ====================
|
|
||||||
# security stage
|
|
||||||
# ====================
|
|
||||||
auditProductionDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --prod
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
auditDevDependencies:
|
|
||||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
|
||||||
stage: security
|
|
||||||
script:
|
|
||||||
- npmci command npm config set registry https://registry.npmjs.org
|
|
||||||
- npmci command pnpm audit --audit-level=high --dev
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
allow_failure: true
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# test stage
|
|
||||||
# ====================
|
|
||||||
|
|
||||||
testStable:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm test
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
testBuild:
|
|
||||||
stage: test
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci npm build
|
|
||||||
coverage: /\d+.?\d+?\%\s*coverage/
|
|
||||||
tags:
|
|
||||||
- docker
|
|
||||||
|
|
||||||
release:
|
|
||||||
stage: release
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm publish
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
# ====================
|
|
||||||
# metadata stage
|
|
||||||
# ====================
|
|
||||||
codequality:
|
|
||||||
stage: metadata
|
|
||||||
allow_failure: true
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
script:
|
|
||||||
- npmci command npm install -g typescript
|
|
||||||
- npmci npm prepare
|
|
||||||
- npmci npm install
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- priv
|
|
||||||
|
|
||||||
trigger:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci trigger
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
|
|
||||||
pages:
|
|
||||||
stage: metadata
|
|
||||||
script:
|
|
||||||
- npmci node install stable
|
|
||||||
- npmci npm install
|
|
||||||
- npmci command npm run buildDocs
|
|
||||||
tags:
|
|
||||||
- lossless
|
|
||||||
- docker
|
|
||||||
- notpriv
|
|
||||||
only:
|
|
||||||
- tags
|
|
||||||
artifacts:
|
|
||||||
expire_in: 1 week
|
|
||||||
paths:
|
|
||||||
- public
|
|
||||||
allow_failure: true
|
|
56
changelog.md
Normal file
56
changelog.md
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 2024-09-17 - 3.0.6 - fix(core)
|
||||||
|
Fix interactive shell execution and update dependencies
|
||||||
|
|
||||||
|
- Corrected the interactive shell execution logic by separating it into a dedicated method.
|
||||||
|
- Updated development dependencies for `@git.zone/tsbuild`, `@git.zone/tsrun`, `@git.zone/tstest`, `@push.rocks/tapbundle`, and `@types/node`.
|
||||||
|
- Updated runtime dependencies for `@push.rocks/smartpromise`, and `@types/which`.
|
||||||
|
- Removed legacy .gitlab-ci.yml file.
|
||||||
|
|
||||||
|
## 2024-05-29 - 3.0.5 - Documentation
|
||||||
|
update description
|
||||||
|
|
||||||
|
## 2024-04-18 - 3.0.4 to 3.0.5 - Maintenance
|
||||||
|
Bug fixes and configuration updates
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
- update tsconfig
|
||||||
|
- update npmextra.json: githost
|
||||||
|
|
||||||
|
## 2024-03-16 - 3.0.3 to 3.0.4 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2023-06-22 - 2.0.30 to 3.0.3 - Major Update
|
||||||
|
Major changes including breaking changes, bug fixes, and improvements.
|
||||||
|
|
||||||
|
- BREAKING CHANGE(core): switched to ES syntax and added support for interactivity
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2021-11-07 - 2.0.27 to 2.0.30 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): cosmetics
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2021-08-17 - 2.0.26 to 2.0.27 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2020-05-22 - 2.0.25 to 2.0.26 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2019-08-27 - 2.0.22 to 2.0.25 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
||||||
|
|
||||||
|
## 2019-05-28 - 2.0.16 to 2.0.22 - Maintenance
|
||||||
|
Bug fixes
|
||||||
|
|
||||||
|
- fix(core): update
|
14
package.json
14
package.json
@ -33,17 +33,17 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://code.foss.global/push.rocks/smartshell",
|
"homepage": "https://code.foss.global/push.rocks/smartshell",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@git.zone/tsbuild": "^2.1.66",
|
"@git.zone/tsbuild": "^2.1.84",
|
||||||
"@git.zone/tsrun": "^1.2.44",
|
"@git.zone/tsrun": "^1.2.49",
|
||||||
"@git.zone/tstest": "^1.0.77",
|
"@git.zone/tstest": "^1.0.90",
|
||||||
"@push.rocks/tapbundle": "^5.0.23",
|
"@push.rocks/tapbundle": "^5.0.24",
|
||||||
"@types/node": "^20.12.7"
|
"@types/node": "^22.5.5"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@push.rocks/smartdelay": "^3.0.1",
|
"@push.rocks/smartdelay": "^3.0.1",
|
||||||
"@push.rocks/smartexit": "^1.0.23",
|
"@push.rocks/smartexit": "^1.0.23",
|
||||||
"@push.rocks/smartpromise": "^4.0.2",
|
"@push.rocks/smartpromise": "^4.0.4",
|
||||||
"@types/which": "^3.0.3",
|
"@types/which": "^3.0.4",
|
||||||
"tree-kill": "^1.2.2",
|
"tree-kill": "^1.2.2",
|
||||||
"which": "^4.0.0"
|
"which": "^4.0.0"
|
||||||
},
|
},
|
||||||
|
7605
pnpm-lock.yaml
generated
7605
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,8 @@
|
|||||||
/**
|
/**
|
||||||
* autocreated commitinfo by @pushrocks/commitinfo
|
* autocreated commitinfo by @push.rocks/commitinfo
|
||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartshell',
|
name: '@push.rocks/smartshell',
|
||||||
version: '3.0.5',
|
version: '3.0.6',
|
||||||
description: 'A library for executing shell commands using promises.'
|
description: 'A library for executing shell commands using promises.'
|
||||||
}
|
}
|
||||||
|
@ -39,39 +39,51 @@ export class Smartshell {
|
|||||||
interactive?: boolean;
|
interactive?: boolean;
|
||||||
}): Promise<IExecResult | IExecResultStreaming | void> {
|
}): Promise<IExecResult | IExecResultStreaming | void> {
|
||||||
if (options.interactive) {
|
if (options.interactive) {
|
||||||
if (process.env.CI) {
|
return await this._execInteractive(options);
|
||||||
return;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const done = plugins.smartpromise.defer();
|
return await this._execCommand(options);
|
||||||
|
}
|
||||||
// Notice that stdio is set to 'inherit'
|
|
||||||
const shell = cp.spawn(options.commandString, {
|
|
||||||
stdio: 'inherit',
|
|
||||||
shell: true,
|
|
||||||
detached: true
|
|
||||||
});
|
|
||||||
|
|
||||||
this.smartexit.addProcess(shell);
|
|
||||||
|
|
||||||
shell.on('close', (code) => {
|
|
||||||
console.log(`interactive shell terminated with code ${code}`);
|
|
||||||
this.smartexit.removeProcess(shell);
|
|
||||||
done.resolve();
|
|
||||||
});
|
|
||||||
|
|
||||||
await done.promise;
|
|
||||||
|
|
||||||
|
private async _execInteractive(options: {
|
||||||
|
commandString: string;
|
||||||
|
interactive?: boolean;
|
||||||
|
}): Promise<void> {
|
||||||
|
if (process.env.CI) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const done = plugins.smartpromise.defer();
|
||||||
|
|
||||||
|
const shell = cp.spawn(options.commandString, {
|
||||||
|
stdio: 'inherit',
|
||||||
|
shell: true,
|
||||||
|
detached: true
|
||||||
|
});
|
||||||
|
|
||||||
|
this.smartexit.addProcess(shell);
|
||||||
|
|
||||||
|
shell.on('close', (code) => {
|
||||||
|
console.log(`interactive shell terminated with code ${code}`);
|
||||||
|
this.smartexit.removeProcess(shell);
|
||||||
|
done.resolve();
|
||||||
|
});
|
||||||
|
|
||||||
|
await done.promise;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async _execCommand(options: {
|
||||||
|
commandString: string;
|
||||||
|
silent?: boolean;
|
||||||
|
strict?: boolean;
|
||||||
|
streaming?: boolean;
|
||||||
|
}): Promise<IExecResult | IExecResultStreaming> {
|
||||||
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
const done = plugins.smartpromise.defer<IExecResult | IExecResultStreaming>();
|
||||||
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
const childProcessEnded = plugins.smartpromise.defer<IExecResult>();
|
||||||
|
|
||||||
let commandToExecute = options.commandString;
|
const commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
||||||
commandToExecute = this.shellEnv.createEnvExecString(options.commandString);
|
|
||||||
|
|
||||||
const spawnlogInstance = new ShellLog();
|
const shellLogInstance = new ShellLog();
|
||||||
const execChildProcess = cp.spawn(commandToExecute, [], {
|
const execChildProcess = cp.spawn(commandToExecute, [], {
|
||||||
shell: true,
|
shell: true,
|
||||||
cwd: process.cwd(),
|
cwd: process.cwd(),
|
||||||
@ -83,16 +95,16 @@ export class Smartshell {
|
|||||||
|
|
||||||
execChildProcess.stdout.on('data', (data) => {
|
execChildProcess.stdout.on('data', (data) => {
|
||||||
if (!options.silent) {
|
if (!options.silent) {
|
||||||
spawnlogInstance.writeToConsole(data);
|
shellLogInstance.writeToConsole(data);
|
||||||
}
|
}
|
||||||
spawnlogInstance.addToBuffer(data);
|
shellLogInstance.addToBuffer(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
execChildProcess.stderr.on('data', (data) => {
|
execChildProcess.stderr.on('data', (data) => {
|
||||||
if (!options.silent) {
|
if (!options.silent) {
|
||||||
spawnlogInstance.writeToConsole(data);
|
shellLogInstance.writeToConsole(data);
|
||||||
}
|
}
|
||||||
spawnlogInstance.addToBuffer(data);
|
shellLogInstance.addToBuffer(data);
|
||||||
});
|
});
|
||||||
|
|
||||||
execChildProcess.on('exit', (code, signal) => {
|
execChildProcess.on('exit', (code, signal) => {
|
||||||
@ -103,7 +115,7 @@ export class Smartshell {
|
|||||||
|
|
||||||
const execResult = {
|
const execResult = {
|
||||||
exitCode: code,
|
exitCode: code,
|
||||||
stdout: spawnlogInstance.logStore.toString(),
|
stdout: shellLogInstance.logStore.toString(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!options.streaming) {
|
if (!options.streaming) {
|
||||||
@ -191,4 +203,4 @@ export class Smartshell {
|
|||||||
public async execAndWaitForLineSilent(commandString: string, regexArg: RegExp) {
|
public async execAndWaitForLineSilent(commandString: string, regexArg: RegExp) {
|
||||||
return this.execAndWaitForLine(commandString, regexArg, true);
|
return this.execAndWaitForLine(commandString, regexArg, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user