UNPKG

piral-cli

Version:

The standard CLI for creating and building a Piral instance or a Pilet.

62 lines 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolvers = void 0; const fs_1 = require("fs"); const path_1 = require("path"); const isWin32 = process.platform === 'win32'; function fromNode() { const nodePath = process.env.NODE_PATH; if (nodePath) { const nodePaths = nodePath.split(path_1.delimiter).map(path_1.normalize); for (let i = 0, l = nodePath.length; i < l; i += 1) { const modulePath = nodePaths[i]; if (modulePath && (0, fs_1.existsSync)(modulePath)) { return modulePath; } } } return undefined; } function fromHome() { const homePath = isWin32 ? process.env['USERPROFILE'] : process.env['HOME']; const paths = ['node_modules', 'node_libraries', 'node_packages']; for (let i = 0, l = paths.length; i < l; i += 1) { const modulePath = (0, path_1.join)(homePath, paths[i]); if (modulePath && (0, fs_1.existsSync)(modulePath)) { return modulePath; } } return undefined; } function fromEnvironment() { const nodeModule = process.env['NODE_MODULES']; if (typeof nodeModule === 'string') { const nodeModules = nodeModule.split(path_1.delimiter); for (let i = 0, l = nodeModules.length; i < l; i += 1) { const modulePath = nodeModules[i]; if (modulePath && (0, fs_1.existsSync)(modulePath)) { return modulePath; } } } return undefined; } function fromLibraries() { if (isWin32) { const prefix = (0, path_1.join)(process.env.APPDATA, 'npm'); const path = (0, path_1.join)(prefix, 'node_modules'); return (0, fs_1.existsSync)(path) && path; } else { const prefix = (0, path_1.join)((0, path_1.dirname)(process.execPath), '..'); const path = (0, path_1.join)(prefix, 'lib', 'node_modules'); return (0, fs_1.existsSync)(path) && path; } } function fromExecutable() { const execPath = (0, path_1.dirname)(process.execPath); const path = isWin32 ? execPath : (0, path_1.join)(execPath, '..', 'lib'); return (0, path_1.join)(path, 'node_modules'); } exports.resolvers = [fromNode, fromHome, fromEnvironment, fromLibraries, fromExecutable]; //# sourceMappingURL=resolvers.js.map