(...files)
| 55 | } |
| 56 | |
| 57 | async function checkFiles(...files) { |
| 58 | const flags = FIX_MODE_ENABLED ? 'r+' : 'r'; |
| 59 | await Promise.all( |
| 60 | files.map(async (file) => { |
| 61 | const fd = await fs.open(file, flags); |
| 62 | if (await hasInvalidHashBang(fd)) { |
| 63 | if (FIX_MODE_ENABLED) { |
| 64 | const file = await fd.readFile(); |
| 65 | |
| 66 | const fileContent = |
| 67 | file[0] === '#'.charCodeAt() ? |
| 68 | file.subarray(file.indexOf('\n') + 1) : |
| 69 | file; |
| 70 | |
| 71 | const toWrite = Buffer.concat([expectedHashBang, fileContent]); |
| 72 | await fd.truncate(toWrite.length); |
| 73 | await fd.write(toWrite, 0, toWrite.length, 0); |
| 74 | } else { |
| 75 | process.exitCode ||= 1; |
| 76 | console.error( |
| 77 | (process.env.GITHUB_ACTIONS ? |
| 78 | `::error file=${file},line=1,col=1::` : |
| 79 | 'Fixable with --fix: ') + |
| 80 | `Invalid hashbang for ${file} (expected /bin/sh).`, |
| 81 | ); |
| 82 | } |
| 83 | } |
| 84 | await fd.close(); |
| 85 | }), |
| 86 | ); |
| 87 | |
| 88 | const stdout = await new Promise((resolve, reject) => { |
| 89 | const SHELLCHECK_EXE = |
| 90 | process.env.SHELLCHECK || |
| 91 | execSync('command -v ' + (USE_NPX ? 'npx' : SHELLCHECK_EXE_NAME)) |
| 92 | .toString() |
| 93 | .trim(); |
| 94 | const NPX_OPTIONS = USE_NPX ? [SHELLCHECK_EXE_NAME] : []; |
| 95 | |
| 96 | const shellcheck = spawn( |
| 97 | SHELLCHECK_EXE, |
| 98 | [ |
| 99 | ...NPX_OPTIONS, |
| 100 | ...SHELLCHECK_OPTIONS, |
| 101 | ...(FIX_MODE_ENABLED ? |
| 102 | files.map((filePath) => relative(SPAWN_OPTIONS.cwd, filePath)) : |
| 103 | files), |
| 104 | ], |
| 105 | SPAWN_OPTIONS, |
| 106 | ); |
| 107 | shellcheck.once('error', reject); |
| 108 | |
| 109 | let json = ''; |
| 110 | let childProcess = shellcheck; |
| 111 | if (FIX_MODE_ENABLED) { |
| 112 | const GIT_EXE = |
| 113 | process.env.GIT || execSync('command -v git').toString().trim(); |
| 114 |
no test coverage detected
searching dependent graphs…