@effectionx/tinyexec 0.1.2

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/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # tinyexec
2
+
3
+ Effection compatible wrapper around
4
+ [tinyexec](https://www.npmjs.com/package/tinyexec) package.
5
+
6
+ ---
7
+
8
+ To run a process, use the `x` function:
9
+
10
+ ```ts
11
+ import { x } from "@effectionx/tinyexec";
12
+ import { each, main } from "effection";
13
+
14
+ await main(function* () {
15
+ let proc = yield* x("echo", ["Hello, World"]);
16
+
17
+ for (let line of yield* each(proc.lines)) {
18
+ console.log(line);
19
+ yield* each.next();
20
+ }
21
+ });
22
+ // => prints "Hello, World"
23
+ ```
24
+
25
+ The process will be automatically destroyed whenever it passes out of scope. For
26
+ example, the following shows the output of the `top` command for five seconds
27
+ before exiting.
28
+
29
+ ```ts
30
+ import { x } from "@effectionx/tinyexec";
31
+ import { each, main, sleep, spawn } from "effection";
32
+
33
+ await main(function* () {
34
+ yield* spawn(function* () {
35
+ let proc = yield* x("top");
36
+
37
+ for (let line of yield* each(proc.lines)) {
38
+ console.log(line);
39
+ yield* each.next();
40
+ }
41
+ });
42
+
43
+ yield* sleep(5000);
44
+ });
45
+ ```
package/esm/mod.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./tinyexec.js";
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
package/esm/mod.js ADDED
@@ -0,0 +1 @@
1
+ export * from "./tinyexec.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,27 @@
1
+ import { type Operation, type Stream } from "effection";
2
+ import { type KillSignal, type Options, type Output } from "tinyexec";
3
+ /**
4
+ * Wraps a [tinyexec](https://github.com/tinylibs/tinyexec) process.
5
+ * To create one use the {@link x} function.
6
+ */
7
+ export interface TinyProcess extends Operation<Output> {
8
+ /**
9
+ * A stream of lines coming from both stdin and stdout. The stream
10
+ * will terminate when stdout and stderr are closed which usually
11
+ * corresponds to the process ending.
12
+ */
13
+ lines: Stream<string, void>;
14
+ /**
15
+ * Send `signal` to this process
16
+ * @paramu signal - the OS signal to send to the process
17
+ */
18
+ kill(signal?: KillSignal): Operation<void>;
19
+ }
20
+ /**
21
+ * Run OS process with `cmd`
22
+ *
23
+ * This will create a {@link TinyProcess} resource. If it is still running
24
+ * when it passes out of scope, it will be killed.
25
+ */
26
+ export declare function x(cmd: string, args?: string[], options?: Partial<Options>): Operation<TinyProcess>;
27
+ //# sourceMappingURL=tinyexec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tinyexec.d.ts","sourceRoot":"","sources":["../src/tinyexec.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,MAAM,EAEZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,MAAM,EAEZ,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,SAAS,CAAC,MAAM,CAAC;IACpD;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE5B;;;OAGG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAgB,CAAC,CACf,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAM,EAAO,EACnB,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GACzB,SAAS,CAAC,WAAW,CAAC,CAyBxB"}
@@ -0,0 +1,31 @@
1
+ import { call, resource, stream, } from "effection";
2
+ import { x as $x, } from "tinyexec";
3
+ /**
4
+ * Run OS process with `cmd`
5
+ *
6
+ * This will create a {@link TinyProcess} resource. If it is still running
7
+ * when it passes out of scope, it will be killed.
8
+ */
9
+ export function x(cmd, args = [], options) {
10
+ return resource(function* (provide) {
11
+ let tinyexec = $x(cmd, args, { ...options });
12
+ let promise = tinyexec;
13
+ let output = call(() => promise);
14
+ let tinyproc = {
15
+ *[Symbol.iterator]() {
16
+ return yield* output;
17
+ },
18
+ lines: stream(tinyexec),
19
+ *kill(signal) {
20
+ tinyexec.kill(signal);
21
+ yield* output;
22
+ },
23
+ };
24
+ try {
25
+ yield* provide(tinyproc);
26
+ }
27
+ finally {
28
+ yield* tinyproc.kill();
29
+ }
30
+ });
31
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@effectionx/tinyexec",
3
+ "version": "0.1.2",
4
+ "author": "engineering@frontside.com",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/thefrontside/effectionx.git"
8
+ },
9
+ "license": "MIT",
10
+ "bugs": {
11
+ "url": "https://github.com/thefrontside/effectionx/issues"
12
+ },
13
+ "main": "./script/mod.js",
14
+ "module": "./esm/mod.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./esm/mod.js",
18
+ "require": "./script/mod.js"
19
+ }
20
+ },
21
+ "engines": {
22
+ "node": ">= 16"
23
+ },
24
+ "sideEffects": false,
25
+ "dependencies": {
26
+ "effection": "3.0.3",
27
+ "tinyexec": "0.3.2"
28
+ },
29
+ "_generatedBy": "dnt@dev"
30
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./tinyexec.js";
2
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
package/script/mod.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./tinyexec.js"), exports);
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,27 @@
1
+ import { type Operation, type Stream } from "effection";
2
+ import { type KillSignal, type Options, type Output } from "tinyexec";
3
+ /**
4
+ * Wraps a [tinyexec](https://github.com/tinylibs/tinyexec) process.
5
+ * To create one use the {@link x} function.
6
+ */
7
+ export interface TinyProcess extends Operation<Output> {
8
+ /**
9
+ * A stream of lines coming from both stdin and stdout. The stream
10
+ * will terminate when stdout and stderr are closed which usually
11
+ * corresponds to the process ending.
12
+ */
13
+ lines: Stream<string, void>;
14
+ /**
15
+ * Send `signal` to this process
16
+ * @paramu signal - the OS signal to send to the process
17
+ */
18
+ kill(signal?: KillSignal): Operation<void>;
19
+ }
20
+ /**
21
+ * Run OS process with `cmd`
22
+ *
23
+ * This will create a {@link TinyProcess} resource. If it is still running
24
+ * when it passes out of scope, it will be killed.
25
+ */
26
+ export declare function x(cmd: string, args?: string[], options?: Partial<Options>): Operation<TinyProcess>;
27
+ //# sourceMappingURL=tinyexec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tinyexec.d.ts","sourceRoot":"","sources":["../src/tinyexec.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,MAAM,EAEZ,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,KAAK,MAAM,EAEZ,MAAM,UAAU,CAAC;AAElB;;;GAGG;AACH,MAAM,WAAW,WAAY,SAAQ,SAAS,CAAC,MAAM,CAAC;IACpD;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAE5B;;;OAGG;IACH,IAAI,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAgB,CAAC,CACf,GAAG,EAAE,MAAM,EACX,IAAI,GAAE,MAAM,EAAO,EACnB,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GACzB,SAAS,CAAC,WAAW,CAAC,CAyBxB"}
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.x = x;
4
+ const effection_1 = require("effection");
5
+ const tinyexec_1 = require("tinyexec");
6
+ /**
7
+ * Run OS process with `cmd`
8
+ *
9
+ * This will create a {@link TinyProcess} resource. If it is still running
10
+ * when it passes out of scope, it will be killed.
11
+ */
12
+ function x(cmd, args = [], options) {
13
+ return (0, effection_1.resource)(function* (provide) {
14
+ let tinyexec = (0, tinyexec_1.x)(cmd, args, { ...options });
15
+ let promise = tinyexec;
16
+ let output = (0, effection_1.call)(() => promise);
17
+ let tinyproc = {
18
+ *[Symbol.iterator]() {
19
+ return yield* output;
20
+ },
21
+ lines: (0, effection_1.stream)(tinyexec),
22
+ *kill(signal) {
23
+ tinyexec.kill(signal);
24
+ yield* output;
25
+ },
26
+ };
27
+ try {
28
+ yield* provide(tinyproc);
29
+ }
30
+ finally {
31
+ yield* tinyproc.kill();
32
+ }
33
+ });
34
+ }