(options?: MakeTempOptions)
| 109 | * @returns The file path to the temporary file. |
| 110 | */ |
| 111 | export function makeTempFileSync(options?: MakeTempOptions): string { |
| 112 | if (isDeno) { |
| 113 | return Deno.makeTempFileSync({ ...options }); |
| 114 | } else { |
| 115 | const { |
| 116 | dir, |
| 117 | prefix, |
| 118 | suffix, |
| 119 | } = options ?? {}; |
| 120 | |
| 121 | try { |
| 122 | const { tmpdir } = getNodeOs(); |
| 123 | const { join } = getNodePath(); |
| 124 | |
| 125 | let tempFilePath; |
| 126 | if (!options) { |
| 127 | tempFilePath = join(tmpdir(), randomId()); |
| 128 | writeTextFileSync(tempFilePath, "", { mode: 0o600 }); |
| 129 | return tempFilePath; |
| 130 | } |
| 131 | |
| 132 | tempFilePath = tmpdir(); |
| 133 | if (dir != null) { |
| 134 | tempFilePath = typeof dir === "string" ? dir : "."; |
| 135 | if (tempFilePath === "") { |
| 136 | tempFilePath = "."; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | if (prefix != null && typeof prefix === "string") { |
| 141 | tempFilePath = join(tempFilePath, prefix + randomId()); |
| 142 | } else { |
| 143 | tempFilePath = join(tempFilePath, randomId()); |
| 144 | } |
| 145 | |
| 146 | if (suffix != null && typeof suffix === "string") { |
| 147 | tempFilePath += suffix; |
| 148 | } |
| 149 | |
| 150 | writeTextFileSync(tempFilePath, "", { mode: 0o600 }); |
| 151 | return tempFilePath; |
| 152 | } catch (error) { |
| 153 | throw mapError(error); |
| 154 | } |
| 155 | } |
| 156 | } |
no test coverage detected