UNPKG

@embrace-io/react-native

Version:
23 lines (22 loc) 727 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.writeIfNotExists = void 0; const fs = require("fs"); const writeIfNotExists = (filePath, contents, caller) => { try { const fd = fs.openSync(filePath, "wx"); fs.writeFileSync(fd, contents); // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e) { if (e && e.message && e.message.includes("EEXIST")) { // Don't try and overwrite the file if it already exists return false; } else { throw new Error(`${caller} failed to write ${filePath}: ${e}`); } } return true; }; exports.writeIfNotExists = writeIfNotExists;