@stryke/fs 0.33.2 → 0.33.3

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
@@ -29,8 +29,8 @@ function getResolutionPaths(n = []) {
29
29
  let r = n;
30
30
  r.includes((0, _cwd.cwd)()) || r.push((0, _cwd.cwd)());
31
31
  const e = (0, _getWorkspaceRoot.getWorkspaceRoot)();
32
- return r.includes(e) || r.push(e), r = (0, _getUnique.getUnique)(r.filter(Boolean).map(s => (0, _correctPath.correctPath)(s)).reduce((s, i, t, o) => (s.push(i), (0, _isType.isAbsolutePath)(i) || (s.push((0, _correctPath.toAbsolutePath)(i, (0, _cwd.cwd)())), s.push((0, _correctPath.toAbsolutePath)(i, e)), o.forEach(f => {
33
- s.push((0, _correctPath.toAbsolutePath)(i, f));
32
+ return r.includes(e) || r.push(e), r = (0, _getUnique.getUnique)(r.filter(Boolean).map(s => (0, _correctPath.correctPath)(s)).reduce((s, t, o, u) => (s.push(t), (0, _isType.isAbsolutePath)(t) || (s.push((0, _correctPath.toAbsolutePath)(t, (0, _cwd.cwd)())), s.push((0, _correctPath.toAbsolutePath)(t, e)), u.forEach(c => {
33
+ s.push((0, _correctPath.toAbsolutePath)(t, c));
34
34
  })), s), [])), r;
35
35
  }
36
36
  function getNodeModulesPaths(n = []) {
@@ -40,81 +40,51 @@ function getResolutionCombinations(n, r = {}) {
40
40
  let e = getResolutionPaths(r.paths);
41
41
  (0, _isType.isNpmScopedPackage)(n) ? e = getNodeModulesPaths(e) : e.push(...getNodeModulesPaths(e));
42
42
  const s = r.extensions ?? DEFAULT_EXTENSIONS;
43
- let i = e.map(t => (0, _joinPaths.joinPaths)(n, t));
43
+ let t = e.map(o => (0, _joinPaths.joinPaths)(n, o));
44
44
  return (0, _filePathFns.findFileName)(n, {
45
45
  withExtension: !1
46
- }) !== "index" && (i = i.reduce((t, o) => (t.push(o), t.push((0, _joinPaths.joinPaths)(o, "index")), t), [])), (0, _filePathFns.findFileExtension)(n) || (i = i.reduce((t, o) => (t.push(o), s.forEach(f => {
47
- t.push((0, _path.appendExtension)(o, f));
48
- }), t), [])), (0, _getUnique.getUnique)(i.filter(Boolean)).map(t => (0, _correctPath.correctPath)(t));
46
+ }) !== "index" && (t = t.reduce((o, u) => (o.push(u), o.push((0, _joinPaths.joinPaths)(u, "index")), o), [])), (0, _filePathFns.findFileExtension)(n) || (t = t.reduce((o, u) => (o.push(u), s.forEach(c => {
47
+ o.push((0, _path.appendExtension)(u, c));
48
+ }), o), [])), (0, _getUnique.getUnique)(t.filter(Boolean)).map(o => (0, _correctPath.correctPath)(o));
49
49
  }
50
50
  async function resolve(n, r = {}) {
51
51
  let e = getResolutionPaths(r.paths);
52
52
  (0, _isType.isNpmScopedPackage)(n) ? e = getNodeModulesPaths(e) : e.push(...getNodeModulesPaths(e));
53
- let s, i;
53
+ let s, t;
54
54
  try {
55
55
  s = await (0, _mlly.resolvePath)(n, {
56
56
  url: e,
57
57
  extensions: r.extensions ?? DEFAULT_EXTENSIONS,
58
58
  conditions: r.conditions
59
59
  });
60
- } catch (t) {
61
- i = t;
62
- }
63
- if (!s) for (let t = 0; t < e.length && !s; t++) try {
64
- s = await (0, _mlly.resolvePath)((0, _path.replacePath)(n, e[t]), {
65
- url: e,
66
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
67
- conditions: r.conditions
68
- });
69
60
  } catch (o) {
70
- i = o;
71
- }
72
- if (!s && (0, _filePathFns.findFileName)(n, {
73
- withExtension: !1
74
- }) !== "index") try {
75
- s = await resolve((0, _joinPaths.joinPaths)(n, "index"), {
76
- ...r,
77
- paths: e
78
- }), s && (s = (0, _filePathFns.findFilePath)(s));
79
- } catch (t) {
80
- i = t;
61
+ t = o;
81
62
  }
82
- if (!s) throw i ?? new Error(`Cannot resolve module '${n}'`);
63
+ if (!s) throw new Error(`Unable to resolve module "${n}". The following import paths were tried:
64
+ ${e.join(`
65
+ `)}`, {
66
+ cause: t
67
+ });
83
68
  return (0, _correctPath.correctPath)(s);
84
69
  }
85
70
  function resolveSync(n, r = {}) {
86
71
  let e = getResolutionPaths(r.paths);
87
72
  (0, _isType.isNpmScopedPackage)(n) ? e = getNodeModulesPaths(e) : e.push(...getNodeModulesPaths(e));
88
- let s, i;
73
+ let s, t;
89
74
  try {
90
75
  s = (0, _mlly.resolvePathSync)(n, {
91
76
  url: e,
92
77
  extensions: r.extensions ?? DEFAULT_EXTENSIONS,
93
78
  conditions: r.conditions
94
79
  });
95
- } catch (t) {
96
- i = t;
97
- }
98
- if (!s) for (let t = 0; t < e.length && !s; t++) try {
99
- s = (0, _mlly.resolvePathSync)((0, _path.replacePath)(n, e[t]), {
100
- url: e,
101
- extensions: r.extensions ?? DEFAULT_EXTENSIONS,
102
- conditions: r.conditions
103
- });
104
80
  } catch (o) {
105
- i = o;
106
- }
107
- if (!s && (0, _filePathFns.findFileName)(n, {
108
- withExtension: !1
109
- }) !== "index") try {
110
- s = resolveSync((0, _joinPaths.joinPaths)(n, "index"), {
111
- ...r,
112
- paths: e
113
- }), s && (s = (0, _filePathFns.findFilePath)(s));
114
- } catch (t) {
115
- i = t;
81
+ t = o;
116
82
  }
117
- if (!s) throw i ?? new Error(`Cannot resolve module '${n}'`);
83
+ if (!s) throw new Error(`Unable to resolve module "${n}". The following import paths were tried:
84
+ ${e.join(`
85
+ `)}`, {
86
+ cause: t
87
+ });
118
88
  return (0, _correctPath.correctPath)(s);
119
89
  }
120
90
  async function resolveSafe(n, r = {}) {
package/dist/resolve.mjs CHANGED
@@ -1 +1,5 @@
1
- import{getUnique as a}from"@stryke/helpers/get-unique";import{appendExtension as v,replacePath as p}from"@stryke/path";import{correctPath as c,toAbsolutePath as d}from"@stryke/path/correct-path";import{cwd as x}from"@stryke/path/cwd";import{findFileExtension as y,findFileName as m,findFilePath as l,findFolderName as w}from"@stryke/path/file-path-fns";import{isAbsolutePath as P,isNpmScopedPackage as g}from"@stryke/path/is-type";import{joinPaths as u}from"@stryke/path/join-paths";import{interopDefault as j,resolvePath as h,resolvePathSync as E}from"mlly";import{existsSync as R}from"./exists";import{getWorkspaceRoot as S}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 r=n;r.includes(x())||r.push(x());const e=S();return r.includes(e)||r.push(e),r=a(r.filter(Boolean).map(s=>c(s)).reduce((s,i,t,o)=>(s.push(i),P(i)||(s.push(d(i,x())),s.push(d(i,e)),o.forEach(f=>{s.push(d(i,f))})),s),[])),r}export function getNodeModulesPaths(n=[]){return a(n.reduce((r,e)=>(w(e)==="node_modules"&&r.push(c(e)),R(u(e,"node_modules"))&&r.push(c(u(e,"node_modules"))),r),[]))}export function getResolutionCombinations(n,r={}){let e=getResolutionPaths(r.paths);g(n)?e=getNodeModulesPaths(e):e.push(...getNodeModulesPaths(e));const s=r.extensions??DEFAULT_EXTENSIONS;let i=e.map(t=>u(n,t));return m(n,{withExtension:!1})!=="index"&&(i=i.reduce((t,o)=>(t.push(o),t.push(u(o,"index")),t),[])),y(n)||(i=i.reduce((t,o)=>(t.push(o),s.forEach(f=>{t.push(v(o,f))}),t),[])),a(i.filter(Boolean)).map(t=>c(t))}export async function resolve(n,r={}){let e=getResolutionPaths(r.paths);g(n)?e=getNodeModulesPaths(e):e.push(...getNodeModulesPaths(e));let s,i;try{s=await h(n,{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(t){i=t}if(!s)for(let t=0;t<e.length&&!s;t++)try{s=await h(p(n,e[t]),{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(o){i=o}if(!s&&m(n,{withExtension:!1})!=="index")try{s=await resolve(u(n,"index"),{...r,paths:e}),s&&(s=l(s))}catch(t){i=t}if(!s)throw i??new Error(`Cannot resolve module '${n}'`);return c(s)}export function resolveSync(n,r={}){let e=getResolutionPaths(r.paths);g(n)?e=getNodeModulesPaths(e):e.push(...getNodeModulesPaths(e));let s,i;try{s=E(n,{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(t){i=t}if(!s)for(let t=0;t<e.length&&!s;t++)try{s=E(p(n,e[t]),{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(o){i=o}if(!s&&m(n,{withExtension:!1})!=="index")try{s=resolveSync(u(n,"index"),{...r,paths:e}),s&&(s=l(s))}catch(t){i=t}if(!s)throw i??new Error(`Cannot resolve module '${n}'`);return c(s)}export async function resolveSafe(n,r={}){try{return await resolve(n,r)}catch{return}}export function resolveSafeSync(n,r={}){try{return resolveSync(n,r)}catch{return}}export async function importModule(n){const r=await import(n);return r&&j(r)}export async function resolvePackage(n,r={}){let e=await resolveSafe(u(n,"package.json"),r);return e||(e=await resolveSafe(u(n,"index.js"),r),e||(e=await resolveSafe(n,r))),e?l(e):void 0}export function resolvePackageSync(n,r={}){let e=resolveSafeSync(u(n,"package.json"),r);return e||(e=resolveSafeSync(u(n,"index.js"),r),e||(e=resolveSafeSync(n,r))),e?l(e):void 0}
1
+ import{getUnique as a}from"@stryke/helpers/get-unique";import{appendExtension as g}from"@stryke/path";import{correctPath as l,toAbsolutePath as f}from"@stryke/path/correct-path";import{cwd as d}from"@stryke/path/cwd";import{findFileExtension as h,findFileName as x,findFilePath as m,findFolderName as v}from"@stryke/path/file-path-fns";import{isAbsolutePath as w,isNpmScopedPackage as p}from"@stryke/path/is-type";import{joinPaths as i}from"@stryke/path/join-paths";import{interopDefault as P,resolvePath as j,resolvePathSync as y}from"mlly";import{existsSync as E}from"./exists";import{getWorkspaceRoot as R}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 r=n;r.includes(d())||r.push(d());const e=R();return r.includes(e)||r.push(e),r=a(r.filter(Boolean).map(s=>l(s)).reduce((s,t,o,u)=>(s.push(t),w(t)||(s.push(f(t,d())),s.push(f(t,e)),u.forEach(c=>{s.push(f(t,c))})),s),[])),r}export function getNodeModulesPaths(n=[]){return a(n.reduce((r,e)=>(v(e)==="node_modules"&&r.push(l(e)),E(i(e,"node_modules"))&&r.push(l(i(e,"node_modules"))),r),[]))}export function getResolutionCombinations(n,r={}){let e=getResolutionPaths(r.paths);p(n)?e=getNodeModulesPaths(e):e.push(...getNodeModulesPaths(e));const s=r.extensions??DEFAULT_EXTENSIONS;let t=e.map(o=>i(n,o));return x(n,{withExtension:!1})!=="index"&&(t=t.reduce((o,u)=>(o.push(u),o.push(i(u,"index")),o),[])),h(n)||(t=t.reduce((o,u)=>(o.push(u),s.forEach(c=>{o.push(g(u,c))}),o),[])),a(t.filter(Boolean)).map(o=>l(o))}export async function resolve(n,r={}){let e=getResolutionPaths(r.paths);p(n)?e=getNodeModulesPaths(e):e.push(...getNodeModulesPaths(e));let s,t;try{s=await j(n,{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(o){t=o}if(!s)throw new Error(`Unable to resolve module "${n}". The following import paths were tried:
2
+ ${e.join(`
3
+ `)}`,{cause:t});return l(s)}export function resolveSync(n,r={}){let e=getResolutionPaths(r.paths);p(n)?e=getNodeModulesPaths(e):e.push(...getNodeModulesPaths(e));let s,t;try{s=y(n,{url:e,extensions:r.extensions??DEFAULT_EXTENSIONS,conditions:r.conditions})}catch(o){t=o}if(!s)throw new Error(`Unable to resolve module "${n}". The following import paths were tried:
4
+ ${e.join(`
5
+ `)}`,{cause:t});return l(s)}export async function resolveSafe(n,r={}){try{return await resolve(n,r)}catch{return}}export function resolveSafeSync(n,r={}){try{return resolveSync(n,r)}catch{return}}export async function importModule(n){const r=await import(n);return r&&P(r)}export async function resolvePackage(n,r={}){let e=await resolveSafe(i(n,"package.json"),r);return e||(e=await resolveSafe(i(n,"index.js"),r),e||(e=await resolveSafe(n,r))),e?m(e):void 0}export function resolvePackageSync(n,r={}){let e=resolveSafeSync(i(n,"package.json"),r);return e||(e=resolveSafeSync(i(n,"index.js"),r),e||(e=resolveSafeSync(n,r))),e?m(e):void 0}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke/fs",
3
- "version": "0.33.2",
3
+ "version": "0.33.3",
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,10 +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.6",
19
- "@stryke/helpers": "^0.9.8",
20
- "@stryke/path": "^0.21.0",
21
- "@stryke/string-format": "^0.12.6",
18
+ "@stryke/convert": "^0.6.7",
19
+ "@stryke/helpers": "^0.9.9",
20
+ "@stryke/path": "^0.21.1",
21
+ "@stryke/string-format": "^0.12.7",
22
22
  "chalk": "^5.6.2",
23
23
  "defu": "^6.1.4",
24
24
  "glob": "^11.1.0",
@@ -26,9 +26,9 @@
26
26
  "nanotar": "^0.2.0",
27
27
  "semver": "7.7.1",
28
28
  "yaml": "^2.8.1",
29
- "@stryke/json": "^0.9.9",
30
- "@stryke/type-checks": "^0.3.16",
31
- "@stryke/types": "^0.10.6"
29
+ "@stryke/json": "^0.9.10",
30
+ "@stryke/type-checks": "^0.3.17",
31
+ "@stryke/types": "^0.10.7"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@types/node": "^24.10.1",
@@ -410,5 +410,5 @@
410
410
  "main": "./dist/index.cjs",
411
411
  "module": "./dist/index.mjs",
412
412
  "types": "./dist/index.d.ts",
413
- "gitHead": "fc3f6e2179191455ef4c9a8e7be4294a77228b07"
413
+ "gitHead": "3e25bbb29dbc40028763147139a99c437e48426b"
414
414
  }