@ms-cloudpack/path-utilities
Advanced tools
Comparing version 2.1.2 to 2.2.0
@@ -5,3 +5,5 @@ /** | ||
* Returns undefined if no package root is found after traversing to the filesystem root. | ||
* @param startFolder - Absolute path to the folder to start searching from. | ||
* @param excludeNodeModules - If true, don't return a path that contains a `node_modules` segment. | ||
*/ | ||
export declare function findPackageRoot(currentPath: string): string | undefined; | ||
export declare function findPackageRoot(startFolder: string, excludeNodeModules?: boolean): string | undefined; |
import fs from 'fs'; | ||
import path from 'path'; | ||
const nodeModulesRegex = /[\\/]node_modules($|[\\/])/; | ||
/** | ||
@@ -7,13 +8,19 @@ * Given an absolute folder path into a package, traverse up the paths | ||
* Returns undefined if no package root is found after traversing to the filesystem root. | ||
* @param startFolder - Absolute path to the folder to start searching from. | ||
* @param excludeNodeModules - If true, don't return a path that contains a `node_modules` segment. | ||
*/ | ||
export function findPackageRoot(currentPath) { | ||
const root = path.parse(currentPath).root; | ||
while (!fs.existsSync(path.join(currentPath, 'package.json'))) { | ||
if (currentPath === root) { | ||
export function findPackageRoot(startFolder, excludeNodeModules) { | ||
const root = path.parse(startFolder).root; | ||
let currentFolder = startFolder; | ||
if (excludeNodeModules && nodeModulesRegex.test(startFolder)) { | ||
currentFolder = startFolder.split(nodeModulesRegex)[0]; | ||
} | ||
while (!fs.existsSync(path.join(currentFolder, 'package.json'))) { | ||
if (currentFolder === root) { | ||
return undefined; | ||
} | ||
currentPath = path.dirname(currentPath); | ||
currentFolder = path.dirname(currentFolder); | ||
} | ||
return currentPath; | ||
return currentFolder; | ||
} | ||
//# sourceMappingURL=findPackageRoot.js.map |
{ | ||
"name": "@ms-cloudpack/path-utilities", | ||
"version": "2.1.2", | ||
"version": "2.2.0", | ||
"description": "Utilities for resolving paths between source/intermediate/output locations in Cloudpack.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22116
202