(filepath: string)
| 71 | } |
| 72 | |
| 73 | function formatFile(filepath: string) { |
| 74 | return Effect.gen(function* () { |
| 75 | yield* Effect.logInfo("formatting", { file: filepath }) |
| 76 | const formatters = yield* Effect.promise(() => getFormatter(path.extname(filepath))) |
| 77 | |
| 78 | if (!formatters.length) return false |
| 79 | |
| 80 | for (const { item, cmd } of formatters) { |
| 81 | yield* Effect.logInfo("running", { command: cmd }) |
| 82 | const replaced = cmd.map((x) => x.replace("$FILE", filepath)) |
| 83 | const dir = yield* InstanceState.directory |
| 84 | const result = yield* appProcess |
| 85 | .run( |
| 86 | ChildProcess.make(replaced[0]!, replaced.slice(1), { |
| 87 | cwd: dir, |
| 88 | env: item.environment, |
| 89 | extendEnv: true, |
| 90 | stdin: "ignore", |
| 91 | stdout: "ignore", |
| 92 | stderr: "ignore", |
| 93 | }), |
| 94 | ) |
| 95 | .pipe( |
| 96 | Effect.catch((error) => |
| 97 | Effect.logError("failed to format file", { |
| 98 | error: "spawn failed", |
| 99 | command: cmd, |
| 100 | ...item.environment, |
| 101 | file: filepath, |
| 102 | cause: errorMessage(error.cause ?? error), |
| 103 | }).pipe(Effect.as(undefined)), |
| 104 | ), |
| 105 | ) |
| 106 | if (result && result.exitCode !== 0) { |
| 107 | yield* Effect.logError("failed", { |
| 108 | command: cmd, |
| 109 | ...item.environment, |
| 110 | }) |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return true |
| 115 | }) |
| 116 | } |
| 117 | |
| 118 | const cfg = yield* config.get() |
| 119 |
no test coverage detected