@opencode-ai/util 0.0.0-next-17430 → 0.0.0-next-17444

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.
@@ -1,13 +1,17 @@
1
1
  import os from "os";
2
2
  import path from "path";
3
- import { xdgCache, xdgConfig, xdgData, xdgState } from "xdg-basedir";
3
+ const home = os.homedir();
4
+ const data = process.env.XDG_DATA_HOME || (home ? path.join(home, ".local", "share") : undefined);
5
+ const cache = process.env.XDG_CACHE_HOME || (home ? path.join(home, ".cache") : undefined);
6
+ const config = process.env.XDG_CONFIG_HOME || (home ? path.join(home, ".config") : undefined);
7
+ const state = process.env.XDG_STATE_HOME || (home ? path.join(home, ".local", "state") : undefined);
4
8
  /** The XDG base directories that root opencode's global paths. */
5
9
  export function roots(app) {
6
10
  return {
7
- data: path.join(xdgData, app),
8
- cache: path.join(xdgCache, app),
9
- config: path.join(xdgConfig, app),
10
- state: path.join(xdgState, app),
11
+ data: path.join(data, app),
12
+ cache: path.join(cache, app),
13
+ config: path.join(config, app),
14
+ state: path.join(state, app),
11
15
  tmp: path.join(os.tmpdir(), app),
12
16
  };
13
17
  }
@@ -1,12 +1,13 @@
1
1
  export * as NpmConfig from "./npm-config.js";
2
2
  import { fileURLToPath } from "url";
3
- // @ts-expect-error npm does not publish types for this internal config API.
4
- import Config from "@npmcli/config";
5
- // @ts-expect-error npm does not publish types for this internal config API.
6
- import { definitions, flatten, nerfDarts, shorthands } from "@npmcli/config/lib/definitions/index.js";
7
3
  import { Effect } from "effect";
8
4
  export const load = (dir) => Effect.tryPromise({
9
5
  try: async () => {
6
+ // @ts-expect-error npm does not publish types for this internal config API.
7
+ const { default: Config } = await import("@npmcli/config");
8
+ // @ts-expect-error npm does not publish types for this internal config API.
9
+ const { default: npmDefinitions } = await import("@npmcli/config/lib/definitions/index.js");
10
+ const { definitions, flatten, nerfDarts, shorthands } = npmDefinitions;
10
11
  const config = new Config({
11
12
  // Resolved per call: on workerd import.meta.url is undefined and building
12
13
  // this URL at module scope fails startup validation; npm config never runs there.
package/dist/npm.d.ts CHANGED
@@ -17,12 +17,6 @@ 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 install: (dir: string, input?: {
21
- add: {
22
- name: string;
23
- version?: string;
24
- }[];
25
- }) => Effect.Effect<void, EffectFlock.LockError | InstallFailedError>;
26
20
  readonly which: (pkg: string, bin?: string) => Effect.Effect<string | undefined>;
27
21
  }
28
22
  declare const Service_base: Context.ServiceClass<Service, "@opencode/Npm", Interface>;
@@ -30,6 +24,5 @@ export declare class Service extends Service_base {
30
24
  }
31
25
  export declare function sanitize(pkg: string): string;
32
26
  export declare const node: LayerNode.Node<Service, never, LayerNode.Tag<"global">>;
33
- export declare function install(...args: Parameters<Interface["install"]>): Promise<void>;
34
27
  export declare function add(...args: Parameters<Interface["add"]>): Promise<EntryPoint>;
35
28
  export declare function which(...args: Parameters<Interface["which"]>): Promise<string | undefined>;
package/dist/npm.js CHANGED
@@ -1,6 +1,5 @@
1
1
  export * as Npm from "./npm.js";
2
2
  import path from "path";
3
- import npa from "npm-package-arg";
4
3
  import { Effect, Schema, Context, Layer, Option, FileSystem } from "effect";
5
4
  import * as NodeFileSystem from "@effect/platform-node/NodeFileSystem";
6
5
  import { FSUtil } from "./fs-util.js";
@@ -78,6 +77,7 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
78
77
  attributes: input,
79
78
  }));
80
79
  const add = Effect.fn("Npm.add")(function* (pkg, options) {
80
+ const { default: npa } = yield* Effect.promise(() => import("npm-package-arg"));
81
81
  const dir = directory(pkg);
82
82
  const name = (() => {
83
83
  try {
@@ -100,48 +100,6 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
100
100
  }
101
101
  return resolveEntryPoint(first.name, first.path, options?.subpaths);
102
102
  }, Effect.scoped);
103
- const install = Effect.fn("Npm.install")(function* (dir, input) {
104
- const canWrite = yield* afs.access(dir, { writable: true }).pipe(Effect.as(true), Effect.orElseSucceed(() => false));
105
- if (!canWrite)
106
- return;
107
- const add = input?.add.map((pkg) => [pkg.name, pkg.version].filter(Boolean).join("@")) ?? [];
108
- if (yield* Effect.gen(function* () {
109
- const nodeModulesExists = yield* afs.existsSafe(path.join(dir, "node_modules"));
110
- if (!nodeModulesExists) {
111
- yield* reify({ add, dir });
112
- return true;
113
- }
114
- return false;
115
- }).pipe(Effect.withSpan("Npm.checkNodeModules")))
116
- return;
117
- yield* Effect.gen(function* () {
118
- const pkg = yield* afs.readJson(path.join(dir, "package.json")).pipe(Effect.orElseSucceed(() => ({})));
119
- const lock = yield* afs.readJson(path.join(dir, "package-lock.json")).pipe(Effect.orElseSucceed(() => ({})));
120
- const pkgAny = pkg;
121
- const lockAny = lock;
122
- const declared = new Set([
123
- ...Object.keys(pkgAny?.dependencies || {}),
124
- ...Object.keys(pkgAny?.devDependencies || {}),
125
- ...Object.keys(pkgAny?.peerDependencies || {}),
126
- ...Object.keys(pkgAny?.optionalDependencies || {}),
127
- ...(input?.add || []).map((pkg) => pkg.name),
128
- ]);
129
- const root = lockAny?.packages?.[""] || {};
130
- const locked = new Set([
131
- ...Object.keys(root?.dependencies || {}),
132
- ...Object.keys(root?.devDependencies || {}),
133
- ...Object.keys(root?.peerDependencies || {}),
134
- ...Object.keys(root?.optionalDependencies || {}),
135
- ]);
136
- for (const name of declared) {
137
- if (!locked.has(name)) {
138
- yield* reify({ dir, add });
139
- return;
140
- }
141
- }
142
- }).pipe(Effect.withSpan("Npm.checkDirty"));
143
- return;
144
- }, Effect.scoped);
145
103
  const which = Effect.fn("Npm.which")(function* (pkg, bin) {
146
104
  const dir = directory(pkg);
147
105
  const binDir = path.join(dir, "node_modules", ".bin");
@@ -186,7 +144,6 @@ const layer = Layer.effect(Service, Effect.gen(function* () {
186
144
  });
187
145
  return Service.of({
188
146
  add,
189
- install,
190
147
  which,
191
148
  });
192
149
  }));
@@ -196,9 +153,6 @@ export const node = makeGlobalNode({
196
153
  deps: [FSUtil.node, Global.node, filesystem, EffectFlock.node],
197
154
  });
198
155
  const { runPromise } = makeRuntime(Service, LayerNode.compile(node));
199
- export async function install(...args) {
200
- return runPromise((svc) => svc.install(...args));
201
- }
202
156
  export async function add(...args) {
203
157
  return runPromise((svc) => svc.add(...args));
204
158
  }
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-next-17430",
4
+ "version": "0.0.0-next-17444",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -58,8 +58,7 @@
58
58
  "mime-types": "3.0.2",
59
59
  "minimatch": "10.2.5",
60
60
  "npm-package-arg": "13.0.2",
61
- "resolve.exports": "2.0.3",
62
- "xdg-basedir": "5.1.0"
61
+ "resolve.exports": "2.0.3"
63
62
  },
64
63
  "devDependencies": {
65
64
  "@tsconfig/bun": "1.0.9",