@stryke/fs 0.33.81 → 0.33.83
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 +36 -0
- package/dist/list-files.cjs +17 -2
- package/dist/list-files.d.cts.map +1 -1
- package/dist/list-files.d.mts.map +1 -1
- package/dist/list-files.mjs +18 -3
- package/dist/list-files.mjs.map +1 -1
- package/dist/resolve.mjs +3 -3
- package/dist/resolve.mjs.map +1 -1
- package/package.json +9 -9
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - Fs
|
|
4
4
|
|
|
5
|
+
## [0.33.82](https://github.com/storm-software/stryke/releases/tag/fs%400.33.82) (06/01/2026)
|
|
6
|
+
|
|
7
|
+
### Miscellaneous
|
|
8
|
+
|
|
9
|
+
- **monorepo:** Update workspace dependencies and `vitest.config.mts` files ([998ff756](https://github.com/storm-software/stryke/commit/998ff756))
|
|
10
|
+
|
|
11
|
+
### Updated Dependencies
|
|
12
|
+
|
|
13
|
+
- Updated **convert** to **v0.7.13**
|
|
14
|
+
- Updated **helpers** to **v0.10.22**
|
|
15
|
+
- Updated **json** to **v0.15.6**
|
|
16
|
+
- Updated **path** to **v0.29.9**
|
|
17
|
+
- Updated **string-format** to **v0.17.24**
|
|
18
|
+
- Updated **type-checks** to **v0.6.15**
|
|
19
|
+
- Updated **types** to **v0.12.10**
|
|
20
|
+
|
|
21
|
+
## [0.33.81](https://github.com/storm-software/stryke/releases/tag/fs%400.33.81) (05/30/2026)
|
|
22
|
+
|
|
23
|
+
### Miscellaneous
|
|
24
|
+
|
|
25
|
+
- **monorepo:** Remove remaining `jest` configuration ([1fd3d7d2](https://github.com/storm-software/stryke/commit/1fd3d7d2))
|
|
26
|
+
|
|
27
|
+
### Bug Fixes
|
|
28
|
+
|
|
29
|
+
- **monorepo:** Resolve issue with `.test.ts` exports in `package.json` file ([31d85e19](https://github.com/storm-software/stryke/commit/31d85e19))
|
|
30
|
+
|
|
31
|
+
### Updated Dependencies
|
|
32
|
+
|
|
33
|
+
- Updated **convert** to **v0.7.12**
|
|
34
|
+
- Updated **helpers** to **v0.10.21**
|
|
35
|
+
- Updated **json** to **v0.15.5**
|
|
36
|
+
- Updated **path** to **v0.29.8**
|
|
37
|
+
- Updated **string-format** to **v0.17.23**
|
|
38
|
+
- Updated **type-checks** to **v0.6.14**
|
|
39
|
+
- Updated **types** to **v0.12.9**
|
|
40
|
+
|
|
5
41
|
## [0.33.80](https://github.com/storm-software/stryke/releases/tag/fs%400.33.80) (05/30/2026)
|
|
6
42
|
|
|
7
43
|
### Miscellaneous
|
package/dist/list-files.cjs
CHANGED
|
@@ -17,13 +17,28 @@ var list_files_exports = /* @__PURE__ */ require_runtime.__exportAll({
|
|
|
17
17
|
});
|
|
18
18
|
const DEFAULT_OPTIONS = { dot: true };
|
|
19
19
|
/**
|
|
20
|
+
* Determines whether a string contains glob "magic" characters.
|
|
21
|
+
*
|
|
22
|
+
* @remarks
|
|
23
|
+
* This includes wildcards (`*`, `?`), character classes (`[...]`),
|
|
24
|
+
* extglob groups (`!(...)`, `+(...)`, etc.), and brace expansion
|
|
25
|
+
* (`{option1,option2}`). When any of these are present the value should be
|
|
26
|
+
* treated as an existing glob pattern instead of a plain path.
|
|
27
|
+
*
|
|
28
|
+
* @param value - The string to inspect
|
|
29
|
+
* @returns `true` if the string contains glob magic characters
|
|
30
|
+
*/
|
|
31
|
+
function isGlobPattern(value) {
|
|
32
|
+
return /[*?[\]{}()!+@]/.test(value);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
20
35
|
* A files and directories listing helper function
|
|
21
36
|
*
|
|
22
37
|
* @param filesGlob - A glob pattern to match files
|
|
23
38
|
* @returns A list of file paths
|
|
24
39
|
*/
|
|
25
40
|
async function list(filesGlob, options) {
|
|
26
|
-
return (0, glob.glob)((0, _stryke_type_checks.isString)(filesGlob) ? filesGlob.
|
|
41
|
+
return (0, glob.glob)((0, _stryke_type_checks.isString)(filesGlob) ? isGlobPattern(filesGlob) || (0, _stryke_path.hasFileExtension)(filesGlob) ? filesGlob : (0, _stryke_path.joinPaths)(filesGlob, "**/*") : filesGlob.input ? (0, _stryke_path.joinPaths)(filesGlob.input, filesGlob.glob) : filesGlob.glob, (0, defu.default)((0, _stryke_type_checks.isString)(filesGlob) ? {} : {
|
|
27
42
|
dot: filesGlob.dot,
|
|
28
43
|
ignore: filesGlob.ignore
|
|
29
44
|
}, options ?? {}, DEFAULT_OPTIONS));
|
|
@@ -35,7 +50,7 @@ async function list(filesGlob, options) {
|
|
|
35
50
|
* @returns A list of file paths
|
|
36
51
|
*/
|
|
37
52
|
function listSync(filesGlob, options) {
|
|
38
|
-
return glob.glob.sync((0, _stryke_type_checks.isString)(filesGlob) ? filesGlob.
|
|
53
|
+
return glob.glob.sync((0, _stryke_type_checks.isString)(filesGlob) ? isGlobPattern(filesGlob) || (0, _stryke_path.hasFileExtension)(filesGlob) ? filesGlob : (0, _stryke_path.joinPaths)(filesGlob, "**/*") : filesGlob.input ? (0, _stryke_path.joinPaths)(filesGlob.input, filesGlob.glob) : filesGlob.glob, (0, defu.default)((0, _stryke_type_checks.isString)(filesGlob) ? {} : {
|
|
39
54
|
dot: filesGlob.dot,
|
|
40
55
|
ignore: filesGlob.ignore
|
|
41
56
|
}, options ?? {}, DEFAULT_OPTIONS));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-files.d.cts","names":[],"sources":["../src/list-files.ts"],"mappings":";;;;KAyBY,WAAA,GAAc,WAAA;AAAA,KACd,mBAAA,kBAAqC,WAAA,IAC/C,QAAA,iCAAyC,IAAA;AAF3C;;;;;AACA;AADA,
|
|
1
|
+
{"version":3,"file":"list-files.d.cts","names":[],"sources":["../src/list-files.ts"],"mappings":";;;;KAyBY,WAAA,GAAc,WAAA;AAAA,KACd,mBAAA,kBAAqC,WAAA,IAC/C,QAAA,iCAAyC,IAAA;AAF3C;;;;;AACA;AADA,iBA8BsB,IAAA,kBAAsB,WAAA,CAAA,CAC1C,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GACT,OAAA,CAAQ,mBAAA,CAAoB,QAAA;;;;;;;iBAyBf,QAAA,kBAA0B,WAAA,CAAA,CACxC,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GACT,mBAAA,CAAoB,QAAA;;;;;;AA/BvB;iBAwDsB,SAAA,kBAA2B,WAAA,CAAA,CAC/C,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,OAAA,CAAA,mBAAA,CAAA,QAAA;;;;;;;iBAwBJ,aAAA,kBAA+B,WAAA,CAAA,CAC7C,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,mBAAA,CAAA,QAAA;;;;;;;iBAmBE,eAAA,kBAAiC,WAAA,CAAA,CACrD,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,OAAA,CAAA,mBAAA,CAAA,QAAA;;;;;;;iBAwBJ,mBAAA,kBAAqC,WAAA,CAAA,CACnD,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,mBAAA,CAAA,QAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-files.d.mts","names":[],"sources":["../src/list-files.ts"],"mappings":";;;;KAyBY,WAAA,GAAc,WAAA;AAAA,KACd,mBAAA,kBAAqC,WAAA,IAC/C,QAAA,iCAAyC,IAAA;AAF3C;;;;;AACA;AADA,
|
|
1
|
+
{"version":3,"file":"list-files.d.mts","names":[],"sources":["../src/list-files.ts"],"mappings":";;;;KAyBY,WAAA,GAAc,WAAA;AAAA,KACd,mBAAA,kBAAqC,WAAA,IAC/C,QAAA,iCAAyC,IAAA;AAF3C;;;;;AACA;AADA,iBA8BsB,IAAA,kBAAsB,WAAA,CAAA,CAC1C,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GACT,OAAA,CAAQ,mBAAA,CAAoB,QAAA;;;;;;;iBAyBf,QAAA,kBAA0B,WAAA,CAAA,CACxC,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GACT,mBAAA,CAAoB,QAAA;;;;;;AA/BvB;iBAwDsB,SAAA,kBAA2B,WAAA,CAAA,CAC/C,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,OAAA,CAAA,mBAAA,CAAA,QAAA;;;;;;;iBAwBJ,aAAA,kBAA+B,WAAA,CAAA,CAC7C,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,mBAAA,CAAA,QAAA;;;;;;;iBAmBE,eAAA,kBAAiC,WAAA,CAAA,CACrD,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,OAAA,CAAA,mBAAA,CAAA,QAAA;;;;;;;iBAwBJ,mBAAA,kBAAqC,WAAA,CAAA,CACnD,SAAA,WAAoB,IAAA,CAAK,SAAA,aACzB,OAAA,GAAU,QAAA,GAAQ,mBAAA,CAAA,QAAA"}
|
package/dist/list-files.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __exportAll } from "./_virtual/_rolldown/runtime.mjs";
|
|
2
|
-
import { joinPaths } from "@stryke/path";
|
|
2
|
+
import { hasFileExtension, joinPaths } from "@stryke/path";
|
|
3
3
|
import { isString } from "@stryke/type-checks";
|
|
4
4
|
import defu from "defu";
|
|
5
5
|
import { glob } from "glob";
|
|
@@ -15,13 +15,28 @@ var list_files_exports = /* @__PURE__ */ __exportAll({
|
|
|
15
15
|
});
|
|
16
16
|
const DEFAULT_OPTIONS = { dot: true };
|
|
17
17
|
/**
|
|
18
|
+
* Determines whether a string contains glob "magic" characters.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* This includes wildcards (`*`, `?`), character classes (`[...]`),
|
|
22
|
+
* extglob groups (`!(...)`, `+(...)`, etc.), and brace expansion
|
|
23
|
+
* (`{option1,option2}`). When any of these are present the value should be
|
|
24
|
+
* treated as an existing glob pattern instead of a plain path.
|
|
25
|
+
*
|
|
26
|
+
* @param value - The string to inspect
|
|
27
|
+
* @returns `true` if the string contains glob magic characters
|
|
28
|
+
*/
|
|
29
|
+
function isGlobPattern(value) {
|
|
30
|
+
return /[*?[\]{}()!+@]/.test(value);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
18
33
|
* A files and directories listing helper function
|
|
19
34
|
*
|
|
20
35
|
* @param filesGlob - A glob pattern to match files
|
|
21
36
|
* @returns A list of file paths
|
|
22
37
|
*/
|
|
23
38
|
async function list(filesGlob, options) {
|
|
24
|
-
return glob(isString(filesGlob) ? filesGlob
|
|
39
|
+
return glob(isString(filesGlob) ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob) ? filesGlob : joinPaths(filesGlob, "**/*") : filesGlob.input ? joinPaths(filesGlob.input, filesGlob.glob) : filesGlob.glob, defu(isString(filesGlob) ? {} : {
|
|
25
40
|
dot: filesGlob.dot,
|
|
26
41
|
ignore: filesGlob.ignore
|
|
27
42
|
}, options ?? {}, DEFAULT_OPTIONS));
|
|
@@ -33,7 +48,7 @@ async function list(filesGlob, options) {
|
|
|
33
48
|
* @returns A list of file paths
|
|
34
49
|
*/
|
|
35
50
|
function listSync(filesGlob, options) {
|
|
36
|
-
return glob.sync(isString(filesGlob) ? filesGlob
|
|
51
|
+
return glob.sync(isString(filesGlob) ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob) ? filesGlob : joinPaths(filesGlob, "**/*") : filesGlob.input ? joinPaths(filesGlob.input, filesGlob.glob) : filesGlob.glob, defu(isString(filesGlob) ? {} : {
|
|
37
52
|
dot: filesGlob.dot,
|
|
38
53
|
ignore: filesGlob.ignore
|
|
39
54
|
}, options ?? {}, DEFAULT_OPTIONS));
|
package/dist/list-files.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-files.mjs","names":[],"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
|
|
1
|
+
{"version":3,"file":"list-files.mjs","names":[],"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 { hasFileExtension, 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 * Determines whether a string contains glob \"magic\" characters.\n *\n * @remarks\n * This includes wildcards (`*`, `?`), character classes (`[...]`),\n * extglob groups (`!(...)`, `+(...)`, etc.), and brace expansion\n * (`{option1,option2}`). When any of these are present the value should be\n * treated as an existing glob pattern instead of a plain path.\n *\n * @param value - The string to inspect\n * @returns `true` if the string contains glob magic characters\n */\nfunction isGlobPattern(value: string): boolean {\n return /[*?[\\]{}()!+@]/.test(value);\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 ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob)\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 ? isGlobPattern(filesGlob) || hasFileExtension(filesGlob)\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,MAAM,kBAA+B,EACnC,KAAK,MACN;;;;;;;;;;;;;AAcD,SAAS,cAAc,OAAwB;AAC7C,QAAO,iBAAiB,KAAK,MAAM;;;;;;;;AASrC,eAAsB,KACpB,WACA,SACwC;AACxC,QAAO,KACL,SAAS,UAAU,GACf,cAAc,UAAU,IAAI,iBAAiB,UAAU,GACrD,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,cAAc,UAAU,IAAI,iBAAiB,UAAU,GACrD,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/resolve.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { getWorkspaceRoot } from "./get-workspace-root.mjs";
|
|
|
4
4
|
import { appendExtension } from "@stryke/path";
|
|
5
5
|
import { joinPaths as joinPaths$1 } from "@stryke/path/join-paths";
|
|
6
6
|
import { correctPath, toAbsolutePath } from "@stryke/path/correct-path";
|
|
7
|
-
import { findFileName, findFilePath as findFilePath$1, findFolderName as findFolderName$1, hasFileExtension } from "@stryke/path/file-path-fns";
|
|
7
|
+
import { findFileName, findFilePath as findFilePath$1, findFolderName as findFolderName$1, hasFileExtension as hasFileExtension$1 } from "@stryke/path/file-path-fns";
|
|
8
8
|
import { interopDefault, resolvePath, resolvePathSync } from "mlly";
|
|
9
9
|
import { cwd } from "@stryke/path/cwd";
|
|
10
10
|
import { getUnique } from "@stryke/helpers/get-unique";
|
|
@@ -92,7 +92,7 @@ function getResolutionCombinations(path, options = {}) {
|
|
|
92
92
|
ret.push(joinPaths$1(combination, "index"));
|
|
93
93
|
return ret;
|
|
94
94
|
}, []);
|
|
95
|
-
if (!hasFileExtension(path)) {
|
|
95
|
+
if (!hasFileExtension$1(path)) {
|
|
96
96
|
const extensions = options.extensions ?? DEFAULT_EXTENSIONS;
|
|
97
97
|
combinations = combinations.reduce((ret, combination) => {
|
|
98
98
|
ret.push(combination);
|
|
@@ -104,7 +104,7 @@ function getResolutionCombinations(path, options = {}) {
|
|
|
104
104
|
combinations.push(...extensions.map((ext) => getResolutionCombinations(appendExtension(path, ext), options)).flat());
|
|
105
105
|
}
|
|
106
106
|
paths.map((p) => {
|
|
107
|
-
if (hasFileExtension(p)) combinations.push(...getResolutionCombinations(path, {
|
|
107
|
+
if (hasFileExtension$1(p)) combinations.push(...getResolutionCombinations(path, {
|
|
108
108
|
...options,
|
|
109
109
|
useAdditionalPaths: false,
|
|
110
110
|
paths: [findFilePath$1(p)]
|
package/dist/resolve.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve.mjs","names":["findFolderName","joinPaths","findFilePath"],"sources":["../src/resolve.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 { getUnique } from \"@stryke/helpers/get-unique\";\nimport { appendExtension } from \"@stryke/path\";\nimport { correctPath, toAbsolutePath } from \"@stryke/path/correct-path\";\nimport { cwd } from \"@stryke/path/cwd\";\nimport {\n findFileName,\n findFilePath,\n findFolderName,\n hasFileExtension\n} from \"@stryke/path/file-path-fns\";\nimport { isAbsolutePath, isNpmScopedPackage } from \"@stryke/path/is-type\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { interopDefault, resolvePath, resolvePathSync } from \"mlly\";\nimport { existsSync } from \"./exists\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport const DEFAULT_EXTENSIONS = [\n \"js\",\n \"jsx\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"tsx\",\n \"mts\",\n \"cts\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"node\"\n];\n\nexport interface ResolveOptions {\n /**\n * Paths to resolve the package from\n */\n paths?: string[];\n\n /**\n * File extensions to consider when resolving the module\n *\n * @remarks\n * Extensions can be provided with or without the leading dot. The resolver utilities will handle both cases.\n *\n * @defaultValue [\"js\", \"jsx\", \"mjs\", \"cjs\", \"ts\", \"tsx\", \"mts\", \"cts\", \"json\", \"jsonc\", \"json5\", \"node\", \"wasm\"]\n */\n extensions?: string[];\n\n /**\n * Conditions to consider when resolving package exports.\n */\n conditions?: string[];\n}\n\n/**\n * Get the resolution paths based on the provided paths, current working directory, and workspace root.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionPaths(paths: string[] = []) {\n let resolutionPaths = paths;\n if (!resolutionPaths.includes(cwd())) {\n resolutionPaths.push(cwd());\n }\n\n const workspaceRoot = getWorkspaceRoot();\n if (!resolutionPaths.includes(workspaceRoot)) {\n resolutionPaths.push(workspaceRoot);\n }\n\n resolutionPaths = getUnique(\n resolutionPaths\n .filter(Boolean)\n .map(path => correctPath(path))\n .reduce((ret, path, _, arr) => {\n ret.push(path);\n if (!isAbsolutePath(path)) {\n ret.push(toAbsolutePath(path, cwd()));\n ret.push(toAbsolutePath(path, workspaceRoot));\n\n arr.forEach(existing => {\n ret.push(toAbsolutePath(path, existing));\n });\n }\n\n return ret;\n }, [] as string[])\n );\n\n return resolutionPaths;\n}\n\n/**\n * Get the node_modules resolution paths based on the provided paths.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected node_modules resolution paths.\n */\nexport function getNodeModulesPaths(paths: string[] = []) {\n return getUnique(\n paths.reduce((ret, path) => {\n if (findFolderName(path) === \"node_modules\") {\n ret.push(correctPath(path));\n }\n\n if (existsSync(joinPaths(path, \"node_modules\"))) {\n ret.push(correctPath(joinPaths(path, \"node_modules\")));\n }\n\n return ret;\n }, [] as string[])\n );\n}\n\nexport interface ResolutionCombinationOptions extends ResolveOptions {\n /**\n * Whether to include additional paths (like node_modules) in the resolution combinations. If set to false, only the provided paths will be used for generating combinations. This can be useful for scenarios where you want to limit the resolution to specific directories without considering the default node_modules paths.\n *\n * @defaultValue true\n */\n useAdditionalPaths?: boolean;\n}\n\n/**\n * Get all combinations of resolution paths for a given path and options.\n *\n * @param path - The base path to combine with resolution paths.\n * @param options - The options containing resolution paths.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionCombinations(\n path: string,\n options: ResolutionCombinationOptions = {}\n) {\n let paths = options.useAdditionalPaths\n ? getResolutionPaths(options.paths)\n : (options.paths ?? []);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let combinations = paths.map(base => joinPaths(base, path));\n if (findFileName(path, { withExtension: false }) !== \"index\") {\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n ret.push(joinPaths(combination, \"index\"));\n\n return ret;\n }, [] as string[]);\n }\n\n if (!hasFileExtension(path)) {\n const extensions = options.extensions ?? DEFAULT_EXTENSIONS;\n\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n extensions.forEach(ext => {\n ret.push(appendExtension(combination, ext));\n });\n\n return ret;\n }, [] as string[]);\n\n combinations.push(\n ...extensions\n .map(ext =>\n getResolutionCombinations(appendExtension(path, ext), options)\n )\n .flat()\n );\n }\n\n paths.map(p => {\n if (hasFileExtension(p)) {\n combinations.push(\n ...getResolutionCombinations(path, {\n ...options,\n useAdditionalPaths: false,\n paths: [findFilePath(p)]\n })\n );\n }\n });\n\n return getUnique(combinations.filter(Boolean)).map(p => correctPath(p));\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolve(\n path: string,\n options: ResolveOptions = {}\n): Promise<string> {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result: string | undefined;\n let error: Error | undefined;\n\n try {\n result = await resolvePath(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = await resolvePath(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSync(path: string, options: ResolveOptions = {}) {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result!: string;\n let error: Error | undefined;\n\n try {\n result = resolvePathSync(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = resolvePathSync(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n // if (!result && findFileName(path, { withExtension: false }) !== \"index\") {\n // try {\n // result = resolveSync(joinPaths(path, \"index\"), {\n // ...options,\n // paths\n // });\n // if (result) {\n // // Remove the previously added index file from the path\n // result = findFilePath(result);\n // }\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolveSafe(name: string, options: ResolveOptions = {}) {\n try {\n return await resolve(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSafeSync(name: string, options: ResolveOptions = {}) {\n try {\n return resolveSync(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Import a module from a specified path\n *\n * @param path - The path to the module\n * @returns The module\n */\nexport async function importModule<T = any>(path: string): Promise<T> {\n const i = await import(path);\n\n if (i) {\n return interopDefault(i);\n }\n\n return i;\n}\n\n/**\n * Resolve the path to a specified package asynchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @returns A promise for the module or undefined\n */\nexport async function resolvePackage(\n name: string,\n options: ResolveOptions = {}\n) {\n let result = await resolveSafe(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = await resolveSafe(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = await resolveSafe(name, options);\n }\n }\n\n return result ? findFilePath(result) : undefined;\n}\n\n/**\n * Resolve the path to a specified package synchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The module or undefined\n */\nexport function resolvePackageSync(name: string, options: ResolveOptions = {}) {\n let result = resolveSafeSync(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = resolveSafeSync(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = resolveSafeSync(name, options);\n }\n }\n\n return result ? findFilePath(result) : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AA8BD,SAAgB,mBAAmB,QAAkB,EAAE,EAAE;CACvD,IAAI,kBAAkB;AACtB,KAAI,CAAC,gBAAgB,SAAS,KAAK,CAAC,CAClC,iBAAgB,KAAK,KAAK,CAAC;CAG7B,MAAM,gBAAgB,kBAAkB;AACxC,KAAI,CAAC,gBAAgB,SAAS,cAAc,CAC1C,iBAAgB,KAAK,cAAc;AAGrC,mBAAkB,UAChB,gBACG,OAAO,QAAQ,CACf,KAAI,SAAQ,YAAY,KAAK,CAAC,CAC9B,QAAQ,KAAK,MAAM,GAAG,QAAQ;AAC7B,MAAI,KAAK,KAAK;AACd,MAAI,CAAC,eAAe,KAAK,EAAE;AACzB,OAAI,KAAK,eAAe,MAAM,KAAK,CAAC,CA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,KAAK,KAAK,IAC/D,EACE,OAAO,OACR,CACF;AAGH,QAAO,YAAY,OAAO;;;;;;;;;AAU5B,eAAsB,YAAY,MAAc,UAA0B,EAAE,EAAE;AAC5E,KAAI;AACF,SAAO,MAAM,QAAQ,MAAM,QAAQ;SAC7B;AACN;;;;;;;;;;AAWJ,SAAgB,gBAAgB,MAAc,UAA0B,EAAE,EAAE;AAC1E,KAAI;AACF,SAAO,YAAY,MAAM,QAAQ;SAC3B;AACN;;;;;;;;;AAUJ,eAAsB,aAAsB,MAA0B;CACpE,MAAM,IAAI,MAAM,OAAO;AAEvB,KAAI,EACF,QAAO,eAAe,EAAE;AAG1B,QAAO;;;;;;;;;;;AAYT,eAAsB,eACpB,MACA,UAA0B,EAAE,EAC5B;CACA,IAAI,SAAS,MAAM,YAAYD,YAAU,MAAM,eAAe,EAAE,QAAQ;AACxE,KAAI,CAAC,QAAQ;AACX,WAAS,MAAM,YAAYA,YAAU,MAAM,WAAW,EAAE,QAAQ;AAChE,MAAI,CAAC,OACH,UAAS,MAAM,YAAY,MAAM,QAAQ;;AAI7C,QAAO,SAASC,eAAa,OAAO,GAAG;;;;;;;;;;;;AAazC,SAAgB,mBAAmB,MAAc,UAA0B,EAAE,EAAE;CAC7E,IAAI,SAAS,gBAAgBD,YAAU,MAAM,eAAe,EAAE,QAAQ;AACtE,KAAI,CAAC,QAAQ;AACX,WAAS,gBAAgBA,YAAU,MAAM,WAAW,EAAE,QAAQ;AAC9D,MAAI,CAAC,OACH,UAAS,gBAAgB,MAAM,QAAQ;;AAI3C,QAAO,SAASC,eAAa,OAAO,GAAG"}
|
|
1
|
+
{"version":3,"file":"resolve.mjs","names":["findFolderName","joinPaths","hasFileExtension","findFilePath"],"sources":["../src/resolve.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 { getUnique } from \"@stryke/helpers/get-unique\";\nimport { appendExtension } from \"@stryke/path\";\nimport { correctPath, toAbsolutePath } from \"@stryke/path/correct-path\";\nimport { cwd } from \"@stryke/path/cwd\";\nimport {\n findFileName,\n findFilePath,\n findFolderName,\n hasFileExtension\n} from \"@stryke/path/file-path-fns\";\nimport { isAbsolutePath, isNpmScopedPackage } from \"@stryke/path/is-type\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport { interopDefault, resolvePath, resolvePathSync } from \"mlly\";\nimport { existsSync } from \"./exists\";\nimport { getWorkspaceRoot } from \"./get-workspace-root\";\n\nexport const DEFAULT_EXTENSIONS = [\n \"js\",\n \"jsx\",\n \"mjs\",\n \"cjs\",\n \"ts\",\n \"tsx\",\n \"mts\",\n \"cts\",\n \"json\",\n \"jsonc\",\n \"json5\",\n \"node\"\n];\n\nexport interface ResolveOptions {\n /**\n * Paths to resolve the package from\n */\n paths?: string[];\n\n /**\n * File extensions to consider when resolving the module\n *\n * @remarks\n * Extensions can be provided with or without the leading dot. The resolver utilities will handle both cases.\n *\n * @defaultValue [\"js\", \"jsx\", \"mjs\", \"cjs\", \"ts\", \"tsx\", \"mts\", \"cts\", \"json\", \"jsonc\", \"json5\", \"node\", \"wasm\"]\n */\n extensions?: string[];\n\n /**\n * Conditions to consider when resolving package exports.\n */\n conditions?: string[];\n}\n\n/**\n * Get the resolution paths based on the provided paths, current working directory, and workspace root.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionPaths(paths: string[] = []) {\n let resolutionPaths = paths;\n if (!resolutionPaths.includes(cwd())) {\n resolutionPaths.push(cwd());\n }\n\n const workspaceRoot = getWorkspaceRoot();\n if (!resolutionPaths.includes(workspaceRoot)) {\n resolutionPaths.push(workspaceRoot);\n }\n\n resolutionPaths = getUnique(\n resolutionPaths\n .filter(Boolean)\n .map(path => correctPath(path))\n .reduce((ret, path, _, arr) => {\n ret.push(path);\n if (!isAbsolutePath(path)) {\n ret.push(toAbsolutePath(path, cwd()));\n ret.push(toAbsolutePath(path, workspaceRoot));\n\n arr.forEach(existing => {\n ret.push(toAbsolutePath(path, existing));\n });\n }\n\n return ret;\n }, [] as string[])\n );\n\n return resolutionPaths;\n}\n\n/**\n * Get the node_modules resolution paths based on the provided paths.\n *\n * @param paths - An array of paths to include in the resolution.\n * @returns An array of unique, corrected node_modules resolution paths.\n */\nexport function getNodeModulesPaths(paths: string[] = []) {\n return getUnique(\n paths.reduce((ret, path) => {\n if (findFolderName(path) === \"node_modules\") {\n ret.push(correctPath(path));\n }\n\n if (existsSync(joinPaths(path, \"node_modules\"))) {\n ret.push(correctPath(joinPaths(path, \"node_modules\")));\n }\n\n return ret;\n }, [] as string[])\n );\n}\n\nexport interface ResolutionCombinationOptions extends ResolveOptions {\n /**\n * Whether to include additional paths (like node_modules) in the resolution combinations. If set to false, only the provided paths will be used for generating combinations. This can be useful for scenarios where you want to limit the resolution to specific directories without considering the default node_modules paths.\n *\n * @defaultValue true\n */\n useAdditionalPaths?: boolean;\n}\n\n/**\n * Get all combinations of resolution paths for a given path and options.\n *\n * @param path - The base path to combine with resolution paths.\n * @param options - The options containing resolution paths.\n * @returns An array of unique, corrected resolution paths.\n */\nexport function getResolutionCombinations(\n path: string,\n options: ResolutionCombinationOptions = {}\n) {\n let paths = options.useAdditionalPaths\n ? getResolutionPaths(options.paths)\n : (options.paths ?? []);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let combinations = paths.map(base => joinPaths(base, path));\n if (findFileName(path, { withExtension: false }) !== \"index\") {\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n ret.push(joinPaths(combination, \"index\"));\n\n return ret;\n }, [] as string[]);\n }\n\n if (!hasFileExtension(path)) {\n const extensions = options.extensions ?? DEFAULT_EXTENSIONS;\n\n combinations = combinations.reduce((ret, combination) => {\n ret.push(combination);\n extensions.forEach(ext => {\n ret.push(appendExtension(combination, ext));\n });\n\n return ret;\n }, [] as string[]);\n\n combinations.push(\n ...extensions\n .map(ext =>\n getResolutionCombinations(appendExtension(path, ext), options)\n )\n .flat()\n );\n }\n\n paths.map(p => {\n if (hasFileExtension(p)) {\n combinations.push(\n ...getResolutionCombinations(path, {\n ...options,\n useAdditionalPaths: false,\n paths: [findFilePath(p)]\n })\n );\n }\n });\n\n return getUnique(combinations.filter(Boolean)).map(p => correctPath(p));\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolve(\n path: string,\n options: ResolveOptions = {}\n): Promise<string> {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result: string | undefined;\n let error: Error | undefined;\n\n try {\n result = await resolvePath(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = await resolvePath(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module\n *\n * @param path - The path to the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSync(path: string, options: ResolveOptions = {}) {\n let paths = getResolutionPaths(options.paths);\n if (isNpmScopedPackage(path)) {\n paths = getNodeModulesPaths(paths);\n } else {\n paths.push(...getNodeModulesPaths(paths));\n }\n\n let result!: string;\n let error: Error | undefined;\n\n try {\n result = resolvePathSync(path, {\n url: paths,\n extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n conditions: options.conditions\n });\n } catch (err) {\n error = err as Error;\n }\n\n // if (!result) {\n // for (let i = 0; i < paths.length && !result; i++) {\n // try {\n // result = resolvePathSync(replacePath(path, paths[i]), {\n // url: paths,\n // extensions: options.extensions ?? DEFAULT_EXTENSIONS,\n // conditions: options.conditions\n // });\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n // }\n\n // if (!result && findFileName(path, { withExtension: false }) !== \"index\") {\n // try {\n // result = resolveSync(joinPaths(path, \"index\"), {\n // ...options,\n // paths\n // });\n // if (result) {\n // // Remove the previously added index file from the path\n // result = findFilePath(result);\n // }\n // } catch (err) {\n // error = err as Error;\n // }\n // }\n\n if (!result) {\n throw new Error(\n `Unable to resolve module \"${\n path\n }\". The following import paths were tried: \\n${paths.join(\"\\n\")}`,\n {\n cause: error\n }\n );\n }\n\n return correctPath(result);\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns A promise for the path to the module\n */\nexport async function resolveSafe(name: string, options: ResolveOptions = {}) {\n try {\n return await resolve(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Resolve the path to a specified module with error handling\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The path to the module or undefined\n */\nexport function resolveSafeSync(name: string, options: ResolveOptions = {}) {\n try {\n return resolveSync(name, options);\n } catch {\n return undefined;\n }\n}\n\n/**\n * Import a module from a specified path\n *\n * @param path - The path to the module\n * @returns The module\n */\nexport async function importModule<T = any>(path: string): Promise<T> {\n const i = await import(path);\n\n if (i) {\n return interopDefault(i);\n }\n\n return i;\n}\n\n/**\n * Resolve the path to a specified package asynchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @returns A promise for the module or undefined\n */\nexport async function resolvePackage(\n name: string,\n options: ResolveOptions = {}\n) {\n let result = await resolveSafe(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = await resolveSafe(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = await resolveSafe(name, options);\n }\n }\n\n return result ? findFilePath(result) : undefined;\n}\n\n/**\n * Resolve the path to a specified package synchronously\n *\n * @remarks\n * This path points to the root of the package, which is usually the directory containing the `package.json` file. Please note: this path does not include the `package.json` file itself.\n *\n * @param name - The name of the module\n * @param options - The options to use when resolving the module\n * @returns The module or undefined\n */\nexport function resolvePackageSync(name: string, options: ResolveOptions = {}) {\n let result = resolveSafeSync(joinPaths(name, \"package.json\"), options);\n if (!result) {\n result = resolveSafeSync(joinPaths(name, \"index.js\"), options);\n if (!result) {\n result = resolveSafeSync(name, options);\n }\n }\n\n return result ? findFilePath(result) : undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;;;;;;AA8BD,SAAgB,mBAAmB,QAAkB,EAAE,EAAE;CACvD,IAAI,kBAAkB;AACtB,KAAI,CAAC,gBAAgB,SAAS,KAAK,CAAC,CAClC,iBAAgB,KAAK,KAAK,CAAC;CAG7B,MAAM,gBAAgB,kBAAkB;AACxC,KAAI,CAAC,gBAAgB,SAAS,cAAc,CAC1C,iBAAgB,KAAK,cAAc;AAGrC,mBAAkB,UAChB,gBACG,OAAO,QAAQ,CACf,KAAI,SAAQ,YAAY,KAAK,CAAC,CAC9B,QAAQ,KAAK,MAAM,GAAG,QAAQ;AAC7B,MAAI,KAAK,KAAK;AACd,MAAI,CAAC,eA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CV,KAAI,CAAC,OACH,OAAM,IAAI,MACR,6BACE,KACD,8CAA8C,MAAM,KAAK,KAAK,IAC/D,EACE,OAAO,OACR,CACF;AAGH,QAAO,YAAY,OAAO;;;;;;;;;AAU5B,eAAsB,YAAY,MAAc,UAA0B,EAAE,EAAE;AAC5E,KAAI;AACF,SAAO,MAAM,QAAQ,MAAM,QAAQ;SAC7B;AACN;;;;;;;;;;AAWJ,SAAgB,gBAAgB,MAAc,UAA0B,EAAE,EAAE;AAC1E,KAAI;AACF,SAAO,YAAY,MAAM,QAAQ;SAC3B;AACN;;;;;;;;;AAUJ,eAAsB,aAAsB,MAA0B;CACpE,MAAM,IAAI,MAAM,OAAO;AAEvB,KAAI,EACF,QAAO,eAAe,EAAE;AAG1B,QAAO;;;;;;;;;;;AAYT,eAAsB,eACpB,MACA,UAA0B,EAAE,EAC5B;CACA,IAAI,SAAS,MAAM,YAAYF,YAAU,MAAM,eAAe,EAAE,QAAQ;AACxE,KAAI,CAAC,QAAQ;AACX,WAAS,MAAM,YAAYA,YAAU,MAAM,WAAW,EAAE,QAAQ;AAChE,MAAI,CAAC,OACH,UAAS,MAAM,YAAY,MAAM,QAAQ;;AAI7C,QAAO,SAASE,eAAa,OAAO,GAAG;;;;;;;;;;;;AAazC,SAAgB,mBAAmB,MAAc,UAA0B,EAAE,EAAE;CAC7E,IAAI,SAAS,gBAAgBF,YAAU,MAAM,eAAe,EAAE,QAAQ;AACtE,KAAI,CAAC,QAAQ;AACX,WAAS,gBAAgBA,YAAU,MAAM,WAAW,EAAE,QAAQ;AAC9D,MAAI,CAAC,OACH,UAAS,gBAAgB,MAAM,QAAQ;;AAI3C,QAAO,SAASE,eAAa,OAAO,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/fs",
|
|
3
|
-
"version": "0.33.
|
|
3
|
+
"version": "0.33.83",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
|
|
6
6
|
"repository": {
|
|
@@ -206,13 +206,13 @@
|
|
|
206
206
|
"dependencies": {
|
|
207
207
|
"@antfu/install-pkg": "^1.1.0",
|
|
208
208
|
"@storm-software/config-tools": "^1.190.37",
|
|
209
|
-
"@stryke/convert": "^0.7.
|
|
210
|
-
"@stryke/helpers": "^0.10.
|
|
211
|
-
"@stryke/json": "^0.15.
|
|
212
|
-
"@stryke/path": "^0.29.
|
|
213
|
-
"@stryke/string-format": "^0.17.
|
|
214
|
-
"@stryke/type-checks": "^0.6.
|
|
215
|
-
"@stryke/types": "^0.12.
|
|
209
|
+
"@stryke/convert": "^0.7.13",
|
|
210
|
+
"@stryke/helpers": "^0.10.22",
|
|
211
|
+
"@stryke/json": "^0.15.6",
|
|
212
|
+
"@stryke/path": "^0.29.9",
|
|
213
|
+
"@stryke/string-format": "^0.17.24",
|
|
214
|
+
"@stryke/type-checks": "^0.6.15",
|
|
215
|
+
"@stryke/types": "^0.12.10",
|
|
216
216
|
"chalk": "^5.6.2",
|
|
217
217
|
"defu": "^6.1.7",
|
|
218
218
|
"glob": "^11.1.0",
|
|
@@ -229,5 +229,5 @@
|
|
|
229
229
|
"tsdown": "^0.21.10"
|
|
230
230
|
},
|
|
231
231
|
"publishConfig": { "access": "public" },
|
|
232
|
-
"gitHead": "
|
|
232
|
+
"gitHead": "382b4bec8c654cae2ab6503f33515f8958d8468e"
|
|
233
233
|
}
|