functionalscript 0.12.7 → 0.12.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/io/module.f.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Effect } from '../types/effects/module.f.ts';
2
- import type { ExecResult, Headers, IoResult, NodeOp } from '../types/effects/node/module.f.ts';
2
+ import type { ExecParam, ExecResult, Headers, IoResult, NodeOp } from '../types/effects/node/module.f.ts';
3
3
  import { type Result } from '../types/result/module.f.ts';
4
4
  /**
5
5
  * Represents a directory entry (file or directory) in the filesystem
@@ -97,7 +97,7 @@ export type Http = {
97
97
  readonly createServer: (_: RequestListener) => Server;
98
98
  };
99
99
  export type ChildProcess = {
100
- readonly exec: (command: string) => Promise<IoResult<ExecResult>>;
100
+ readonly exec: (param: ExecParam) => Promise<IoResult<ExecResult>>;
101
101
  };
102
102
  /**
103
103
  * Core IO operations interface providing access to system resources
package/io/module.js CHANGED
@@ -8,12 +8,14 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
8
8
  };
9
9
  import http from 'node:http';
10
10
  import { exec } from 'node:child_process';
11
- import { fromIo, run } from "./module.f.js";
12
11
  import fs from 'node:fs';
13
12
  import process from 'node:process';
13
+ import { promisify } from 'node:util';
14
+ import { fromIo, run } from "./module.f.js";
14
15
  import { concat } from "../path/module.f.js";
15
16
  import { error, ok } from "../types/result/module.f.js";
16
17
  const prefix = 'file:///';
18
+ const execAsync = promisify(exec);
17
19
  export const io = {
18
20
  console,
19
21
  fs,
@@ -43,7 +45,13 @@ export const io = {
43
45
  },
44
46
  http,
45
47
  childProcess: {
46
- exec: command => new Promise(resolve => exec(command, (e, stdout, stderr) => resolve(e !== null ? error(e) : ok({ stdout, stderr })))),
48
+ exec: ([command, stdin]) => {
49
+ const promise = execAsync(command);
50
+ if (stdin !== undefined && promise.child.stdin !== null) {
51
+ promise.child.stdin.end(stdin);
52
+ }
53
+ return promise.then(({ stdout, stderr }) => ok({ stdout, stderr }), (e) => error(e));
54
+ },
47
55
  },
48
56
  };
49
57
  export const legacyRun = run(io);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "functionalscript",
3
- "version": "0.12.7",
3
+ "version": "0.12.8",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "**/*.js",
@@ -47,8 +47,9 @@ export type ExecResult = {
47
47
  readonly stdout: string;
48
48
  readonly stderr: string;
49
49
  };
50
- export type Exec = readonly ['exec', (_: string) => IoResult<ExecResult>];
51
- export declare const exec: Func<Exec>;
50
+ export type ExecParam = readonly [string, string?];
51
+ export type Exec = readonly ['exec', (_: ExecParam) => IoResult<ExecResult>];
52
+ export declare const exec: RestFunc<Exec>;
52
53
  export type Fs = Mkdir | ReadFile | Readdir | WriteFile | Rm | Exec;
53
54
  export type Error = ['error', (_: string) => void];
54
55
  export declare const error: Func<Error>;
@@ -15,7 +15,7 @@ export const readFile = do_('readFile');
15
15
  export const readdir = doRest('readdir');
16
16
  export const writeFile = doRest('writeFile');
17
17
  export const rm = do_('rm');
18
- export const exec = do_('exec');
18
+ export const exec = doRest('exec');
19
19
  export const error = do_('error');
20
20
  export const log = do_('log');
21
21
  export const createServer = do_('createServer');