@opencode/util 2.0.17 → 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.
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.17",
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": {