@opencode/util 2.3.1 → 2.4.0
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/encode.js +1 -1
- package/dist/glob.d.ts +3 -1
- package/dist/glob.js +2 -2
- package/dist/npm.d.ts +11 -0
- package/dist/npm.js +44 -4
- package/package.json +1 -1
package/dist/encode.js
CHANGED
|
@@ -28,7 +28,7 @@ export function sampledChecksum(content, limit = 500_000) {
|
|
|
28
28
|
Math.floor(content.length * 0.25),
|
|
29
29
|
Math.floor(content.length * 0.5),
|
|
30
30
|
Math.floor(content.length * 0.75),
|
|
31
|
-
content.length
|
|
31
|
+
content.length,
|
|
32
32
|
]
|
|
33
33
|
.map((point) => {
|
|
34
34
|
const start = Math.max(0, Math.min(content.length - size, point - Math.floor(size / 2)));
|
package/dist/glob.d.ts
CHANGED
|
@@ -8,5 +8,7 @@ export declare namespace Glob {
|
|
|
8
8
|
ignore?: string[];
|
|
9
9
|
}
|
|
10
10
|
function scan(pattern: string, options?: Options): Promise<string[]>;
|
|
11
|
-
function match(pattern: string, filepath: string
|
|
11
|
+
function match(pattern: string, filepath: string, options?: {
|
|
12
|
+
dot?: boolean;
|
|
13
|
+
}): boolean;
|
|
12
14
|
}
|
package/dist/glob.js
CHANGED
|
@@ -16,8 +16,8 @@ export var Glob;
|
|
|
16
16
|
return glob(pattern, toGlobOptions(options));
|
|
17
17
|
}
|
|
18
18
|
Glob.scan = scan;
|
|
19
|
-
function match(pattern, filepath) {
|
|
20
|
-
return minimatch(filepath, pattern, { dot: true });
|
|
19
|
+
function match(pattern, filepath, options = {}) {
|
|
20
|
+
return minimatch(filepath, pattern, { dot: options.dot ?? true });
|
|
21
21
|
}
|
|
22
22
|
Glob.match = match;
|
|
23
23
|
})(Glob || (Glob = {}));
|
package/dist/npm.d.ts
CHANGED
|
@@ -20,6 +20,17 @@ export interface Interface {
|
|
|
20
20
|
readonly resolve: (pkg: string) => Effect.Effect<Package>;
|
|
21
21
|
readonly check: (pkg: string) => Effect.Effect<boolean, InstallFailedError>;
|
|
22
22
|
readonly update: (pkg: string) => Effect.Effect<Package, InstallFailedError | EffectFlock.LockError>;
|
|
23
|
+
/**
|
|
24
|
+
* Whether newer versions should install on their own because the package names what to follow: `name@latest`, a
|
|
25
|
+
* version range, a Git `semver:` range, or a Git ref the remote lists as a branch. A bare name or repository, other
|
|
26
|
+
* dist-tags, Git tags and commits stay on what's installed.
|
|
27
|
+
*/
|
|
28
|
+
readonly follows: (pkg: string) => Effect.Effect<boolean, InstallFailedError>;
|
|
29
|
+
/**
|
|
30
|
+
* Stop using the newest installed version when it is `version`, so the previous one is current again. Its files stay
|
|
31
|
+
* until they expire, for anything still running it. False when it isn't the newest or there is no previous one.
|
|
32
|
+
*/
|
|
33
|
+
readonly reject: (pkg: string, version: string) => Effect.Effect<boolean, InstallFailedError | EffectFlock.LockError>;
|
|
23
34
|
readonly which: (pkg: string, bin?: string) => Effect.Effect<string | undefined>;
|
|
24
35
|
}
|
|
25
36
|
declare const Service_base: Context.ServiceClass<Service, "@opencode/Npm", Interface>;
|
package/dist/npm.js
CHANGED
|
@@ -46,11 +46,14 @@ async function parse(pkg) {
|
|
|
46
46
|
try {
|
|
47
47
|
const result = npa(pkg);
|
|
48
48
|
if (result.type === "git") {
|
|
49
|
+
const mutable = !isCommit(result.gitCommittish);
|
|
49
50
|
return {
|
|
50
51
|
type: "git",
|
|
51
52
|
...(result.name ? { name: result.name } : {}),
|
|
52
53
|
slug: gitSlug(pkg),
|
|
53
|
-
mutable
|
|
54
|
+
mutable,
|
|
55
|
+
follows: Boolean(result.gitRange),
|
|
56
|
+
...(mutable && result.gitCommittish ? { ref: result.gitCommittish } : {}),
|
|
54
57
|
};
|
|
55
58
|
}
|
|
56
59
|
if (!result.name || !["version", "range", "tag"].includes(result.type))
|
|
@@ -60,6 +63,9 @@ async function parse(pkg) {
|
|
|
60
63
|
name: result.name,
|
|
61
64
|
spec: result.raw === result.name ? "latest" : result.rawSpec,
|
|
62
65
|
mutable: result.type !== "version",
|
|
66
|
+
// npm parses a bare name as the range `*`; only a written `@latest` or range follows.
|
|
67
|
+
follows: result.raw !== result.name &&
|
|
68
|
+
(result.type === "range" || (result.type === "tag" && result.rawSpec === "latest")),
|
|
63
69
|
};
|
|
64
70
|
}
|
|
65
71
|
catch {
|
|
@@ -106,7 +112,7 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
106
112
|
const directory = (pkg, target) => path.join(global.cache, "npm", key(pkg, target));
|
|
107
113
|
const generations = Effect.fnUntraced(function* (dir) {
|
|
108
114
|
return yield* fs.readDirectory(dir).pipe(Effect.orElseSucceed(() => []), Effect.map((entries) => entries
|
|
109
|
-
.filter((entry) => /^\d+$/.test(entry))
|
|
115
|
+
.filter((entry) => /^\d+$/.test(entry) && !entries.includes(`${entry}.rejected`))
|
|
110
116
|
.toSorted((a, b) => Number(a) - Number(b))));
|
|
111
117
|
});
|
|
112
118
|
const current = Effect.fnUntraced(function* (dir) {
|
|
@@ -253,8 +259,8 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
253
259
|
const keep = new Set(completed.slice(-2));
|
|
254
260
|
const entries = yield* fs.readDirectory(dir).pipe(Effect.orElseSucceed(() => []));
|
|
255
261
|
yield* Effect.forEach(entries, (name) => {
|
|
256
|
-
const timestamp = /^\d
|
|
257
|
-
? Number(name)
|
|
262
|
+
const timestamp = /^\d+(\.rejected)?$/.test(name)
|
|
263
|
+
? Number(name.split(".")[0])
|
|
258
264
|
: Number(name.match(/^\.staging-(\d+)-/)?.[1] ?? Number.NaN);
|
|
259
265
|
const maximumAge = name.startsWith(".staging-") ? stagingRetention : retention;
|
|
260
266
|
if (!Number.isFinite(timestamp) || keep.has(name) || now - timestamp <= maximumAge)
|
|
@@ -323,6 +329,38 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
323
329
|
yield* collect(dir);
|
|
324
330
|
return installed;
|
|
325
331
|
}, Effect.scoped);
|
|
332
|
+
const follows = Effect.fn("Npm.follows")(function* (pkg) {
|
|
333
|
+
const target = yield* Effect.promise(() => parse(pkg));
|
|
334
|
+
if (target?.type !== "git" || !target.ref)
|
|
335
|
+
return target?.follows ?? false;
|
|
336
|
+
const root = directory(pkg, target);
|
|
337
|
+
// Only the remote knows whether a ref is a branch or a tag. pacote keeps the ref it resolved, and Git reuses the
|
|
338
|
+
// refs the update check just listed for a few minutes, so this usually doesn't ask the remote again.
|
|
339
|
+
const { GitFetcher } = (yield* Effect.promise(() => import("pacote")));
|
|
340
|
+
const fetcher = new GitFetcher(pkg, { ...(yield* NpmConfig.load(root)), ignoreScripts: true, windowsHide: true });
|
|
341
|
+
yield* Effect.tryPromise({
|
|
342
|
+
try: () => fetcher.resolve(),
|
|
343
|
+
catch: (cause) => new InstallFailedError({ dir: root, cause }),
|
|
344
|
+
});
|
|
345
|
+
return fetcher.resolvedRef?.type === "branch";
|
|
346
|
+
});
|
|
347
|
+
const reject = Effect.fn("Npm.reject")(function* (pkg, version) {
|
|
348
|
+
const target = yield* Effect.promise(() => parse(pkg));
|
|
349
|
+
const dir = directory(pkg, target);
|
|
350
|
+
yield* flock.acquire(`npm-install:${dir}`);
|
|
351
|
+
const completed = yield* generations(dir);
|
|
352
|
+
const newest = completed.at(-1);
|
|
353
|
+
if (completed.length < 2 || !newest)
|
|
354
|
+
return false;
|
|
355
|
+
const root = path.join(dir, newest);
|
|
356
|
+
const name = yield* installedName(pkg, root, target);
|
|
357
|
+
if ((yield* metadata(root, name, path.join(root, "node_modules", name), target)).version !== version)
|
|
358
|
+
return false;
|
|
359
|
+
yield* fs
|
|
360
|
+
.writeFileString(path.join(dir, `${newest}.rejected`), "")
|
|
361
|
+
.pipe(Effect.mapError((cause) => new InstallFailedError({ dir, cause })));
|
|
362
|
+
return true;
|
|
363
|
+
}, Effect.scoped);
|
|
326
364
|
const which = Effect.fn("Npm.which")(function* (pkg, bin) {
|
|
327
365
|
const target = yield* Effect.promise(() => parse(pkg));
|
|
328
366
|
const root = directory(pkg, target);
|
|
@@ -370,6 +408,8 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
370
408
|
resolve,
|
|
371
409
|
check,
|
|
372
410
|
update,
|
|
411
|
+
follows,
|
|
412
|
+
reject,
|
|
373
413
|
which,
|
|
374
414
|
});
|
|
375
415
|
}));
|