Skip to content

Commit dce0de7

Browse files
committed
feat: Added stdin option
1 parent 960e7dd commit dce0de7

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codify-plugin-lib",
3-
"version": "1.0.182-beta9",
3+
"version": "1.0.182-beta10",
44
"description": "Library plugin library",
55
"main": "dist/index.js",
66
"typings": "dist/index.d.ts",
@@ -22,7 +22,7 @@
2222
"ajv": "^8.12.0",
2323
"ajv-formats": "^2.1.1",
2424
"clean-deep": "^3.4.0",
25-
"codify-schemas": "1.0.86-beta4",
25+
"codify-schemas": "1.0.86-beta5",
2626
"lodash.isequal": "^4.5.0",
2727
"nanoid": "^5.0.9",
2828
"strip-ansi": "^7.1.0",

src/pty/index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export enum SpawnStatus {
2828
*/
2929
export interface SpawnOptions {
3030
cwd?: string;
31-
env?: Record<string, unknown>,
32-
interactive?: boolean,
33-
requiresRoot?: boolean,
31+
env?: Record<string, unknown>;
32+
interactive?: boolean;
33+
requiresRoot?: boolean;
34+
stdin?: boolean;
3435
}
3536

3637
export class SpawnError extends Error {

src/pty/seqeuntial-pty.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ export class SequentialPty implements IPty {
3434
}
3535

3636
async spawnSafe(cmd: string, options?: SpawnOptions): Promise<SpawnResult> {
37+
if (cmd.includes('sudo')) {
38+
throw new Error('Do not directly use sudo. Use the option { requiresRoot: true } instead')
39+
}
40+
3741
// If sudo is required, we must delegate to the main codify process.
38-
if (options?.interactive || options?.requiresRoot) {
42+
if (options?.stdin || options?.requiresRoot) {
3943
return this.externalSpawn(cmd, options);
4044
}
4145

@@ -59,8 +63,10 @@ export class SequentialPty implements IPty {
5963
const initialCols = process.stdout.columns ?? 80;
6064
const initialRows = process.stdout.rows ?? 24;
6165

66+
const args = options?.interactive ? ['-i', '-c', cmd] : ['-c', cmd]
67+
6268
// Run the command in a pty for interactivity
63-
const mPty = pty.spawn(this.getDefaultShell(), ['-c', cmd], {
69+
const mPty = pty.spawn(this.getDefaultShell(), args, {
6470
...options,
6571
cols: initialCols,
6672
rows: initialRows,

0 commit comments

Comments
 (0)