@opencode-ai/util 0.0.0-dev-17637 → 0.0.0-dev-17643
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 +29 -0
- package/package.json +1 -1
package/dist/npm.d.ts
CHANGED
|
@@ -17,12 +17,17 @@ export interface Interface {
|
|
|
17
17
|
readonly add: (pkg: string, options?: {
|
|
18
18
|
readonly subpaths?: readonly string[];
|
|
19
19
|
}) => Effect.Effect<EntryPoint, InstallFailedError | EffectFlock.LockError>;
|
|
20
|
+
readonly resolve: (pkg: string, options?: {
|
|
21
|
+
readonly subpaths?: readonly string[];
|
|
22
|
+
}) => Effect.Effect<EntryPoint>;
|
|
20
23
|
readonly which: (pkg: string, bin?: string) => Effect.Effect<string | undefined>;
|
|
21
24
|
}
|
|
22
25
|
declare const Service_base: Context.ServiceClass<Service, "@opencode/Npm", Interface>;
|
|
23
26
|
export declare class Service extends Service_base {
|
|
24
27
|
}
|
|
25
28
|
export declare function sanitize(pkg: string): string;
|
|
29
|
+
export declare function isRegistryPackage(pkg: string): Promise<boolean>;
|
|
26
30
|
export declare const node: LayerNode.Node<Service, never, LayerNode.Tag<"global">>;
|
|
27
31
|
export declare function add(...args: Parameters<Interface["add"]>): Promise<EntryPoint>;
|
|
32
|
+
export declare function resolve(...args: Parameters<Interface["resolve"]>): Promise<EntryPoint>;
|
|
28
33
|
export declare function which(...args: Parameters<Interface["which"]>): Promise<string | undefined>;
|
package/dist/npm.js
CHANGED
|
@@ -25,6 +25,16 @@ export function sanitize(pkg) {
|
|
|
25
25
|
return pkg;
|
|
26
26
|
return Array.from(pkg, (char) => (illegal.has(char) || char.charCodeAt(0) < 32 ? "_" : char)).join("");
|
|
27
27
|
}
|
|
28
|
+
export async function isRegistryPackage(pkg) {
|
|
29
|
+
const { default: npa } = await import("npm-package-arg");
|
|
30
|
+
try {
|
|
31
|
+
const result = npa(pkg);
|
|
32
|
+
return result.name !== undefined && ["version", "range", "tag"].includes(result.type);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
28
38
|
const resolveEntryPoint = (name, dir, subpaths = [""]) => {
|
|
29
39
|
const entrypoint = subpaths
|
|
30
40
|
.map((subpath) => {
|
|
@@ -100,6 +110,21 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
100
110
|
}
|
|
101
111
|
return resolveEntryPoint(first.name, first.path, options?.subpaths);
|
|
102
112
|
}, Effect.scoped);
|
|
113
|
+
const resolve = Effect.fn("Npm.resolve")(function* (pkg, options) {
|
|
114
|
+
const { default: npa } = yield* Effect.promise(() => import("npm-package-arg"));
|
|
115
|
+
const name = (() => {
|
|
116
|
+
try {
|
|
117
|
+
return npa(pkg).name ?? pkg;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return pkg;
|
|
121
|
+
}
|
|
122
|
+
})();
|
|
123
|
+
const dir = path.join(directory(pkg), "node_modules", name);
|
|
124
|
+
if (!(yield* afs.existsSafe(dir)))
|
|
125
|
+
return { directory: dir };
|
|
126
|
+
return resolveEntryPoint(name, dir, options?.subpaths);
|
|
127
|
+
});
|
|
103
128
|
const which = Effect.fn("Npm.which")(function* (pkg, bin) {
|
|
104
129
|
const dir = directory(pkg);
|
|
105
130
|
const binDir = path.join(dir, "node_modules", ".bin");
|
|
@@ -144,6 +169,7 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
|
|
|
144
169
|
});
|
|
145
170
|
return Service.of({
|
|
146
171
|
add,
|
|
172
|
+
resolve,
|
|
147
173
|
which,
|
|
148
174
|
});
|
|
149
175
|
}));
|
|
@@ -156,6 +182,9 @@ const { runPromise } = makeRuntime(Service, LayerNode.compile(node));
|
|
|
156
182
|
export async function add(...args) {
|
|
157
183
|
return runPromise((svc) => svc.add(...args));
|
|
158
184
|
}
|
|
185
|
+
export async function resolve(...args) {
|
|
186
|
+
return runPromise((svc) => svc.resolve(...args));
|
|
187
|
+
}
|
|
159
188
|
export async function which(...args) {
|
|
160
189
|
return runPromise((svc) => svc.which(...args));
|
|
161
190
|
}
|