You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1.5 KiB
34 lines
1.5 KiB
"use strict";
|
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.findProjectRoot = exports.isLocalPath = void 0;
|
|
const findup_sync_1 = __importDefault(require("findup-sync"));
|
|
const fs_1 = __importDefault(require("fs"));
|
|
const path_1 = __importDefault(require("path"));
|
|
/**
|
|
* Attempts to detect whether the string is a local path regardless of its
|
|
* existence by checking its format. The point is to distinguish between
|
|
* paths and modules on the npm registry. This will fail for non-existent
|
|
* local Windows paths that begin with a drive letter, e.g. C:..\generator.js,
|
|
* but will succeed for any existing files and any absolute paths.
|
|
*
|
|
* @param {String} str - string to check
|
|
* @returns {Boolean} whether the string could be a path to a local file or directory
|
|
*/
|
|
function isLocalPath(str) {
|
|
return path_1.default.isAbsolute(str) || /^\./.test(str) || fs_1.default.existsSync(str);
|
|
}
|
|
exports.isLocalPath = isLocalPath;
|
|
/**
|
|
* Find the root directory path of a project.
|
|
* @param {String} cwd - Any custom starting point to walk through directories
|
|
* @returns {String} Absolute path of the project root.
|
|
*/
|
|
function findProjectRoot(cwd = process.cwd()) {
|
|
const rootFilePath = findup_sync_1.default('package.json', { cwd });
|
|
const projectRoot = path_1.default.dirname(rootFilePath);
|
|
return projectRoot;
|
|
}
|
|
exports.findProjectRoot = findProjectRoot;
|
|
|