* 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, )
| 52 | * Uses O_EXCL ('wx') for atomic create-if-missing. |
| 53 | */ |
| 54 | async function writeIfMissing( |
| 55 | path: string, |
| 56 | content: string, |
| 57 | mode?: number, |
| 58 | ): Promise<boolean> { |
| 59 | try { |
| 60 | await writeFile(path, content, { encoding: 'utf8', flag: 'wx', mode }) |
| 61 | return true |
| 62 | } catch (e) { |
| 63 | if (getErrnoCode(e) === 'EEXIST') return false |
| 64 | throw e |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Ensure the local package environment is set up |
no test coverage detected