UNPKG

@visulima/fs

Version:

Human friendly file system utilities for Node.js

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