@stryke/fs 0.33.32 → 0.33.34
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/CHANGELOG.md +18 -0
- package/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/buffer.cjs +60 -1
- package/dist/buffer.mjs +56 -1
- package/dist/buffer.mjs.map +1 -1
- package/dist/chmod-x.cjs +93 -1
- package/dist/chmod-x.mjs +87 -1
- package/dist/chmod-x.mjs.map +1 -1
- package/dist/command-exists.cjs +102 -1
- package/dist/command-exists.mjs +100 -1
- package/dist/command-exists.mjs.map +1 -1
- package/dist/compress.cjs +29 -1
- package/dist/compress.mjs +28 -1
- package/dist/compress.mjs.map +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/convert/src/array-buffer-to-string.cjs +19 -1
- package/dist/convert/src/array-buffer-to-string.mjs +18 -1
- package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
- package/dist/convert/src/to-array.cjs +15 -1
- package/dist/convert/src/to-array.mjs +14 -1
- package/dist/convert/src/to-array.mjs.map +1 -1
- package/dist/convert/src/uint8-array-to-string.cjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
- package/dist/copy-file.cjs +87 -1
- package/dist/copy-file.mjs +83 -1
- package/dist/copy-file.mjs.map +1 -1
- package/dist/exists.cjs +27 -1
- package/dist/exists.mjs +25 -1
- package/dist/exists.mjs.map +1 -1
- package/dist/get-parent-path.cjs +35 -1
- package/dist/get-parent-path.mjs +34 -1
- package/dist/get-parent-path.mjs.map +1 -1
- package/dist/get-workspace-root.cjs +158 -1
- package/dist/get-workspace-root.mjs +150 -1
- package/dist/get-workspace-root.mjs.map +1 -1
- package/dist/helpers/src/get-unique.cjs +14 -1
- package/dist/helpers/src/get-unique.mjs +13 -1
- package/dist/helpers/src/get-unique.mjs.map +1 -1
- package/dist/helpers.cjs +83 -1
- package/dist/helpers.mjs +77 -1
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +122 -1
- package/dist/index.mjs +25 -1
- package/dist/install.cjs +35 -1
- package/dist/install.mjs +33 -1
- package/dist/install.mjs.map +1 -1
- package/dist/is-file.cjs +51 -1
- package/dist/is-file.mjs +47 -1
- package/dist/is-file.mjs.map +1 -1
- package/dist/json/src/storm-json.cjs +117 -1
- package/dist/json/src/storm-json.mjs +115 -1
- package/dist/json/src/storm-json.mjs.map +1 -1
- package/dist/json/src/utils/code-frames.cjs +77 -3
- package/dist/json/src/utils/code-frames.mjs +76 -3
- package/dist/json/src/utils/code-frames.mjs.map +1 -1
- package/dist/json/src/utils/parse-error.cjs +34 -1
- package/dist/json/src/utils/parse-error.mjs +33 -1
- package/dist/json/src/utils/parse-error.mjs.map +1 -1
- package/dist/json/src/utils/parse.cjs +45 -1
- package/dist/json/src/utils/parse.mjs +45 -1
- package/dist/json/src/utils/parse.mjs.map +1 -1
- package/dist/json/src/utils/stringify.cjs +67 -1
- package/dist/json/src/utils/stringify.mjs +67 -1
- package/dist/json/src/utils/stringify.mjs.map +1 -1
- package/dist/json/src/utils/strip-comments.cjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs +86 -4
- package/dist/json/src/utils/strip-comments.mjs.map +1 -1
- package/dist/json.cjs +74 -1
- package/dist/json.mjs +71 -1
- package/dist/json.mjs.map +1 -1
- package/dist/list-files.cjs +86 -1
- package/dist/list-files.mjs +79 -1
- package/dist/list-files.mjs.map +1 -1
- package/dist/package-fns.cjs +148 -1
- package/dist/package-fns.mjs +141 -1
- package/dist/package-fns.mjs.map +1 -1
- package/dist/path/src/append.cjs +57 -1
- package/dist/path/src/append.mjs +56 -1
- package/dist/path/src/append.mjs.map +1 -1
- package/dist/path/src/correct-path.cjs +138 -1
- package/dist/path/src/correct-path.mjs +134 -1
- package/dist/path/src/correct-path.mjs.map +1 -1
- package/dist/path/src/cwd.cjs +17 -1
- package/dist/path/src/cwd.mjs +16 -1
- package/dist/path/src/cwd.mjs.map +1 -1
- package/dist/path/src/file-path-fns.cjs +169 -1
- package/dist/path/src/file-path-fns.mjs +164 -1
- package/dist/path/src/file-path-fns.mjs.map +1 -1
- package/dist/path/src/is-parent-path.cjs +32 -1
- package/dist/path/src/is-parent-path.mjs +32 -1
- package/dist/path/src/is-parent-path.mjs.map +1 -1
- package/dist/path/src/is-root-dir.cjs +14 -1
- package/dist/path/src/is-root-dir.mjs +13 -1
- package/dist/path/src/is-root-dir.mjs.map +1 -1
- package/dist/path/src/is-type.cjs +68 -1
- package/dist/path/src/is-type.mjs +66 -1
- package/dist/path/src/is-type.mjs.map +1 -1
- package/dist/path/src/join-paths.cjs +106 -1
- package/dist/path/src/join-paths.mjs +106 -1
- package/dist/path/src/join-paths.mjs.map +1 -1
- package/dist/path/src/regex.cjs +18 -1
- package/dist/path/src/regex.mjs +11 -1
- package/dist/path/src/regex.mjs.map +1 -1
- package/dist/path/src/replace.cjs +24 -1
- package/dist/path/src/replace.mjs +24 -1
- package/dist/path/src/replace.mjs.map +1 -1
- package/dist/path/src/resolve-parent-path.cjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs +18 -1
- package/dist/path/src/resolve-parent-path.mjs.map +1 -1
- package/dist/path/src/slash.cjs +15 -1
- package/dist/path/src/slash.mjs +14 -1
- package/dist/path/src/slash.mjs.map +1 -1
- package/dist/read-file.cjs +47 -1
- package/dist/read-file.mjs +43 -1
- package/dist/read-file.mjs.map +1 -1
- package/dist/registry.cjs +142 -1
- package/dist/registry.mjs +137 -1
- package/dist/registry.mjs.map +1 -1
- package/dist/remove-file.cjs +27 -1
- package/dist/remove-file.mjs +25 -1
- package/dist/remove-file.mjs.map +1 -1
- package/dist/resolve.cjs +228 -3
- package/dist/resolve.mjs +217 -3
- package/dist/resolve.mjs.map +1 -1
- package/dist/semver-fns.cjs +129 -1
- package/dist/semver-fns.mjs +119 -1
- package/dist/semver-fns.mjs.map +1 -1
- package/dist/string-format/src/package.cjs +92 -1
- package/dist/string-format/src/package.mjs +91 -1
- package/dist/string-format/src/package.mjs.map +1 -1
- package/dist/toml.cjs +66 -3
- package/dist/toml.mjs +61 -3
- package/dist/toml.mjs.map +1 -1
- package/dist/tsconfig.cjs +37 -1
- package/dist/tsconfig.mjs +35 -1
- package/dist/tsconfig.mjs.map +1 -1
- package/dist/type-checks/src/get-object-tag.cjs +15 -1
- package/dist/type-checks/src/get-object-tag.mjs +14 -1
- package/dist/type-checks/src/get-object-tag.mjs.map +1 -1
- package/dist/type-checks/src/index.cjs +14 -1
- package/dist/type-checks/src/index.mjs +16 -1
- package/dist/type-checks/src/is-buffer.cjs +12 -1
- package/dist/type-checks/src/is-buffer.mjs +11 -1
- package/dist/type-checks/src/is-buffer.mjs.map +1 -1
- package/dist/type-checks/src/is-collection.cjs +1 -1
- package/dist/type-checks/src/is-collection.mjs +3 -1
- package/dist/type-checks/src/is-empty.cjs +20 -1
- package/dist/type-checks/src/is-empty.mjs +20 -1
- package/dist/type-checks/src/is-empty.mjs.map +1 -1
- package/dist/type-checks/src/is-error.cjs +29 -1
- package/dist/type-checks/src/is-error.mjs +29 -1
- package/dist/type-checks/src/is-error.mjs.map +1 -1
- package/dist/type-checks/src/is-null.cjs +12 -1
- package/dist/type-checks/src/is-null.mjs +11 -1
- package/dist/type-checks/src/is-null.mjs.map +1 -1
- package/dist/type-checks/src/is-number.cjs +18 -1
- package/dist/type-checks/src/is-number.mjs +17 -1
- package/dist/type-checks/src/is-number.mjs.map +1 -1
- package/dist/type-checks/src/is-object.cjs +19 -1
- package/dist/type-checks/src/is-object.mjs +19 -1
- package/dist/type-checks/src/is-object.mjs.map +1 -1
- package/dist/type-checks/src/is-plain-object.cjs +64 -1
- package/dist/type-checks/src/is-plain-object.mjs +63 -1
- package/dist/type-checks/src/is-plain-object.mjs.map +1 -1
- package/dist/type-checks/src/is-set-string.cjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs +20 -1
- package/dist/type-checks/src/is-set-string.mjs.map +1 -1
- package/dist/type-checks/src/is-set.cjs +19 -1
- package/dist/type-checks/src/is-set.mjs +19 -1
- package/dist/type-checks/src/is-set.mjs.map +1 -1
- package/dist/type-checks/src/is-string.cjs +12 -1
- package/dist/type-checks/src/is-string.mjs +11 -1
- package/dist/type-checks/src/is-string.mjs.map +1 -1
- package/dist/type-checks/src/is-undefined.cjs +8 -1
- package/dist/type-checks/src/is-undefined.mjs +7 -1
- package/dist/type-checks/src/is-undefined.mjs.map +1 -1
- package/dist/type-checks/src/type-detect.cjs +15 -1
- package/dist/type-checks/src/type-detect.mjs +16 -1
- package/dist/type-checks/src/type-detect.mjs.map +1 -1
- package/dist/types/src/base.cjs +6 -1
- package/dist/types/src/base.mjs +5 -1
- package/dist/types/src/base.mjs.map +1 -1
- package/dist/write-file.cjs +40 -1
- package/dist/write-file.mjs +38 -1
- package/dist/write-file.mjs.map +1 -1
- package/dist/yaml.cjs +29 -1
- package/dist/yaml.mjs +27 -1
- package/dist/yaml.mjs.map +1 -1
- package/package.json +6 -6
package/dist/get-parent-path.cjs
CHANGED
|
@@ -1 +1,35 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_cwd = require('./path/src/cwd.cjs');
|
|
3
|
+
const require_join_paths = require('./path/src/join-paths.cjs');
|
|
4
|
+
const require_resolve_parent_path = require('./path/src/resolve-parent-path.cjs');
|
|
5
|
+
const require_is_file = require('./is-file.cjs');
|
|
6
|
+
const require_to_array = require('./convert/src/to-array.cjs');
|
|
7
|
+
let node_fs = require("node:fs");
|
|
8
|
+
|
|
9
|
+
//#region src/get-parent-path.ts
|
|
10
|
+
/**
|
|
11
|
+
* Get the first parent path that has a file or directory with the provided name.
|
|
12
|
+
*
|
|
13
|
+
* @param name - The name (or names) of the file to look for in the parent paths.
|
|
14
|
+
* @param cwd - The current working directory.
|
|
15
|
+
* @returns The first parent path that exists.
|
|
16
|
+
*/
|
|
17
|
+
const getParentPath = (name, cwd$1 = require_cwd.cwd(), options = {}) => {
|
|
18
|
+
const ignoreCase = options?.ignoreCase ?? true;
|
|
19
|
+
const skipCwd = options?.skipCwd ?? false;
|
|
20
|
+
const includeNameInResults = options?.includeNameInResults ?? false;
|
|
21
|
+
let dir = cwd$1;
|
|
22
|
+
if (skipCwd) dir = require_resolve_parent_path.resolveParentPath(cwd$1);
|
|
23
|
+
let names = require_to_array.toArray(name);
|
|
24
|
+
if (ignoreCase) names = names.map((name$1) => name$1.toLowerCase());
|
|
25
|
+
while (true) {
|
|
26
|
+
const target = names.find((name$1) => (0, node_fs.existsSync)(require_join_paths.joinPaths(dir, name$1)));
|
|
27
|
+
if (target) return includeNameInResults || require_is_file.isDirectory(require_join_paths.joinPaths(dir, target)) ? require_join_paths.joinPaths(dir, target) : dir;
|
|
28
|
+
const parentDir = require_resolve_parent_path.resolveParentPath(dir);
|
|
29
|
+
if (parentDir === dir) return;
|
|
30
|
+
dir = parentDir;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.getParentPath = getParentPath;
|
package/dist/get-parent-path.mjs
CHANGED
|
@@ -1,2 +1,35 @@
|
|
|
1
|
-
import{cwd
|
|
1
|
+
import { cwd } from "./path/src/cwd.mjs";
|
|
2
|
+
import { joinPaths } from "./path/src/join-paths.mjs";
|
|
3
|
+
import { resolveParentPath } from "./path/src/resolve-parent-path.mjs";
|
|
4
|
+
import { isDirectory } from "./is-file.mjs";
|
|
5
|
+
import { toArray } from "./convert/src/to-array.mjs";
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
|
|
8
|
+
//#region src/get-parent-path.ts
|
|
9
|
+
/**
|
|
10
|
+
* Get the first parent path that has a file or directory with the provided name.
|
|
11
|
+
*
|
|
12
|
+
* @param name - The name (or names) of the file to look for in the parent paths.
|
|
13
|
+
* @param cwd - The current working directory.
|
|
14
|
+
* @returns The first parent path that exists.
|
|
15
|
+
*/
|
|
16
|
+
const getParentPath = (name, cwd$1 = cwd(), options = {}) => {
|
|
17
|
+
const ignoreCase = options?.ignoreCase ?? true;
|
|
18
|
+
const skipCwd = options?.skipCwd ?? false;
|
|
19
|
+
const includeNameInResults = options?.includeNameInResults ?? false;
|
|
20
|
+
let dir = cwd$1;
|
|
21
|
+
if (skipCwd) dir = resolveParentPath(cwd$1);
|
|
22
|
+
let names = toArray(name);
|
|
23
|
+
if (ignoreCase) names = names.map((name$1) => name$1.toLowerCase());
|
|
24
|
+
while (true) {
|
|
25
|
+
const target = names.find((name$1) => existsSync(joinPaths(dir, name$1)));
|
|
26
|
+
if (target) return includeNameInResults || isDirectory(joinPaths(dir, target)) ? joinPaths(dir, target) : dir;
|
|
27
|
+
const parentDir = resolveParentPath(dir);
|
|
28
|
+
if (parentDir === dir) return;
|
|
29
|
+
dir = parentDir;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//#endregion
|
|
34
|
+
export { getParentPath };
|
|
2
35
|
//# sourceMappingURL=get-parent-path.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-parent-path.mjs","names":["currentDir","cwd","name"],"sources":["../src/get-parent-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { cwd as currentDir } from \"@stryke/path/cwd\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { existsSync } from \"node:fs\";\nimport { isDirectory } from \"./is-file\";\n\nexport interface GetParentPathOptions {\n /**\n * Whether to ignore the case of the file names when checking for existence.\n *\n * @defaultValue true\n */\n ignoreCase: boolean;\n\n /**\n * Whether to skip the current working directory when checking for the file.\n *\n * @defaultValue false\n */\n skipCwd: boolean;\n\n /**\n * Should we include the found file/directory name in the results.\n *\n * @defaultValue false\n */\n includeNameInResults?: boolean;\n}\n\n/**\n * Get the first parent path that has a file or directory with the provided name.\n *\n * @param name - The name (or names) of the file to look for in the parent paths.\n * @param cwd - The current working directory.\n * @returns The first parent path that exists.\n */\nexport const getParentPath = (\n name: string | string[],\n cwd = currentDir(),\n options: Partial<GetParentPathOptions> = {}\n): string | undefined => {\n const ignoreCase = options?.ignoreCase ?? true;\n const skipCwd = options?.skipCwd ?? false;\n const includeNameInResults = options?.includeNameInResults ?? false;\n\n let dir = cwd;\n if (skipCwd) {\n dir = resolveParentPath(cwd);\n }\n\n let names = toArray(name);\n if (ignoreCase) {\n names = names.map(name => name.toLowerCase());\n }\n\n while (true) {\n const target = names.find(name => existsSync(joinPaths(dir, name)));\n if (target) {\n return includeNameInResults || isDirectory(joinPaths(dir, target))\n ? joinPaths(dir, target)\n : dir;\n }\n\n const parentDir = resolveParentPath(dir);\n if (parentDir === dir) {\n // It'll fail anyway\n return undefined;\n }\n\n dir = parentDir;\n }\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-parent-path.mjs","names":["currentDir","cwd","name"],"sources":["../src/get-parent-path.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { toArray } from \"@stryke/convert/to-array\";\nimport { cwd as currentDir } from \"@stryke/path/cwd\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { resolveParentPath } from \"@stryke/path/resolve-parent-path\";\nimport { existsSync } from \"node:fs\";\nimport { isDirectory } from \"./is-file\";\n\nexport interface GetParentPathOptions {\n /**\n * Whether to ignore the case of the file names when checking for existence.\n *\n * @defaultValue true\n */\n ignoreCase: boolean;\n\n /**\n * Whether to skip the current working directory when checking for the file.\n *\n * @defaultValue false\n */\n skipCwd: boolean;\n\n /**\n * Should we include the found file/directory name in the results.\n *\n * @defaultValue false\n */\n includeNameInResults?: boolean;\n}\n\n/**\n * Get the first parent path that has a file or directory with the provided name.\n *\n * @param name - The name (or names) of the file to look for in the parent paths.\n * @param cwd - The current working directory.\n * @returns The first parent path that exists.\n */\nexport const getParentPath = (\n name: string | string[],\n cwd = currentDir(),\n options: Partial<GetParentPathOptions> = {}\n): string | undefined => {\n const ignoreCase = options?.ignoreCase ?? true;\n const skipCwd = options?.skipCwd ?? false;\n const includeNameInResults = options?.includeNameInResults ?? false;\n\n let dir = cwd;\n if (skipCwd) {\n dir = resolveParentPath(cwd);\n }\n\n let names = toArray(name);\n if (ignoreCase) {\n names = names.map(name => name.toLowerCase());\n }\n\n while (true) {\n const target = names.find(name => existsSync(joinPaths(dir, name)));\n if (target) {\n return includeNameInResults || isDirectory(joinPaths(dir, target))\n ? joinPaths(dir, target)\n : dir;\n }\n\n const parentDir = resolveParentPath(dir);\n if (parentDir === dir) {\n // It'll fail anyway\n return undefined;\n }\n\n dir = parentDir;\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;AAuDA,MAAa,iBACX,MACA,QAAMA,KAAY,EAClB,UAAyC,EAAE,KACpB;CACvB,MAAM,aAAa,SAAS,cAAc;CAC1C,MAAM,UAAU,SAAS,WAAW;CACpC,MAAM,uBAAuB,SAAS,wBAAwB;CAE9D,IAAI,MAAMC;AACV,KAAI,QACF,OAAM,kBAAkBA,MAAI;CAG9B,IAAI,QAAQ,QAAQ,KAAK;AACzB,KAAI,WACF,SAAQ,MAAM,KAAI,WAAQC,OAAK,aAAa,CAAC;AAG/C,QAAO,MAAM;EACX,MAAM,SAAS,MAAM,MAAK,WAAQ,WAAW,UAAU,KAAKA,OAAK,CAAC,CAAC;AACnE,MAAI,OACF,QAAO,wBAAwB,YAAY,UAAU,KAAK,OAAO,CAAC,GAC9D,UAAU,KAAK,OAAO,GACtB;EAGN,MAAM,YAAY,kBAAkB,IAAI;AACxC,MAAI,cAAc,IAEhB;AAGF,QAAM"}
|
|
@@ -1 +1,158 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_cwd = require('./path/src/cwd.cjs');
|
|
3
|
+
const require_file_path_fns = require('./path/src/file-path-fns.cjs');
|
|
4
|
+
const require_is_root_dir = require('./path/src/is-root-dir.cjs');
|
|
5
|
+
const require_get_parent_path = require('./get-parent-path.cjs');
|
|
6
|
+
let __storm_software_config_tools = require("@storm-software/config-tools");
|
|
7
|
+
|
|
8
|
+
//#region src/get-workspace-root.ts
|
|
9
|
+
const WORKSPACE_ROOT_CONTENT = [
|
|
10
|
+
".all-contributorsrc",
|
|
11
|
+
".commitlintrc",
|
|
12
|
+
".github",
|
|
13
|
+
".git",
|
|
14
|
+
".husky",
|
|
15
|
+
".huskyrc",
|
|
16
|
+
".lintstagedrc",
|
|
17
|
+
".log4brains.yml",
|
|
18
|
+
".npmrc",
|
|
19
|
+
".nx",
|
|
20
|
+
".storm-workspace.js",
|
|
21
|
+
".storm-workspace.json",
|
|
22
|
+
".storm-workspace.ts",
|
|
23
|
+
".storm-workspace.yaml",
|
|
24
|
+
".storm-workspace.yml",
|
|
25
|
+
".vscode",
|
|
26
|
+
".whitesource",
|
|
27
|
+
"bun.lock",
|
|
28
|
+
"bun.lockb",
|
|
29
|
+
"lefthook.yaml",
|
|
30
|
+
"lefthook.yml",
|
|
31
|
+
"lerna.json",
|
|
32
|
+
"npm-lock.json",
|
|
33
|
+
"npm-lock.yaml",
|
|
34
|
+
"npm-lock.yml",
|
|
35
|
+
"npm-workspace.json",
|
|
36
|
+
"npm-workspace.yaml",
|
|
37
|
+
"npm-workspace.yml",
|
|
38
|
+
"nx.json",
|
|
39
|
+
"package-lock.json",
|
|
40
|
+
"patches",
|
|
41
|
+
"pnpm-lock.json",
|
|
42
|
+
"pnpm-lock.yaml",
|
|
43
|
+
"pnpm-lock.yml",
|
|
44
|
+
"pnpm-workspace.json",
|
|
45
|
+
"pnpm-workspace.yaml",
|
|
46
|
+
"pnpm-workspace.yml",
|
|
47
|
+
"socket.yaml",
|
|
48
|
+
"storm-workspace.js",
|
|
49
|
+
"storm-workspace.json",
|
|
50
|
+
"storm-workspace.ts",
|
|
51
|
+
"storm-workspace.yaml",
|
|
52
|
+
"storm-workspace.yml",
|
|
53
|
+
"syncpack.config.js",
|
|
54
|
+
"syncpack.json",
|
|
55
|
+
"turbo.json",
|
|
56
|
+
"yarn-lock.json",
|
|
57
|
+
"yarn-lock.yaml",
|
|
58
|
+
"yarn-lock.yml",
|
|
59
|
+
"yarn-workspace.json",
|
|
60
|
+
"yarn-workspace.yaml",
|
|
61
|
+
"yarn-workspace.yml",
|
|
62
|
+
"yarn.lock"
|
|
63
|
+
];
|
|
64
|
+
const PROJECT_ROOT_CONTENT = [
|
|
65
|
+
".powerlines",
|
|
66
|
+
".storm",
|
|
67
|
+
"package.json",
|
|
68
|
+
"powerlines.json",
|
|
69
|
+
"powerlines.yaml",
|
|
70
|
+
"powerlines.yml",
|
|
71
|
+
"powerlines.toml",
|
|
72
|
+
"powerlines.config.js",
|
|
73
|
+
"powerlines.config.ts",
|
|
74
|
+
"project.json"
|
|
75
|
+
];
|
|
76
|
+
/**
|
|
77
|
+
* Get the workspace root path
|
|
78
|
+
*
|
|
79
|
+
* @param dir - A directory to start the search from
|
|
80
|
+
* @returns The workspace root path
|
|
81
|
+
*/
|
|
82
|
+
function getWorkspaceRoot(dir = require_cwd.cwd()) {
|
|
83
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) return process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH;
|
|
84
|
+
const root = (0, __storm_software_config_tools.findWorkspaceRootSafe)(dir);
|
|
85
|
+
if (root) return root;
|
|
86
|
+
let result = require_get_parent_path.getParentPath(WORKSPACE_ROOT_CONTENT, dir);
|
|
87
|
+
if (result) return result;
|
|
88
|
+
result = dir;
|
|
89
|
+
while (result && !require_is_root_dir.isSystemRoot(result)) {
|
|
90
|
+
result = require_get_parent_path.getParentPath("storm-workspace.json", result, {
|
|
91
|
+
skipCwd: true,
|
|
92
|
+
includeNameInResults: false
|
|
93
|
+
});
|
|
94
|
+
if (result) return result;
|
|
95
|
+
}
|
|
96
|
+
return dir;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Check if the given directory is the workspace root
|
|
100
|
+
*
|
|
101
|
+
* @param dir - A directory to check
|
|
102
|
+
* @returns True if the directory is the workspace root, false otherwise
|
|
103
|
+
*/
|
|
104
|
+
function isWorkspaceRoot(dir = require_cwd.cwd()) {
|
|
105
|
+
const workspaceRoot = getWorkspaceRoot(dir);
|
|
106
|
+
if (workspaceRoot) return workspaceRoot === dir;
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the project root path
|
|
111
|
+
*
|
|
112
|
+
* @param dir - A directory to start the search from
|
|
113
|
+
* @returns The project root path
|
|
114
|
+
*/
|
|
115
|
+
function getProjectRoot(dir = require_cwd.cwd()) {
|
|
116
|
+
const result = require_get_parent_path.getParentPath(PROJECT_ROOT_CONTENT, dir);
|
|
117
|
+
if (result) return result;
|
|
118
|
+
return dir;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Check if the given directory is the project root
|
|
122
|
+
*
|
|
123
|
+
* @param dir - A directory to check
|
|
124
|
+
* @returns True if the directory is the project root, false otherwise
|
|
125
|
+
*/
|
|
126
|
+
function isProjectRoot(dir = require_cwd.cwd()) {
|
|
127
|
+
const projectRoot = getProjectRoot(dir);
|
|
128
|
+
if (projectRoot) return projectRoot === dir;
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Find the file path relative to the workspace root path.
|
|
133
|
+
*
|
|
134
|
+
* @param filePath - The file path to process
|
|
135
|
+
* @returns The file path relative to the workspace root
|
|
136
|
+
*/
|
|
137
|
+
function relativeToWorkspaceRoot(filePath) {
|
|
138
|
+
return require_file_path_fns.relativePath(filePath, getWorkspaceRoot());
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Find the file path relative to the project root path.
|
|
142
|
+
*
|
|
143
|
+
* @param filePath - The file path to process
|
|
144
|
+
* @returns The file path relative to the project root
|
|
145
|
+
*/
|
|
146
|
+
function relativeToProjectRoot(filePath) {
|
|
147
|
+
return require_file_path_fns.relativePath(filePath, getProjectRoot());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
exports.PROJECT_ROOT_CONTENT = PROJECT_ROOT_CONTENT;
|
|
152
|
+
exports.WORKSPACE_ROOT_CONTENT = WORKSPACE_ROOT_CONTENT;
|
|
153
|
+
exports.getProjectRoot = getProjectRoot;
|
|
154
|
+
exports.getWorkspaceRoot = getWorkspaceRoot;
|
|
155
|
+
exports.isProjectRoot = isProjectRoot;
|
|
156
|
+
exports.isWorkspaceRoot = isWorkspaceRoot;
|
|
157
|
+
exports.relativeToProjectRoot = relativeToProjectRoot;
|
|
158
|
+
exports.relativeToWorkspaceRoot = relativeToWorkspaceRoot;
|
|
@@ -1,2 +1,151 @@
|
|
|
1
|
-
import{cwd
|
|
1
|
+
import { cwd } from "./path/src/cwd.mjs";
|
|
2
|
+
import { relativePath } from "./path/src/file-path-fns.mjs";
|
|
3
|
+
import { isSystemRoot } from "./path/src/is-root-dir.mjs";
|
|
4
|
+
import { getParentPath } from "./get-parent-path.mjs";
|
|
5
|
+
import { findWorkspaceRootSafe } from "@storm-software/config-tools";
|
|
6
|
+
|
|
7
|
+
//#region src/get-workspace-root.ts
|
|
8
|
+
const WORKSPACE_ROOT_CONTENT = [
|
|
9
|
+
".all-contributorsrc",
|
|
10
|
+
".commitlintrc",
|
|
11
|
+
".github",
|
|
12
|
+
".git",
|
|
13
|
+
".husky",
|
|
14
|
+
".huskyrc",
|
|
15
|
+
".lintstagedrc",
|
|
16
|
+
".log4brains.yml",
|
|
17
|
+
".npmrc",
|
|
18
|
+
".nx",
|
|
19
|
+
".storm-workspace.js",
|
|
20
|
+
".storm-workspace.json",
|
|
21
|
+
".storm-workspace.ts",
|
|
22
|
+
".storm-workspace.yaml",
|
|
23
|
+
".storm-workspace.yml",
|
|
24
|
+
".vscode",
|
|
25
|
+
".whitesource",
|
|
26
|
+
"bun.lock",
|
|
27
|
+
"bun.lockb",
|
|
28
|
+
"lefthook.yaml",
|
|
29
|
+
"lefthook.yml",
|
|
30
|
+
"lerna.json",
|
|
31
|
+
"npm-lock.json",
|
|
32
|
+
"npm-lock.yaml",
|
|
33
|
+
"npm-lock.yml",
|
|
34
|
+
"npm-workspace.json",
|
|
35
|
+
"npm-workspace.yaml",
|
|
36
|
+
"npm-workspace.yml",
|
|
37
|
+
"nx.json",
|
|
38
|
+
"package-lock.json",
|
|
39
|
+
"patches",
|
|
40
|
+
"pnpm-lock.json",
|
|
41
|
+
"pnpm-lock.yaml",
|
|
42
|
+
"pnpm-lock.yml",
|
|
43
|
+
"pnpm-workspace.json",
|
|
44
|
+
"pnpm-workspace.yaml",
|
|
45
|
+
"pnpm-workspace.yml",
|
|
46
|
+
"socket.yaml",
|
|
47
|
+
"storm-workspace.js",
|
|
48
|
+
"storm-workspace.json",
|
|
49
|
+
"storm-workspace.ts",
|
|
50
|
+
"storm-workspace.yaml",
|
|
51
|
+
"storm-workspace.yml",
|
|
52
|
+
"syncpack.config.js",
|
|
53
|
+
"syncpack.json",
|
|
54
|
+
"turbo.json",
|
|
55
|
+
"yarn-lock.json",
|
|
56
|
+
"yarn-lock.yaml",
|
|
57
|
+
"yarn-lock.yml",
|
|
58
|
+
"yarn-workspace.json",
|
|
59
|
+
"yarn-workspace.yaml",
|
|
60
|
+
"yarn-workspace.yml",
|
|
61
|
+
"yarn.lock"
|
|
62
|
+
];
|
|
63
|
+
const PROJECT_ROOT_CONTENT = [
|
|
64
|
+
".powerlines",
|
|
65
|
+
".storm",
|
|
66
|
+
"package.json",
|
|
67
|
+
"powerlines.json",
|
|
68
|
+
"powerlines.yaml",
|
|
69
|
+
"powerlines.yml",
|
|
70
|
+
"powerlines.toml",
|
|
71
|
+
"powerlines.config.js",
|
|
72
|
+
"powerlines.config.ts",
|
|
73
|
+
"project.json"
|
|
74
|
+
];
|
|
75
|
+
/**
|
|
76
|
+
* Get the workspace root path
|
|
77
|
+
*
|
|
78
|
+
* @param dir - A directory to start the search from
|
|
79
|
+
* @returns The workspace root path
|
|
80
|
+
*/
|
|
81
|
+
function getWorkspaceRoot(dir = cwd()) {
|
|
82
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) return process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH;
|
|
83
|
+
const root = findWorkspaceRootSafe(dir);
|
|
84
|
+
if (root) return root;
|
|
85
|
+
let result = getParentPath(WORKSPACE_ROOT_CONTENT, dir);
|
|
86
|
+
if (result) return result;
|
|
87
|
+
result = dir;
|
|
88
|
+
while (result && !isSystemRoot(result)) {
|
|
89
|
+
result = getParentPath("storm-workspace.json", result, {
|
|
90
|
+
skipCwd: true,
|
|
91
|
+
includeNameInResults: false
|
|
92
|
+
});
|
|
93
|
+
if (result) return result;
|
|
94
|
+
}
|
|
95
|
+
return dir;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Check if the given directory is the workspace root
|
|
99
|
+
*
|
|
100
|
+
* @param dir - A directory to check
|
|
101
|
+
* @returns True if the directory is the workspace root, false otherwise
|
|
102
|
+
*/
|
|
103
|
+
function isWorkspaceRoot(dir = cwd()) {
|
|
104
|
+
const workspaceRoot = getWorkspaceRoot(dir);
|
|
105
|
+
if (workspaceRoot) return workspaceRoot === dir;
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the project root path
|
|
110
|
+
*
|
|
111
|
+
* @param dir - A directory to start the search from
|
|
112
|
+
* @returns The project root path
|
|
113
|
+
*/
|
|
114
|
+
function getProjectRoot(dir = cwd()) {
|
|
115
|
+
const result = getParentPath(PROJECT_ROOT_CONTENT, dir);
|
|
116
|
+
if (result) return result;
|
|
117
|
+
return dir;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Check if the given directory is the project root
|
|
121
|
+
*
|
|
122
|
+
* @param dir - A directory to check
|
|
123
|
+
* @returns True if the directory is the project root, false otherwise
|
|
124
|
+
*/
|
|
125
|
+
function isProjectRoot(dir = cwd()) {
|
|
126
|
+
const projectRoot = getProjectRoot(dir);
|
|
127
|
+
if (projectRoot) return projectRoot === dir;
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Find the file path relative to the workspace root path.
|
|
132
|
+
*
|
|
133
|
+
* @param filePath - The file path to process
|
|
134
|
+
* @returns The file path relative to the workspace root
|
|
135
|
+
*/
|
|
136
|
+
function relativeToWorkspaceRoot(filePath) {
|
|
137
|
+
return relativePath(filePath, getWorkspaceRoot());
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Find the file path relative to the project root path.
|
|
141
|
+
*
|
|
142
|
+
* @param filePath - The file path to process
|
|
143
|
+
* @returns The file path relative to the project root
|
|
144
|
+
*/
|
|
145
|
+
function relativeToProjectRoot(filePath) {
|
|
146
|
+
return relativePath(filePath, getProjectRoot());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
export { PROJECT_ROOT_CONTENT, WORKSPACE_ROOT_CONTENT, getProjectRoot, getWorkspaceRoot, isProjectRoot, isWorkspaceRoot, relativeToProjectRoot, relativeToWorkspaceRoot };
|
|
2
151
|
//# sourceMappingURL=get-workspace-root.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-workspace-root.mjs","names":["WORKSPACE_ROOT_CONTENT: string[]","PROJECT_ROOT_CONTENT: string[]"],"sources":["../src/get-workspace-root.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { findWorkspaceRootSafe } from \"@storm-software/config-tools\";\nimport { cwd } from \"@stryke/path/cwd\";\nimport { relativePath } from \"@stryke/path/file-path-fns\";\nimport { isSystemRoot } from \"@stryke/path/is-root-dir\";\nimport { getParentPath } from \"./get-parent-path\";\n\nexport const WORKSPACE_ROOT_CONTENT: string[] = [\n \".all-contributorsrc\",\n \".commitlintrc\",\n \".github\",\n \".git\",\n \".husky\",\n \".huskyrc\",\n \".lintstagedrc\",\n \".log4brains.yml\",\n \".npmrc\",\n \".nx\",\n \".storm-workspace.js\",\n \".storm-workspace.json\",\n \".storm-workspace.ts\",\n \".storm-workspace.yaml\",\n \".storm-workspace.yml\",\n \".vscode\",\n \".whitesource\",\n \"bun.lock\",\n \"bun.lockb\",\n \"lefthook.yaml\",\n \"lefthook.yml\",\n \"lerna.json\",\n \"npm-lock.json\",\n \"npm-lock.yaml\",\n \"npm-lock.yml\",\n \"npm-workspace.json\",\n \"npm-workspace.yaml\",\n \"npm-workspace.yml\",\n \"nx.json\",\n \"package-lock.json\",\n \"patches\",\n \"pnpm-lock.json\",\n \"pnpm-lock.yaml\",\n \"pnpm-lock.yml\",\n \"pnpm-workspace.json\",\n \"pnpm-workspace.yaml\",\n \"pnpm-workspace.yml\",\n \"socket.yaml\",\n \"storm-workspace.js\",\n \"storm-workspace.json\",\n \"storm-workspace.ts\",\n \"storm-workspace.yaml\",\n \"storm-workspace.yml\",\n \"syncpack.config.js\",\n \"syncpack.json\",\n \"turbo.json\",\n \"yarn-lock.json\",\n \"yarn-lock.yaml\",\n \"yarn-lock.yml\",\n \"yarn-workspace.json\",\n \"yarn-workspace.yaml\",\n \"yarn-workspace.yml\",\n \"yarn.lock\"\n] as const;\n\nexport const PROJECT_ROOT_CONTENT: string[] = [\n \".powerlines\",\n \".storm\",\n \"package.json\",\n \"powerlines.json\",\n \"powerlines.yaml\",\n \"powerlines.yml\",\n \"powerlines.toml\",\n \"powerlines.config.js\",\n \"powerlines.config.ts\",\n \"project.json\"\n] as const;\n\n/**\n * Get the workspace root path\n *\n * @param dir - A directory to start the search from\n * @returns The workspace root path\n */\nexport function getWorkspaceRoot(dir = cwd()) {\n if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {\n return (process.env.STORM_WORKSPACE_ROOT ||\n process.env.NX_WORKSPACE_ROOT_PATH)!;\n }\n\n const root = findWorkspaceRootSafe(dir);\n if (root) {\n return root;\n }\n\n let result = getParentPath(WORKSPACE_ROOT_CONTENT, dir);\n if (result) {\n return result;\n }\n\n result = dir;\n while (result && !isSystemRoot(result)) {\n result = getParentPath(\"storm-workspace.json\", result, {\n skipCwd: true,\n includeNameInResults: false\n });\n if (result) {\n return result;\n }\n }\n\n return dir;\n}\n\n/**\n * Check if the given directory is the workspace root\n *\n * @param dir - A directory to check\n * @returns True if the directory is the workspace root, false otherwise\n */\nexport function isWorkspaceRoot(dir = cwd()): boolean {\n const workspaceRoot = getWorkspaceRoot(dir);\n if (workspaceRoot) {\n return workspaceRoot === dir;\n }\n\n return false;\n}\n\n/**\n * Get the project root path\n *\n * @param dir - A directory to start the search from\n * @returns The project root path\n */\nexport function getProjectRoot(dir = cwd()) {\n const result = getParentPath(PROJECT_ROOT_CONTENT, dir);\n\n if (result) {\n return result;\n }\n\n return dir;\n}\n\n/**\n * Check if the given directory is the project root\n *\n * @param dir - A directory to check\n * @returns True if the directory is the project root, false otherwise\n */\nexport function isProjectRoot(dir = cwd()): boolean {\n const projectRoot = getProjectRoot(dir);\n if (projectRoot) {\n return projectRoot === dir;\n }\n\n return false;\n}\n\n/**\n * Find the file path relative to the workspace root path.\n *\n * @param filePath - The file path to process\n * @returns The file path relative to the workspace root\n */\nexport function relativeToWorkspaceRoot(filePath: string) {\n return relativePath(filePath, getWorkspaceRoot());\n}\n\n/**\n * Find the file path relative to the project root path.\n *\n * @param filePath - The file path to process\n * @returns The file path relative to the project root\n */\nexport function relativeToProjectRoot(filePath: string) {\n return relativePath(filePath, getProjectRoot());\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-workspace-root.mjs","names":["WORKSPACE_ROOT_CONTENT: string[]","PROJECT_ROOT_CONTENT: string[]"],"sources":["../src/get-workspace-root.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { findWorkspaceRootSafe } from \"@storm-software/config-tools\";\nimport { cwd } from \"@stryke/path/cwd\";\nimport { relativePath } from \"@stryke/path/file-path-fns\";\nimport { isSystemRoot } from \"@stryke/path/is-root-dir\";\nimport { getParentPath } from \"./get-parent-path\";\n\nexport const WORKSPACE_ROOT_CONTENT: string[] = [\n \".all-contributorsrc\",\n \".commitlintrc\",\n \".github\",\n \".git\",\n \".husky\",\n \".huskyrc\",\n \".lintstagedrc\",\n \".log4brains.yml\",\n \".npmrc\",\n \".nx\",\n \".storm-workspace.js\",\n \".storm-workspace.json\",\n \".storm-workspace.ts\",\n \".storm-workspace.yaml\",\n \".storm-workspace.yml\",\n \".vscode\",\n \".whitesource\",\n \"bun.lock\",\n \"bun.lockb\",\n \"lefthook.yaml\",\n \"lefthook.yml\",\n \"lerna.json\",\n \"npm-lock.json\",\n \"npm-lock.yaml\",\n \"npm-lock.yml\",\n \"npm-workspace.json\",\n \"npm-workspace.yaml\",\n \"npm-workspace.yml\",\n \"nx.json\",\n \"package-lock.json\",\n \"patches\",\n \"pnpm-lock.json\",\n \"pnpm-lock.yaml\",\n \"pnpm-lock.yml\",\n \"pnpm-workspace.json\",\n \"pnpm-workspace.yaml\",\n \"pnpm-workspace.yml\",\n \"socket.yaml\",\n \"storm-workspace.js\",\n \"storm-workspace.json\",\n \"storm-workspace.ts\",\n \"storm-workspace.yaml\",\n \"storm-workspace.yml\",\n \"syncpack.config.js\",\n \"syncpack.json\",\n \"turbo.json\",\n \"yarn-lock.json\",\n \"yarn-lock.yaml\",\n \"yarn-lock.yml\",\n \"yarn-workspace.json\",\n \"yarn-workspace.yaml\",\n \"yarn-workspace.yml\",\n \"yarn.lock\"\n] as const;\n\nexport const PROJECT_ROOT_CONTENT: string[] = [\n \".powerlines\",\n \".storm\",\n \"package.json\",\n \"powerlines.json\",\n \"powerlines.yaml\",\n \"powerlines.yml\",\n \"powerlines.toml\",\n \"powerlines.config.js\",\n \"powerlines.config.ts\",\n \"project.json\"\n] as const;\n\n/**\n * Get the workspace root path\n *\n * @param dir - A directory to start the search from\n * @returns The workspace root path\n */\nexport function getWorkspaceRoot(dir = cwd()) {\n if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {\n return (process.env.STORM_WORKSPACE_ROOT ||\n process.env.NX_WORKSPACE_ROOT_PATH)!;\n }\n\n const root = findWorkspaceRootSafe(dir);\n if (root) {\n return root;\n }\n\n let result = getParentPath(WORKSPACE_ROOT_CONTENT, dir);\n if (result) {\n return result;\n }\n\n result = dir;\n while (result && !isSystemRoot(result)) {\n result = getParentPath(\"storm-workspace.json\", result, {\n skipCwd: true,\n includeNameInResults: false\n });\n if (result) {\n return result;\n }\n }\n\n return dir;\n}\n\n/**\n * Check if the given directory is the workspace root\n *\n * @param dir - A directory to check\n * @returns True if the directory is the workspace root, false otherwise\n */\nexport function isWorkspaceRoot(dir = cwd()): boolean {\n const workspaceRoot = getWorkspaceRoot(dir);\n if (workspaceRoot) {\n return workspaceRoot === dir;\n }\n\n return false;\n}\n\n/**\n * Get the project root path\n *\n * @param dir - A directory to start the search from\n * @returns The project root path\n */\nexport function getProjectRoot(dir = cwd()) {\n const result = getParentPath(PROJECT_ROOT_CONTENT, dir);\n\n if (result) {\n return result;\n }\n\n return dir;\n}\n\n/**\n * Check if the given directory is the project root\n *\n * @param dir - A directory to check\n * @returns True if the directory is the project root, false otherwise\n */\nexport function isProjectRoot(dir = cwd()): boolean {\n const projectRoot = getProjectRoot(dir);\n if (projectRoot) {\n return projectRoot === dir;\n }\n\n return false;\n}\n\n/**\n * Find the file path relative to the workspace root path.\n *\n * @param filePath - The file path to process\n * @returns The file path relative to the workspace root\n */\nexport function relativeToWorkspaceRoot(filePath: string) {\n return relativePath(filePath, getWorkspaceRoot());\n}\n\n/**\n * Find the file path relative to the project root path.\n *\n * @param filePath - The file path to process\n * @returns The file path relative to the project root\n */\nexport function relativeToProjectRoot(filePath: string) {\n return relativePath(filePath, getProjectRoot());\n}\n"],"mappings":";;;;;;;AAwBA,MAAaA,yBAAmC;CAC9C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAaC,uBAAiC;CAC5C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AAQD,SAAgB,iBAAiB,MAAM,KAAK,EAAE;AAC5C,KAAI,QAAQ,IAAI,wBAAwB,QAAQ,IAAI,uBAClD,QAAQ,QAAQ,IAAI,wBAClB,QAAQ,IAAI;CAGhB,MAAM,OAAO,sBAAsB,IAAI;AACvC,KAAI,KACF,QAAO;CAGT,IAAI,SAAS,cAAc,wBAAwB,IAAI;AACvD,KAAI,OACF,QAAO;AAGT,UAAS;AACT,QAAO,UAAU,CAAC,aAAa,OAAO,EAAE;AACtC,WAAS,cAAc,wBAAwB,QAAQ;GACrD,SAAS;GACT,sBAAsB;GACvB,CAAC;AACF,MAAI,OACF,QAAO;;AAIX,QAAO;;;;;;;;AAST,SAAgB,gBAAgB,MAAM,KAAK,EAAW;CACpD,MAAM,gBAAgB,iBAAiB,IAAI;AAC3C,KAAI,cACF,QAAO,kBAAkB;AAG3B,QAAO;;;;;;;;AAST,SAAgB,eAAe,MAAM,KAAK,EAAE;CAC1C,MAAM,SAAS,cAAc,sBAAsB,IAAI;AAEvD,KAAI,OACF,QAAO;AAGT,QAAO;;;;;;;;AAST,SAAgB,cAAc,MAAM,KAAK,EAAW;CAClD,MAAM,cAAc,eAAe,IAAI;AACvC,KAAI,YACF,QAAO,gBAAgB;AAGzB,QAAO;;;;;;;;AAST,SAAgB,wBAAwB,UAAkB;AACxD,QAAO,aAAa,UAAU,kBAAkB,CAAC;;;;;;;;AASnD,SAAgB,sBAAsB,UAAkB;AACtD,QAAO,aAAa,UAAU,gBAAgB,CAAC"}
|
|
@@ -1 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
//#region ../helpers/src/get-unique.ts
|
|
3
|
+
/**
|
|
4
|
+
* Returns an array of unique values from the given array.
|
|
5
|
+
*
|
|
6
|
+
* @param arr - The array to get unique values from.
|
|
7
|
+
* @returns An array of unique values.
|
|
8
|
+
*/
|
|
9
|
+
const getUnique = (arr) => {
|
|
10
|
+
return [...new Set(arr)];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.getUnique = getUnique;
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
//#region ../helpers/src/get-unique.ts
|
|
2
|
+
/**
|
|
3
|
+
* Returns an array of unique values from the given array.
|
|
4
|
+
*
|
|
5
|
+
* @param arr - The array to get unique values from.
|
|
6
|
+
* @returns An array of unique values.
|
|
7
|
+
*/
|
|
8
|
+
const getUnique = (arr) => {
|
|
9
|
+
return [...new Set(arr)];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
//#endregion
|
|
13
|
+
export { getUnique };
|
|
2
14
|
//# sourceMappingURL=get-unique.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-unique.mjs","names":[],"sources":["../../../../helpers/src/get-unique.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Returns an array of unique values from the given array.\n *\n * @param arr - The array to get unique values from.\n * @returns An array of unique values.\n */\nexport const getUnique = <T = any>(arr: T[]): T[] => {\n return [...new Set(arr)];\n};\n\n/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.2, 5.7, 7.19]\n * ```\n *\n * @param arr - The array to process.\n * @param mapper - The function used to convert the array elements.\n * @returns A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n */\nexport function getUniqueBy<T, U>(\n arr: readonly T[],\n mapper: (item: T) => U = item => item as unknown as U\n): T[] {\n const map = new Map<U, T>();\n\n for (const item of arr) {\n const key = mapper(item);\n\n if (!map.has(key)) {\n map.set(key, item);\n }\n }\n\n return [...map.values()];\n}\n"],"mappings":"AAwBA,MAAa,
|
|
1
|
+
{"version":3,"file":"get-unique.mjs","names":[],"sources":["../../../../helpers/src/get-unique.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Stryke\n\n This code was released as part of the Stryke project. Stryke\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/stryke.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/stryke\n Documentation: https://docs.stormsoftware.com/projects/stryke\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\n/**\n * Returns an array of unique values from the given array.\n *\n * @param arr - The array to get unique values from.\n * @returns An array of unique values.\n */\nexport const getUnique = <T = any>(arr: T[]): T[] => {\n return [...new Set(arr)];\n};\n\n/**\n * Returns a new array containing only the unique elements from the original array,\n * based on the values returned by the mapper function.\n *\n * @example\n * ```ts\n * uniqBy([1.2, 1.5, 2.1, 3.2, 5.7, 5.3, 7.19], Math.floor);\n * // [1.2, 2.1, 3.2, 5.7, 7.19]\n * ```\n *\n * @param arr - The array to process.\n * @param mapper - The function used to convert the array elements.\n * @returns A new array containing only the unique elements from the original array, based on the values returned by the mapper function.\n */\nexport function getUniqueBy<T, U>(\n arr: readonly T[],\n mapper: (item: T) => U = item => item as unknown as U\n): T[] {\n const map = new Map<U, T>();\n\n for (const item of arr) {\n const key = mapper(item);\n\n if (!map.has(key)) {\n map.set(key, item);\n }\n }\n\n return [...map.values()];\n}\n"],"mappings":";;;;;;;AAwBA,MAAa,aAAsB,QAAkB;AACnD,QAAO,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC"}
|
package/dist/helpers.cjs
CHANGED
|
@@ -1 +1,83 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_exists = require('./exists.cjs');
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_fs_promises = require("node:fs/promises");
|
|
5
|
+
let nanotar = require("nanotar");
|
|
6
|
+
|
|
7
|
+
//#region src/helpers.ts
|
|
8
|
+
/**
|
|
9
|
+
* Create a directory if it does not exist.
|
|
10
|
+
*
|
|
11
|
+
* @param path - The directory path to check
|
|
12
|
+
* @returns An indicator specifying if the directory exists
|
|
13
|
+
*/
|
|
14
|
+
function createDirectorySync(path) {
|
|
15
|
+
if (require_exists.existsSync(path)) return;
|
|
16
|
+
return (0, node_fs.mkdirSync)(path, { recursive: true });
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a directory if it does not exist.
|
|
20
|
+
*
|
|
21
|
+
* @param path - The directory path to check
|
|
22
|
+
* @returns An indicator specifying if the directory exists
|
|
23
|
+
*/
|
|
24
|
+
async function createDirectory(path) {
|
|
25
|
+
if (await require_exists.exists(path)) return;
|
|
26
|
+
return (0, node_fs_promises.mkdir)(path, { recursive: true });
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Remove a directory if it exists.
|
|
30
|
+
*
|
|
31
|
+
* @param path - The directory path to check
|
|
32
|
+
* @returns An indicator specifying if the directory exists
|
|
33
|
+
*/
|
|
34
|
+
function removeDirectorySync(path) {
|
|
35
|
+
if (!require_exists.existsSync(path)) return;
|
|
36
|
+
return (0, node_fs.rmSync)(path, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Remove a directory if it exists.
|
|
40
|
+
*
|
|
41
|
+
* @param path - The directory path to check
|
|
42
|
+
* @returns An indicator specifying if the directory exists
|
|
43
|
+
*/
|
|
44
|
+
async function removeDirectory(path) {
|
|
45
|
+
if (!require_exists.existsSync(path)) return;
|
|
46
|
+
return (0, node_fs_promises.rm)(path, { recursive: true });
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Extracts a file from a given tarball to the specified destination.
|
|
50
|
+
*
|
|
51
|
+
* @param tarballPath - The path to the tarball from where the file should be extracted.
|
|
52
|
+
* @param file - The path to the file inside the tarball.
|
|
53
|
+
* @param destinationFilePath - The destination file path.
|
|
54
|
+
* @returns True if the file was extracted successfully, false otherwise.
|
|
55
|
+
*/
|
|
56
|
+
async function extractFileFromTar(tarballPath, file, destinationFilePath) {
|
|
57
|
+
const entry = (0, nanotar.parseTar)(await (0, node_fs_promises.readFile)(tarballPath)).find((e) => e.name === file);
|
|
58
|
+
if (!entry?.data) return;
|
|
59
|
+
if (!await require_exists.exists(destinationFilePath)) await (0, node_fs_promises.mkdir)(destinationFilePath, { recursive: true });
|
|
60
|
+
(0, node_fs.createWriteStream)(destinationFilePath).write(entry.data);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Extracts a file from a given TarGzip to the specified destination.
|
|
64
|
+
*
|
|
65
|
+
* @param tarballPath - The path to the tarball from where the file should be extracted.
|
|
66
|
+
* @param file - The path to the file inside the tarball.
|
|
67
|
+
* @param destinationFilePath - The destination file path.
|
|
68
|
+
* @returns True if the file was extracted successfully, false otherwise.
|
|
69
|
+
*/
|
|
70
|
+
async function extractFileFromTarGzip(tarballPath, file, destinationFilePath) {
|
|
71
|
+
const entry = (await (0, nanotar.parseTarGzip)(await (0, node_fs_promises.readFile)(tarballPath))).find((e) => e.name === file);
|
|
72
|
+
if (!entry?.data) return;
|
|
73
|
+
if (!await require_exists.exists(destinationFilePath)) await (0, node_fs_promises.mkdir)(destinationFilePath, { recursive: true });
|
|
74
|
+
(0, node_fs.createWriteStream)(destinationFilePath).write(entry.data);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.createDirectory = createDirectory;
|
|
79
|
+
exports.createDirectorySync = createDirectorySync;
|
|
80
|
+
exports.extractFileFromTar = extractFileFromTar;
|
|
81
|
+
exports.extractFileFromTarGzip = extractFileFromTarGzip;
|
|
82
|
+
exports.removeDirectory = removeDirectory;
|
|
83
|
+
exports.removeDirectorySync = removeDirectorySync;
|