@opencode/util 0.0.0-reserved → 2.0.1
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/activity-calendar.d.ts +21 -0
- package/dist/activity-calendar.js +42 -0
- package/dist/activity-calendar.test.d.ts +1 -0
- package/dist/activity-calendar.test.js +119 -0
- package/dist/binary.d.ts +7 -0
- package/dist/binary.js +34 -0
- package/dist/binary.test.d.ts +1 -0
- package/dist/binary.test.js +16 -0
- package/dist/bom.d.ts +22 -0
- package/dist/bom.js +36 -0
- package/dist/bom.test.d.ts +1 -0
- package/dist/bom.test.js +19 -0
- package/dist/cross-spawn-spawner.d.ts +3 -0
- package/dist/cross-spawn-spawner.js +438 -0
- package/dist/effect/app-node-platform.d.ts +6 -0
- package/dist/effect/app-node-platform.js +11 -0
- package/dist/effect/app-node.d.ts +62 -0
- package/dist/effect/app-node.js +8 -0
- package/dist/effect/layer-node.d.ts +135 -0
- package/dist/effect/layer-node.js +156 -0
- package/dist/effect/memo-map.d.ts +2 -0
- package/dist/effect/memo-map.js +2 -0
- package/dist/effect/runtime.d.ts +8 -0
- package/dist/effect/runtime.js +16 -0
- package/dist/effect/service-use.d.ts +7 -0
- package/dist/effect/service-use.js +27 -0
- package/dist/effect-flock.d.ts +31 -0
- package/dist/effect-flock.js +186 -0
- package/dist/encode.d.ts +4 -0
- package/dist/encode.js +38 -0
- package/dist/encode.test.d.ts +1 -0
- package/dist/encode.test.js +23 -0
- package/dist/flock.d.ts +30 -0
- package/dist/flock.js +273 -0
- package/dist/fs-util.d.ts +137 -0
- package/dist/fs-util.js +211 -0
- package/dist/glob.d.ts +12 -0
- package/dist/glob.js +26 -0
- package/dist/global-roots.d.ts +8 -0
- package/dist/global-roots.js +17 -0
- package/dist/global-roots.workerd.d.ts +7 -0
- package/dist/global-roots.workerd.js +15 -0
- package/dist/global.d.ts +30 -0
- package/dist/global.js +54 -0
- package/dist/hash.d.ts +4 -0
- package/dist/hash.js +12 -0
- package/dist/npm-config.d.ts +4 -0
- package/dist/npm-config.js +34 -0
- package/dist/npm.d.ts +37 -0
- package/dist/npm.js +386 -0
- package/dist/observability/logging.d.ts +14 -0
- package/dist/observability/logging.js +151 -0
- package/dist/observability/otlp.d.ts +18 -0
- package/dist/observability/otlp.js +76 -0
- package/dist/observability/shared.d.ts +1 -0
- package/dist/observability/shared.js +7 -0
- package/dist/observability.d.ts +13 -0
- package/dist/observability.js +37 -0
- package/dist/patch.d.ts +43 -0
- package/dist/patch.js +331 -0
- package/dist/path.d.ts +4 -0
- package/dist/path.js +33 -0
- package/dist/path.test.d.ts +1 -0
- package/dist/path.test.js +36 -0
- package/dist/process.d.ts +54 -0
- package/dist/process.js +167 -0
- package/dist/retry.d.ts +8 -0
- package/dist/retry.js +37 -0
- package/dist/retry.test.d.ts +1 -0
- package/dist/retry.test.js +31 -0
- package/dist/runtime/import.bun.d.ts +2 -0
- package/dist/runtime/import.bun.js +8 -0
- package/dist/runtime/import.node.d.ts +2 -0
- package/dist/runtime/import.node.js +62 -0
- package/dist/runtime/import.workerd.d.ts +2 -0
- package/dist/runtime/import.workerd.js +7 -0
- package/dist/runtime-import.d.ts +1 -0
- package/dist/runtime-import.js +1 -0
- package/dist/session-title-fallback.d.ts +16 -0
- package/dist/session-title-fallback.js +23 -0
- package/package.json +66 -6
- package/README.md +0 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { retry } from "./retry.js";
|
|
3
|
+
describe("client retry", () => {
|
|
4
|
+
test("retries transient failures up to the configured attempt count", async () => {
|
|
5
|
+
const failures = [];
|
|
6
|
+
const value = await retry(async () => {
|
|
7
|
+
failures.push("attempt");
|
|
8
|
+
if (failures.length < 3)
|
|
9
|
+
throw new Error("Failed to fetch");
|
|
10
|
+
return "ready";
|
|
11
|
+
}, { delay: 0 });
|
|
12
|
+
expect(value).toBe("ready");
|
|
13
|
+
expect(failures).toHaveLength(3);
|
|
14
|
+
});
|
|
15
|
+
test("does not retry other failures", async () => {
|
|
16
|
+
const failures = [];
|
|
17
|
+
await expect(retry(async () => {
|
|
18
|
+
failures.push("attempt");
|
|
19
|
+
throw new Error("invalid response");
|
|
20
|
+
})).rejects.toThrow("invalid response");
|
|
21
|
+
expect(failures).toHaveLength(1);
|
|
22
|
+
});
|
|
23
|
+
test("uses a caller-owned retry condition", async () => {
|
|
24
|
+
const failures = [];
|
|
25
|
+
await expect(retry(async () => {
|
|
26
|
+
failures.push("attempt");
|
|
27
|
+
throw new Error("retry me");
|
|
28
|
+
}, { attempts: 2, delay: 0, retryIf: () => true })).rejects.toThrow("retry me");
|
|
29
|
+
expect(failures).toHaveLength(2);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
export function importModule(specifier) {
|
|
3
|
+
return import(specifier);
|
|
4
|
+
}
|
|
5
|
+
export function resolveModule(specifier, directory) {
|
|
6
|
+
const resolved = Bun.resolveSync(specifier, directory);
|
|
7
|
+
return resolved.startsWith("node:") ? resolved : pathToFileURL(resolved).href;
|
|
8
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Script, constants } from "node:vm";
|
|
2
|
+
import { registerHooks } from "node:module";
|
|
3
|
+
import { statSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { pathToFileURL } from "node:url";
|
|
6
|
+
export async function importModule(specifier) {
|
|
7
|
+
const imported = (await new Script(`import(${JSON.stringify(specifier)})`, {
|
|
8
|
+
importModuleDynamically: constants.USE_MAIN_CONTEXT_DEFAULT_LOADER,
|
|
9
|
+
}).runInThisContext());
|
|
10
|
+
if (typeof imported !== "object" || imported === null)
|
|
11
|
+
return imported;
|
|
12
|
+
const module = imported;
|
|
13
|
+
const exports = module["module.exports"];
|
|
14
|
+
if (exports !== module.default || (typeof exports !== "object" && typeof exports !== "function") || exports === null)
|
|
15
|
+
return imported;
|
|
16
|
+
return Object.assign({}, module, exports);
|
|
17
|
+
}
|
|
18
|
+
export function resolveModule(specifier, directory) {
|
|
19
|
+
// Node only accepts import.meta.resolve's parent URL behind an experimental
|
|
20
|
+
// flag. Scope this synchronous resolution to the caller's package directory
|
|
21
|
+
// through the supported resolver hook instead.
|
|
22
|
+
const hook = registerHooks({
|
|
23
|
+
resolve(specifier, context, nextResolve) {
|
|
24
|
+
return nextResolve(specifier, { ...context, parentURL: pathToFileURL(path.join(directory, "package.json")).href });
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
const resolve = (target) => {
|
|
29
|
+
const resolved = import.meta.resolve(path.isAbsolute(target) ? pathToFileURL(target).href : target);
|
|
30
|
+
if (resolved.startsWith("file:"))
|
|
31
|
+
statSync(new URL(resolved));
|
|
32
|
+
return resolved;
|
|
33
|
+
};
|
|
34
|
+
try {
|
|
35
|
+
return resolve(specifier);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (path.extname(specifier) || !missing(error))
|
|
39
|
+
throw error;
|
|
40
|
+
// Node does not infer extensions for local files or legacy package
|
|
41
|
+
// subpaths. Resolve each candidate natively so package exports still apply.
|
|
42
|
+
for (const extension of [".ts", ".tsx", ".js", ".jsx", ".mts", ".mjs", ".cts", ".cjs"]) {
|
|
43
|
+
try {
|
|
44
|
+
return resolve(specifier + extension);
|
|
45
|
+
}
|
|
46
|
+
catch (cause) {
|
|
47
|
+
if (!missing(cause))
|
|
48
|
+
throw cause;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
hook.deregister();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function missing(error) {
|
|
59
|
+
return (error instanceof Error &&
|
|
60
|
+
"code" in error &&
|
|
61
|
+
["ENOENT", "ENOTDIR", "ERR_MODULE_NOT_FOUND"].includes(String(error.code)));
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { importModule, resolveModule } from "#runtime-import";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { importModule, resolveModule } from "#runtime-import";
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export * as SessionTitleFallback from "./session-title-fallback.js";
|
|
2
|
+
interface Info {
|
|
3
|
+
readonly title?: string;
|
|
4
|
+
readonly parentID?: string;
|
|
5
|
+
readonly time: {
|
|
6
|
+
readonly created: number;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
/** Supplies the timestamped title required by compatibility surfaces. */
|
|
10
|
+
export declare function withTimestampedFallback(info: Info): string;
|
|
11
|
+
/** Supplies a compact human label and collapses historical timestamped fallbacks. */
|
|
12
|
+
export declare function displayLabel(info: Pick<Info, "title" | "parentID">): string;
|
|
13
|
+
/** Recognizes missing and historical root or child fallback titles. */
|
|
14
|
+
export declare function isFallbackTitle(title?: string): boolean;
|
|
15
|
+
/** Recognizes a missing title or the exact root fallback for this session. */
|
|
16
|
+
export declare function isExactRootFallback(info: Pick<Info, "title" | "time">): boolean;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * as SessionTitleFallback from "./session-title-fallback.js";
|
|
2
|
+
const pattern = /^(New session|Child session) - \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
3
|
+
/** Supplies the timestamped title required by compatibility surfaces. */
|
|
4
|
+
export function withTimestampedFallback(info) {
|
|
5
|
+
return info.title ?? fallback(info);
|
|
6
|
+
}
|
|
7
|
+
/** Supplies a compact human label and collapses historical timestamped fallbacks. */
|
|
8
|
+
export function displayLabel(info) {
|
|
9
|
+
if (!info.title)
|
|
10
|
+
return info.parentID ? "Child session" : "New session";
|
|
11
|
+
return info.title.match(pattern)?.[1] ?? info.title;
|
|
12
|
+
}
|
|
13
|
+
/** Recognizes missing and historical root or child fallback titles. */
|
|
14
|
+
export function isFallbackTitle(title) {
|
|
15
|
+
return title === undefined || pattern.test(title);
|
|
16
|
+
}
|
|
17
|
+
/** Recognizes a missing title or the exact root fallback for this session. */
|
|
18
|
+
export function isExactRootFallback(info) {
|
|
19
|
+
return info.title === undefined || info.title === fallback({ time: info.time });
|
|
20
|
+
}
|
|
21
|
+
function fallback(info) {
|
|
22
|
+
return `${info.parentID ? "Child" : "New"} session - ${new Date(info.time.created).toISOString()}`;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,75 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package.json",
|
|
2
3
|
"name": "@opencode/util",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
4
|
+
"version": "2.0.1",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"license": "MIT",
|
|
6
7
|
"repository": {
|
|
7
8
|
"type": "git",
|
|
8
|
-
"url": "git+https://github.com/anomalyco/opencode.git"
|
|
9
|
+
"url": "git+https://github.com/anomalyco/opencode.git",
|
|
10
|
+
"directory": "packages/util"
|
|
9
11
|
},
|
|
10
12
|
"publishConfig": {
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
"./effect/layer-node": {
|
|
20
|
+
"import": "./dist/effect/layer-node.js",
|
|
21
|
+
"types": "./dist/effect/layer-node.d.ts"
|
|
22
|
+
},
|
|
23
|
+
"./*": {
|
|
24
|
+
"import": "./dist/*.js",
|
|
25
|
+
"types": "./dist/*.d.ts"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"imports": {
|
|
29
|
+
"#global-roots": {
|
|
30
|
+
"workerd": "./dist/global-roots.workerd.js",
|
|
31
|
+
"default": "./dist/global-roots.js"
|
|
32
|
+
},
|
|
33
|
+
"#runtime-import": {
|
|
34
|
+
"workerd": "./dist/runtime/import.workerd.js",
|
|
35
|
+
"bun": "./dist/runtime/import.bun.js",
|
|
36
|
+
"node": "./dist/runtime/import.node.js",
|
|
37
|
+
"default": "./dist/runtime/import.bun.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "bun run script/build.ts",
|
|
42
|
+
"test": "bun test --only-failures",
|
|
43
|
+
"typecheck": "tsgo --noEmit",
|
|
44
|
+
"typecheck:dist": "bun run build && bun typecheck --project tsconfig.dist.json"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@effect/opentelemetry": "4.0.0-rc.112",
|
|
48
|
+
"@effect/platform-node": "4.0.0-rc.112",
|
|
49
|
+
"@effect/platform-node-shared": "4.0.0-rc.112",
|
|
50
|
+
"@npmcli/arborist": "9.4.0",
|
|
51
|
+
"@npmcli/config": "10.8.1",
|
|
52
|
+
"@opentelemetry/api": "1.9.0",
|
|
53
|
+
"@opentelemetry/context-async-hooks": "2.6.1",
|
|
54
|
+
"@opentelemetry/exporter-trace-otlp-http": "0.214.0",
|
|
55
|
+
"@opentelemetry/sdk-trace-base": "2.6.1",
|
|
56
|
+
"@opentelemetry/sdk-trace-node": "2.6.1",
|
|
57
|
+
"cross-spawn": "7.0.6",
|
|
58
|
+
"effect": "4.0.0-rc.112",
|
|
59
|
+
"glob": "13.0.5",
|
|
60
|
+
"mime-types": "3.0.2",
|
|
61
|
+
"minimatch": "10.2.5",
|
|
62
|
+
"npm-package-arg": "13.0.2",
|
|
63
|
+
"pacote": "21.5.1"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@tsconfig/bun": "1.0.9",
|
|
67
|
+
"@types/bun": "1.4.0",
|
|
68
|
+
"@types/cross-spawn": "6.0.6",
|
|
69
|
+
"@types/node": "24.12.2",
|
|
70
|
+
"@types/npm-package-arg": "6.1.4",
|
|
71
|
+
"@types/npmcli__arborist": "6.3.3",
|
|
72
|
+
"@types/pacote": "11.1.8",
|
|
73
|
+
"@typescript/native-preview": "7.0.0-dev.20251207.1"
|
|
14
74
|
}
|
|
15
75
|
}
|