History

[codex] Enforce canonical Node namespace imports (#3238)

Julius Marminge committed 4 months ago

Commit 2fa37ec1 parent db2750271 files · +1205 −952Browse files

Showing the changes to packages/shared/src (2 of 71 files). Show all

Unified · Split

2 files
  1. packages/shared/src/logging.ts +15 −15
  2. packages/shared/src/shell.ts +8 −8
packages/shared/src/logging.ts+15−15
@@ -1,6 +1,6 @@
11 // @effect-diagnostics nodeBuiltinImport:off
2−import fs from "node:fs";
3−import path from "node:path";
2+import * as NodeFS from "node:fs";
3+import * as NodePath from "node:path";
44
55 export interface RotatingFileSinkOptions {
66 readonly filePath: string;
@@ -29,7 +29,7 @@ export class RotatingFileSink { · 22 unmodified lines
2929 this.maxFiles = options.maxFiles;
3030 this.throwOnError = options.throwOnError ?? false;
3131
32− fs.mkdirSync(path.dirname(this.filePath), { recursive: true });
32+ NodeFS.mkdirSync(NodePath.dirname(this.filePath), { recursive: true });
3333 this.pruneOverflowBackups();
3434 this.currentSize = this.readCurrentSize();
3535 }
@@ -43,7 +43,7 @@ export class RotatingFileSink { · 7 unmodified lines
4343 this.rotate();
4444 }
4545
46− fs.appendFileSync(this.filePath, buffer);
46+ NodeFS.appendFileSync(this.filePath, buffer);
4747 this.currentSize += buffer.length;
4848
4949 if (this.currentSize > this.maxBytes) {
@@ -60,20 +60,20 @@ export class RotatingFileSink { · 10 unmodified lines
6060 private rotate(): void {
6161 try {
6262 const oldest = this.withSuffix(this.maxFiles);
63− if (fs.existsSync(oldest)) {
64− fs.rmSync(oldest, { force: true });
63+ if (NodeFS.existsSync(oldest)) {
64+ NodeFS.rmSync(oldest, { force: true });
6565 }
6666
6767 for (let index = this.maxFiles - 1; index >= 1; index -= 1) {
6868 const source = this.withSuffix(index);
6969 const target = this.withSuffix(index + 1);
70− if (fs.existsSync(source)) {
71− fs.renameSync(source, target);
70+ if (NodeFS.existsSync(source)) {
71+ NodeFS.renameSync(source, target);
7272 }
7373 }
7474
75− if (fs.existsSync(this.filePath)) {
76− fs.renameSync(this.filePath, this.withSuffix(1));
75+ if (NodeFS.existsSync(this.filePath)) {
76+ NodeFS.renameSync(this.filePath, this.withSuffix(1));
7777 }
7878
7979 this.currentSize = 0;
@@ -87,13 +87,13 @@ export class RotatingFileSink { · 7 unmodified lines
8787
8888 private pruneOverflowBackups(): void {
8989 try {
90− const dir = path.dirname(this.filePath);
91− const baseName = path.basename(this.filePath);
92− for (const entry of fs.readdirSync(dir)) {
90+ const dir = NodePath.dirname(this.filePath);
91+ const baseName = NodePath.basename(this.filePath);
92+ for (const entry of NodeFS.readdirSync(dir)) {
9393 if (!entry.startsWith(`${baseName}.`)) continue;
9494 const suffix = Number(entry.slice(baseName.length + 1));
9595 if (!Number.isInteger(suffix) || suffix <= this.maxFiles) continue;
96− fs.rmSync(path.join(dir, entry), { force: true });
96+ NodeFS.rmSync(NodePath.join(dir, entry), { force: true });
9797 }
9898 } catch {
9999 if (this.throwOnError) {
@@ -104,7 +104,7 @@ export class RotatingFileSink { · 4 unmodified lines
104104
105105 private readCurrentSize(): number {
106106 try {
107− return fs.statSync(this.filePath).size;
107+ return NodeFS.statSync(this.filePath).size;
108108 } catch {
109109 return 0;
110110 }
packages/shared/src/shell.ts+8−8
@@ -1,8 +1,8 @@
11 // @effect-diagnostics nodeBuiltinImport:off
22 import * as NodeOS from "node:os";
33 import * as NodePath from "node:path";
4−import { execFileSync } from "node:child_process";
5−import { accessSync, constants as fileSystemConstants, statSync } from "node:fs";
4+import * as NodeChildProcess from "node:child_process";
5+import * as NodeFS from "node:fs";
66 import * as Data from "effect/Data";
77 import * as Effect from "effect/Effect";
88 import * as FileSystem from "effect/FileSystem";
@@ -26,7 +26,7 @@ type ExecFileSyncLike = ( · 17 unmodified lines
2626
2727 function canExecuteFile(filePath: string): boolean {
2828 try {
29− accessSync(filePath, fileSystemConstants.X_OK);
29+ NodeFS.accessSync(filePath, NodeFS.constants.X_OK);
3030 return true;
3131 } catch {
3232 return false;
@@ -108,7 +108,7 @@ function resolveSpawnExecutableWithNode( · 75 unmodified lines
108108 );
109109 const isExecutable = (candidate: string) => {
110110 try {
111− if (!statSync(candidate).isFile()) return false;
111+ if (!NodeFS.statSync(candidate).isFile()) return false;
112112 if (platform === "win32") {
113113 return windowsPathExtensions.includes(path.extname(candidate).toUpperCase());
114114 }
@@ -192,13 +192,13 @@ export function extractPathFromShellOutput(output: string): string | null { · 77 unmodified lines
192192
193193 export function readPathFromLoginShell(
194194 shell: string,
195− execFile: ExecFileSyncLike = execFileSync,
195+ execFile: ExecFileSyncLike = NodeChildProcess.execFileSync,
196196 ): string | undefined {
197197 return readEnvironmentFromLoginShell(shell, ["PATH"], execFile).PATH;
198198 }
199199
200200 export function readPathFromLaunchctl(
201− execFile: ExecFileSyncLike = execFileSync,
201+ execFile: ExecFileSyncLike = NodeChildProcess.execFileSync,
202202 ): string | undefined {
203203 try {
204204 return trimNonEmpty(
@@ -305,7 +305,7 @@ export type ShellEnvironmentReader = ( · 100 unmodified lines
305305 export const readEnvironmentFromLoginShell: ShellEnvironmentReader = (
306306 shell,
307307 names,
308− execFile = execFileSync,
308+ execFile = NodeChildProcess.execFileSync,
309309 ) => {
310310 if (names.length === 0) {
311311 return {};
@@ -371,7 +371,7 @@ export function readEnvironmentFromWindowsShell( · 59 unmodified lines
371371 const execFile: ExecFileSyncLike =
372372 typeof optionsOrExecFile === "function"
373373 ? optionsOrExecFile
374− : (maybeExecFile ?? (execFileSync as ExecFileSyncLike));
374+ : (maybeExecFile ?? (NodeChildProcess.execFileSync as ExecFileSyncLike));
375375 const command = buildWindowsEnvironmentCaptureCommand(names);
376376 const args = [
377377 "-NoLogo",