bit-bin
Version:
<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b
62 lines (46 loc) • 1.7 kB
JavaScript
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.pathJoinLinux = pathJoinLinux;
exports.pathNormalizeToLinux = pathNormalizeToLinux;
exports.pathRelativeLinux = pathRelativeLinux;
exports.pathResolveToLinux = pathResolveToLinux;
exports.getPathRelativeRegardlessCWD = getPathRelativeRegardlessCWD;
function path() {
const data = _interopRequireWildcard(require("path"));
path = function () {
return data;
};
return data;
}
function _normalizePath() {
const data = _interopRequireDefault(require("normalize-path"));
_normalizePath = function () {
return data;
};
return data;
}
function pathJoinLinux(...paths) {
return (0, _normalizePath().default)(path().join(...paths));
}
function pathNormalizeToLinux(pathToNormalize) {
return pathToNormalize ? (0, _normalizePath().default)(pathToNormalize) : pathToNormalize;
}
function pathRelativeLinux(from, to) {
return (0, _normalizePath().default)(path().relative(from, to));
}
function pathResolveToLinux(arr) {
return (0, _normalizePath().default)(path().resolve(arr.join(',')));
}
/**
* path.resolve uses current working dir.
* sometimes the cwd is not important. a user may running bit command from an inner dir.
*/
function getPathRelativeRegardlessCWD(from, to) {
const fromLinux = pathNormalizeToLinux(from);
const toLinux = pathNormalizeToLinux(to); // change them to absolute so path.relative won't consider the cwd
return pathRelativeLinux(`/${fromLinux}`, `/${toLinux}`);
}
;