@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 +75 -69
- package/dist/resolve.d.ts +2 -2
- package/dist/resolve.mjs +1 -1
- package/package.json +9 -8
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(
|
|
23
|
-
let
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
30
|
-
url:
|
|
31
|
-
extensions:
|
|
32
|
-
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 (
|
|
35
|
-
|
|
38
|
+
} catch (t) {
|
|
39
|
+
c = t;
|
|
36
40
|
}
|
|
37
|
-
if (!
|
|
38
|
-
|
|
39
|
-
url:
|
|
40
|
-
extensions:
|
|
41
|
-
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 (
|
|
44
|
-
|
|
47
|
+
} catch (i) {
|
|
48
|
+
c = i;
|
|
45
49
|
}
|
|
46
|
-
if (!
|
|
50
|
+
if (!s && (0, _filePathFns.findFileName)(n, {
|
|
47
51
|
withExtension: !1
|
|
48
52
|
}) !== "index") try {
|
|
49
|
-
|
|
50
|
-
...
|
|
51
|
-
paths:
|
|
52
|
-
}),
|
|
53
|
-
} catch (
|
|
54
|
-
|
|
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 (!
|
|
57
|
-
return (0, _correctPath.correctPath)(
|
|
60
|
+
if (!s) throw c ?? new Error(`Cannot resolve module '${n}'`);
|
|
61
|
+
return (0, _correctPath.correctPath)(s);
|
|
58
62
|
}
|
|
59
|
-
function resolveSync(
|
|
60
|
-
let
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
67
|
-
url:
|
|
68
|
-
extensions:
|
|
69
|
-
conditions:
|
|
72
|
+
s = (0, _mlly.resolvePathSync)(n, {
|
|
73
|
+
url: r,
|
|
74
|
+
extensions: e.extensions ?? DEFAULT_EXTENSIONS,
|
|
75
|
+
conditions: e.conditions
|
|
70
76
|
});
|
|
71
|
-
} catch (
|
|
72
|
-
|
|
77
|
+
} catch (t) {
|
|
78
|
+
c = t;
|
|
73
79
|
}
|
|
74
|
-
if (!
|
|
75
|
-
|
|
76
|
-
url:
|
|
77
|
-
extensions:
|
|
78
|
-
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 (
|
|
81
|
-
|
|
86
|
+
} catch (i) {
|
|
87
|
+
c = i;
|
|
82
88
|
}
|
|
83
|
-
if (!
|
|
89
|
+
if (!s && (0, _filePathFns.findFileName)(n, {
|
|
84
90
|
withExtension: !1
|
|
85
91
|
}) !== "index") try {
|
|
86
|
-
|
|
87
|
-
...
|
|
88
|
-
paths:
|
|
89
|
-
}),
|
|
90
|
-
} catch (
|
|
91
|
-
|
|
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 (!
|
|
94
|
-
return (0, _correctPath.correctPath)(
|
|
99
|
+
if (!s) throw c ?? new Error(`Cannot resolve module '${n}'`);
|
|
100
|
+
return (0, _correctPath.correctPath)(s);
|
|
95
101
|
}
|
|
96
|
-
async function resolveSafe(
|
|
102
|
+
async function resolveSafe(n, e = {}) {
|
|
97
103
|
try {
|
|
98
|
-
return await resolve(
|
|
104
|
+
return await resolve(n, e);
|
|
99
105
|
} catch {
|
|
100
106
|
return;
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
|
-
function resolveSafeSync(
|
|
109
|
+
function resolveSafeSync(n, e = {}) {
|
|
104
110
|
try {
|
|
105
|
-
return resolveSync(
|
|
111
|
+
return resolveSync(n, e);
|
|
106
112
|
} catch {
|
|
107
113
|
return;
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
|
-
async function importModule(
|
|
111
|
-
const
|
|
112
|
-
return
|
|
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(
|
|
115
|
-
let
|
|
116
|
-
return
|
|
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(
|
|
119
|
-
let
|
|
120
|
-
return
|
|
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<
|
|
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<
|
|
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
|
|
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.
|
|
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.
|
|
19
|
-
"@stryke/
|
|
20
|
-
"@stryke/
|
|
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.
|
|
29
|
-
"@stryke/type-checks": "^0.3.
|
|
30
|
-
"@stryke/types": "^0.10.
|
|
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": "
|
|
413
|
+
"gitHead": "201972005e4b1291d431d46e3fb49764f44690c5"
|
|
413
414
|
}
|