'use strict'; const fs = require('node:fs'); const nodePath = require('node:path'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; } const fs__default = /*#__PURE__*/_interopDefaultCompat(fs); const nodePath__default = /*#__PURE__*/_interopDefaultCompat(nodePath); const validateUint32 = (value, name) => { if (typeof value !== "number") { throw new Error(`${name}: ${value} is not number`); } if (!Number.isInteger(value)) { throw new Error(`${name}: ${value} is not an integer`); } const min = 0; const max = 4294967295; if (value < min || value > max) { throw new Error(`${name}: ${value} must >= ${min} && <= ${max}`); } }; function parseFileMode(value, name, def) { value ?? (value = def); if (typeof value === "string") { if (!/^[0-7]+$/.test(value)) { throw new Error(`${name}: ${value} is invalid`); } value = Number.parseInt(value, 8); } validateUint32(value, name); return value; } function mkdirSyncRecursive(path, options) { let mode = 511; if (typeof options === "number" || typeof options === "string") { mode = parseFileMode(options, "mode"); } else if (options) { if (options.mode !== void 0) { mode = parseFileMode(options.mode, "options.mode"); } } const dirs = path.split("/"); let dirPath = ""; const result = []; for (const dir of dirs) { dirPath += `${dir}/`; mkdir(dirPath, mode); } function mkdir(path2, mode2) { if (!fs__default.existsSync(dirPath)) { try { fs__default.mkdirSync(path2, mode2); result.push(path2); return true; } catch (error) { console.error(error); return false; } } return void 0; } return result.length ? nodePath__default.resolve(result[0]) : void 0; } module.exports = mkdirSyncRecursive;