UNPKG

@k14v/nlink

Version:

Modifies the global NodeJS module links to transpiled directory src -> lib

53 lines (52 loc) 1.6 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cleanUndef = exports.symlinkRelative = exports.symlinkRealpathSync = exports.symlinkExistsSync = void 0; const path_1 = __importDefault(require("path")); const fs_1 = __importDefault(require("fs")); const symlinkExistsSync = (path) => { try { const stats = fs_1.default.lstatSync(path); return stats.isSymbolicLink(); } catch (ex) { return false; } }; exports.symlinkExistsSync = symlinkExistsSync; const symlinkRealpathSync = (path) => { try { return fs_1.default.realpathSync(path); } catch (ex) { return false; } }; exports.symlinkRealpathSync = symlinkRealpathSync; const symlinkRelative = (target, linkpath, force = false, type) => { if (force && (0, exports.symlinkExistsSync)(linkpath)) { fs_1.default.unlinkSync(linkpath); } try { const targetRelative = path_1.default.relative(path_1.default.join(linkpath, '..'), target); fs_1.default.symlinkSync(targetRelative, linkpath, type); return true; } catch (ex) { if (force) console.warn(ex); return false; } }; exports.symlinkRelative = symlinkRelative; const cleanUndef = (obj) => { Object.keys(obj).forEach((key) => { if (obj[key] === undefined) { delete obj[key]; } }); return obj; }; exports.cleanUndef = cleanUndef;