@opencode-ai/util 0.0.0-dev-18259 → 0.0.0-dev-18262

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 CHANGED
@@ -16,6 +16,7 @@ export interface EntryPoint {
16
16
  export interface Interface {
17
17
  readonly add: (pkg: string, options?: {
18
18
  readonly subpaths?: readonly string[];
19
+ readonly refresh?: boolean;
19
20
  }) => Effect.Effect<EntryPoint, InstallFailedError | EffectFlock.LockError>;
20
21
  readonly resolve: (pkg: string, options?: {
21
22
  readonly subpaths?: readonly string[];
package/dist/npm.js CHANGED
@@ -94,13 +94,15 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
94
94
  }
95
95
  return pkg;
96
96
  });
97
+ const refreshed = new Set();
97
98
  const reify = (input) => Effect.gen(function* () {
98
99
  yield* flock.acquire(`npm-install:${input.dir}`);
99
100
  const { Arborist } = yield* Effect.promise(() => import("@npmcli/arborist"));
100
101
  const add = input.add ?? [];
101
102
  const npmOptions = yield* NpmConfig.load(input.dir);
103
+ const options = input.update ? { ...npmOptions, preferOnline: true, noGitRevCache: true } : npmOptions;
102
104
  const arborist = new Arborist({
103
- ...npmOptions,
105
+ ...options,
104
106
  path: input.dir,
105
107
  binLinks: true,
106
108
  progress: false,
@@ -109,8 +111,9 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
109
111
  });
110
112
  return yield* Effect.tryPromise({
111
113
  try: () => arborist.reify({
112
- ...npmOptions,
114
+ ...options,
113
115
  add,
116
+ update: input.update,
114
117
  save: true,
115
118
  saveType: "prod",
116
119
  }),
@@ -125,17 +128,25 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
125
128
  }));
126
129
  const add = Effect.fn("Npm.add")(function* (pkg, options) {
127
130
  const { default: npa } = yield* Effect.promise(() => import("npm-package-arg"));
128
- const parsedName = (() => {
131
+ const parsed = (() => {
129
132
  try {
130
- return npa(pkg).name ?? undefined;
133
+ return npa(pkg);
131
134
  }
132
135
  catch {
133
136
  return undefined;
134
137
  }
135
138
  })();
139
+ const parsedName = parsed?.name ?? undefined;
136
140
  const dir = yield* directory(pkg);
137
141
  const name = yield* installedName(pkg, dir, parsedName);
138
- if (yield* afs.existsSafe(path.join(dir, "node_modules", name))) {
142
+ const cached = yield* afs.existsSafe(path.join(dir, "node_modules", name));
143
+ const refresh = options?.refresh && isMutable(parsed) && !refreshed.has(pkg);
144
+ if (refresh) {
145
+ refreshed.add(pkg);
146
+ if (cached)
147
+ yield* reify({ dir, add: [pkg], update: true }).pipe(Effect.catchCause(() => Effect.logWarning("failed to refresh cached package; using installed version")));
148
+ }
149
+ if (cached) {
139
150
  return resolveEntryPoint(name, path.join(dir, "node_modules", name), options?.subpaths);
140
151
  }
141
152
  const tree = yield* reify({ dir, add: [pkg] });
@@ -229,3 +240,12 @@ export async function resolve(...args) {
229
240
  export async function which(...args) {
230
241
  return runPromise((svc) => svc.which(...args));
231
242
  }
243
+ function isMutable(parsed) {
244
+ if (!parsed)
245
+ return false;
246
+ if (["tag", "range"].includes(parsed.type))
247
+ return true;
248
+ if (parsed.type !== "git")
249
+ return false;
250
+ return !/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/i.test(parsed.gitCommittish ?? "");
251
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode-ai/util",
4
- "version": "0.0.0-dev-18259",
4
+ "version": "0.0.0-dev-18262",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {