Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ms-cloudpack/path-utilities

Package Overview
Dependencies
Maintainers
2
Versions
88
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ms-cloudpack/path-utilities - npm Package Compare versions

Comparing version 2.1.2 to 2.2.0

4

lib/findPackageRoot.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc