@stryke/fs 0.32.14 → 0.32.15

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
@@ -11,111 +11,117 @@ exports.resolvePackageSync = resolvePackageSync;
11
11
  exports.resolveSafe = resolveSafe;
12
12
  exports.resolveSafeSync = resolveSafeSync;
13
13
  exports.resolveSync = resolveSync;
14
+ var _getUnique = require("@stryke/helpers/get-unique");
14
15
  var _path = require("@stryke/path");
15
16
  var _correctPath = require("@stryke/path/correct-path");
16
17
  var _cwd = require("@stryke/path/cwd");
17
18
  var _filePathFns = require("@stryke/path/file-path-fns");
18
19
  var _joinPaths = require("@stryke/path/join-paths");
19
20
  var _mlly = require("mlly");
21
+ var _nodeFs = require("node:fs");
20
22
  var _getWorkspaceRoot = require("./get-workspace-root.cjs");
21
23
  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;
24
+ async function resolve(n, e = {}) {
25
+ let r = e.paths ?? [];
26
+ r.length === 0 && r.push((0, _cwd.cwd)());
27
+ const o = (0, _getWorkspaceRoot.getWorkspaceRoot)();
28
+ r.includes(o) || r.push(o), r = (0, _getUnique.getUnique)(r.filter(Boolean).map(t => (0, _correctPath.correctPath)(t)).reduce((t, i, E, x) => (t.push(i), (0, _nodeFs.existsSync)((0, _path.appendPath)(i, o)) && t.push((0, _path.appendPath)(i, o)), x.forEach(l => {
29
+ (0, _nodeFs.existsSync)((0, _path.appendPath)(i, l)) && t.push((0, _path.appendPath)(i, l));
30
+ }), t), []));
31
+ let s, c;
28
32
  try {
29
- n = await (0, _mlly.resolvePath)(t, {
30
- url: e,
31
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
32
- conditions: r.conditions
33
+ s = await (0, _mlly.resolvePath)(n, {
34
+ url: r,
35
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
36
+ conditions: e.conditions
33
37
  });
34
- } catch (o) {
35
- i = o;
38
+ } catch (t) {
39
+ c = t;
36
40
  }
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
41
+ if (!s) for (let t = 0; t < r.length && !s; t++) try {
42
+ s = await (0, _mlly.resolvePath)((0, _path.replacePath)(n, r[t]), {
43
+ url: r,
44
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
45
+ conditions: e.conditions
42
46
  });
43
- } catch (f) {
44
- i = f;
47
+ } catch (i) {
48
+ c = i;
45
49
  }
46
- if (!n && (0, _filePathFns.findFileName)(t, {
50
+ if (!s && (0, _filePathFns.findFileName)(n, {
47
51
  withExtension: !1
48
52
  }) !== "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;
53
+ s = await resolve((0, _joinPaths.joinPaths)(n, "index"), {
54
+ ...e,
55
+ paths: r
56
+ }), s && (s = (0, _filePathFns.findFilePath)(s));
57
+ } catch (t) {
58
+ c = t;
55
59
  }
56
- if (!n) throw i ?? new Error(`Cannot resolve module '${t}'`);
57
- return (0, _correctPath.correctPath)(n);
60
+ if (!s) throw c ?? new Error(`Cannot resolve module '${n}'`);
61
+ return (0, _correctPath.correctPath)(s);
58
62
  }
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;
63
+ function resolveSync(n, e = {}) {
64
+ let r = e.paths ?? [];
65
+ r.length === 0 && r.push(process.cwd());
66
+ const o = (0, _getWorkspaceRoot.getWorkspaceRoot)();
67
+ r.includes(o) || r.push(o), r = (0, _getUnique.getUnique)(r.filter(Boolean).map(t => (0, _correctPath.correctPath)(t)).reduce((t, i, E, x) => (t.push(i), (0, _nodeFs.existsSync)((0, _path.appendPath)(i, o)) && t.push((0, _path.appendPath)(i, o)), x.forEach(l => {
68
+ (0, _nodeFs.existsSync)((0, _path.appendPath)(i, l)) && t.push((0, _path.appendPath)(i, l));
69
+ }), t), []));
70
+ let s, c;
65
71
  try {
66
- n = (0, _mlly.resolvePathSync)(t, {
67
- url: e,
68
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
69
- conditions: r.conditions
72
+ s = (0, _mlly.resolvePathSync)(n, {
73
+ url: r,
74
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
75
+ conditions: e.conditions
70
76
  });
71
- } catch (o) {
72
- i = o;
77
+ } catch (t) {
78
+ c = t;
73
79
  }
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
80
+ if (!s) for (let t = 0; t < r.length && !s; t++) try {
81
+ s = (0, _mlly.resolvePathSync)((0, _path.replacePath)(n, r[t]), {
82
+ url: r,
83
+ extensions: e.extensions ?? DEFAULT_EXTENSIONS,
84
+ conditions: e.conditions
79
85
  });
80
- } catch (f) {
81
- i = f;
86
+ } catch (i) {
87
+ c = i;
82
88
  }
83
- if (!n && (0, _filePathFns.findFileName)(t, {
89
+ if (!s && (0, _filePathFns.findFileName)(n, {
84
90
  withExtension: !1
85
91
  }) !== "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;
92
+ s = resolveSync((0, _joinPaths.joinPaths)(n, "index"), {
93
+ ...e,
94
+ paths: r
95
+ }), s && (s = (0, _filePathFns.findFilePath)(s));
96
+ } catch (t) {
97
+ c = t;
92
98
  }
93
- if (!n) throw i ?? new Error(`Cannot resolve module '${t}'`);
94
- return (0, _correctPath.correctPath)(n);
99
+ if (!s) throw c ?? new Error(`Cannot resolve module '${n}'`);
100
+ return (0, _correctPath.correctPath)(s);
95
101
  }
96
- async function resolveSafe(t, r = {}) {
102
+ async function resolveSafe(n, e = {}) {
97
103
  try {
98
- return await resolve(t, r);
104
+ return await resolve(n, e);
99
105
  } catch {
100
106
  return;
101
107
  }
102
108
  }
103
- function resolveSafeSync(t, r = {}) {
109
+ function resolveSafeSync(n, e = {}) {
104
110
  try {
105
- return resolveSync(t, r);
111
+ return resolveSync(n, e);
106
112
  } catch {
107
113
  return;
108
114
  }
109
115
  }
110
- async function importModule(t) {
111
- const r = await Promise.resolve(`${t}`).then(s => require(s));
112
- return r && (0, _mlly.interopDefault)(r);
116
+ async function importModule(n) {
117
+ const e = await Promise.resolve(`${n}`).then(s => require(s));
118
+ return e && (0, _mlly.interopDefault)(e);
113
119
  }
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;
120
+ async function resolvePackage(n, e = {}) {
121
+ let r = await resolveSafe((0, _joinPaths.joinPaths)(n, "package.json"), e);
122
+ return r || (r = await resolveSafe((0, _joinPaths.joinPaths)(n, "index.js"), e), r || (r = await resolveSafe(n, e))), r ? (0, _filePathFns.findFilePath)(r) : void 0;
117
123
  }
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;
124
+ function resolvePackageSync(n, e = {}) {
125
+ let r = resolveSafeSync((0, _joinPaths.joinPaths)(n, "package.json"), e);
126
+ return r || (r = resolveSafeSync((0, _joinPaths.joinPaths)(n, "index.js"), e), r || (r = resolveSafeSync(n, e))), r ? (0, _filePathFns.findFilePath)(r) : void 0;
121
127
  }
package/dist/resolve.d.ts CHANGED
@@ -25,7 +25,7 @@ export interface ResolveOptions {
25
25
  * @param options - The options to use when resolving the module
26
26
  * @returns A promise for the path to the module
27
27
  */
28
- export declare function resolve(path: string, options?: ResolveOptions): Promise<any>;
28
+ export declare function resolve(path: string, options?: ResolveOptions): Promise<string>;
29
29
  /**
30
30
  * Resolve the path to a specified module
31
31
  *
@@ -41,7 +41,7 @@ export declare function resolveSync(path: string, options?: ResolveOptions): any
41
41
  * @param options - The options to use when resolving the module
42
42
  * @returns A promise for the path to the module
43
43
  */
44
- export declare function resolveSafe(name: string, options?: ResolveOptions): Promise<any>;
44
+ export declare function resolveSafe(name: string, options?: ResolveOptions): Promise<string | undefined>;
45
45
  /**
46
46
  * Resolve the path to a specified module with error handling
47
47
  *
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 m}from"@stryke/helpers/get-unique";import{appendPath as a,replacePath as p}from"@stryke/path";import{correctPath as u}from"@stryke/path/correct-path";import{cwd as j}from"@stryke/path/cwd";import{findFileName as g,findFilePath as d}from"@stryke/path/file-path-fns";import{joinPaths as f}from"@stryke/path/join-paths";import{interopDefault as P,resolvePath as w,resolvePathSync as y}from"mlly";import{existsSync as h}from"node:fs";import{getWorkspaceRoot as v}from"./get-workspace-root";export const DEFAULT_EXTENSIONS=["js","jsx","mjs","cjs","ts","tsx","mts","cts","json","jsonc","json5","node"];export async function resolve(n,e={}){let r=e.paths??[];r.length===0&&r.push(j());const o=v();r.includes(o)||r.push(o),r=m(r.filter(Boolean).map(t=>u(t)).reduce((t,i,E,x)=>(t.push(i),h(a(i,o))&&t.push(a(i,o)),x.forEach(l=>{h(a(i,l))&&t.push(a(i,l))}),t),[]));let s,c;try{s=await w(n,{url:r,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(t){c=t}if(!s)for(let t=0;t<r.length&&!s;t++)try{s=await w(p(n,r[t]),{url:r,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(i){c=i}if(!s&&g(n,{withExtension:!1})!=="index")try{s=await resolve(f(n,"index"),{...e,paths:r}),s&&(s=d(s))}catch(t){c=t}if(!s)throw c??new Error(`Cannot resolve module '${n}'`);return u(s)}export function resolveSync(n,e={}){let r=e.paths??[];r.length===0&&r.push(process.cwd());const o=v();r.includes(o)||r.push(o),r=m(r.filter(Boolean).map(t=>u(t)).reduce((t,i,E,x)=>(t.push(i),h(a(i,o))&&t.push(a(i,o)),x.forEach(l=>{h(a(i,l))&&t.push(a(i,l))}),t),[]));let s,c;try{s=y(n,{url:r,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(t){c=t}if(!s)for(let t=0;t<r.length&&!s;t++)try{s=y(p(n,r[t]),{url:r,extensions:e.extensions??DEFAULT_EXTENSIONS,conditions:e.conditions})}catch(i){c=i}if(!s&&g(n,{withExtension:!1})!=="index")try{s=resolveSync(f(n,"index"),{...e,paths:r}),s&&(s=d(s))}catch(t){c=t}if(!s)throw c??new Error(`Cannot resolve module '${n}'`);return u(s)}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&&P(e)}export async function resolvePackage(n,e={}){let r=await resolveSafe(f(n,"package.json"),e);return r||(r=await resolveSafe(f(n,"index.js"),e),r||(r=await resolveSafe(n,e))),r?d(r):void 0}export function resolvePackageSync(n,e={}){let r=resolveSafeSync(f(n,"package.json"),e);return r||(r=resolveSafeSync(f(n,"index.js"),e),r||(r=resolveSafeSync(n,e))),r?d(r):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.32.15",
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.4",
19
+ "@stryke/helpers": "^0.9.6",
20
+ "@stryke/path": "^0.19.4",
21
+ "@stryke/string-format": "^0.12.4",
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.7",
30
+ "@stryke/type-checks": "^0.3.14",
31
+ "@stryke/types": "^0.10.4"
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": "201972005e4b1291d431d46e3fb49764f44690c5"
413
414
  }