(filePaths: string[])
| 1070 | } |
| 1071 | |
| 1072 | async function followLogFiles(filePaths: string[]): Promise<void> { |
| 1073 | const positions = new Map<string, number>(); |
| 1074 | for (const filePath of filePaths) { |
| 1075 | try { |
| 1076 | const stats = await fsp.stat(filePath); |
| 1077 | positions.set(filePath, stats.size); |
| 1078 | } catch { |
| 1079 | positions.set(filePath, 0); |
| 1080 | } |
| 1081 | } |
| 1082 | await new Promise<void>(() => { |
| 1083 | const timer = setInterval(async () => { |
| 1084 | for (const filePath of filePaths) { |
| 1085 | try { |
| 1086 | const stats = await fsp.stat(filePath); |
| 1087 | const previousSize = positions.get(filePath) ?? 0; |
| 1088 | if (stats.size <= previousSize) { |
| 1089 | continue; |
| 1090 | } |
| 1091 | const handle = await fsp.open(filePath, 'r'); |
| 1092 | try { |
| 1093 | const buffer = Buffer.alloc(stats.size - previousSize); |
| 1094 | await handle.read(buffer, 0, buffer.length, previousSize); |
| 1095 | process.stdout.write(buffer.toString('utf8')); |
| 1096 | positions.set(filePath, stats.size); |
| 1097 | } finally { |
| 1098 | await handle.close(); |
| 1099 | } |
| 1100 | } catch { |
| 1101 | // Ignore transient read errors while following logs. |
| 1102 | } |
| 1103 | } |
| 1104 | }, 1000); |
| 1105 | process.on('SIGINT', () => clearInterval(timer)); |
| 1106 | process.on('SIGTERM', () => clearInterval(timer)); |
| 1107 | }); |
| 1108 | } |
| 1109 | |
| 1110 | function buildServicePathEnv(platform: NodeJS.Platform, currentPath: string | undefined, nodeBin: string): string { |
| 1111 | const parts = new Set<string>(); |
no test coverage detected