@opencode/util 0.0.0-dev-1313 → 0.0.0-dev-1315
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/npm.d.ts +5 -0
- package/dist/npm.js +21 -3
- package/package.json +1 -1
package/dist/npm.d.ts
CHANGED
|
@@ -20,6 +20,11 @@ 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
|
+
* Stop using the newest installed version when it is `version`, so the previous one is current again. Its files stay
|
|
25
|
+
* until they expire, for anything still running it. False when it isn't the newest or there is no previous one.
|
|
26
|
+
*/
|
|
27
|
+
readonly reject: (pkg: string, version: string) => Effect.Effect<boolean, InstallFailedError | EffectFlock.LockError>;
|
|
23
28
|
readonly which: (pkg: string, bin?: string) => Effect.Effect<string | undefined>;
|
|
24
29
|
}
|
|
25
30
|
declare const Service_base: Context.ServiceClass<Service, "@opencode/Npm", Interface>;
|
package/dist/npm.js
CHANGED
|
@@ -106,7 +106,7 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
106
106
|
const directory = (pkg, target) => path.join(global.cache, "npm", key(pkg, target));
|
|
107
107
|
const generations = Effect.fnUntraced(function* (dir) {
|
|
108
108
|
return yield* fs.readDirectory(dir).pipe(Effect.orElseSucceed(() => []), Effect.map((entries) => entries
|
|
109
|
-
.filter((entry) => /^\d+$/.test(entry))
|
|
109
|
+
.filter((entry) => /^\d+$/.test(entry) && !entries.includes(`${entry}.rejected`))
|
|
110
110
|
.toSorted((a, b) => Number(a) - Number(b))));
|
|
111
111
|
});
|
|
112
112
|
const current = Effect.fnUntraced(function* (dir) {
|
|
@@ -253,8 +253,8 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
253
253
|
const keep = new Set(completed.slice(-2));
|
|
254
254
|
const entries = yield* fs.readDirectory(dir).pipe(Effect.orElseSucceed(() => []));
|
|
255
255
|
yield* Effect.forEach(entries, (name) => {
|
|
256
|
-
const timestamp = /^\d
|
|
257
|
-
? Number(name)
|
|
256
|
+
const timestamp = /^\d+(\.rejected)?$/.test(name)
|
|
257
|
+
? Number(name.split(".")[0])
|
|
258
258
|
: Number(name.match(/^\.staging-(\d+)-/)?.[1] ?? Number.NaN);
|
|
259
259
|
const maximumAge = name.startsWith(".staging-") ? stagingRetention : retention;
|
|
260
260
|
if (!Number.isFinite(timestamp) || keep.has(name) || now - timestamp <= maximumAge)
|
|
@@ -323,6 +323,23 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
323
323
|
yield* collect(dir);
|
|
324
324
|
return installed;
|
|
325
325
|
}, Effect.scoped);
|
|
326
|
+
const reject = Effect.fn("Npm.reject")(function* (pkg, version) {
|
|
327
|
+
const target = yield* Effect.promise(() => parse(pkg));
|
|
328
|
+
const dir = directory(pkg, target);
|
|
329
|
+
yield* flock.acquire(`npm-install:${dir}`);
|
|
330
|
+
const completed = yield* generations(dir);
|
|
331
|
+
const newest = completed.at(-1);
|
|
332
|
+
if (completed.length < 2 || !newest)
|
|
333
|
+
return false;
|
|
334
|
+
const root = path.join(dir, newest);
|
|
335
|
+
const name = yield* installedName(pkg, root, target);
|
|
336
|
+
if ((yield* metadata(root, name, path.join(root, "node_modules", name), target)).version !== version)
|
|
337
|
+
return false;
|
|
338
|
+
yield* fs
|
|
339
|
+
.writeFileString(path.join(dir, `${newest}.rejected`), "")
|
|
340
|
+
.pipe(Effect.mapError((cause) => new InstallFailedError({ dir, cause })));
|
|
341
|
+
return true;
|
|
342
|
+
}, Effect.scoped);
|
|
326
343
|
const which = Effect.fn("Npm.which")(function* (pkg, bin) {
|
|
327
344
|
const target = yield* Effect.promise(() => parse(pkg));
|
|
328
345
|
const root = directory(pkg, target);
|
|
@@ -370,6 +387,7 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
370
387
|
resolve,
|
|
371
388
|
check,
|
|
372
389
|
update,
|
|
390
|
+
reject,
|
|
373
391
|
which,
|
|
374
392
|
});
|
|
375
393
|
}));
|