|
14 | 14 |
|
15 | 15 | import os from 'node:os'
|
16 | 16 | import path from 'node:path'
|
17 |
| -import fs from 'node:fs' |
| 17 | +import fs, { type Mode } from 'node:fs' |
18 | 18 | import { chalk, type RequestInfo, type RequestInit } from './vendor-core.js'
|
19 | 19 | import { inspect } from 'node:util'
|
20 | 20 |
|
21 | 21 | export { isStringLiteral } from './vendor-core.js'
|
22 | 22 |
|
23 |
| -export function tempdir(prefix: string = `zx-${randomId()}`): string { |
| 23 | +export function tempdir( |
| 24 | + prefix: string = `zx-${randomId()}`, |
| 25 | + mode?: Mode |
| 26 | +): string { |
24 | 27 | const dirpath = path.join(os.tmpdir(), prefix)
|
25 |
| - fs.mkdirSync(dirpath, { recursive: true }) |
| 28 | + fs.mkdirSync(dirpath, { recursive: true, mode }) |
26 | 29 |
|
27 | 30 | return dirpath
|
28 | 31 | }
|
29 | 32 |
|
30 |
| -export function tempfile(name?: string, data?: string | Buffer): string { |
| 33 | +export function tempfile( |
| 34 | + name?: string, |
| 35 | + data?: string | Buffer, |
| 36 | + mode?: Mode |
| 37 | +): string { |
31 | 38 | const filepath = name
|
32 | 39 | ? path.join(tempdir(), name)
|
33 | 40 | : path.join(os.tmpdir(), `zx-${randomId()}`)
|
34 | 41 |
|
35 |
| - if (data === undefined) fs.closeSync(fs.openSync(filepath, 'w')) |
36 |
| - else fs.writeFileSync(filepath, data) |
| 42 | + if (data === undefined) fs.closeSync(fs.openSync(filepath, 'w', mode)) |
| 43 | + else fs.writeFileSync(filepath, data, { mode }) |
37 | 44 |
|
38 | 45 | return filepath
|
39 | 46 | }
|
|
0 commit comments