@k14v/nlink
Advanced tools
+43
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const yargs_1 = __importDefault(require("yargs")); | ||
| const path_1 = __importDefault(require("path")); | ||
| const helpers_1 = require("yargs/helpers"); | ||
| const ensureLinks_1 = __importDefault(require("./ensureLinks")); | ||
| const logger_1 = __importDefault(require("./logger")); | ||
| (async () => { | ||
| const argv = await (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)) | ||
| .option('verbose', { | ||
| alias: 'v', | ||
| type: 'boolean', | ||
| description: 'Run with verbose logging', | ||
| }) | ||
| .option('lib', { | ||
| alias: 'l', | ||
| type: 'string', | ||
| description: 'Directory to bind' | ||
| }) | ||
| .option('cwd', { | ||
| alias: 'c', | ||
| type: 'string', | ||
| description: 'Directory to where the modules is located' | ||
| }) | ||
| .option('no-workspace', { | ||
| type: 'boolean', | ||
| description: 'Apply links if workspace if present', | ||
| }) | ||
| .parse(); | ||
| const cwd = argv.cwd ? path_1.default.resolve(argv.cwd) : process.cwd(); | ||
| if (argv.verbose) { | ||
| logger_1.default.enableVerbose(); | ||
| } | ||
| (0, ensureLinks_1.default)({ | ||
| logger: logger_1.default, | ||
| cwd, | ||
| workspace: argv.workspace, | ||
| lib: argv.lib | ||
| }); | ||
| })(); |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.ensureLinks = void 0; | ||
| /// <reference path="../typings/npm-root.d.ts" /> | ||
| const find_up_1 = __importDefault(require("find-up")); | ||
| const path_1 = __importDefault(require("path")); | ||
| const util_1 = __importDefault(require("util")); | ||
| const fs_1 = __importDefault(require("fs")); | ||
| const os_1 = require("os"); | ||
| const utils_1 = require("./utils"); | ||
| const readConfig_1 = __importDefault(require("./readConfig")); | ||
| const logger_1 = __importDefault(require("./logger")); | ||
| const npm_root_1 = __importDefault(require("npm-root")); | ||
| const npmrp = util_1.default.promisify(npm_root_1.default); | ||
| const ensureLinks = async (opts) => { | ||
| const { cwd: cwdDir = process.cwd(), logger = logger_1.default, workspace = true, ...restOptions } = { ...opts }; | ||
| const linkModule = (target, linkpath) => { | ||
| const realpathLinkedModuleDir = (0, utils_1.symlinkRealpathSync)(linkpath); | ||
| if (target === realpathLinkedModuleDir) { | ||
| logger.silly(`Already linked to ${target}`); | ||
| return false; | ||
| } | ||
| else { | ||
| logger.silly(`Removing ${linkpath}`); | ||
| logger.silly(`Linking ${linkpath} -> ${target}`); | ||
| return (0, utils_1.symlinkRelative)(target, linkpath, true); | ||
| } | ||
| }; | ||
| const config = { ...(await (0, readConfig_1.default)(opts)), ...(0, utils_1.cleanUndef)(restOptions) }; | ||
| const pkgLinkPath = path_1.default.join(config.lib, 'package.json'); | ||
| logger.silly(`Linking package.json to "${pkgLinkPath}"`); | ||
| if ((0, utils_1.symlinkRelative)(config.pkgPath, pkgLinkPath, true)) { | ||
| logger(`Package.json linked "${config.pkgPath}" to "${pkgLinkPath}"`); | ||
| } | ||
| else { | ||
| throw new Error('Failed to link package.json'); | ||
| } | ||
| ; | ||
| const linkSuites = [{ | ||
| name: 'yarn', | ||
| dir: path_1.default.resolve((0, os_1.homedir)(), '.config/yarn/link'), | ||
| }, { | ||
| name: 'npm', | ||
| dir: await npmrp({ global: true }), | ||
| }]; | ||
| linkSuites.forEach(({ dir, name }) => { | ||
| logger.silly(`Checking if "${name}" config exist in "${dir}"`); | ||
| if (fs_1.default.existsSync(dir)) { | ||
| logger.info(`Detected "${name}" config in "${dir}"`); | ||
| const linkedModuleDir = path_1.default.resolve(dir, config.name); | ||
| logger.silly(`Checking if the module exists as "${name}" link in "${linkedModuleDir}"`); | ||
| if ((0, utils_1.symlinkExistsSync)(linkedModuleDir)) { | ||
| logger.info(`Detected linked module "${linkedModuleDir}"`); | ||
| logger.silly(`Replacing module link "${linkedModuleDir}" to "${config.lib}"`); | ||
| if (linkModule(config.lib, linkedModuleDir)) { | ||
| logger(`Module linked "${linkedModuleDir}" to "${config.lib}"`); | ||
| } | ||
| ; | ||
| } | ||
| } | ||
| }); | ||
| if (workspace) { | ||
| const workspacePkgPath = find_up_1.default.sync('package.json', { | ||
| cwd: path_1.default.resolve(cwdDir, '..'), | ||
| }); | ||
| if (workspacePkgPath) { | ||
| const linkedModuleDir = path_1.default.resolve(path_1.default.dirname(workspacePkgPath), 'node_modules', config.name); | ||
| logger.silly(`Checking if the module exist as link in workspace "${linkedModuleDir}"`); | ||
| if ((0, utils_1.symlinkExistsSync)(linkedModuleDir)) { | ||
| logger.info(`Detected workspace linked path "${linkedModuleDir}"`); | ||
| linkModule(config.lib, linkedModuleDir); | ||
| } | ||
| else { | ||
| logger.silly(`Skiping "${config.name}" doesn't exist in workspace "${workspacePkgPath}"`); | ||
| } | ||
| } | ||
| } | ||
| else { | ||
| logger.silly(`Skiping find module in workspace "opts.workspace=${workspace}"`); | ||
| } | ||
| }; | ||
| exports.ensureLinks = ensureLinks; | ||
| exports.default = exports.ensureLinks; |
+15
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| const debug_1 = __importDefault(require("debug")); | ||
| const logger = (0, debug_1.default)('nlink'); | ||
| debug_1.default.enable('nlink,nlink:info'); | ||
| exports.default = Object.assign(logger, { | ||
| info: logger.extend('info'), | ||
| silly: logger.extend('silly'), | ||
| enableVerbose: () => { | ||
| debug_1.default.enable('nlink*'); | ||
| } | ||
| }); |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.readConfig = void 0; | ||
| const fs_1 = __importDefault(require("fs")); | ||
| const path_1 = __importDefault(require("path")); | ||
| const read_tsconfig_1 = __importDefault(require("read-tsconfig")); | ||
| const logger_1 = __importDefault(require("./logger")); | ||
| const readConfig = async (opts) => { | ||
| var _a, _b; | ||
| const { cwd = process.cwd(), logger = logger_1.default, } = { ...opts }; | ||
| const pkgPath = path_1.default.resolve(cwd, 'package.json'); | ||
| const pkgContents = fs_1.default.readFileSync(pkgPath); | ||
| const pkgJSON = JSON.parse(pkgContents.toString()); | ||
| let libDir = (_a = pkgJSON === null || pkgJSON === void 0 ? void 0 : pkgJSON.nlink) === null || _a === void 0 ? void 0 : _a.lib; | ||
| if (libDir) { | ||
| logger.info(`Detected configuration for lib directory from pkg.nlink.lib: "${libDir}"`); | ||
| } | ||
| else { | ||
| libDir = (_b = (await (0, read_tsconfig_1.default)({ cwd })).compilerOptions) === null || _b === void 0 ? void 0 : _b.outDir; | ||
| if (libDir) { | ||
| logger.info(`Detected configuration for lib directory from tsconfig: "${libDir}"`); | ||
| } | ||
| } | ||
| if (typeof libDir !== 'string') { | ||
| throw new Error('nlink: Can\'t not guess the transpiled lib directory'); | ||
| } | ||
| const resolvedLib = path_1.default.resolve(cwd, libDir); | ||
| if (!fs_1.default.existsSync(resolvedLib)) { | ||
| throw new Error(`nlink: Missing is not exists "${resolvedLib}"`); | ||
| } | ||
| if (!pkgJSON.name) { | ||
| throw new Error(`nlink: Empty package.json name property`); | ||
| } | ||
| return { | ||
| pkgPath, | ||
| name: pkgJSON.name, | ||
| lib: resolvedLib | ||
| }; | ||
| }; | ||
| exports.readConfig = readConfig; | ||
| exports.default = exports.readConfig; |
+52
| "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; |
+61
-8
| { | ||
| "name": "@k14v/nlink", | ||
| "version": "0.0.1", | ||
| "description": "Expose a directory using require links usefull when transpiled src -> lib ", | ||
| "bin": "cli", | ||
| "version": "2.0.0-beta", | ||
| "description": "Modifies the global NodeJS module links to transpiled directory src -> lib", | ||
| "bin": "bin/cli", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| "test": "nyc --reporter=lcov ava --verbose", | ||
| "build": "tsc", | ||
| "prepublishOnly": "npm run build", | ||
| "prepack": "npm run build" | ||
| }, | ||
| "husky": { | ||
| "hooks": { | ||
| "pre-push": "npm test" | ||
| } | ||
| }, | ||
| "repository": { | ||
@@ -21,2 +29,3 @@ "type": "git", | ||
| "babel", | ||
| "typescript", | ||
| "transpiled", | ||
@@ -26,3 +35,14 @@ "require", | ||
| ], | ||
| "author": "", | ||
| "contributors": [ | ||
| { | ||
| "name": "kelvur", | ||
| "email": "osorio10.92@gmail.com", | ||
| "url": "https://github.com/kelvur" | ||
| }, | ||
| { | ||
| "name": "rubeniskov", | ||
| "email": "me@rubeniskov.com", | ||
| "url": "https://github.com/rubeniskov" | ||
| } | ||
| ], | ||
| "license": "MIT", | ||
@@ -34,6 +54,39 @@ "bugs": { | ||
| "dependencies": { | ||
| "glob": "^7.1.3", | ||
| "mkdirp": "^0.5.1", | ||
| "rimraf": "^2.6.3" | ||
| "debug": "^4.3.4", | ||
| "find-up": "^4.1.0", | ||
| "glob": "^7.1.6", | ||
| "mkdirp": "^1.0.4", | ||
| "npm-root": "^1.1.0", | ||
| "read-tsconfig": "^1.0.1", | ||
| "rimraf": "^3.0.2", | ||
| "yargs": "^17.4.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@schemastore/package": "^0.0.6", | ||
| "@tsconfig/node10": "^1.0.8", | ||
| "@types/debug": "^4.1.7", | ||
| "@types/node": "^17.0.23", | ||
| "@types/yargs": "^17.0.10", | ||
| "ava": "^4.1.0", | ||
| "execa": "^5.1.1", | ||
| "file-fixture": "^0.0.2", | ||
| "husky": "^4.2.5", | ||
| "nyc": "^15.1.0", | ||
| "ts-node": "^10.7.0", | ||
| "typescript": "^4.6.3" | ||
| }, | ||
| "engines": { | ||
| "node": ">=10" | ||
| }, | ||
| "ava": { | ||
| "files": [ | ||
| "src/*.spec.ts" | ||
| ], | ||
| "extensions": [ | ||
| "ts" | ||
| ], | ||
| "nodeArguments": [ | ||
| "--loader=ts-node/esm" | ||
| ] | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
| import test from 'ava'; | ||
| test('it should create') | ||
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
11280
81.18%6
50%240
11900%0
-100%1
-50%8
166.67%12
Infinity%3
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
Updated
Updated
Updated