UNPKG

machinepack-paths

Version:

Utilities for handling and transforming file paths.

73 lines (44 loc) 1.79 kB
module.exports = { friendlyName: 'Resolve path', description: 'Resolve and normalize a potentially-relative path into an absolute path.', extendedDescription: 'The resulting path is also normalized, and trailing slashes are removed unless the path gets resolved to the root directory.', moreInfoUrl: 'https://nodejs.org/docs/latest/api/path.html#path_path_resolve_from_to', cacheable: true, sync: true, inputs: { path: { friendlyName: 'Path', description: 'The path to be resolved to an absolute path.', extendedDescription: 'If first path is not absolute, it will be resolved from the process\'s present working directory (`pwd`).', example: 'node_modules/sails/bin/sails.js', required: true }, from: { friendlyName: 'From', description: 'The working directory to resolve from.', extendedDescription: 'If omitted, the result path will be resolved from the process\'s present working directory (`pwd`). '+ 'If `from` is not absolute, then it will first be resolved from the present working directory itself before being used to resolve `path`.', example: '/usr/local/lib' } }, exits: { success: { outputVariableName: 'path', outputDescription: 'An absolute path.', example: '/usr/local/lib/node_modules/sails/bin/sails.js' } }, fn: function (inputs,exits) { var result; // If `from` was provided, resolve `path` from it. // (if `from` is a relative path it will be resolved relative to pwd first) if (inputs.from) { result = require('path').resolve(inputs.from, inputs.path); } // Otherwise, use pwd. else { result = require('path').resolve(inputs.path); } return exits.success(result); } };