@stryke/fs 0.33.31 → 0.33.33
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.d.cts.map +1 -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/list-files.cjs
CHANGED
|
@@ -1 +1,86 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_join_paths = require('./path/src/join-paths.cjs');
|
|
3
|
+
const require_is_string = require('./type-checks/src/is-string.cjs');
|
|
4
|
+
require('./type-checks/src/index.cjs');
|
|
5
|
+
let defu = require("defu");
|
|
6
|
+
defu = require_rolldown_runtime.__toESM(defu);
|
|
7
|
+
let glob = require("glob");
|
|
8
|
+
|
|
9
|
+
//#region src/list-files.ts
|
|
10
|
+
const DEFAULT_OPTIONS = { dot: true };
|
|
11
|
+
/**
|
|
12
|
+
* A files and directories listing helper function
|
|
13
|
+
*
|
|
14
|
+
* @param filesGlob - A glob pattern to match files
|
|
15
|
+
* @returns A list of file paths
|
|
16
|
+
*/
|
|
17
|
+
async function list(filesGlob, options) {
|
|
18
|
+
return (0, glob.glob)(require_is_string.isString(filesGlob) ? filesGlob.includes("*") ? filesGlob : require_join_paths.joinPaths(filesGlob, "**/*") : filesGlob.input ? require_join_paths.joinPaths(filesGlob.input, filesGlob.glob) : filesGlob.glob, (0, defu.default)(require_is_string.isString(filesGlob) ? {} : {
|
|
19
|
+
dot: filesGlob.dot,
|
|
20
|
+
ignore: filesGlob.ignore
|
|
21
|
+
}, options ?? {}, DEFAULT_OPTIONS));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A synchronous files and directories listing helper function
|
|
25
|
+
*
|
|
26
|
+
* @param filesGlob - A glob pattern to match files
|
|
27
|
+
* @returns A list of file paths
|
|
28
|
+
*/
|
|
29
|
+
function listSync(filesGlob, options) {
|
|
30
|
+
return glob.glob.sync(require_is_string.isString(filesGlob) ? filesGlob.includes("*") ? filesGlob : require_join_paths.joinPaths(filesGlob, "**/*") : filesGlob.input ? require_join_paths.joinPaths(filesGlob.input, filesGlob.glob) : filesGlob.glob, (0, defu.default)(require_is_string.isString(filesGlob) ? {} : {
|
|
31
|
+
dot: filesGlob.dot,
|
|
32
|
+
ignore: filesGlob.ignore
|
|
33
|
+
}, options ?? {}, DEFAULT_OPTIONS));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A file listing helper function
|
|
37
|
+
*
|
|
38
|
+
* @param filesGlob - A glob pattern to match files
|
|
39
|
+
* @returns A list of file paths
|
|
40
|
+
*/
|
|
41
|
+
async function listFiles(filesGlob, options) {
|
|
42
|
+
const result = (await list(filesGlob, (0, defu.default)({ withFileTypes: true }, options ?? {}))).filter((ret) => ret.isFile());
|
|
43
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A synchronous file listing helper function
|
|
48
|
+
*
|
|
49
|
+
* @param filesGlob - A glob pattern to match files
|
|
50
|
+
* @returns A list of file paths
|
|
51
|
+
*/
|
|
52
|
+
function listFilesSync(filesGlob, options) {
|
|
53
|
+
const result = listSync(filesGlob, (0, defu.default)({ withFileTypes: true }, options ?? {})).filter((ret) => ret.isFile());
|
|
54
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* A directories listing helper function
|
|
59
|
+
*
|
|
60
|
+
* @param filesGlob - A glob pattern to match files
|
|
61
|
+
* @returns A list of file paths
|
|
62
|
+
*/
|
|
63
|
+
async function listDirectories(filesGlob, options) {
|
|
64
|
+
const result = (await list(filesGlob, (0, defu.default)({ withFileTypes: true }, options ?? {}))).filter((ret) => ret.isDirectory());
|
|
65
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A synchronous directories listing helper function
|
|
70
|
+
*
|
|
71
|
+
* @param filesGlob - A glob pattern to match files
|
|
72
|
+
* @returns A list of file paths
|
|
73
|
+
*/
|
|
74
|
+
function listDirectoriesSync(filesGlob, options) {
|
|
75
|
+
const result = listSync(filesGlob, (0, defu.default)({ withFileTypes: true }, options ?? {})).filter((ret) => ret.isDirectory());
|
|
76
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
exports.list = list;
|
|
82
|
+
exports.listDirectories = listDirectories;
|
|
83
|
+
exports.listDirectoriesSync = listDirectoriesSync;
|
|
84
|
+
exports.listFiles = listFiles;
|
|
85
|
+
exports.listFilesSync = listFilesSync;
|
|
86
|
+
exports.listSync = listSync;
|
package/dist/list-files.mjs
CHANGED
|
@@ -1,2 +1,80 @@
|
|
|
1
|
-
import{joinPaths
|
|
1
|
+
import { joinPaths } from "./path/src/join-paths.mjs";
|
|
2
|
+
import { isString } from "./type-checks/src/is-string.mjs";
|
|
3
|
+
import "./type-checks/src/index.mjs";
|
|
4
|
+
import defu from "defu";
|
|
5
|
+
import { glob } from "glob";
|
|
6
|
+
|
|
7
|
+
//#region src/list-files.ts
|
|
8
|
+
const DEFAULT_OPTIONS = { dot: true };
|
|
9
|
+
/**
|
|
10
|
+
* A files and directories listing helper function
|
|
11
|
+
*
|
|
12
|
+
* @param filesGlob - A glob pattern to match files
|
|
13
|
+
* @returns A list of file paths
|
|
14
|
+
*/
|
|
15
|
+
async function list(filesGlob, options) {
|
|
16
|
+
return glob(isString(filesGlob) ? filesGlob.includes("*") ? filesGlob : joinPaths(filesGlob, "**/*") : filesGlob.input ? joinPaths(filesGlob.input, filesGlob.glob) : filesGlob.glob, defu(isString(filesGlob) ? {} : {
|
|
17
|
+
dot: filesGlob.dot,
|
|
18
|
+
ignore: filesGlob.ignore
|
|
19
|
+
}, options ?? {}, DEFAULT_OPTIONS));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A synchronous files and directories listing helper function
|
|
23
|
+
*
|
|
24
|
+
* @param filesGlob - A glob pattern to match files
|
|
25
|
+
* @returns A list of file paths
|
|
26
|
+
*/
|
|
27
|
+
function listSync(filesGlob, options) {
|
|
28
|
+
return glob.sync(isString(filesGlob) ? filesGlob.includes("*") ? filesGlob : joinPaths(filesGlob, "**/*") : filesGlob.input ? joinPaths(filesGlob.input, filesGlob.glob) : filesGlob.glob, defu(isString(filesGlob) ? {} : {
|
|
29
|
+
dot: filesGlob.dot,
|
|
30
|
+
ignore: filesGlob.ignore
|
|
31
|
+
}, options ?? {}, DEFAULT_OPTIONS));
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* A file listing helper function
|
|
35
|
+
*
|
|
36
|
+
* @param filesGlob - A glob pattern to match files
|
|
37
|
+
* @returns A list of file paths
|
|
38
|
+
*/
|
|
39
|
+
async function listFiles(filesGlob, options) {
|
|
40
|
+
const result = (await list(filesGlob, defu({ withFileTypes: true }, options ?? {}))).filter((ret) => ret.isFile());
|
|
41
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
42
|
+
return result;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A synchronous file listing helper function
|
|
46
|
+
*
|
|
47
|
+
* @param filesGlob - A glob pattern to match files
|
|
48
|
+
* @returns A list of file paths
|
|
49
|
+
*/
|
|
50
|
+
function listFilesSync(filesGlob, options) {
|
|
51
|
+
const result = listSync(filesGlob, defu({ withFileTypes: true }, options ?? {})).filter((ret) => ret.isFile());
|
|
52
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A directories listing helper function
|
|
57
|
+
*
|
|
58
|
+
* @param filesGlob - A glob pattern to match files
|
|
59
|
+
* @returns A list of file paths
|
|
60
|
+
*/
|
|
61
|
+
async function listDirectories(filesGlob, options) {
|
|
62
|
+
const result = (await list(filesGlob, defu({ withFileTypes: true }, options ?? {}))).filter((ret) => ret.isDirectory());
|
|
63
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* A synchronous directories listing helper function
|
|
68
|
+
*
|
|
69
|
+
* @param filesGlob - A glob pattern to match files
|
|
70
|
+
* @returns A list of file paths
|
|
71
|
+
*/
|
|
72
|
+
function listDirectoriesSync(filesGlob, options) {
|
|
73
|
+
const result = listSync(filesGlob, defu({ withFileTypes: true }, options ?? {})).filter((ret) => ret.isDirectory());
|
|
74
|
+
if (!options?.withFileTypes) return result.map((file) => file.fullpath());
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { list, listDirectories, listDirectoriesSync, listFiles, listFilesSync, listSync };
|
|
2
80
|
//# sourceMappingURL=list-files.mjs.map
|
package/dist/list-files.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-files.mjs","names":["DEFAULT_OPTIONS: ListOptions"],"sources":["../src/list-files.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 { joinPaths } from \"@stryke/path\";\nimport { isString } from \"@stryke/type-checks\";\nimport type { AssetGlob } from \"@stryke/types/file\";\nimport defu from \"defu\";\nimport type { GlobOptions, GlobOptionsWithFileTypesTrue, Path } from \"glob\";\nimport { glob } from \"glob\";\n\nexport type ListOptions = GlobOptions;\nexport type InferListReturnType<TOptions extends GlobOptions> =\n TOptions[\"withFileTypes\"] extends true ? Path[] : string[];\n\nconst DEFAULT_OPTIONS: ListOptions = {\n dot: true\n};\n\n/**\n * A files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function list<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): Promise<InferListReturnType<TOptions>> {\n return glob(\n isString(filesGlob)\n ? filesGlob.includes(\"*\")\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as Promise<InferListReturnType<TOptions>>;\n}\n\n/**\n * A synchronous files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): InferListReturnType<TOptions> {\n return glob.sync(\n isString(filesGlob)\n ? filesGlob.includes(\"*\")\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as InferListReturnType<TOptions>;\n}\n\n/**\n * A file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listFiles<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listFilesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listDirectories<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listDirectoriesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"list-files.mjs","names":["DEFAULT_OPTIONS: ListOptions"],"sources":["../src/list-files.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 { joinPaths } from \"@stryke/path\";\nimport { isString } from \"@stryke/type-checks\";\nimport type { AssetGlob } from \"@stryke/types/file\";\nimport defu from \"defu\";\nimport type { GlobOptions, GlobOptionsWithFileTypesTrue, Path } from \"glob\";\nimport { glob } from \"glob\";\n\nexport type ListOptions = GlobOptions;\nexport type InferListReturnType<TOptions extends GlobOptions> =\n TOptions[\"withFileTypes\"] extends true ? Path[] : string[];\n\nconst DEFAULT_OPTIONS: ListOptions = {\n dot: true\n};\n\n/**\n * A files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function list<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): Promise<InferListReturnType<TOptions>> {\n return glob(\n isString(filesGlob)\n ? filesGlob.includes(\"*\")\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as Promise<InferListReturnType<TOptions>>;\n}\n\n/**\n * A synchronous files and directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n): InferListReturnType<TOptions> {\n return glob.sync(\n isString(filesGlob)\n ? filesGlob.includes(\"*\")\n ? filesGlob\n : joinPaths(filesGlob, \"**/*\")\n : filesGlob.input\n ? joinPaths(filesGlob.input, filesGlob.glob)\n : filesGlob.glob,\n defu(\n isString(filesGlob)\n ? {}\n : { dot: filesGlob.dot, ignore: filesGlob.ignore },\n options ?? {},\n DEFAULT_OPTIONS\n )\n ) as InferListReturnType<TOptions>;\n}\n\n/**\n * A file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listFiles<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous file listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listFilesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isFile());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport async function listDirectories<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = (\n await list(\n filesGlob,\n defu(\n { withFileTypes: true },\n options ?? {}\n ) as GlobOptionsWithFileTypesTrue\n )\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n\n/**\n * A synchronous directories listing helper function\n *\n * @param filesGlob - A glob pattern to match files\n * @returns A list of file paths\n */\nexport function listDirectoriesSync<TOptions extends ListOptions>(\n filesGlob: string | Omit<AssetGlob, \"output\">,\n options?: TOptions\n) {\n const result = listSync(\n filesGlob,\n defu({ withFileTypes: true }, options ?? {}) as GlobOptionsWithFileTypesTrue\n ).filter(ret => ret.isDirectory());\n if (!options?.withFileTypes) {\n return result.map(file => file.fullpath()) as InferListReturnType<TOptions>;\n }\n\n return result as InferListReturnType<TOptions>;\n}\n"],"mappings":";;;;;;;AA6BA,MAAMA,kBAA+B,EACnC,KAAK,MACN;;;;;;;AAQD,eAAsB,KACpB,WACA,SACwC;AACxC,QAAO,KACL,SAAS,UAAU,GACf,UAAU,SAAS,IAAI,GACrB,YACA,UAAU,WAAW,OAAO,GAC9B,UAAU,QACR,UAAU,UAAU,OAAO,UAAU,KAAK,GAC1C,UAAU,MAChB,KACE,SAAS,UAAU,GACf,EAAE,GACF;EAAE,KAAK,UAAU;EAAK,QAAQ,UAAU;EAAQ,EACpD,WAAW,EAAE,EACb,gBACD,CACF;;;;;;;;AASH,SAAgB,SACd,WACA,SAC+B;AAC/B,QAAO,KAAK,KACV,SAAS,UAAU,GACf,UAAU,SAAS,IAAI,GACrB,YACA,UAAU,WAAW,OAAO,GAC9B,UAAU,QACR,UAAU,UAAU,OAAO,UAAU,KAAK,GAC1C,UAAU,MAChB,KACE,SAAS,UAAU,GACf,EAAE,GACF;EAAE,KAAK,UAAU;EAAK,QAAQ,UAAU;EAAQ,EACpD,WAAW,EAAE,EACb,gBACD,CACF;;;;;;;;AASH,eAAsB,UACpB,WACA,SACA;CACA,MAAM,UACJ,MAAM,KACJ,WACA,KACE,EAAE,eAAe,MAAM,EACvB,WAAW,EAAE,CACd,CACF,EACD,QAAO,QAAO,IAAI,QAAQ,CAAC;AAC7B,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,SAAgB,cACd,WACA,SACA;CACA,MAAM,SAAS,SACb,WACA,KAAK,EAAE,eAAe,MAAM,EAAE,WAAW,EAAE,CAAC,CAC7C,CAAC,QAAO,QAAO,IAAI,QAAQ,CAAC;AAC7B,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,eAAsB,gBACpB,WACA,SACA;CACA,MAAM,UACJ,MAAM,KACJ,WACA,KACE,EAAE,eAAe,MAAM,EACvB,WAAW,EAAE,CACd,CACF,EACD,QAAO,QAAO,IAAI,aAAa,CAAC;AAClC,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO;;;;;;;;AAST,SAAgB,oBACd,WACA,SACA;CACA,MAAM,SAAS,SACb,WACA,KAAK,EAAE,eAAe,MAAM,EAAE,WAAW,EAAE,CAAC,CAC7C,CAAC,QAAO,QAAO,IAAI,aAAa,CAAC;AAClC,KAAI,CAAC,SAAS,cACZ,QAAO,OAAO,KAAI,SAAQ,KAAK,UAAU,CAAC;AAG5C,QAAO"}
|
package/dist/package-fns.cjs
CHANGED
|
@@ -1 +1,148 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
+
const require_join_paths = require('./path/src/join-paths.cjs');
|
|
3
|
+
const require_is_string = require('./type-checks/src/is-string.cjs');
|
|
4
|
+
const require_file_path_fns = require('./path/src/file-path-fns.cjs');
|
|
5
|
+
const require_exists = require('./exists.cjs');
|
|
6
|
+
const require_get_parent_path = require('./get-parent-path.cjs');
|
|
7
|
+
const require_get_workspace_root = require('./get-workspace-root.cjs');
|
|
8
|
+
const require_resolve = require('./resolve.cjs');
|
|
9
|
+
const require_json = require('./json.cjs');
|
|
10
|
+
const require_package = require('./string-format/src/package.cjs');
|
|
11
|
+
let node_fs = require("node:fs");
|
|
12
|
+
let semver = require("semver");
|
|
13
|
+
|
|
14
|
+
//#region src/package-fns.ts
|
|
15
|
+
/**
|
|
16
|
+
* Get the package manager used in the project
|
|
17
|
+
*
|
|
18
|
+
* @param dir - The path to the project
|
|
19
|
+
* @returns The package manager used in the project
|
|
20
|
+
*/
|
|
21
|
+
function getPackageManager(dir = require_get_workspace_root.getWorkspaceRoot()) {
|
|
22
|
+
const lockFile = require_get_parent_path.getParentPath([
|
|
23
|
+
"package-lock.json",
|
|
24
|
+
"yarn.lock",
|
|
25
|
+
"pnpm-lock.yaml",
|
|
26
|
+
"bun.lock"
|
|
27
|
+
], dir, { includeNameInResults: true });
|
|
28
|
+
if (!lockFile) return "pnpm";
|
|
29
|
+
switch (require_file_path_fns.findFileName(lockFile)) {
|
|
30
|
+
case "yarn.lock": return "yarn";
|
|
31
|
+
case "pnpm-lock.yaml": return "pnpm";
|
|
32
|
+
case "bun.lock": return "bun";
|
|
33
|
+
default: return "npm";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function searchPackageJson(dir) {
|
|
37
|
+
let packageJsonPath;
|
|
38
|
+
while (true) {
|
|
39
|
+
if (!dir) return;
|
|
40
|
+
const newDir = require_file_path_fns.findFilePath(dir);
|
|
41
|
+
if (newDir === dir) return;
|
|
42
|
+
dir = newDir;
|
|
43
|
+
packageJsonPath = require_join_paths.joinPaths(dir, "package.json");
|
|
44
|
+
if (await require_exists.exists(packageJsonPath)) break;
|
|
45
|
+
}
|
|
46
|
+
return packageJsonPath;
|
|
47
|
+
}
|
|
48
|
+
async function getPackageJsonPath(name, options = {}) {
|
|
49
|
+
const entry = await require_resolve.resolvePackage(name, options);
|
|
50
|
+
if (!entry) return;
|
|
51
|
+
return searchPackageJson(entry);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get package info
|
|
55
|
+
*
|
|
56
|
+
* @param name - The name of the package
|
|
57
|
+
* @param options - The options to use when resolving the package
|
|
58
|
+
* @returns The package info
|
|
59
|
+
*/
|
|
60
|
+
async function getPackageInfo(name, options = {}) {
|
|
61
|
+
const packageJsonPath = await getPackageJsonPath(name, options);
|
|
62
|
+
if (!packageJsonPath) return;
|
|
63
|
+
const packageJson = await require_json.readJsonFile(packageJsonPath);
|
|
64
|
+
return {
|
|
65
|
+
name,
|
|
66
|
+
version: packageJson.version,
|
|
67
|
+
rootPath: require_file_path_fns.findFilePath(packageJsonPath),
|
|
68
|
+
packageJsonPath,
|
|
69
|
+
packageJson
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the package info from the package.json file
|
|
74
|
+
*
|
|
75
|
+
* @param cwd - The current working directory
|
|
76
|
+
* @returns The package info
|
|
77
|
+
*/
|
|
78
|
+
async function loadPackageJson(cwd = require_get_workspace_root.getWorkspaceRoot()) {
|
|
79
|
+
const path = require_get_parent_path.getParentPath("package.json", cwd, {
|
|
80
|
+
skipCwd: false,
|
|
81
|
+
includeNameInResults: true
|
|
82
|
+
});
|
|
83
|
+
if (!path || !(0, node_fs.existsSync)(path)) return null;
|
|
84
|
+
return require_json.readJsonFile(path);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if a package is listed in the package.json file
|
|
88
|
+
*
|
|
89
|
+
* @param name - The name of the package
|
|
90
|
+
* @param cwdOrOptions - The current working directory or options to use when checking if the package is listed
|
|
91
|
+
* @returns An indicator specifying if the package is listed
|
|
92
|
+
*/
|
|
93
|
+
async function isPackageListed(name, cwdOrOptions) {
|
|
94
|
+
const packageName = require_package.getPackageName(name);
|
|
95
|
+
const packageJson = await loadPackageJson(require_is_string.isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd);
|
|
96
|
+
if (!packageJson) return false;
|
|
97
|
+
return Boolean(packageJson.dependencies && packageName in packageJson.dependencies && packageJson.dependencies[packageName] || packageJson.devDependencies && packageName in packageJson.devDependencies && packageJson.devDependencies[packageName]);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Return the package version and dependency type listed in the package.json file
|
|
101
|
+
*
|
|
102
|
+
* @param name - The name of the package
|
|
103
|
+
* @param cwdOrOptions - The current working directory or options to use when checking if the package is listed
|
|
104
|
+
* @returns The version and type of the package if listed, otherwise undefined
|
|
105
|
+
*/
|
|
106
|
+
async function getPackageListing(name, cwdOrOptions) {
|
|
107
|
+
const packageName = require_package.getPackageName(name);
|
|
108
|
+
const packageJson = await loadPackageJson(require_is_string.isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd);
|
|
109
|
+
if (!packageJson) return;
|
|
110
|
+
const version = packageJson.dependencies && packageName in packageJson.dependencies ? packageJson.dependencies[packageName] : packageJson.devDependencies && packageName in packageJson.devDependencies ? packageJson.devDependencies[packageName] : void 0;
|
|
111
|
+
const type = (packageJson.dependencies && packageName in packageJson.dependencies ? "dependencies" : packageJson.devDependencies && packageName in packageJson.devDependencies ? "devDependencies" : void 0) || void 0;
|
|
112
|
+
return version && type ? {
|
|
113
|
+
version,
|
|
114
|
+
type
|
|
115
|
+
} : void 0;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if a package version matches a specific version range
|
|
119
|
+
*
|
|
120
|
+
* @param name - The name of the package
|
|
121
|
+
* @param version - The version to check against
|
|
122
|
+
* @param cwd - The current working directory
|
|
123
|
+
* @returns An indicator specifying if the package version matches the range
|
|
124
|
+
*/
|
|
125
|
+
async function doesPackageMatch(name, version, cwd) {
|
|
126
|
+
const pkg = await getPackageListing(name, { cwd });
|
|
127
|
+
if (!pkg) return false;
|
|
128
|
+
return pkg.version.startsWith("catalog:") || pkg.version.startsWith("workspace:") || (0, semver.subset)(pkg.version, version);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Check if a package exists
|
|
132
|
+
*
|
|
133
|
+
* @param name - The name of the package
|
|
134
|
+
* @param options - The options to use when resolving the package
|
|
135
|
+
* @returns An indicator specifying if the package exists
|
|
136
|
+
*/
|
|
137
|
+
function isPackageExists(name, options = {}) {
|
|
138
|
+
return Boolean(require_resolve.resolvePackage(name, options));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
//#endregion
|
|
142
|
+
exports.doesPackageMatch = doesPackageMatch;
|
|
143
|
+
exports.getPackageInfo = getPackageInfo;
|
|
144
|
+
exports.getPackageListing = getPackageListing;
|
|
145
|
+
exports.getPackageManager = getPackageManager;
|
|
146
|
+
exports.isPackageExists = isPackageExists;
|
|
147
|
+
exports.isPackageListed = isPackageListed;
|
|
148
|
+
exports.loadPackageJson = loadPackageJson;
|
package/dist/package-fns.mjs
CHANGED
|
@@ -1,2 +1,142 @@
|
|
|
1
|
-
import{joinPaths
|
|
1
|
+
import { joinPaths } from "./path/src/join-paths.mjs";
|
|
2
|
+
import { isString } from "./type-checks/src/is-string.mjs";
|
|
3
|
+
import { findFileName, findFilePath } from "./path/src/file-path-fns.mjs";
|
|
4
|
+
import { exists } from "./exists.mjs";
|
|
5
|
+
import { getParentPath } from "./get-parent-path.mjs";
|
|
6
|
+
import { getWorkspaceRoot } from "./get-workspace-root.mjs";
|
|
7
|
+
import { resolvePackage } from "./resolve.mjs";
|
|
8
|
+
import { readJsonFile } from "./json.mjs";
|
|
9
|
+
import { getPackageName } from "./string-format/src/package.mjs";
|
|
10
|
+
import { existsSync } from "node:fs";
|
|
11
|
+
import { subset } from "semver";
|
|
12
|
+
|
|
13
|
+
//#region src/package-fns.ts
|
|
14
|
+
/**
|
|
15
|
+
* Get the package manager used in the project
|
|
16
|
+
*
|
|
17
|
+
* @param dir - The path to the project
|
|
18
|
+
* @returns The package manager used in the project
|
|
19
|
+
*/
|
|
20
|
+
function getPackageManager(dir = getWorkspaceRoot()) {
|
|
21
|
+
const lockFile = getParentPath([
|
|
22
|
+
"package-lock.json",
|
|
23
|
+
"yarn.lock",
|
|
24
|
+
"pnpm-lock.yaml",
|
|
25
|
+
"bun.lock"
|
|
26
|
+
], dir, { includeNameInResults: true });
|
|
27
|
+
if (!lockFile) return "pnpm";
|
|
28
|
+
switch (findFileName(lockFile)) {
|
|
29
|
+
case "yarn.lock": return "yarn";
|
|
30
|
+
case "pnpm-lock.yaml": return "pnpm";
|
|
31
|
+
case "bun.lock": return "bun";
|
|
32
|
+
default: return "npm";
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
async function searchPackageJson(dir) {
|
|
36
|
+
let packageJsonPath;
|
|
37
|
+
while (true) {
|
|
38
|
+
if (!dir) return;
|
|
39
|
+
const newDir = findFilePath(dir);
|
|
40
|
+
if (newDir === dir) return;
|
|
41
|
+
dir = newDir;
|
|
42
|
+
packageJsonPath = joinPaths(dir, "package.json");
|
|
43
|
+
if (await exists(packageJsonPath)) break;
|
|
44
|
+
}
|
|
45
|
+
return packageJsonPath;
|
|
46
|
+
}
|
|
47
|
+
async function getPackageJsonPath(name, options = {}) {
|
|
48
|
+
const entry = await resolvePackage(name, options);
|
|
49
|
+
if (!entry) return;
|
|
50
|
+
return searchPackageJson(entry);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get package info
|
|
54
|
+
*
|
|
55
|
+
* @param name - The name of the package
|
|
56
|
+
* @param options - The options to use when resolving the package
|
|
57
|
+
* @returns The package info
|
|
58
|
+
*/
|
|
59
|
+
async function getPackageInfo(name, options = {}) {
|
|
60
|
+
const packageJsonPath = await getPackageJsonPath(name, options);
|
|
61
|
+
if (!packageJsonPath) return;
|
|
62
|
+
const packageJson = await readJsonFile(packageJsonPath);
|
|
63
|
+
return {
|
|
64
|
+
name,
|
|
65
|
+
version: packageJson.version,
|
|
66
|
+
rootPath: findFilePath(packageJsonPath),
|
|
67
|
+
packageJsonPath,
|
|
68
|
+
packageJson
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the package info from the package.json file
|
|
73
|
+
*
|
|
74
|
+
* @param cwd - The current working directory
|
|
75
|
+
* @returns The package info
|
|
76
|
+
*/
|
|
77
|
+
async function loadPackageJson(cwd = getWorkspaceRoot()) {
|
|
78
|
+
const path = getParentPath("package.json", cwd, {
|
|
79
|
+
skipCwd: false,
|
|
80
|
+
includeNameInResults: true
|
|
81
|
+
});
|
|
82
|
+
if (!path || !existsSync(path)) return null;
|
|
83
|
+
return readJsonFile(path);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Check if a package is listed in the package.json file
|
|
87
|
+
*
|
|
88
|
+
* @param name - The name of the package
|
|
89
|
+
* @param cwdOrOptions - The current working directory or options to use when checking if the package is listed
|
|
90
|
+
* @returns An indicator specifying if the package is listed
|
|
91
|
+
*/
|
|
92
|
+
async function isPackageListed(name, cwdOrOptions) {
|
|
93
|
+
const packageName = getPackageName(name);
|
|
94
|
+
const packageJson = await loadPackageJson(isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd);
|
|
95
|
+
if (!packageJson) return false;
|
|
96
|
+
return Boolean(packageJson.dependencies && packageName in packageJson.dependencies && packageJson.dependencies[packageName] || packageJson.devDependencies && packageName in packageJson.devDependencies && packageJson.devDependencies[packageName]);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Return the package version and dependency type listed in the package.json file
|
|
100
|
+
*
|
|
101
|
+
* @param name - The name of the package
|
|
102
|
+
* @param cwdOrOptions - The current working directory or options to use when checking if the package is listed
|
|
103
|
+
* @returns The version and type of the package if listed, otherwise undefined
|
|
104
|
+
*/
|
|
105
|
+
async function getPackageListing(name, cwdOrOptions) {
|
|
106
|
+
const packageName = getPackageName(name);
|
|
107
|
+
const packageJson = await loadPackageJson(isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd);
|
|
108
|
+
if (!packageJson) return;
|
|
109
|
+
const version = packageJson.dependencies && packageName in packageJson.dependencies ? packageJson.dependencies[packageName] : packageJson.devDependencies && packageName in packageJson.devDependencies ? packageJson.devDependencies[packageName] : void 0;
|
|
110
|
+
const type = (packageJson.dependencies && packageName in packageJson.dependencies ? "dependencies" : packageJson.devDependencies && packageName in packageJson.devDependencies ? "devDependencies" : void 0) || void 0;
|
|
111
|
+
return version && type ? {
|
|
112
|
+
version,
|
|
113
|
+
type
|
|
114
|
+
} : void 0;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Check if a package version matches a specific version range
|
|
118
|
+
*
|
|
119
|
+
* @param name - The name of the package
|
|
120
|
+
* @param version - The version to check against
|
|
121
|
+
* @param cwd - The current working directory
|
|
122
|
+
* @returns An indicator specifying if the package version matches the range
|
|
123
|
+
*/
|
|
124
|
+
async function doesPackageMatch(name, version, cwd) {
|
|
125
|
+
const pkg = await getPackageListing(name, { cwd });
|
|
126
|
+
if (!pkg) return false;
|
|
127
|
+
return pkg.version.startsWith("catalog:") || pkg.version.startsWith("workspace:") || subset(pkg.version, version);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Check if a package exists
|
|
131
|
+
*
|
|
132
|
+
* @param name - The name of the package
|
|
133
|
+
* @param options - The options to use when resolving the package
|
|
134
|
+
* @returns An indicator specifying if the package exists
|
|
135
|
+
*/
|
|
136
|
+
function isPackageExists(name, options = {}) {
|
|
137
|
+
return Boolean(resolvePackage(name, options));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//#endregion
|
|
141
|
+
export { doesPackageMatch, getPackageInfo, getPackageListing, getPackageManager, isPackageExists, isPackageListed, loadPackageJson };
|
|
2
142
|
//# sourceMappingURL=package-fns.mjs.map
|
package/dist/package-fns.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-fns.mjs","names":[],"sources":["../src/package-fns.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 { findFileName, findFilePath } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { getPackageName } from \"@stryke/string-format/package\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { PackageJson } from \"@stryke/types/package-json\";\nimport type { PackageManager } from \"@stryke/types/package-manager\";\nimport { existsSync } from \"node:fs\";\nimport type { Range } from \"semver\";\nimport { subset } from \"semver\";\nimport { exists } from \"./exists\";\nimport { getParentPath } from \"./get-parent-path\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\nimport { readJsonFile } from \"./json\";\nimport type { ResolveOptions } from \"./resolve\";\nimport { resolvePackage } from \"./resolve\";\n\n/**\n * Get the package manager used in the project\n *\n * @param dir - The path to the project\n * @returns The package manager used in the project\n */\nexport function getPackageManager(dir = getWorkspaceRoot()): PackageManager {\n const lockFile = getParentPath(\n [\"package-lock.json\", \"yarn.lock\", \"pnpm-lock.yaml\", \"bun.lock\"],\n dir,\n {\n includeNameInResults: true\n }\n );\n\n if (!lockFile) {\n // default use pnpm\n return \"pnpm\";\n }\n\n switch (findFileName(lockFile)) {\n case \"yarn.lock\": {\n return \"yarn\";\n }\n case \"pnpm-lock.yaml\": {\n return \"pnpm\";\n }\n case \"bun.lock\": {\n return \"bun\";\n }\n default: {\n return \"npm\";\n }\n }\n}\n\n// Much of the below code comes from https://github.com/antfu-collective/local-pkg with some modifications\n\nasync function searchPackageJson(dir: string) {\n let packageJsonPath;\n\n while (true) {\n if (!dir) {\n return;\n }\n const newDir = findFilePath(dir);\n\n if (newDir === dir) {\n return;\n }\n\n dir = newDir;\n packageJsonPath = joinPaths(dir, \"package.json\");\n\n if (await exists(packageJsonPath)) {\n break;\n }\n }\n\n return packageJsonPath;\n}\n\nasync function getPackageJsonPath(name: string, options: ResolveOptions = {}) {\n const entry = await resolvePackage(name, options);\n if (!entry) {\n return;\n }\n\n return searchPackageJson(entry);\n}\n\n/**\n * Get package info\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns The package info\n */\nexport async function getPackageInfo(\n name: string,\n options: ResolveOptions = {}\n) {\n const packageJsonPath = await getPackageJsonPath(name, options);\n if (!packageJsonPath) {\n return;\n }\n\n const packageJson = await readJsonFile<PackageJson>(packageJsonPath);\n\n return {\n name,\n version: packageJson.version,\n rootPath: findFilePath(packageJsonPath),\n packageJsonPath,\n packageJson\n };\n}\n\n/**\n * Get the package info from the package.json file\n *\n * @param cwd - The current working directory\n * @returns The package info\n */\nexport async function loadPackageJson(\n cwd = getWorkspaceRoot()\n): Promise<PackageJson | null> {\n const path = getParentPath(\"package.json\", cwd, {\n skipCwd: false,\n includeNameInResults: true\n });\n if (!path || !existsSync(path)) {\n return null;\n }\n\n return readJsonFile<PackageJson>(path);\n}\n\nexport interface PackageExistsOptions {\n /**\n * The current working directory\n */\n cwd?: string;\n}\n\nexport interface PackageMatchesOptions extends PackageExistsOptions {\n /**\n * The version range of the package to check\n */\n version?: string | Range;\n}\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwd?: string\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param options - The options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n options?: PackageExistsOptions\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<boolean> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return false;\n }\n\n return Boolean(\n (packageJson.dependencies &&\n packageName in packageJson.dependencies &&\n packageJson.dependencies[packageName]) ||\n (packageJson.devDependencies &&\n packageName in packageJson.devDependencies &&\n packageJson.devDependencies[packageName])\n );\n}\n\nexport interface GetPackageListingReturn {\n version: string;\n type: \"dependencies\" | \"devDependencies\";\n}\n\n/**\n * Return the package version and dependency type listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns The version and type of the package if listed, otherwise undefined\n */\nexport async function getPackageListing(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<GetPackageListingReturn | undefined> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return undefined;\n }\n\n const version =\n packageJson.dependencies && packageName in packageJson.dependencies\n ? packageJson.dependencies[packageName]\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? packageJson.devDependencies[packageName]\n : undefined;\n const type =\n (packageJson.dependencies && packageName in packageJson.dependencies\n ? \"dependencies\"\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? \"devDependencies\"\n : undefined) || undefined;\n\n return version && type\n ? {\n version,\n type\n }\n : undefined;\n}\n\n/**\n * Check if a package version matches a specific version range\n *\n * @param name - The name of the package\n * @param version - The version to check against\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package version matches the range\n */\nexport async function doesPackageMatch(\n name: string,\n version: string,\n cwd?: string\n): Promise<boolean> {\n const pkg = await getPackageListing(name, { cwd });\n if (!pkg) {\n return false;\n }\n\n return (\n pkg.version.startsWith(\"catalog:\") ||\n pkg.version.startsWith(\"workspace:\") ||\n subset(pkg.version, version)\n );\n}\n\n/**\n * Check if a package exists\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns An indicator specifying if the package exists\n */\nexport function isPackageExists(name: string, options: ResolveOptions = {}) {\n return Boolean(resolvePackage(name, options));\n}\n"],"mappings":"sjBAwCA,SAAgB,EAAkB,EAAM,GAAkB,CAAkB,CAC1E,IAAM,EAAW,EACf,CAAC,oBAAqB,YAAa,iBAAkB,WAAW,CAChE,EACA,CACE,qBAAsB,GACvB,CACF,CAED,GAAI,CAAC,EAEH,MAAO,OAGT,OAAQ,EAAa,EAAS,CAA9B,CACE,IAAK,YACH,MAAO,OAET,IAAK,iBACH,MAAO,OAET,IAAK,WACH,MAAO,MAET,QACE,MAAO,OAOb,eAAe,EAAkB,EAAa,CAC5C,IAAI,EAEJ,OAAa,CACX,GAAI,CAAC,EACH,OAEF,IAAM,EAAS,EAAa,EAAI,CAEhC,GAAI,IAAW,EACb,OAMF,GAHA,EAAM,EACN,EAAkB,EAAU,EAAK,eAAe,CAE5C,MAAM,EAAO,EAAgB,CAC/B,MAIJ,OAAO,EAGT,eAAe,EAAmB,EAAc,EAA0B,EAAE,CAAE,CAC5E,IAAM,EAAQ,MAAM,EAAe,EAAM,EAAQ,CAC5C,KAIL,OAAO,EAAkB,EAAM,CAUjC,eAAsB,EACpB,EACA,EAA0B,EAAE,CAC5B,CACA,IAAM,EAAkB,MAAM,EAAmB,EAAM,EAAQ,CAC/D,GAAI,CAAC,EACH,OAGF,IAAM,EAAc,MAAM,EAA0B,EAAgB,CAEpE,MAAO,CACL,OACA,QAAS,EAAY,QACrB,SAAU,EAAa,EAAgB,CACvC,kBACA,cACD,CASH,eAAsB,EACpB,EAAM,GAAkB,CACK,CAC7B,IAAM,EAAO,EAAc,eAAgB,EAAK,CAC9C,QAAS,GACT,qBAAsB,GACvB,CAAC,CAKF,MAJI,CAAC,GAAQ,CAAC,EAAW,EAAK,CACrB,KAGF,EAA0B,EAAK,CAgDxC,eAAsB,EACpB,EACA,EACkB,CAClB,IAAM,EAAc,EAAe,EAAK,CAGlC,EAAc,MAAM,EAFd,EAAS,EAAa,CAAG,EAAe,GAAc,IAEpB,CAK9C,OAJK,EAIE,GACJ,EAAY,cACX,KAAe,EAAY,cAC3B,EAAY,aAAa,IAC1B,EAAY,iBACX,KAAe,EAAY,iBAC3B,EAAY,gBAAgB,IATvB,GAyBX,eAAsB,EACpB,EACA,EAC8C,CAC9C,IAAM,EAAc,EAAe,EAAK,CAGlC,EAAc,MAAM,EAFd,EAAS,EAAa,CAAG,EAAe,GAAc,IAEpB,CAC9C,GAAI,CAAC,EACH,OAGF,IAAM,EACJ,EAAY,cAAgB,KAAe,EAAY,aACnD,EAAY,aAAa,GACzB,EAAY,iBACV,KAAe,EAAY,gBAC3B,EAAY,gBAAgB,GAC5B,IAAA,GACF,GACH,EAAY,cAAgB,KAAe,EAAY,aACpD,eACA,EAAY,iBACV,KAAe,EAAY,gBAC3B,kBACA,IAAA,KAAc,IAAA,GAEtB,OAAO,GAAW,EACd,CACE,UACA,OACD,CACD,IAAA,GAWN,eAAsB,EACpB,EACA,EACA,EACkB,CAClB,IAAM,EAAM,MAAM,EAAkB,EAAM,CAAE,MAAK,CAAC,CAKlD,OAJK,EAKH,EAAI,QAAQ,WAAW,WAAW,EAClC,EAAI,QAAQ,WAAW,aAAa,EACpC,EAAO,EAAI,QAAS,EAAQ,CANrB,GAiBX,SAAgB,EAAgB,EAAc,EAA0B,EAAE,CAAE,CAC1E,MAAO,EAAQ,EAAe,EAAM,EAAQ"}
|
|
1
|
+
{"version":3,"file":"package-fns.mjs","names":[],"sources":["../src/package-fns.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 { findFileName, findFilePath } from \"@stryke/path/file-path-fns\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { getPackageName } from \"@stryke/string-format/package\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport type { PackageJson } from \"@stryke/types/package-json\";\nimport type { PackageManager } from \"@stryke/types/package-manager\";\nimport { existsSync } from \"node:fs\";\nimport type { Range } from \"semver\";\nimport { subset } from \"semver\";\nimport { exists } from \"./exists\";\nimport { getParentPath } from \"./get-parent-path\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\nimport { readJsonFile } from \"./json\";\nimport type { ResolveOptions } from \"./resolve\";\nimport { resolvePackage } from \"./resolve\";\n\n/**\n * Get the package manager used in the project\n *\n * @param dir - The path to the project\n * @returns The package manager used in the project\n */\nexport function getPackageManager(dir = getWorkspaceRoot()): PackageManager {\n const lockFile = getParentPath(\n [\"package-lock.json\", \"yarn.lock\", \"pnpm-lock.yaml\", \"bun.lock\"],\n dir,\n {\n includeNameInResults: true\n }\n );\n\n if (!lockFile) {\n // default use pnpm\n return \"pnpm\";\n }\n\n switch (findFileName(lockFile)) {\n case \"yarn.lock\": {\n return \"yarn\";\n }\n case \"pnpm-lock.yaml\": {\n return \"pnpm\";\n }\n case \"bun.lock\": {\n return \"bun\";\n }\n default: {\n return \"npm\";\n }\n }\n}\n\n// Much of the below code comes from https://github.com/antfu-collective/local-pkg with some modifications\n\nasync function searchPackageJson(dir: string) {\n let packageJsonPath;\n\n while (true) {\n if (!dir) {\n return;\n }\n const newDir = findFilePath(dir);\n\n if (newDir === dir) {\n return;\n }\n\n dir = newDir;\n packageJsonPath = joinPaths(dir, \"package.json\");\n\n if (await exists(packageJsonPath)) {\n break;\n }\n }\n\n return packageJsonPath;\n}\n\nasync function getPackageJsonPath(name: string, options: ResolveOptions = {}) {\n const entry = await resolvePackage(name, options);\n if (!entry) {\n return;\n }\n\n return searchPackageJson(entry);\n}\n\n/**\n * Get package info\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns The package info\n */\nexport async function getPackageInfo(\n name: string,\n options: ResolveOptions = {}\n) {\n const packageJsonPath = await getPackageJsonPath(name, options);\n if (!packageJsonPath) {\n return;\n }\n\n const packageJson = await readJsonFile<PackageJson>(packageJsonPath);\n\n return {\n name,\n version: packageJson.version,\n rootPath: findFilePath(packageJsonPath),\n packageJsonPath,\n packageJson\n };\n}\n\n/**\n * Get the package info from the package.json file\n *\n * @param cwd - The current working directory\n * @returns The package info\n */\nexport async function loadPackageJson(\n cwd = getWorkspaceRoot()\n): Promise<PackageJson | null> {\n const path = getParentPath(\"package.json\", cwd, {\n skipCwd: false,\n includeNameInResults: true\n });\n if (!path || !existsSync(path)) {\n return null;\n }\n\n return readJsonFile<PackageJson>(path);\n}\n\nexport interface PackageExistsOptions {\n /**\n * The current working directory\n */\n cwd?: string;\n}\n\nexport interface PackageMatchesOptions extends PackageExistsOptions {\n /**\n * The version range of the package to check\n */\n version?: string | Range;\n}\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwd?: string\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param options - The options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n options?: PackageExistsOptions\n): Promise<boolean>;\n\n/**\n * Check if a package is listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns An indicator specifying if the package is listed\n */\nexport async function isPackageListed(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<boolean> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return false;\n }\n\n return Boolean(\n (packageJson.dependencies &&\n packageName in packageJson.dependencies &&\n packageJson.dependencies[packageName]) ||\n (packageJson.devDependencies &&\n packageName in packageJson.devDependencies &&\n packageJson.devDependencies[packageName])\n );\n}\n\nexport interface GetPackageListingReturn {\n version: string;\n type: \"dependencies\" | \"devDependencies\";\n}\n\n/**\n * Return the package version and dependency type listed in the package.json file\n *\n * @param name - The name of the package\n * @param cwdOrOptions - The current working directory or options to use when checking if the package is listed\n * @returns The version and type of the package if listed, otherwise undefined\n */\nexport async function getPackageListing(\n name: string,\n cwdOrOptions?: string | PackageExistsOptions\n): Promise<GetPackageListingReturn | undefined> {\n const packageName = getPackageName(name);\n const cwd = isString(cwdOrOptions) ? cwdOrOptions : cwdOrOptions?.cwd;\n\n const packageJson = await loadPackageJson(cwd);\n if (!packageJson) {\n return undefined;\n }\n\n const version =\n packageJson.dependencies && packageName in packageJson.dependencies\n ? packageJson.dependencies[packageName]\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? packageJson.devDependencies[packageName]\n : undefined;\n const type =\n (packageJson.dependencies && packageName in packageJson.dependencies\n ? \"dependencies\"\n : packageJson.devDependencies &&\n packageName in packageJson.devDependencies\n ? \"devDependencies\"\n : undefined) || undefined;\n\n return version && type\n ? {\n version,\n type\n }\n : undefined;\n}\n\n/**\n * Check if a package version matches a specific version range\n *\n * @param name - The name of the package\n * @param version - The version to check against\n * @param cwd - The current working directory\n * @returns An indicator specifying if the package version matches the range\n */\nexport async function doesPackageMatch(\n name: string,\n version: string,\n cwd?: string\n): Promise<boolean> {\n const pkg = await getPackageListing(name, { cwd });\n if (!pkg) {\n return false;\n }\n\n return (\n pkg.version.startsWith(\"catalog:\") ||\n pkg.version.startsWith(\"workspace:\") ||\n subset(pkg.version, version)\n );\n}\n\n/**\n * Check if a package exists\n *\n * @param name - The name of the package\n * @param options - The options to use when resolving the package\n * @returns An indicator specifying if the package exists\n */\nexport function isPackageExists(name: string, options: ResolveOptions = {}) {\n return Boolean(resolvePackage(name, options));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,SAAgB,kBAAkB,MAAM,kBAAkB,EAAkB;CAC1E,MAAM,WAAW,cACf;EAAC;EAAqB;EAAa;EAAkB;EAAW,EAChE,KACA,EACE,sBAAsB,MACvB,CACF;AAED,KAAI,CAAC,SAEH,QAAO;AAGT,SAAQ,aAAa,SAAS,EAA9B;EACE,KAAK,YACH,QAAO;EAET,KAAK,iBACH,QAAO;EAET,KAAK,WACH,QAAO;EAET,QACE,QAAO;;;AAOb,eAAe,kBAAkB,KAAa;CAC5C,IAAI;AAEJ,QAAO,MAAM;AACX,MAAI,CAAC,IACH;EAEF,MAAM,SAAS,aAAa,IAAI;AAEhC,MAAI,WAAW,IACb;AAGF,QAAM;AACN,oBAAkB,UAAU,KAAK,eAAe;AAEhD,MAAI,MAAM,OAAO,gBAAgB,CAC/B;;AAIJ,QAAO;;AAGT,eAAe,mBAAmB,MAAc,UAA0B,EAAE,EAAE;CAC5E,MAAM,QAAQ,MAAM,eAAe,MAAM,QAAQ;AACjD,KAAI,CAAC,MACH;AAGF,QAAO,kBAAkB,MAAM;;;;;;;;;AAUjC,eAAsB,eACpB,MACA,UAA0B,EAAE,EAC5B;CACA,MAAM,kBAAkB,MAAM,mBAAmB,MAAM,QAAQ;AAC/D,KAAI,CAAC,gBACH;CAGF,MAAM,cAAc,MAAM,aAA0B,gBAAgB;AAEpE,QAAO;EACL;EACA,SAAS,YAAY;EACrB,UAAU,aAAa,gBAAgB;EACvC;EACA;EACD;;;;;;;;AASH,eAAsB,gBACpB,MAAM,kBAAkB,EACK;CAC7B,MAAM,OAAO,cAAc,gBAAgB,KAAK;EAC9C,SAAS;EACT,sBAAsB;EACvB,CAAC;AACF,KAAI,CAAC,QAAQ,CAAC,WAAW,KAAK,CAC5B,QAAO;AAGT,QAAO,aAA0B,KAAK;;;;;;;;;AAgDxC,eAAsB,gBACpB,MACA,cACkB;CAClB,MAAM,cAAc,eAAe,KAAK;CAGxC,MAAM,cAAc,MAAM,gBAFd,SAAS,aAAa,GAAG,eAAe,cAAc,IAEpB;AAC9C,KAAI,CAAC,YACH,QAAO;AAGT,QAAO,QACJ,YAAY,gBACX,eAAe,YAAY,gBAC3B,YAAY,aAAa,gBAC1B,YAAY,mBACX,eAAe,YAAY,mBAC3B,YAAY,gBAAgB,aAC/B;;;;;;;;;AAeH,eAAsB,kBACpB,MACA,cAC8C;CAC9C,MAAM,cAAc,eAAe,KAAK;CAGxC,MAAM,cAAc,MAAM,gBAFd,SAAS,aAAa,GAAG,eAAe,cAAc,IAEpB;AAC9C,KAAI,CAAC,YACH;CAGF,MAAM,UACJ,YAAY,gBAAgB,eAAe,YAAY,eACnD,YAAY,aAAa,eACzB,YAAY,mBACV,eAAe,YAAY,kBAC3B,YAAY,gBAAgB,eAC5B;CACR,MAAM,QACH,YAAY,gBAAgB,eAAe,YAAY,eACpD,iBACA,YAAY,mBACV,eAAe,YAAY,kBAC3B,oBACA,WAAc;AAEtB,QAAO,WAAW,OACd;EACE;EACA;EACD,GACD;;;;;;;;;;AAWN,eAAsB,iBACpB,MACA,SACA,KACkB;CAClB,MAAM,MAAM,MAAM,kBAAkB,MAAM,EAAE,KAAK,CAAC;AAClD,KAAI,CAAC,IACH,QAAO;AAGT,QACE,IAAI,QAAQ,WAAW,WAAW,IAClC,IAAI,QAAQ,WAAW,aAAa,IACpC,OAAO,IAAI,SAAS,QAAQ;;;;;;;;;AAWhC,SAAgB,gBAAgB,MAAc,UAA0B,EAAE,EAAE;AAC1E,QAAO,QAAQ,eAAe,MAAM,QAAQ,CAAC"}
|
package/dist/path/src/append.cjs
CHANGED
|
@@ -1 +1,57 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_cwd = require('./cwd.cjs');
|
|
2
|
+
const require_slash = require('./slash.cjs');
|
|
3
|
+
const require_is_parent_path = require('./is-parent-path.cjs');
|
|
4
|
+
const require_join_paths = require('./join-paths.cjs');
|
|
5
|
+
|
|
6
|
+
//#region ../path/src/append.ts
|
|
7
|
+
/**
|
|
8
|
+
* If not already a parent path, append the base path from the beginning of the given child path.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* appendPath("src/index.ts", "/home/user/project");
|
|
13
|
+
* // returns "/home/user/project/src/index.ts"
|
|
14
|
+
*
|
|
15
|
+
* appendPath("/user/dev/app.ts", "/user/dev");
|
|
16
|
+
* // returns "/user/dev/app.ts"
|
|
17
|
+
*
|
|
18
|
+
* appendPath("docs/readme.md");
|
|
19
|
+
* // returns "<current_working_directory>/docs/readme.md"
|
|
20
|
+
*
|
|
21
|
+
* appendPath("src/index.ts", "/home/user/project", { skipIfAlreadyParent: false });
|
|
22
|
+
* // returns "/home/user/project/src/index.ts"
|
|
23
|
+
*
|
|
24
|
+
* appendPath("/home/user/project/src/index.ts", "/home/user/project", { skipIfAlreadyParent: false });
|
|
25
|
+
* // returns "/home/user/project/src/index.ts"
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param childPath - The child path to append to the {@link parentPath}
|
|
29
|
+
* @param parentPath - The parent path to add the {@link childPath} to
|
|
30
|
+
* @param options - Options for appending the path
|
|
31
|
+
* @returns The {@link parentPath} with the {@link childPath} appended
|
|
32
|
+
*/
|
|
33
|
+
function appendPath(childPath, parentPath = require_cwd.cwd(), options = {}) {
|
|
34
|
+
return require_slash.slash(options.skipIfAlreadyParent !== false && require_is_parent_path.isParentPath(childPath, parentPath) ? childPath : require_join_paths.joinPaths(parentPath, childPath));
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Append the extension to the given path.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* appendExtension("/home/user/project/src/index", ".ts");
|
|
42
|
+
* // returns "/home/user/project/src/index.ts"
|
|
43
|
+
* appendExtension("/home/user/project/src/index.ts", ".js");
|
|
44
|
+
* // returns "/home/user/project/src/index.ts.js"
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param path - The path to append the extension to.
|
|
48
|
+
* @param extension - The extension to append.
|
|
49
|
+
* @returns The path with the appended extension.
|
|
50
|
+
*/
|
|
51
|
+
function appendExtension(path, extension) {
|
|
52
|
+
return `${path}.${extension.replace(/^\./, "")}`;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
//#endregion
|
|
56
|
+
exports.appendExtension = appendExtension;
|
|
57
|
+
exports.appendPath = appendPath;
|