@stryke/fs 0.27.0 → 0.28.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.
@@ -8,13 +8,16 @@ exports.getProjectRoot = getProjectRoot;
8
8
  exports.getWorkspaceRoot = getWorkspaceRoot;
9
9
  exports.isProjectRoot = isProjectRoot;
10
10
  exports.isWorkspaceRoot = isWorkspaceRoot;
11
+ exports.relativeToProjectRoot = relativeToProjectRoot;
12
+ exports.relativeToWorkspaceRoot = relativeToWorkspaceRoot;
11
13
  var _configTools = require("@storm-software/config-tools");
12
14
  var _cwd = require("@stryke/path/cwd");
15
+ var _filePathFns = require("@stryke/path/file-path-fns");
13
16
  var _getParentPath = require("@stryke/path/get-parent-path");
14
17
  var _isRootDir = require("@stryke/path/is-root-dir");
15
18
  const WORKSPACE_ROOT_CONTENT = exports.WORKSPACE_ROOT_CONTENT = ["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lock", "nx.json", "knip.json", "pnpm-workspace.yaml", "LICENSE", ".all-contributorsrc", ".whitesource", "syncpack.config.js", "syncpack.json", "socket.yaml", "lefthook.yaml", ".npmrc", ".log4brains.yml", ".huskyrc", ".husky", ".lintstagedrc", ".commitlintrc", "lefthook.yml", ".github", ".nx", ".vscode", "patches"],
16
19
  PROJECT_ROOT_CONTENT = exports.PROJECT_ROOT_CONTENT = ["project.json", "package.json", ".storm"];
17
- function getWorkspaceRoot(o = process.cwd()) {
20
+ function getWorkspaceRoot(o = (0, _cwd.cwd)()) {
18
21
  if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) return process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH;
19
22
  const t = (0, _configTools.findWorkspaceRootSafe)(o);
20
23
  if (t) return t;
@@ -29,11 +32,17 @@ function isWorkspaceRoot(o = (0, _cwd.cwd)()) {
29
32
  const t = getWorkspaceRoot(o);
30
33
  return t ? t === o : !1;
31
34
  }
32
- function getProjectRoot(o = process.cwd()) {
35
+ function getProjectRoot(o = (0, _cwd.cwd)()) {
33
36
  const t = (0, _getParentPath.getParentPath)(PROJECT_ROOT_CONTENT, o);
34
37
  return t || o;
35
38
  }
36
- function isProjectRoot(o = process.cwd()) {
39
+ function isProjectRoot(o = (0, _cwd.cwd)()) {
37
40
  const t = getProjectRoot(o);
38
41
  return t ? t === o : !1;
42
+ }
43
+ function relativeToWorkspaceRoot(o) {
44
+ return (0, _filePathFns.relativePath)(o, getWorkspaceRoot());
45
+ }
46
+ function relativeToProjectRoot(o) {
47
+ return (0, _filePathFns.relativePath)(o, getProjectRoot());
39
48
  }
@@ -6,25 +6,39 @@ export declare const PROJECT_ROOT_CONTENT: string[];
6
6
  * @param dir - A directory to start the search from
7
7
  * @returns The workspace root path
8
8
  */
9
- export declare function getWorkspaceRoot(dir?: string): any;
9
+ export declare function getWorkspaceRoot(dir?: any): any;
10
10
  /**
11
11
  * Check if the given directory is the workspace root
12
12
  *
13
13
  * @param dir - A directory to check
14
14
  * @returns True if the directory is the workspace root, false otherwise
15
15
  */
16
- export declare function isWorkspaceRoot(dir?: string): boolean;
16
+ export declare function isWorkspaceRoot(dir?: any): boolean;
17
17
  /**
18
18
  * Get the project root path
19
19
  *
20
20
  * @param dir - A directory to start the search from
21
21
  * @returns The project root path
22
22
  */
23
- export declare function getProjectRoot(dir?: string): any;
23
+ export declare function getProjectRoot(dir?: any): any;
24
24
  /**
25
25
  * Check if the given directory is the project root
26
26
  *
27
27
  * @param dir - A directory to check
28
28
  * @returns True if the directory is the project root, false otherwise
29
29
  */
30
- export declare function isProjectRoot(dir?: string): boolean;
30
+ export declare function isProjectRoot(dir?: any): boolean;
31
+ /**
32
+ * Find the file path relative to the workspace root path.
33
+ *
34
+ * @param filePath - The file path to process
35
+ * @returns The file path relative to the workspace root
36
+ */
37
+ export declare function relativeToWorkspaceRoot(filePath: string): any;
38
+ /**
39
+ * Find the file path relative to the project root path.
40
+ *
41
+ * @param filePath - The file path to process
42
+ * @returns The file path relative to the project root
43
+ */
44
+ export declare function relativeToProjectRoot(filePath: string): any;
@@ -1 +1 @@
1
- import{findWorkspaceRootSafe as e}from"@storm-software/config-tools";import{cwd as n}from"@stryke/path/cwd";import{getParentPath as s}from"@stryke/path/get-parent-path";import{isSystemRoot as c}from"@stryke/path/is-root-dir";export const WORKSPACE_ROOT_CONTENT=["package-lock.json","yarn.lock","pnpm-lock.yaml","bun.lock","nx.json","knip.json","pnpm-workspace.yaml","LICENSE",".all-contributorsrc",".whitesource","syncpack.config.js","syncpack.json","socket.yaml","lefthook.yaml",".npmrc",".log4brains.yml",".huskyrc",".husky",".lintstagedrc",".commitlintrc","lefthook.yml",".github",".nx",".vscode","patches"],PROJECT_ROOT_CONTENT=["project.json","package.json",".storm"];export function getWorkspaceRoot(o=process.cwd()){if(process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH)return process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH;const t=e(o);if(t)return t;let r=s(WORKSPACE_ROOT_CONTENT,o);if(r)return r;for(r=o;r&&!c(r);)if(r=s("storm-workspace.json",r,{skipCwd:!0}),r)return r;return o}export function isWorkspaceRoot(o=n()){const t=getWorkspaceRoot(o);return t?t===o:!1}export function getProjectRoot(o=process.cwd()){const t=s(PROJECT_ROOT_CONTENT,o);return t||o}export function isProjectRoot(o=process.cwd()){const t=getProjectRoot(o);return t?t===o:!1}
1
+ import{findWorkspaceRootSafe as c}from"@storm-software/config-tools";import{cwd as e}from"@stryke/path/cwd";import{relativePath as s}from"@stryke/path/file-path-fns";import{getParentPath as n}from"@stryke/path/get-parent-path";import{isSystemRoot as p}from"@stryke/path/is-root-dir";export const WORKSPACE_ROOT_CONTENT=["package-lock.json","yarn.lock","pnpm-lock.yaml","bun.lock","nx.json","knip.json","pnpm-workspace.yaml","LICENSE",".all-contributorsrc",".whitesource","syncpack.config.js","syncpack.json","socket.yaml","lefthook.yaml",".npmrc",".log4brains.yml",".huskyrc",".husky",".lintstagedrc",".commitlintrc","lefthook.yml",".github",".nx",".vscode","patches"],PROJECT_ROOT_CONTENT=["project.json","package.json",".storm"];export function getWorkspaceRoot(o=e()){if(process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH)return process.env.STORM_WORKSPACE_ROOT||process.env.NX_WORKSPACE_ROOT_PATH;const t=c(o);if(t)return t;let r=n(WORKSPACE_ROOT_CONTENT,o);if(r)return r;for(r=o;r&&!p(r);)if(r=n("storm-workspace.json",r,{skipCwd:!0}),r)return r;return o}export function isWorkspaceRoot(o=e()){const t=getWorkspaceRoot(o);return t?t===o:!1}export function getProjectRoot(o=e()){const t=n(PROJECT_ROOT_CONTENT,o);return t||o}export function isProjectRoot(o=e()){const t=getProjectRoot(o);return t?t===o:!1}export function relativeToWorkspaceRoot(o){return s(o,getWorkspaceRoot())}export function relativeToProjectRoot(o){return s(o,getProjectRoot())}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
6
6
  "repository": {
@@ -15,7 +15,7 @@
15
15
  "@antfu/install-pkg": "^1.0.0",
16
16
  "@ltd/j-toml": "^1.38.0",
17
17
  "@storm-software/config-tools": "latest",
18
- "@stryke/convert": "^0.3.1",
18
+ "@stryke/convert": "^0.3.2",
19
19
  "@stryke/path": "^0.13.1",
20
20
  "@stryke/string-format": "^0.10.0",
21
21
  "@zkochan/js-yaml": "^0.0.7",
@@ -395,5 +395,5 @@
395
395
  "main": "./dist/index.cjs",
396
396
  "module": "./dist/index.mjs",
397
397
  "types": "./dist/index.d.ts",
398
- "gitHead": "7ec1f888f4eb3038ac5316409189322fda2e5aa6"
398
+ "gitHead": "9ffb207d2adb9fe9e86ed419d88a9029f6b8e9e9"
399
399
  }