* Write `content` to `path` only if the file does not already exist. * Uses O_EXCL ('wx') for atomic create-if-missing.
( path: string, content: string, mode?: number, )
| 36 | * Uses O_EXCL ('wx') for atomic create-if-missing. |
| 37 | */ |
| 38 | async function writeIfMissing( |
| 39 | path: string, |
| 40 | content: string, |
| 41 | mode?: number, |
| 42 | ): Promise<boolean> { |
| 43 | try { |
| 44 | await writeFile(path, content, { encoding: 'utf8', flag: 'wx', mode }) |
| 45 | return true |
| 46 | } catch (e) { |
| 47 | if (getErrnoCode(e) === 'EEXIST') return false |
| 48 | throw e |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Ensure the local package environment is set up |
no test coverage detected