@opencode/util 0.0.0-dev-1326 → 0.0.0-dev-1329
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 +6 -0
- package/dist/npm.js +23 -1
- package/package.json +1 -1
package/dist/npm.d.ts
CHANGED
|
@@ -20,6 +20,12 @@ 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>;
|
|
23
29
|
/**
|
|
24
30
|
* Stop using the newest installed version when it is `version`, so the previous one is current again. Its files stay
|
|
25
31
|
* until they expire, for anything still running it. False when it isn't the newest or there is no previous one.
|
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 {
|
|
@@ -323,6 +329,21 @@ 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
|
+
});
|
|
326
347
|
const reject = Effect.fn("Npm.reject")(function* (pkg, version) {
|
|
327
348
|
const target = yield* Effect.promise(() => parse(pkg));
|
|
328
349
|
const dir = directory(pkg, target);
|
|
@@ -387,6 +408,7 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
387
408
|
resolve,
|
|
388
409
|
check,
|
|
389
410
|
update,
|
|
411
|
+
follows,
|
|
390
412
|
reject,
|
|
391
413
|
which,
|
|
392
414
|
});
|