@lowlighter/run 2.0.3 → 2.0.5

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 CHANGED
@@ -9,6 +9,42 @@
9
9
  > [!WARNING]
10
10
  > Deno exclusive!
11
11
 
12
+ ## 📑 Examples
13
+
14
+ ### Run a command
15
+
16
+ ```ts
17
+ import { command } from "./command.ts"
18
+
19
+ // Commands are run asynchronously, and support Deno.command options alongside additional options
20
+ // For example, stdio can also be set to a Logger level too or you can automatically append an extension when running on Windows
21
+ await command("deno", ["version"], { stdout: "debug", stderr: "piped", winext: ".exe" })
22
+
23
+ // Commands can be run synchronously too, and can also throw an error automatically when the process exits with a non-zero code
24
+ command("deno", ["version"], { sync: true, throw: true })
25
+ ```
26
+
27
+ ### Writing to stdin
28
+
29
+ ```ts
30
+ import { command } from "./command.ts"
31
+
32
+ const { stdout } = await command("deno", ["repl"], {
33
+ env: { NO_COLOR: "true" },
34
+ // Passing a callback will automatically set `stdin` to `"piped"`
35
+ // You can then write to the process using utility functions
36
+ callback: async ({ i, stdio, write, close, wait }) => {
37
+ if ((!stdio.stdout.includes("exit using")) || i) {
38
+ return
39
+ }
40
+ await write("console.log('hello')")
41
+ await wait(1000)
42
+ close()
43
+ },
44
+ })
45
+ console.assert(stdout.includes("hello"))
46
+ ```
47
+
12
48
  ## ✨ Features
13
49
 
14
50
  - Supports `stdin` interactivity through callbacks.
package/command.ts CHANGED
@@ -161,9 +161,18 @@ export function command(bin: string, args: string[], options?: options & { sync:
161
161
  * @example
162
162
  * ```ts
163
163
  * import { command } from "./command.ts"
164
+ *
164
165
  * const { stdout } = await command("deno", ["repl"], {
165
166
  * env: { NO_COLOR: "true" },
166
- * callback: ({ i, write, close }) => i === 0 ? write("console.log('hello')") : close(),
167
+ * // Passing a callback will automatically set `stdin` to `"piped"`
168
+ * // You can then write to the process using utility functions
169
+ * callback: async ({ i, stdio, write, close, wait }) => {
170
+ * if ((!stdio.stdout.includes("exit using")) || (i))
171
+ * return
172
+ * await write("console.log('hello')")
173
+ * await wait(1000)
174
+ * close()
175
+ * },
167
176
  * })
168
177
  * console.assert(stdout.includes("hello"))
169
178
  * ```
package/command_test.ts CHANGED
@@ -20,7 +20,7 @@ test("deno")("command() can spawn subprocesses synchronously", () => {
20
20
  }, { permissions: { run: ["deno"] } })
21
21
 
22
22
  test("deno")("command() handles callback<write()> and callback<close()> calls", async () => {
23
- const result = await command("deno", ["repl"], { env: { NO_COLOR: "true" }, callback: ({ i, write, close }) => i === 0 ? write("console.log('hello')") : close() })
23
+ const result = await command("deno", ["repl"], { stdin: "debug", env: { NO_COLOR: "true" }, callback: ({ i, write, close }) => i === 0 ? write("console.log('hello')") : close() })
24
24
  expect(result).toMatchObject({ success: true, code: 0, stdin: "console.log('hello')" })
25
25
  expect(result.stdout).toMatch(/hello/)
26
26
  }, { permissions: { run: ["deno"] } })
@@ -48,7 +48,7 @@ test("deno")("command() handles callback<wait()> calls", async () => {
48
48
  for (const sync of [false, true]) {
49
49
  for (const mode of ["inherit", "piped", null, "debug", "log", "info", "warn", "error"] as const) {
50
50
  test("deno")(`command() supports stdio set to "${mode}" in "${sync ? "sync" : "async"}" mode`, async () => {
51
- const result = await command("deno", ["--version"], {
51
+ const result = await command("deno", ["eval", "null"], {
52
52
  logger: new Logger({ level: "disabled" }),
53
53
  env: { NO_COLOR: "true" },
54
54
  stdin: mode,
@@ -121,3 +121,7 @@ test("deno")("command() does nothing in dryrun", async () => {
121
121
  expect(command("deno", ["--version"], { dryrun: true, sync: true })).toMatchObject({ success: true, code: 0, stdio: [], stdin: "", stderr: "", stdout: "" })
122
122
  await expect(command("deno", ["--version"], { dryrun: true })).resolves.toMatchObject({ success: true, code: 0, stdio: [], stdin: "", stderr: "", stdout: "" })
123
123
  }, { permissions: { run: ["deno"] } })
124
+
125
+ test("deno")("command() appends windows extension when os platform is windows", () => {
126
+ expect(command("", ["--version"], { logger: new Logger({ level: "disabled" }), sync: true, winext: "deno", os: "windows" })).toMatchObject({ success: true, code: 0 })
127
+ }, { permissions: { run: ["deno"] } })
package/deno.jsonc CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "icon": "⏯️",
3
3
  "name": "@libs/run",
4
- "version": "2.0.3",
4
+ "version": "2.0.5",
5
5
  "description": "Utilities to run subprocess.",
6
6
  "keywords": [
7
7
  "subprocess",
@@ -43,11 +43,13 @@
43
43
  "tasks": {
44
44
  "test": "deno test --allow-run=deno,node,bun,npx --no-prompt --coverage --clean --trace-leaks --doc",
45
45
  "dev": "deno fmt && deno task test --filter='/^\\[deno\\]/' && deno coverage --exclude=.js --detailed && deno task lint",
46
- "test:deno": "deno fmt --check && deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js && deno lint",
47
- "test:deno-future": "DENO_FUTURE=1 && deno task test:deno",
48
- "test:others": "deno fmt --check && deno task test --filter='/^\\[node|bun \\]/' --quiet && deno coverage --exclude=.js && deno lint",
46
+ "test:deno": "deno task clean:deno && deno fmt --check && deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js && deno lint",
47
+ "test:deno-future": "deno task clean:deno && DENO_FUTURE=1 && deno task test:deno",
48
+ "test:others": "deno task clean:others && deno fmt --check && deno task test --filter='/^\\[node|bun \\]/' --quiet && deno coverage --exclude=.js && deno lint",
49
49
  "coverage:html": "deno task test --filter='/^\\[deno\\]/' --quiet && deno coverage --exclude=.js --html && sleep 1",
50
- "lint": "deno fmt --check && deno lint && deno doc --lint mod.ts && deno publish --dry-run --quiet --allow-dirty"
50
+ "lint": "deno fmt --check && deno lint && deno doc --lint mod.ts && deno publish --dry-run --quiet --allow-dirty",
51
+ "clean:deno": "rm -rf node_modules .npmrc deno.lock",
52
+ "clean:others": "rm -rf node_modules .npmrc deno.lock package.json package-lock.json bun.lockb"
51
53
  },
52
54
  "lint": {
53
55
  "rules": {
package/deno.lock CHANGED
@@ -2,22 +2,22 @@
2
2
  "version": "3",
3
3
  "packages": {
4
4
  "specifiers": {
5
- "jsr:@libs/logger": "jsr:@libs/logger@2.1.1",
6
- "jsr:@libs/logger@2": "jsr:@libs/logger@2.1.1",
5
+ "jsr:@libs/logger": "jsr:@libs/logger@2.1.2",
6
+ "jsr:@libs/logger@2": "jsr:@libs/logger@2.1.2",
7
7
  "jsr:@libs/testing@2": "jsr:@libs/testing@2.2.4",
8
8
  "jsr:@libs/typing@2": "jsr:@libs/typing@2.8.2",
9
- "jsr:@std/assert@1": "jsr:@std/assert@1.0.2",
10
- "jsr:@std/assert@^1.0.1": "jsr:@std/assert@1.0.2",
11
- "jsr:@std/async@1": "jsr:@std/async@1.0.3",
12
- "jsr:@std/bytes@^1.0.2-rc.3": "jsr:@std/bytes@1.0.2",
13
- "jsr:@std/expect@1": "jsr:@std/expect@1.0.0",
14
- "jsr:@std/http@1": "jsr:@std/http@1.0.3",
15
- "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1",
16
- "jsr:@std/streams@1": "jsr:@std/streams@1.0.2"
9
+ "jsr:@std/assert@1": "jsr:@std/assert@1.0.3",
10
+ "jsr:@std/assert@^1.0.3": "jsr:@std/assert@1.0.3",
11
+ "jsr:@std/async@1": "jsr:@std/async@1.0.4",
12
+ "jsr:@std/bytes@^1.0.2": "jsr:@std/bytes@1.0.2",
13
+ "jsr:@std/expect@1": "jsr:@std/expect@1.0.1",
14
+ "jsr:@std/http@1": "jsr:@std/http@1.0.4",
15
+ "jsr:@std/internal@^1.0.2": "jsr:@std/internal@1.0.2",
16
+ "jsr:@std/streams@1": "jsr:@std/streams@1.0.3"
17
17
  },
18
18
  "jsr": {
19
- "@libs/logger@2.1.1": {
20
- "integrity": "508216c245aa7a13d55972cec6cf2ff45b341469334634a2748cd60c938677d6"
19
+ "@libs/logger@2.1.2": {
20
+ "integrity": "2a5f4b148fd8d6b1221ff89cff73367ca0511137f4d6548c532b6e220ed22bcc"
21
21
  },
22
22
  "@libs/testing@2.2.4": {
23
23
  "integrity": "3ef407b62cf18424b3e2e604eef5df81d3c07cf8adb4b78ab4cf40db2a029f2c",
@@ -31,35 +31,35 @@
31
31
  "@libs/typing@2.8.2": {
32
32
  "integrity": "c53f8aad9b01621de893aeac5d6cd592ec2ce783f8e89b677dcd81490a3be0a0"
33
33
  },
34
- "@std/assert@1.0.2": {
35
- "integrity": "ccacec332958126deaceb5c63ff8b4eaf9f5ed0eac9feccf124110435e59e49c",
34
+ "@std/assert@1.0.3": {
35
+ "integrity": "b0d03ce1ced880df67132eea140623010d415848df66f6aa5df76507ca7c26d8",
36
36
  "dependencies": [
37
- "jsr:@std/internal@^1.0.1"
37
+ "jsr:@std/internal@^1.0.2"
38
38
  ]
39
39
  },
40
- "@std/async@1.0.3": {
41
- "integrity": "6ed64678db43451683c6c176a21426a2ccd21ba0269ebb2c36133ede3f165792"
40
+ "@std/async@1.0.4": {
41
+ "integrity": "373f5168a01b46ecaabc785d4e0f9ef18a010ab867af069fb905d93a9129ae5b"
42
42
  },
43
43
  "@std/bytes@1.0.2": {
44
44
  "integrity": "fbdee322bbd8c599a6af186a1603b3355e59a5fb1baa139f8f4c3c9a1b3e3d57"
45
45
  },
46
- "@std/expect@1.0.0": {
47
- "integrity": "030275683c23d6708878c5439a3ffd99285948d708e00835fd38fcef9a0bb921",
46
+ "@std/expect@1.0.1": {
47
+ "integrity": "44075d9c2cb701ddfc4d5a260da2fb26ba3cfd94c45d3a0359f63cabbf85a058",
48
48
  "dependencies": [
49
- "jsr:@std/assert@^1.0.1",
50
- "jsr:@std/internal@^1.0.1"
49
+ "jsr:@std/assert@^1.0.3",
50
+ "jsr:@std/internal@^1.0.2"
51
51
  ]
52
52
  },
53
- "@std/http@1.0.3": {
54
- "integrity": "bff3770c4df4711567de1711fe988d28db9535be0c9b0f1d2de8d0fb97e8b44c"
53
+ "@std/http@1.0.4": {
54
+ "integrity": "1a8142217907d49c4687f90ef3d257e7df2baf344c5122c322d7316df09df453"
55
55
  },
56
- "@std/internal@1.0.1": {
57
- "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6"
56
+ "@std/internal@1.0.2": {
57
+ "integrity": "f4cabe2021352e8bfc24e6569700df87bf070914fc38d4b23eddd20108ac4495"
58
58
  },
59
- "@std/streams@1.0.2": {
60
- "integrity": "187c3c875675221f5355807a735e51b0f8769caade2cbca6d7f4fa710ea4ace4",
59
+ "@std/streams@1.0.3": {
60
+ "integrity": "d62e645ab981cee2c3d03040eb03cf387fc6bceef6d4564f3ed485a43741a81f",
61
61
  "dependencies": [
62
- "jsr:@std/bytes@^1.0.2-rc.3"
62
+ "jsr:@std/bytes@^1.0.2"
63
63
  ]
64
64
  }
65
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowlighter/run",
3
- "version": "2.0.3",
3
+ "version": "2.0.5",
4
4
  "type": "module",
5
5
  "scripts": {},
6
6
  "dependencies": {},