[codex] Enforce canonical Node namespace imports (#3238)
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
db27502aff
commit
2fa37ec183
71 files changed
+1205
-952
No files matched your search
@@ -1,13 +1,14 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import fsPromises from "node:fs/promises";
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodeServices from "@effect/platform-node/NodeServices";
|
||||
import { FileFinder } from "@ff-labs/fff-node";
|
||||
import { it, afterEach, describe, expect, vi } from "@effect/vitest";
|
||||
import { it, afterEach, describe, expect } from "@effect/vitest";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as FileSystem from "effect/FileSystem";
|
||||
import * as Layer from "effect/Layer";
|
||||
import * as Path from "effect/Path";
|
||||
import * as PlatformError from "effect/PlatformError";
|
||||
import { vi } from "vite-plus/test";
|
||||
|
||||
import * as ServerConfig from "../config.ts";
|
||||
import { HostProcessPlatform } from "@t3tools/shared/hostProcess";
|
||||
@@ -15,6 +16,11 @@ import * as VcsProcess from "../vcs/VcsProcess.ts";
|
||||
import * as WorkspaceEntries from "./WorkspaceEntries.ts";
|
||||
import * as WorkspacePaths from "./WorkspacePaths.ts";
|
||||
|
||||
vi.mock("node:fs/promises", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("node:fs/promises")>();
|
||||
return { ...actual, readdir: vi.fn(actual.readdir) };
|
||||
});
|
||||
|
||||
const TestLayer = Layer.empty.pipe(
|
||||
Layer.provideMerge(WorkspaceEntries.layer.pipe(Layer.provide(WorkspacePaths.layer))),
|
||||
Layer.provideMerge(WorkspacePaths.layer),
|
||||
@@ -376,7 +382,7 @@ it.layer(TestLayer, { excludeTestServices: true })("WorkspaceEntries", (it) => {
|
||||
const cwd = yield* makeTempDir({ prefix: "t3code-workspace-browse-eacces-" });
|
||||
|
||||
const denied = Object.assign(new Error("EACCES: permission denied"), { code: "EACCES" });
|
||||
vi.spyOn(fsPromises, "readdir").mockRejectedValueOnce(denied);
|
||||
vi.mocked(NodeFSP.readdir).mockRejectedValueOnce(denied);
|
||||
|
||||
const result = yield* workspaceEntries.browse({
|
||||
partialPath: yield* appendSeparator(cwd),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// @effect-diagnostics nodeBuiltinImport:off
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
import * as NodeOS from "node:os";
|
||||
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
@@ -98,10 +98,10 @@ export class WorkspaceEntries extends Context.Service<
|
||||
|
||||
function expandHomePath(input: string, path: Path.Path): string {
|
||||
if (input === "~") {
|
||||
return homedir();
|
||||
return NodeOS.homedir();
|
||||
}
|
||||
if (input.startsWith("~/") || input.startsWith("~\\")) {
|
||||
return path.join(homedir(), input.slice(2));
|
||||
return path.join(NodeOS.homedir(), input.slice(2));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ export const make = Effect.gen(function* () {
|
||||
const prefix = endsWithSeparator ? "" : path.basename(resolvedInputPath);
|
||||
|
||||
const dirents = yield* Effect.tryPromise({
|
||||
try: () => readdir(parentPath, { withFileTypes: true }),
|
||||
try: () => NodeFSP.readdir(parentPath, { withFileTypes: true }),
|
||||
catch: (cause) =>
|
||||
new WorkspaceEntriesReadDirectoryError({
|
||||
cwd: input.cwd,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*
|
||||
* @module WorkspaceFileSystem
|
||||
*/
|
||||
import { open, realpath } from "node:fs/promises";
|
||||
import * as NodeFSP from "node:fs/promises";
|
||||
|
||||
import type {
|
||||
ProjectReadFileInput,
|
||||
@@ -89,8 +89,8 @@ export const make = Effect.gen(function* () {
|
||||
return yield* Effect.tryPromise({
|
||||
try: async () => {
|
||||
const [realWorkspaceRoot, realTargetPath] = await Promise.all([
|
||||
realpath(input.cwd),
|
||||
realpath(target.absolutePath),
|
||||
NodeFSP.realpath(input.cwd),
|
||||
NodeFSP.realpath(target.absolutePath),
|
||||
]);
|
||||
const relativeRealPath = path.relative(realWorkspaceRoot, realTargetPath);
|
||||
if (
|
||||
@@ -101,7 +101,7 @@ export const make = Effect.gen(function* () {
|
||||
throw new Error("Workspace file path resolves outside the project root.");
|
||||
}
|
||||
|
||||
const handle = await open(realTargetPath, "r");
|
||||
const handle = await NodeFSP.open(realTargetPath, "r");
|
||||
try {
|
||||
const stat = await handle.stat();
|
||||
if (!stat.isFile()) {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
* @module WorkspacePaths
|
||||
*/
|
||||
import { homedir } from "node:os";
|
||||
import * as NodeOS from "node:os";
|
||||
|
||||
import * as Context from "effect/Context";
|
||||
import * as Effect from "effect/Effect";
|
||||
@@ -105,10 +105,10 @@ function toPosixRelativePath(input: string): string {
|
||||
|
||||
function expandHomePath(input: string, path: Path.Path): string {
|
||||
if (input === "~") {
|
||||
return homedir();
|
||||
return NodeOS.homedir();
|
||||
}
|
||||
if (input.startsWith("~/") || input.startsWith("~\\")) {
|
||||
return path.join(homedir(), input.slice(2));
|
||||
return path.join(NodeOS.homedir(), input.slice(2));
|
||||
}
|
||||
return input;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user