@opencode/util 0.0.0-dev-21133 → 0.0.0-dev-21134
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/fs-util.d.ts +2 -0
- package/dist/fs-util.js +17 -3
- package/package.json +1 -1
package/dist/fs-util.d.ts
CHANGED
|
@@ -128,6 +128,8 @@ export declare namespace FSUtil {
|
|
|
128
128
|
};
|
|
129
129
|
export const layer: Layer.Layer<Service, never, FileSystem.FileSystem>;
|
|
130
130
|
export const node: import("./effect/layer-node.js").Provider<Service, never, import("./effect/layer-node.js").Tag<"global">>;
|
|
131
|
+
/** Permission denial, including macOS sandbox and privacy denials that surface as Unknown with an EPERM cause. */
|
|
132
|
+
export function isAccessDenied(error: PlatformError): boolean;
|
|
131
133
|
export function mimeType(p: string): string;
|
|
132
134
|
export function normalizePath(p: string): string;
|
|
133
135
|
export function normalizePathPattern(p: string): string;
|
package/dist/fs-util.js
CHANGED
|
@@ -32,7 +32,9 @@ export var FSUtil;
|
|
|
32
32
|
return yield* fs.exists(path).pipe(Effect.orElseSucceed(() => false));
|
|
33
33
|
});
|
|
34
34
|
const readFileStringSafe = Effect.fn("FileSystem.readFileStringSafe")(function* (path) {
|
|
35
|
-
return yield* fs
|
|
35
|
+
return yield* fs
|
|
36
|
+
.readFileString(path)
|
|
37
|
+
.pipe(Effect.catchIf((error) => error.reason._tag === "NotFound" || isAccessDenied(error), () => Effect.undefined));
|
|
36
38
|
});
|
|
37
39
|
const isDir = Effect.fn("FileSystem.isDir")(function* (path) {
|
|
38
40
|
const info = yield* fs.stat(path).pipe(Effect.catch(() => Effect.void));
|
|
@@ -56,7 +58,8 @@ export var FSUtil;
|
|
|
56
58
|
});
|
|
57
59
|
const resolve = Effect.fn("FileSystem.resolve")(function* (input) {
|
|
58
60
|
const resolved = path.resolve(windowsPath(input));
|
|
59
|
-
|
|
61
|
+
// Sandboxes deny reads outside granted paths; canonicalize what we can see.
|
|
62
|
+
return yield* fs.realPath(resolved).pipe(Effect.catchIf((error) => error.reason._tag === "NotFound" || isAccessDenied(error), () => Effect.succeed(resolved)), Effect.orDie);
|
|
60
63
|
});
|
|
61
64
|
const readJson = Effect.fn("FileSystem.readJson")(function* (path) {
|
|
62
65
|
const text = yield* fs.readFileString(path);
|
|
@@ -154,6 +157,17 @@ export var FSUtil;
|
|
|
154
157
|
});
|
|
155
158
|
}));
|
|
156
159
|
FSUtil.node = makeGlobalNode({ service: Service, layer: FSUtil.layer, deps: [filesystem] });
|
|
160
|
+
/** Permission denial, including macOS sandbox and privacy denials that surface as Unknown with an EPERM cause. */
|
|
161
|
+
function isAccessDenied(error) {
|
|
162
|
+
if (error.reason._tag === "PermissionDenied")
|
|
163
|
+
return true;
|
|
164
|
+
const cause = error.reason.cause;
|
|
165
|
+
return (error.reason._tag === "Unknown" &&
|
|
166
|
+
cause instanceof globalThis.Error &&
|
|
167
|
+
"code" in cause &&
|
|
168
|
+
cause.code === "EPERM");
|
|
169
|
+
}
|
|
170
|
+
FSUtil.isAccessDenied = isAccessDenied;
|
|
157
171
|
// Pure helpers that don't need Effect (path manipulation, sync operations)
|
|
158
172
|
function mimeType(p) {
|
|
159
173
|
return lookup(p) || "application/octet-stream";
|
|
@@ -189,7 +203,7 @@ export var FSUtil;
|
|
|
189
203
|
return normalizePath(realpathSync(resolved));
|
|
190
204
|
}
|
|
191
205
|
catch (e) {
|
|
192
|
-
if (
|
|
206
|
+
if (["ENOENT", "ENOTDIR", "EPERM", "EACCES"].includes(e?.code))
|
|
193
207
|
return normalizePath(resolved);
|
|
194
208
|
throw e;
|
|
195
209
|
}
|