@opencode/util 2.0.16 → 2.0.18

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.
@@ -1,3 +1,7 @@
1
1
  import { ChildProcessSpawner } from "effect/unstable/process/ChildProcessSpawner";
2
+ export declare class KilledBySignal extends Error {
3
+ readonly signal: NodeJS.Signals;
4
+ constructor(signal: NodeJS.Signals);
5
+ }
2
6
  export declare const node: import("./effect/layer-node.js").Provider<ChildProcessSpawner, never, import("./effect/layer-node.js").Tag<"global">>;
3
7
  export * as CrossSpawnSpawner from "./cross-spawn-spawner.js";
@@ -67,6 +67,13 @@ const toPlatformError = (method, err, command) => {
67
67
  cause: err,
68
68
  });
69
69
  };
70
+ export class KilledBySignal extends Error {
71
+ signal;
72
+ constructor(signal) {
73
+ super(`Process interrupted due to receipt of signal: '${signal}'`);
74
+ this.signal = signal;
75
+ }
76
+ }
70
77
  const makeCrossSpawnSpawner = Effect.gen(function* () {
71
78
  const fs = yield* FileSystem.FileSystem;
72
79
  const path = yield* Path.Path;
@@ -377,7 +384,8 @@ const makeCrossSpawnSpawner = Effect.gen(function* () {
377
384
  exitCode: Effect.flatMap(completion, ([code, signal]) => {
378
385
  if (Predicate.isNotNull(code))
379
386
  return Effect.succeed(ExitCode(code));
380
- return Effect.fail(toPlatformError("exitCode", new Error(`Process interrupted due to receipt of signal: '${signal}'`), command));
387
+ // Node reports a signal whenever the exit code is null.
388
+ return Effect.fail(toPlatformError("exitCode", new KilledBySignal(signal), command));
381
389
  }),
382
390
  kill: (opts) => stop(command, proc, closed, stopOutput, opts),
383
391
  unref: Effect.sync(() => {
package/dist/open.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export declare function openUrl(input: string): Promise<import("child_process").ChildProcess>;
2
+ export declare function openPath(path: string): Promise<import("child_process").ChildProcess>;
package/dist/open.js ADDED
@@ -0,0 +1,10 @@
1
+ import open from "open";
2
+ export function openUrl(input) {
3
+ const url = URL.canParse(input) ? new URL(input) : undefined;
4
+ if (!url || (url.protocol !== "http:" && url.protocol !== "https:"))
5
+ return Promise.reject(new Error(`Only http and https links can be opened in the browser: ${input}`));
6
+ return open(url.href);
7
+ }
8
+ export function openPath(path) {
9
+ return open(path);
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { describe, expect, test } from "bun:test";
2
+ import { openUrl } from "./open.js";
3
+ describe("openUrl", () => {
4
+ test("rejects values that are not URLs", async () => {
5
+ await expect(openUrl("not a url")).rejects.toThrow("Only http and https links");
6
+ await expect(openUrl("")).rejects.toThrow("Only http and https links");
7
+ });
8
+ test("rejects non-http schemes", async () => {
9
+ await expect(openUrl("file:///etc/hosts")).rejects.toThrow("Only http and https links");
10
+ await expect(openUrl("javascript:alert(1)")).rejects.toThrow("Only http and https links");
11
+ await expect(openUrl("ms-msdt:/id PCWDiagnostic")).rejects.toThrow("Only http and https links");
12
+ await expect(openUrl("\\\\server\\share\\file.html")).rejects.toThrow("Only http and https links");
13
+ });
14
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode/util",
4
- "version": "2.0.16",
4
+ "version": "2.0.18",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -64,6 +64,7 @@
64
64
  "mime-types": "3.0.2",
65
65
  "minimatch": "10.2.5",
66
66
  "npm-package-arg": "13.0.2",
67
+ "open": "11.0.4",
67
68
  "pacote": "21.5.1"
68
69
  },
69
70
  "devDependencies": {