@ms-cloudpack/path-utilities 2.0.2 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/findPackageRoot.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Given an absolute folder path into a package, traverse up the paths
|
|
3
|
-
* until the root has been found (containing the package.json file.
|
|
3
|
+
* until the root has been found (containing the package.json file).
|
|
4
|
+
* Returns undefined if no package root is found after traversing to the filesystem root.
|
|
4
5
|
*/
|
|
5
|
-
export declare function findPackageRoot(currentPath: string): string;
|
|
6
|
+
export declare function findPackageRoot(currentPath: string): string | undefined;
|
package/lib/findPackageRoot.js
CHANGED
|
@@ -2,10 +2,15 @@ import fs from 'fs';
|
|
|
2
2
|
import path from 'path';
|
|
3
3
|
/**
|
|
4
4
|
* Given an absolute folder path into a package, traverse up the paths
|
|
5
|
-
* until the root has been found (containing the package.json file.
|
|
5
|
+
* until the root has been found (containing the package.json file).
|
|
6
|
+
* Returns undefined if no package root is found after traversing to the filesystem root.
|
|
6
7
|
*/
|
|
7
8
|
export function findPackageRoot(currentPath) {
|
|
8
|
-
|
|
9
|
+
const root = path.parse(currentPath).root;
|
|
10
|
+
while (!fs.existsSync(path.join(currentPath, 'package.json'))) {
|
|
11
|
+
if (currentPath === root) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
9
14
|
currentPath = path.join(currentPath, '..');
|
|
10
15
|
}
|
|
11
16
|
return currentPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findPackageRoot.js","sourceRoot":"","sources":["../src/findPackageRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB
|
|
1
|
+
{"version":3,"file":"findPackageRoot.js","sourceRoot":"","sources":["../src/findPackageRoot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,WAAmB;IACjD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC;IAE1C,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC,EAAE;QAC7D,IAAI,WAAW,KAAK,IAAI,EAAE;YACxB,OAAO,SAAS,CAAC;SAClB;QACD,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC;KAC5C;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|