MCPcopy Create free account
hub / github.com/vercel/vercel / writeJsonFileSync

Function writeJsonFileSync

packages/cli-config/src/cli-config.ts:68–97  ·  view source on GitHub ↗
(
  filePath: string,
  value: unknown,
  options: WriteConfigFileOptions = {}
)

Source from the content-addressed store, hash-verified

66}
67
68function writeJsonFileSync(
69 filePath: string,
70 value: unknown,
71 options: WriteConfigFileOptions = {}
72): void {
73 const directory = path.dirname(filePath);
74 const tempFilePath = path.join(
75 directory,
76 `.${path.basename(filePath)}.${process.pid}.${Date.now()}.tmp`
77 );
78 const content = `${JSON.stringify(value, null, options.indent ?? 2)}\n`;
79
80 fs.mkdirSync(directory, { recursive: true });
81
82 try {
83 fs.writeFileSync(tempFilePath, content, {
84 encoding: 'utf8',
85 mode: options.mode,
86 });
87 fs.renameSync(tempFilePath, filePath);
88 } catch (error) {
89 try {
90 fs.rmSync(tempFilePath, { force: true });
91 } catch {
92 // Best-effort cleanup for failed atomic writes.
93 }
94
95 throw error;
96 }
97}
98
99export function readConfigFile<S extends z.ZodType>(
100 configPath: string,

Callers 1

writeConfigFileFunction · 0.85

Calls 4

joinMethod · 0.45
mkdirSyncMethod · 0.45
writeFileSyncMethod · 0.45
renameSyncMethod · 0.45

Tested by

no test coverage detected