Showing the changes to apps/server/src/workspace (4 of 71 files). Show all
Unified · Split
| @@ -1,13 +1,14 @@ | |||
| 1 | // @effect-diagnostics nodeBuiltinImport:off | 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import fsPromises from "node:fs/promises"; | 2 | import * as NodeFSP from "node:fs/promises"; |
| 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; | 3 | import * as NodeServices from "@effect/platform-node/NodeServices"; |
| 4 | import { FileFinder } from "@ff-labs/fff-node"; | 4 | import { FileFinder } from "@ff-labs/fff-node"; |
| 5 | import { it, afterEach, describe, expect, vi } from "@effect/vitest"; | 5 | import { it, afterEach, describe, expect } from "@effect/vitest"; |
| 6 | import * as Effect from "effect/Effect"; | 6 | import * as Effect from "effect/Effect"; |
| 7 | import * as FileSystem from "effect/FileSystem"; | 7 | import * as FileSystem from "effect/FileSystem"; |
| 8 | import * as Layer from "effect/Layer"; | 8 | import * as Layer from "effect/Layer"; |
| 9 | import * as Path from "effect/Path"; | 9 | import * as Path from "effect/Path"; |
| 10 | import * as PlatformError from "effect/PlatformError"; | 10 | import * as PlatformError from "effect/PlatformError"; |
| 11 | import { vi } from "vite-plus/test"; | ||
| 11 | 12 | ||
| 12 | import * as ServerConfig from "../config.ts"; | 13 | import * as ServerConfig from "../config.ts"; |
| 13 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; | 14 | import { HostProcessPlatform } from "@t3tools/shared/hostProcess"; |
| @@ -15,6 +16,11 @@ import * as VcsProcess from "../vcs/VcsProcess.ts"; · 1 unmodified line | |||
| 15 | import * as WorkspaceEntries from "./WorkspaceEntries.ts"; | 16 | import * as WorkspaceEntries from "./WorkspaceEntries.ts"; |
| 16 | import * as WorkspacePaths from "./WorkspacePaths.ts"; | 17 | import * as WorkspacePaths from "./WorkspacePaths.ts"; |
| 17 | 18 | ||
| 19 | vi.mock("node:fs/promises", async (importOriginal) => { | ||
| 20 | const actual = await importOriginal<typeof import("node:fs/promises")>(); | ||
| 21 | return { ...actual, readdir: vi.fn(actual.readdir) }; | ||
| 22 | }); | ||
| 23 | |||
| 18 | const TestLayer = Layer.empty.pipe( | 24 | const TestLayer = Layer.empty.pipe( |
| 19 | Layer.provideMerge(WorkspaceEntries.layer.pipe(Layer.provide(WorkspacePaths.layer))), | 25 | Layer.provideMerge(WorkspaceEntries.layer.pipe(Layer.provide(WorkspacePaths.layer))), |
| 20 | Layer.provideMerge(WorkspacePaths.layer), | 26 | Layer.provideMerge(WorkspacePaths.layer), |
| @@ -376,7 +382,7 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceEntries", (it) => { · 355 unmodified lines | |||
| 376 | const cwd = yield* makeTempDir({ prefix: "t3code-workspace-browse-eacces-" }); | 382 | const cwd = yield* makeTempDir({ prefix: "t3code-workspace-browse-eacces-" }); |
| 377 | 383 | ||
| 378 | const denied = Object.assign(new Error("EACCES: permission denied"), { code: "EACCES" }); | 384 | const denied = Object.assign(new Error("EACCES: permission denied"), { code: "EACCES" }); |
| 379 | vi.spyOn(fsPromises, "readdir").mockRejectedValueOnce(denied); | 385 | vi.mocked(NodeFSP.readdir).mockRejectedValueOnce(denied); |
| 380 | 386 | ||
| 381 | const result = yield* workspaceEntries.browse({ | 387 | const result = yield* workspaceEntries.browse({ |
| 382 | partialPath: yield* appendSeparator(cwd), | 388 | partialPath: yield* appendSeparator(cwd), |
| @@ -1,6 +1,6 @@ | |||
| 1 | // @effect-diagnostics nodeBuiltinImport:off | 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import { readdir } from "node:fs/promises"; | 2 | import * as NodeFSP from "node:fs/promises"; |
| 3 | import { homedir } from "node:os"; | 3 | import * as NodeOS from "node:os"; |
| 4 | 4 | ||
| 5 | import * as Context from "effect/Context"; | 5 | import * as Context from "effect/Context"; |
| 6 | import * as Effect from "effect/Effect"; | 6 | import * as Effect from "effect/Effect"; |
| @@ -98,10 +98,10 @@ export class WorkspaceEntries extends Context.Service< · 91 unmodified lines | |||
| 98 | 98 | ||
| 99 | function expandHomePath(input: string, path: Path.Path): string { | 99 | function expandHomePath(input: string, path: Path.Path): string { |
| 100 | if (input === "~") { | 100 | if (input === "~") { |
| 101 | return homedir(); | 101 | return NodeOS.homedir(); |
| 102 | } | 102 | } |
| 103 | if (input.startsWith("~/") || input.startsWith("~\\")) { | 103 | if (input.startsWith("~/") || input.startsWith("~\\")) { |
| 104 | return path.join(homedir(), input.slice(2)); | 104 | return path.join(NodeOS.homedir(), input.slice(2)); |
| 105 | } | 105 | } |
| 106 | return input; | 106 | return input; |
| 107 | } | 107 | } |
| @@ -176,7 +176,7 @@ export const make = Effect.gen(function* () { · 68 unmodified lines | |||
| 176 | const prefix = endsWithSeparator ? "" : path.basename(resolvedInputPath); | 176 | const prefix = endsWithSeparator ? "" : path.basename(resolvedInputPath); |
| 177 | 177 | ||
| 178 | const dirents = yield* Effect.tryPromise({ | 178 | const dirents = yield* Effect.tryPromise({ |
| 179 | try: () => readdir(parentPath, { withFileTypes: true }), | 179 | try: () => NodeFSP.readdir(parentPath, { withFileTypes: true }), |
| 180 | catch: (cause) => | 180 | catch: (cause) => |
| 181 | new WorkspaceEntriesReadDirectoryError({ | 181 | new WorkspaceEntriesReadDirectoryError({ |
| 182 | cwd: input.cwd, | 182 | cwd: input.cwd, |
| @@ -7,7 +7,7 @@ · 6 unmodified lines | |||
| 7 | * | 7 | * |
| 8 | * @module WorkspaceFileSystem | 8 | * @module WorkspaceFileSystem |
| 9 | */ | 9 | */ |
| 10 | import { open, realpath } from "node:fs/promises"; | 10 | import * as NodeFSP from "node:fs/promises"; |
| 11 | 11 | ||
| 12 | import type { | 12 | import type { |
| 13 | ProjectReadFileInput, | 13 | ProjectReadFileInput, |
| @@ -89,8 +89,8 @@ export const make = Effect.gen(function* () { · 75 unmodified lines | |||
| 89 | return yield* Effect.tryPromise({ | 89 | return yield* Effect.tryPromise({ |
| 90 | try: async () => { | 90 | try: async () => { |
| 91 | const [realWorkspaceRoot, realTargetPath] = await Promise.all([ | 91 | const [realWorkspaceRoot, realTargetPath] = await Promise.all([ |
| 92 | realpath(input.cwd), | 92 | NodeFSP.realpath(input.cwd), |
| 93 | realpath(target.absolutePath), | 93 | NodeFSP.realpath(target.absolutePath), |
| 94 | ]); | 94 | ]); |
| 95 | const relativeRealPath = path.relative(realWorkspaceRoot, realTargetPath); | 95 | const relativeRealPath = path.relative(realWorkspaceRoot, realTargetPath); |
| 96 | if ( | 96 | if ( |
| @@ -101,7 +101,7 @@ export const make = Effect.gen(function* () { · 4 unmodified lines | |||
| 101 | throw new Error("Workspace file path resolves outside the project root."); | 101 | throw new Error("Workspace file path resolves outside the project root."); |
| 102 | } | 102 | } |
| 103 | 103 | ||
| 104 | const handle = await open(realTargetPath, "r"); | 104 | const handle = await NodeFSP.open(realTargetPath, "r"); |
| 105 | try { | 105 | try { |
| 106 | const stat = await handle.stat(); | 106 | const stat = await handle.stat(); |
| 107 | if (!stat.isFile()) { | 107 | if (!stat.isFile()) { |
| @@ -6,7 +6,7 @@ · 5 unmodified lines | |||
| 6 | * | 6 | * |
| 7 | * @module WorkspacePaths | 7 | * @module WorkspacePaths |
| 8 | */ | 8 | */ |
| 9 | import { homedir } from "node:os"; | 9 | import * as NodeOS from "node:os"; |
| 10 | 10 | ||
| 11 | import * as Context from "effect/Context"; | 11 | import * as Context from "effect/Context"; |
| 12 | import * as Effect from "effect/Effect"; | 12 | import * as Effect from "effect/Effect"; |
| @@ -105,10 +105,10 @@ function toPosixRelativePath(input: string): string { · 92 unmodified lines | |||
| 105 | 105 | ||
| 106 | function expandHomePath(input: string, path: Path.Path): string { | 106 | function expandHomePath(input: string, path: Path.Path): string { |
| 107 | if (input === "~") { | 107 | if (input === "~") { |
| 108 | return homedir(); | 108 | return NodeOS.homedir(); |
| 109 | } | 109 | } |
| 110 | if (input.startsWith("~/") || input.startsWith("~\\")) { | 110 | if (input.startsWith("~/") || input.startsWith("~\\")) { |
| 111 | return path.join(homedir(), input.slice(2)); | 111 | return path.join(NodeOS.homedir(), input.slice(2)); |
| 112 | } | 112 | } |
| 113 | return input; | 113 | return input; |
| 114 | } | 114 | } |