UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

37 lines (33 loc) 1.31 kB
'use strict'; const node_fs = require('node:fs'); const path = require('@visulima/path'); const utils = require('@visulima/path/utils'); const assertValidFileOrDirectoryPath = require('./assertValidFileOrDirectoryPath-BMbgA-eI.cjs'); const ensureDirSync = require('./ensureDirSync-DHmWi3CF.cjs'); const isStatsIdentical = require('./is-stats-identical-BfdEfO6i.cjs'); var __defProp = Object.defineProperty; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); const ensureLinkSync = /* @__PURE__ */ __name((source, destination) => { assertValidFileOrDirectoryPath(source); assertValidFileOrDirectoryPath(destination); source = path.toNamespacedPath(utils.toPath(source)); destination = path.toNamespacedPath(utils.toPath(destination)); let destinationStat; try { destinationStat = node_fs.lstatSync(destination); } catch { } let sourceStat; try { sourceStat = node_fs.lstatSync(source); } catch (error) { error.message = error.message.replace("lstat", "ensureLink"); throw error; } if (destinationStat && isStatsIdentical.isStatsIdentical(sourceStat, destinationStat)) { return; } ensureDirSync(path.dirname(destination)); node_fs.linkSync(source, destination); }, "ensureLinkSync"); module.exports = ensureLinkSync;