Showing the changes to packages/shared/src (2 of 71 files). Show all
Unified · Split
| @@ -1,6 +1,6 @@ | |||
| 1 | // @effect-diagnostics nodeBuiltinImport:off | 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import fs from "node:fs"; | 2 | import * as NodeFS from "node:fs"; |
| 3 | import path from "node:path"; | 3 | import * as NodePath from "node:path"; |
| 4 | 4 | ||
| 5 | export interface RotatingFileSinkOptions { | 5 | export interface RotatingFileSinkOptions { |
| 6 | readonly filePath: string; | 6 | readonly filePath: string; |
| @@ -29,7 +29,7 @@ export class RotatingFileSink { · 22 unmodified lines | |||
| 29 | this.maxFiles = options.maxFiles; | 29 | this.maxFiles = options.maxFiles; |
| 30 | this.throwOnError = options.throwOnError ?? false; | 30 | this.throwOnError = options.throwOnError ?? false; |
| 31 | 31 | ||
| 32 | fs.mkdirSync(path.dirname(this.filePath), { recursive: true }); | 32 | NodeFS.mkdirSync(NodePath.dirname(this.filePath), { recursive: true }); |
| 33 | this.pruneOverflowBackups(); | 33 | this.pruneOverflowBackups(); |
| 34 | this.currentSize = this.readCurrentSize(); | 34 | this.currentSize = this.readCurrentSize(); |
| 35 | } | 35 | } |
| @@ -43,7 +43,7 @@ export class RotatingFileSink { · 7 unmodified lines | |||
| 43 | this.rotate(); | 43 | this.rotate(); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | fs.appendFileSync(this.filePath, buffer); | 46 | NodeFS.appendFileSync(this.filePath, buffer); |
| 47 | this.currentSize += buffer.length; | 47 | this.currentSize += buffer.length; |
| 48 | 48 | ||
| 49 | if (this.currentSize > this.maxBytes) { | 49 | if (this.currentSize > this.maxBytes) { |
| @@ -60,20 +60,20 @@ export class RotatingFileSink { · 10 unmodified lines | |||
| 60 | private rotate(): void { | 60 | private rotate(): void { |
| 61 | try { | 61 | try { |
| 62 | const oldest = this.withSuffix(this.maxFiles); | 62 | const oldest = this.withSuffix(this.maxFiles); |
| 63 | if (fs.existsSync(oldest)) { | 63 | if (NodeFS.existsSync(oldest)) { |
| 64 | fs.rmSync(oldest, { force: true }); | 64 | NodeFS.rmSync(oldest, { force: true }); |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | for (let index = this.maxFiles - 1; index >= 1; index -= 1) { | 67 | for (let index = this.maxFiles - 1; index >= 1; index -= 1) { |
| 68 | const source = this.withSuffix(index); | 68 | const source = this.withSuffix(index); |
| 69 | const target = this.withSuffix(index + 1); | 69 | const target = this.withSuffix(index + 1); |
| 70 | if (fs.existsSync(source)) { | 70 | if (NodeFS.existsSync(source)) { |
| 71 | fs.renameSync(source, target); | 71 | NodeFS.renameSync(source, target); |
| 72 | } | 72 | } |
| 73 | } | 73 | } |
| 74 | 74 | ||
| 75 | if (fs.existsSync(this.filePath)) { | 75 | if (NodeFS.existsSync(this.filePath)) { |
| 76 | fs.renameSync(this.filePath, this.withSuffix(1)); | 76 | NodeFS.renameSync(this.filePath, this.withSuffix(1)); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | this.currentSize = 0; | 79 | this.currentSize = 0; |
| @@ -87,13 +87,13 @@ export class RotatingFileSink { · 7 unmodified lines | |||
| 87 | 87 | ||
| 88 | private pruneOverflowBackups(): void { | 88 | private pruneOverflowBackups(): void { |
| 89 | try { | 89 | try { |
| 90 | const dir = path.dirname(this.filePath); | 90 | const dir = NodePath.dirname(this.filePath); |
| 91 | const baseName = path.basename(this.filePath); | 91 | const baseName = NodePath.basename(this.filePath); |
| 92 | for (const entry of fs.readdirSync(dir)) { | 92 | for (const entry of NodeFS.readdirSync(dir)) { |
| 93 | if (!entry.startsWith(`${baseName}.`)) continue; | 93 | if (!entry.startsWith(`${baseName}.`)) continue; |
| 94 | const suffix = Number(entry.slice(baseName.length + 1)); | 94 | const suffix = Number(entry.slice(baseName.length + 1)); |
| 95 | if (!Number.isInteger(suffix) || suffix <= this.maxFiles) continue; | 95 | 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 }); |
| 97 | } | 97 | } |
| 98 | } catch { | 98 | } catch { |
| 99 | if (this.throwOnError) { | 99 | if (this.throwOnError) { |
| @@ -104,7 +104,7 @@ export class RotatingFileSink { · 4 unmodified lines | |||
| 104 | 104 | ||
| 105 | private readCurrentSize(): number { | 105 | private readCurrentSize(): number { |
| 106 | try { | 106 | try { |
| 107 | return fs.statSync(this.filePath).size; | 107 | return NodeFS.statSync(this.filePath).size; |
| 108 | } catch { | 108 | } catch { |
| 109 | return 0; | 109 | return 0; |
| 110 | } | 110 | } |
| @@ -1,8 +1,8 @@ | |||
| 1 | // @effect-diagnostics nodeBuiltinImport:off | 1 | // @effect-diagnostics nodeBuiltinImport:off |
| 2 | import * as NodeOS from "node:os"; | 2 | import * as NodeOS from "node:os"; |
| 3 | import * as NodePath from "node:path"; | 3 | import * as NodePath from "node:path"; |
| 4 | import { execFileSync } from "node:child_process"; | 4 | import * as NodeChildProcess from "node:child_process"; |
| 5 | import { accessSync, constants as fileSystemConstants, statSync } from "node:fs"; | 5 | import * as NodeFS from "node:fs"; |
| 6 | import * as Data from "effect/Data"; | 6 | import * as Data from "effect/Data"; |
| 7 | import * as Effect from "effect/Effect"; | 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as FileSystem from "effect/FileSystem"; | 8 | import * as FileSystem from "effect/FileSystem"; |
| @@ -26,7 +26,7 @@ type ExecFileSyncLike = ( · 17 unmodified lines | |||
| 26 | 26 | ||
| 27 | function canExecuteFile(filePath: string): boolean { | 27 | function canExecuteFile(filePath: string): boolean { |
| 28 | try { | 28 | try { |
| 29 | accessSync(filePath, fileSystemConstants.X_OK); | 29 | NodeFS.accessSync(filePath, NodeFS.constants.X_OK); |
| 30 | return true; | 30 | return true; |
| 31 | } catch { | 31 | } catch { |
| 32 | return false; | 32 | return false; |
| @@ -108,7 +108,7 @@ function resolveSpawnExecutableWithNode( · 75 unmodified lines | |||
| 108 | ); | 108 | ); |
| 109 | const isExecutable = (candidate: string) => { | 109 | const isExecutable = (candidate: string) => { |
| 110 | try { | 110 | try { |
| 111 | if (!statSync(candidate).isFile()) return false; | 111 | if (!NodeFS.statSync(candidate).isFile()) return false; |
| 112 | if (platform === "win32") { | 112 | if (platform === "win32") { |
| 113 | return windowsPathExtensions.includes(path.extname(candidate).toUpperCase()); | 113 | return windowsPathExtensions.includes(path.extname(candidate).toUpperCase()); |
| 114 | } | 114 | } |
| @@ -192,13 +192,13 @@ export function extractPathFromShellOutput(output: string): string | null { · 77 unmodified lines | |||
| 192 | 192 | ||
| 193 | export function readPathFromLoginShell( | 193 | export function readPathFromLoginShell( |
| 194 | shell: string, | 194 | shell: string, |
| 195 | execFile: ExecFileSyncLike = execFileSync, | 195 | execFile: ExecFileSyncLike = NodeChildProcess.execFileSync, |
| 196 | ): string | undefined { | 196 | ): string | undefined { |
| 197 | return readEnvironmentFromLoginShell(shell, ["PATH"], execFile).PATH; | 197 | return readEnvironmentFromLoginShell(shell, ["PATH"], execFile).PATH; |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | export function readPathFromLaunchctl( | 200 | export function readPathFromLaunchctl( |
| 201 | execFile: ExecFileSyncLike = execFileSync, | 201 | execFile: ExecFileSyncLike = NodeChildProcess.execFileSync, |
| 202 | ): string | undefined { | 202 | ): string | undefined { |
| 203 | try { | 203 | try { |
| 204 | return trimNonEmpty( | 204 | return trimNonEmpty( |
| @@ -305,7 +305,7 @@ export type ShellEnvironmentReader = ( · 100 unmodified lines | |||
| 305 | export const readEnvironmentFromLoginShell: ShellEnvironmentReader = ( | 305 | export const readEnvironmentFromLoginShell: ShellEnvironmentReader = ( |
| 306 | shell, | 306 | shell, |
| 307 | names, | 307 | names, |
| 308 | execFile = execFileSync, | 308 | execFile = NodeChildProcess.execFileSync, |
| 309 | ) => { | 309 | ) => { |
| 310 | if (names.length === 0) { | 310 | if (names.length === 0) { |
| 311 | return {}; | 311 | return {}; |
| @@ -371,7 +371,7 @@ export function readEnvironmentFromWindowsShell( · 59 unmodified lines | |||
| 371 | const execFile: ExecFileSyncLike = | 371 | const execFile: ExecFileSyncLike = |
| 372 | typeof optionsOrExecFile === "function" | 372 | typeof optionsOrExecFile === "function" |
| 373 | ? optionsOrExecFile | 373 | ? optionsOrExecFile |
| 374 | : (maybeExecFile ?? (execFileSync as ExecFileSyncLike)); | 374 | : (maybeExecFile ?? (NodeChildProcess.execFileSync as ExecFileSyncLike)); |
| 375 | const command = buildWindowsEnvironmentCaptureCommand(names); | 375 | const command = buildWindowsEnvironmentCaptureCommand(names); |
| 376 | const args = [ | 376 | const args = [ |
| 377 | "-NoLogo", | 377 | "-NoLogo", |