pnpm
Version:
A fast implementation of npm install
37 lines • 1.63 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
const fs = require('mz/fs');
const debug_1 = require('../debug');
const debug = debug_1.default('pnpm:symlink');
/**
* Creates a symlink. Re-link if a symlink already exists at the supplied
* srcPath. API compatible with [`fs#symlink`](https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback).
*/
function forceSymlink(srcPath, dstPath, type) {
return __awaiter(this, void 0, void 0, function* () {
debug(`${srcPath} -> ${dstPath}`);
try {
yield fs.symlink(srcPath, dstPath, type);
}
catch (err) {
if (err.code !== 'EEXIST')
throw err;
const linkString = yield fs.readlink(dstPath);
if (srcPath === linkString) {
return;
}
yield fs.unlink(dstPath);
yield forceSymlink(srcPath, dstPath, type);
}
});
}
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = forceSymlink;
//# sourceMappingURL=forceSymlink.js.map