@stryke/fs 0.32.14 → 0.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/resolve.cjs CHANGED
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.DEFAULT_EXTENSIONS = void 0;
7
+ exports.getResolutionCombinations = getResolutionCombinations;
8
+ exports.getResolutionPaths = getResolutionPaths;
7
9
  exports.importModule = importModule;
8
10
  exports.resolve = resolve;
9
11
  exports.resolvePackage = resolvePackage;
@@ -11,111 +13,125 @@ exports.resolvePackageSync = resolvePackageSync;
11
13
  exports.resolveSafe = resolveSafe;
12
14
  exports.resolveSafeSync = resolveSafeSync;
13
15
  exports.resolveSync = resolveSync;
16
+ var _getUnique = require("@stryke/helpers/get-unique");
14
17
  var _path = require("@stryke/path");
15
18
  var _correctPath = require("@stryke/path/correct-path");
16
19
  var _cwd = require("@stryke/path/cwd");
17
20
  var _filePathFns = require("@stryke/path/file-path-fns");
21
+ var _isType = require("@stryke/path/is-type");
18
22
  var _joinPaths = require("@stryke/path/join-paths");
19
23
  var _mlly = require("mlly");
20
24
  var _getWorkspaceRoot = require("./get-workspace-root.cjs");
21
25
  const DEFAULT_EXTENSIONS = exports.DEFAULT_EXTENSIONS = ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "json", "jsonc", "json5", "node"];
22
- async function resolve(t, r = {}) {
23
- let e = r.paths ?? [];
24
- e.length === 0 && e.push((0, _cwd.cwd)());
25
- const c = (0, _getWorkspaceRoot.getWorkspaceRoot)();
26
- e.includes(c) || e.push(c), e = e.filter(Boolean).map(o => (0, _correctPath.correctPath)(o));
27
- let n, i;
26
+ function getResolutionPaths(n = []) {
27
+ let e = n;
28
+ e.includes((0, _cwd.cwd)()) || e.push((0, _cwd.cwd)());
29
+ const t = (0, _getWorkspaceRoot.getWorkspaceRoot)();
30
+ return e.includes(t) || e.push(t), e = (0, _getUnique.getUnique)(e.filter(Boolean).map(r => (0, _correctPath.correctPath)(r)).reduce((r, i, s, o) => (r.push(i), (0, _isType.isAbsolutePath)(i) || (r.push((0, _correctPath.toAbsolutePath)(i, (0, _cwd.cwd)())), r.push((0, _correctPath.toAbsolutePath)(i, t)), o.forEach(l => {
31
+ r.push((0, _correctPath.toAbsolutePath)(i, l));
32
+ })), r), [])), e;
33
+ }
34
+ function getResolutionCombinations(n, e = {}) {
35
+ const t = getResolutionPaths(e.paths),
36
+ r = e.extensions ?? DEFAULT_EXTENSIONS;
37
+ let i = t.map(s => (0, _joinPaths.joinPaths)(n, s));
38
+ return (0, _filePathFns.findFileName)(n, {
39
+ withExtension: !1
40
+ }) !== "index" && (i = i.reduce((s, o) => (s.push(o), s.push((0, _joinPaths.joinPaths)(o, "index")), s), [])), (0, _filePathFns.findFileExtension)(n) || (i = i.reduce((s, o) => (s.push(o), r.forEach(l => {
41
+ s.push((0, _path.appendExtension)(o, l));
42
+ }), s), [])), (0, _getUnique.getUnique)(i.filter(Boolean)).map(s => (0, _correctPath.correctPath)(s));
43
+ }
44
+ async function resolve(n, e = {}) {
45
+ const t = getResolutionPaths(e.paths);
46
+ let r, i;
28
47
  try {
29
- n = await (0, _mlly.resolvePath)(t, {
30
- url: e,
31
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
32
- conditions: r.conditions
48
+ r = await (0, _mlly.resolvePath)(n, {
49
+ url: t,
50
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
51
+ conditions: e.conditions
33
52
  });
34
- } catch (o) {
35
- i = o;
53
+ } catch (s) {
54
+ i = s;
36
55
  }
37
- if (!n) for (let o = 0; o < e.length && !n; o++) try {
38
- n = await (0, _mlly.resolvePath)((0, _path.replacePath)(t, e[o]), {
39
- url: e,
40
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
41
- conditions: r.conditions
56
+ if (!r) for (let s = 0; s < t.length && !r; s++) try {
57
+ r = await (0, _mlly.resolvePath)((0, _path.replacePath)(n, t[s]), {
58
+ url: t,
59
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
60
+ conditions: e.conditions
42
61
  });
43
- } catch (f) {
44
- i = f;
62
+ } catch (o) {
63
+ i = o;
45
64
  }
46
- if (!n && (0, _filePathFns.findFileName)(t, {
65
+ if (!r && (0, _filePathFns.findFileName)(n, {
47
66
  withExtension: !1
48
67
  }) !== "index") try {
49
- n = await resolve((0, _joinPaths.joinPaths)(t, "index"), {
50
- ...r,
51
- paths: e
52
- }), n && (n = (0, _filePathFns.findFilePath)(n));
53
- } catch (o) {
54
- i = o;
68
+ r = await resolve((0, _joinPaths.joinPaths)(n, "index"), {
69
+ ...e,
70
+ paths: t
71
+ }), r && (r = (0, _filePathFns.findFilePath)(r));
72
+ } catch (s) {
73
+ i = s;
55
74
  }
56
- if (!n) throw i ?? new Error(`Cannot resolve module '${t}'`);
57
- return (0, _correctPath.correctPath)(n);
75
+ if (!r) throw i ?? new Error(`Cannot resolve module '${n}'`);
76
+ return (0, _correctPath.correctPath)(r);
58
77
  }
59
- function resolveSync(t, r = {}) {
60
- let e = r.paths ?? [];
61
- e.length === 0 && e.push(process.cwd());
62
- const c = (0, _getWorkspaceRoot.getWorkspaceRoot)();
63
- e.includes(c) || e.push(c), e = e.filter(Boolean).map(o => (0, _correctPath.correctPath)(o));
64
- let n, i;
78
+ function resolveSync(n, e = {}) {
79
+ const t = getResolutionPaths(e.paths);
80
+ let r, i;
65
81
  try {
66
- n = (0, _mlly.resolvePathSync)(t, {
67
- url: e,
68
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
69
- conditions: r.conditions
82
+ r = (0, _mlly.resolvePathSync)(n, {
83
+ url: t,
84
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
85
+ conditions: e.conditions
70
86
  });
71
- } catch (o) {
72
- i = o;
87
+ } catch (s) {
88
+ i = s;
73
89
  }
74
- if (!n) for (let o = 0; o < e.length && !n; o++) try {
75
- n = (0, _mlly.resolvePathSync)((0, _path.replacePath)(t, e[o]), {
76
- url: e,
77
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
78
- conditions: r.conditions
90
+ if (!r) for (let s = 0; s < t.length && !r; s++) try {
91
+ r = (0, _mlly.resolvePathSync)((0, _path.replacePath)(n, t[s]), {
92
+ url: t,
93
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
94
+ conditions: e.conditions
79
95
  });
80
- } catch (f) {
81
- i = f;
96
+ } catch (o) {
97
+ i = o;
82
98
  }
83
- if (!n && (0, _filePathFns.findFileName)(t, {
99
+ if (!r && (0, _filePathFns.findFileName)(n, {
84
100
  withExtension: !1
85
101
  }) !== "index") try {
86
- n = resolveSync((0, _joinPaths.joinPaths)(t, "index"), {
87
- ...r,
88
- paths: e
89
- }), n && (n = (0, _filePathFns.findFilePath)(n));
90
- } catch (o) {
91
- i = o;
102
+ r = resolveSync((0, _joinPaths.joinPaths)(n, "index"), {
103
+ ...e,
104
+ paths: t
105
+ }), r && (r = (0, _filePathFns.findFilePath)(r));
106
+ } catch (s) {
107
+ i = s;
92
108
  }
93
- if (!n) throw i ?? new Error(`Cannot resolve module '${t}'`);
94
- return (0, _correctPath.correctPath)(n);
109
+ if (!r) throw i ?? new Error(`Cannot resolve module '${n}'`);
110
+ return (0, _correctPath.correctPath)(r);
95
111
  }
96
- async function resolveSafe(t, r = {}) {
112
+ async function resolveSafe(n, e = {}) {
97
113
  try {
98
- return await resolve(t, r);
114
+ return await resolve(n, e);
99
115
  } catch {
100
116
  return;
101
117
  }
102
118
  }
103
- function resolveSafeSync(t, r = {}) {
119
+ function resolveSafeSync(n, e = {}) {
104
120
  try {
105
- return resolveSync(t, r);
121
+ return resolveSync(n, e);
106
122
  } catch {
107
123
  return;
108
124
  }
109
125
  }
110
- async function importModule(t) {
111
- const r = await Promise.resolve(`${t}`).then(s => require(s));
112
- return r && (0, _mlly.interopDefault)(r);
126
+ async function importModule(n) {
127
+ const e = await Promise.resolve(`${n}`).then(s => require(s));
128
+ return e && (0, _mlly.interopDefault)(e);
113
129
  }
114
- async function resolvePackage(t, r = {}) {
115
- let e = await resolveSafe((0, _joinPaths.joinPaths)(t, "package.json"), r);
116
- return e || (e = await resolveSafe((0, _joinPaths.joinPaths)(t, "index.js"), r), e || (e = await resolveSafe(t, r))), e ? (0, _filePathFns.findFilePath)(e) : void 0;
130
+ async function resolvePackage(n, e = {}) {
131
+ let t = await resolveSafe((0, _joinPaths.joinPaths)(n, "package.json"), e);
132
+ return t || (t = await resolveSafe((0, _joinPaths.joinPaths)(n, "index.js"), e), t || (t = await resolveSafe(n, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
117
133
  }
118
- function resolvePackageSync(t, r = {}) {
119
- let e = resolveSafeSync((0, _joinPaths.joinPaths)(t, "package.json"), r);
120
- return e || (e = resolveSafeSync((0, _joinPaths.joinPaths)(t, "index.js"), r), e || (e = resolveSafeSync(t, r))), e ? (0, _filePathFns.findFilePath)(e) : void 0;
134
+ function resolvePackageSync(n, e = {}) {
135
+ let t = resolveSafeSync((0, _joinPaths.joinPaths)(n, "package.json"), e);
136
+ return t || (t = resolveSafeSync((0, _joinPaths.joinPaths)(n, "index.js"), e), t || (t = resolveSafeSync(n, e))), t ? (0, _filePathFns.findFilePath)(t) : void 0;
121
137
  }
package/dist/resolve.d.ts CHANGED
@@ -18,6 +18,21 @@ export interface ResolveOptions {
18
18
  */
19
19
  conditions?: string[];
20
20
  }
21
+ /**
22
+ * Get the resolution paths based on the provided paths, current working directory, and workspace root.
23
+ *
24
+ * @param paths - An array of paths to include in the resolution.
25
+ * @returns An array of unique, corrected resolution paths.
26
+ */
27
+ export declare function getResolutionPaths(paths?: string[]): string[];
28
+ /**
29
+ * Get all combinations of resolution paths for a given path and options.
30
+ *
31
+ * @param path - The base path to combine with resolution paths.
32
+ * @param options - The options containing resolution paths.
33
+ * @returns An array of unique, corrected resolution paths.
34
+ */
35
+ export declare function getResolutionCombinations(path: string, options?: ResolveOptions): any;
21
36
  /**
22
37
  * Resolve the path to a specified module
23
38
  *
@@ -25,7 +40,7 @@ export interface ResolveOptions {
25
40
  * @param options - The options to use when resolving the module
26
41
  * @returns A promise for the path to the module
27
42
  */
28
- export declare function resolve(path: string, options?: ResolveOptions): Promise<any>;
43
+ export declare function resolve(path: string, options?: ResolveOptions): Promise<string>;
29
44
  /**
30
45
  * Resolve the path to a specified module
31
46
  *
@@ -41,7 +56,7 @@ export declare function resolveSync(path: string, options?: ResolveOptions): any
41
56
  * @param options - The options to use when resolving the module
42
57
  * @returns A promise for the path to the module
43
58
  */
44
- export declare function resolveSafe(name: string, options?: ResolveOptions): Promise<any>;
59
+ export declare function resolveSafe(name: string, options?: ResolveOptions): Promise<string | undefined>;
45
60
  /**
46
61
  * Resolve the path to a specified module with error handling
47
62
  *
package/dist/resolve.mjs CHANGED
@@ -1 +1 @@
1
- import{replacePath as u}from"@stryke/path";import{correctPath as a}from"@stryke/path/correct-path";import{cwd as g}from"@stryke/path/cwd";import{findFileName as d,findFilePath as l}from"@stryke/path/file-path-fns";import{joinPaths as s}from"@stryke/path/join-paths";import{interopDefault as m,resolvePath as x,resolvePathSync as h}from"mlly";import{getWorkspaceRoot as p}from"./get-workspace-root";export const DEFAULT_EXTENSIONS=["js","jsx","mjs","cjs","ts","tsx","mts","cts","json","jsonc","json5","node"];export async function resolve(t,r={}){let e=r.paths??[];e.length===0&&e.push(g());const c=p();e.includes(c)||e.push(c),e=e.filter(Boolean).map(o=>a(o));let n,i;try{n=await x(t,{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(o){i=o}if(!n)for(let o=0;o<e.length&&!n;o++)try{n=await x(u(t,e[o]),{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(f){i=f}if(!n&&d(t,{withExtension:!1})!=="index")try{n=await resolve(s(t,"index"),{...r,paths:e}),n&&(n=l(n))}catch(o){i=o}if(!n)throw i??new Error(`Cannot resolve module '${t}'`);return a(n)}export function resolveSync(t,r={}){let e=r.paths??[];e.length===0&&e.push(process.cwd());const c=p();e.includes(c)||e.push(c),e=e.filter(Boolean).map(o=>a(o));let n,i;try{n=h(t,{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(o){i=o}if(!n)for(let o=0;o<e.length&&!n;o++)try{n=h(u(t,e[o]),{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(f){i=f}if(!n&&d(t,{withExtension:!1})!=="index")try{n=resolveSync(s(t,"index"),{...r,paths:e}),n&&(n=l(n))}catch(o){i=o}if(!n)throw i??new Error(`Cannot resolve module '${t}'`);return a(n)}export async function resolveSafe(t,r={}){try{return await resolve(t,r)}catch{return}}export function resolveSafeSync(t,r={}){try{return resolveSync(t,r)}catch{return}}export async function importModule(t){const r=await import(t);return r&&m(r)}export async function resolvePackage(t,r={}){let e=await resolveSafe(s(t,"package.json"),r);return e||(e=await resolveSafe(s(t,"index.js"),r),e||(e=await resolveSafe(t,r))),e?l(e):void 0}export function resolvePackageSync(t,r={}){let e=resolveSafeSync(s(t,"package.json"),r);return e||(e=resolveSafeSync(s(t,"index.js"),r),e||(e=resolveSafeSync(t,r))),e?l(e):void 0}
1
+ import{getUnique as h}from"@stryke/helpers/get-unique";import{appendExtension as E,replacePath as p}from"@stryke/path";import{correctPath as a,toAbsolutePath as f}from"@stryke/path/correct-path";import{cwd as d}from"@stryke/path/cwd";import{findFileExtension as v,findFileName as x,findFilePath as u}from"@stryke/path/file-path-fns";import{isAbsolutePath as w}from"@stryke/path/is-type";import{joinPaths as c}from"@stryke/path/join-paths";import{interopDefault as y,resolvePath as g,resolvePathSync as m}from"mlly";import{getWorkspaceRoot as P}from"./get-workspace-root";export const DEFAULT_EXTENSIONS=["js","jsx","mjs","cjs","ts","tsx","mts","cts","json","jsonc","json5","node"];export function getResolutionPaths(n=[]){let e=n;e.includes(d())||e.push(d());const t=P();return e.includes(t)||e.push(t),e=h(e.filter(Boolean).map(r=>a(r)).reduce((r,i,s,o)=>(r.push(i),w(i)||(r.push(f(i,d())),r.push(f(i,t)),o.forEach(l=>{r.push(f(i,l))})),r),[])),e}export function getResolutionCombinations(n,e={}){const t=getResolutionPaths(e.paths),r=e.extensions??DEFAULT_EXTENSIONS;let i=t.map(s=>c(n,s));return x(n,{withExtension:!1})!=="index"&&(i=i.reduce((s,o)=>(s.push(o),s.push(c(o,"index")),s),[])),v(n)||(i=i.reduce((s,o)=>(s.push(o),r.forEach(l=>{s.push(E(o,l))}),s),[])),h(i.filter(Boolean)).map(s=>a(s))}export async function resolve(n,e={}){const t=getResolutionPaths(e.paths);let r,i;try{r=await g(n,{url:t,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(s){i=s}if(!r)for(let s=0;s<t.length&&!r;s++)try{r=await g(p(n,t[s]),{url:t,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(o){i=o}if(!r&&x(n,{withExtension:!1})!=="index")try{r=await resolve(c(n,"index"),{...e,paths:t}),r&&(r=u(r))}catch(s){i=s}if(!r)throw i??new Error(`Cannot resolve module '${n}'`);return a(r)}export function resolveSync(n,e={}){const t=getResolutionPaths(e.paths);let r,i;try{r=m(n,{url:t,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(s){i=s}if(!r)for(let s=0;s<t.length&&!r;s++)try{r=m(p(n,t[s]),{url:t,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(o){i=o}if(!r&&x(n,{withExtension:!1})!=="index")try{r=resolveSync(c(n,"index"),{...e,paths:t}),r&&(r=u(r))}catch(s){i=s}if(!r)throw i??new Error(`Cannot resolve module '${n}'`);return a(r)}export async function resolveSafe(n,e={}){try{return await resolve(n,e)}catch{return}}export function resolveSafeSync(n,e={}){try{return resolveSync(n,e)}catch{return}}export async function importModule(n){const e=await import(n);return e&&y(e)}export async function resolvePackage(n,e={}){let t=await resolveSafe(c(n,"package.json"),e);return t||(t=await resolveSafe(c(n,"index.js"),e),t||(t=await resolveSafe(n,e))),t?u(t):void 0}export function resolvePackageSync(n,e={}){let t=resolveSafeSync(c(n,"package.json"),e);return t||(t=resolveSafeSync(c(n,"index.js"),e),t||(t=resolveSafeSync(n,e))),t?u(t):void 0}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.32.14",
3
+ "version": "0.33.0",
4
4
  "type": "module",
5
5
  "description": "A package containing various file system utilities that expand the functionality of NodeJs's built-in `fs` module.",
6
6
  "repository": {
@@ -15,9 +15,10 @@
15
15
  "@antfu/install-pkg": "^1.1.0",
16
16
  "@ltd/j-toml": "^1.38.0",
17
17
  "@storm-software/config-tools": "^1.188.48",
18
- "@stryke/convert": "^0.6.3",
19
- "@stryke/path": "^0.19.3",
20
- "@stryke/string-format": "^0.12.3",
18
+ "@stryke/convert": "^0.6.5",
19
+ "@stryke/helpers": "^0.9.7",
20
+ "@stryke/path": "^0.20.0",
21
+ "@stryke/string-format": "^0.12.5",
21
22
  "chalk": "^5.6.2",
22
23
  "defu": "^6.1.4",
23
24
  "glob": "^11.1.0",
@@ -25,9 +26,9 @@
25
26
  "nanotar": "^0.2.0",
26
27
  "semver": "7.7.1",
27
28
  "yaml": "^2.8.1",
28
- "@stryke/json": "^0.9.6",
29
- "@stryke/type-checks": "^0.3.13",
30
- "@stryke/types": "^0.10.3"
29
+ "@stryke/json": "^0.9.8",
30
+ "@stryke/type-checks": "^0.3.15",
31
+ "@stryke/types": "^0.10.5"
31
32
  },
32
33
  "devDependencies": {
33
34
  "@types/node": "^24.10.1",
@@ -409,5 +410,5 @@
409
410
  "main": "./dist/index.cjs",
410
411
  "module": "./dist/index.mjs",
411
412
  "types": "./dist/index.d.ts",
412
- "gitHead": "f96193e785d85704cdc3d2a8c9894766631d7388"
413
+ "gitHead": "2c99ef0e654a63299ca75104ec2e8a46d65997cc"
413
414
  }