@stryke/fs 0.32.15 → 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 +63 -53
- package/dist/resolve.d.ts +15 -0
- package/dist/resolve.mjs +1 -1
- package/package.json +9 -9
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;
|
|
@@ -16,88 +18,96 @@ var _path = require("@stryke/path");
|
|
|
16
18
|
var _correctPath = require("@stryke/path/correct-path");
|
|
17
19
|
var _cwd = require("@stryke/path/cwd");
|
|
18
20
|
var _filePathFns = require("@stryke/path/file-path-fns");
|
|
21
|
+
var _isType = require("@stryke/path/is-type");
|
|
19
22
|
var _joinPaths = require("@stryke/path/join-paths");
|
|
20
23
|
var _mlly = require("mlly");
|
|
21
|
-
var _nodeFs = require("node:fs");
|
|
22
24
|
var _getWorkspaceRoot = require("./get-workspace-root.cjs");
|
|
23
25
|
const DEFAULT_EXTENSIONS = exports.DEFAULT_EXTENSIONS = ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "json", "jsonc", "json5", "node"];
|
|
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
|
+
}
|
|
24
44
|
async function resolve(n, e = {}) {
|
|
25
|
-
|
|
26
|
-
|
|
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;
|
|
45
|
+
const t = getResolutionPaths(e.paths);
|
|
46
|
+
let r, i;
|
|
32
47
|
try {
|
|
33
|
-
|
|
34
|
-
url:
|
|
48
|
+
r = await (0, _mlly.resolvePath)(n, {
|
|
49
|
+
url: t,
|
|
35
50
|
extensions: e.extensions ?? DEFAULT_EXTENSIONS,
|
|
36
51
|
conditions: e.conditions
|
|
37
52
|
});
|
|
38
|
-
} catch (
|
|
39
|
-
|
|
53
|
+
} catch (s) {
|
|
54
|
+
i = s;
|
|
40
55
|
}
|
|
41
|
-
if (!
|
|
42
|
-
|
|
43
|
-
url:
|
|
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,
|
|
44
59
|
extensions: e.extensions ?? DEFAULT_EXTENSIONS,
|
|
45
60
|
conditions: e.conditions
|
|
46
61
|
});
|
|
47
|
-
} catch (
|
|
48
|
-
|
|
62
|
+
} catch (o) {
|
|
63
|
+
i = o;
|
|
49
64
|
}
|
|
50
|
-
if (!
|
|
65
|
+
if (!r && (0, _filePathFns.findFileName)(n, {
|
|
51
66
|
withExtension: !1
|
|
52
67
|
}) !== "index") try {
|
|
53
|
-
|
|
68
|
+
r = await resolve((0, _joinPaths.joinPaths)(n, "index"), {
|
|
54
69
|
...e,
|
|
55
|
-
paths:
|
|
56
|
-
}),
|
|
57
|
-
} catch (
|
|
58
|
-
|
|
70
|
+
paths: t
|
|
71
|
+
}), r && (r = (0, _filePathFns.findFilePath)(r));
|
|
72
|
+
} catch (s) {
|
|
73
|
+
i = s;
|
|
59
74
|
}
|
|
60
|
-
if (!
|
|
61
|
-
return (0, _correctPath.correctPath)(
|
|
75
|
+
if (!r) throw i ?? new Error(`Cannot resolve module '${n}'`);
|
|
76
|
+
return (0, _correctPath.correctPath)(r);
|
|
62
77
|
}
|
|
63
78
|
function resolveSync(n, e = {}) {
|
|
64
|
-
|
|
65
|
-
r
|
|
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;
|
|
79
|
+
const t = getResolutionPaths(e.paths);
|
|
80
|
+
let r, i;
|
|
71
81
|
try {
|
|
72
|
-
|
|
73
|
-
url:
|
|
82
|
+
r = (0, _mlly.resolvePathSync)(n, {
|
|
83
|
+
url: t,
|
|
74
84
|
extensions: e.extensions ?? DEFAULT_EXTENSIONS,
|
|
75
85
|
conditions: e.conditions
|
|
76
86
|
});
|
|
77
|
-
} catch (
|
|
78
|
-
|
|
87
|
+
} catch (s) {
|
|
88
|
+
i = s;
|
|
79
89
|
}
|
|
80
|
-
if (!
|
|
81
|
-
|
|
82
|
-
url:
|
|
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,
|
|
83
93
|
extensions: e.extensions ?? DEFAULT_EXTENSIONS,
|
|
84
94
|
conditions: e.conditions
|
|
85
95
|
});
|
|
86
|
-
} catch (
|
|
87
|
-
|
|
96
|
+
} catch (o) {
|
|
97
|
+
i = o;
|
|
88
98
|
}
|
|
89
|
-
if (!
|
|
99
|
+
if (!r && (0, _filePathFns.findFileName)(n, {
|
|
90
100
|
withExtension: !1
|
|
91
101
|
}) !== "index") try {
|
|
92
|
-
|
|
102
|
+
r = resolveSync((0, _joinPaths.joinPaths)(n, "index"), {
|
|
93
103
|
...e,
|
|
94
|
-
paths:
|
|
95
|
-
}),
|
|
96
|
-
} catch (
|
|
97
|
-
|
|
104
|
+
paths: t
|
|
105
|
+
}), r && (r = (0, _filePathFns.findFilePath)(r));
|
|
106
|
+
} catch (s) {
|
|
107
|
+
i = s;
|
|
98
108
|
}
|
|
99
|
-
if (!
|
|
100
|
-
return (0, _correctPath.correctPath)(
|
|
109
|
+
if (!r) throw i ?? new Error(`Cannot resolve module '${n}'`);
|
|
110
|
+
return (0, _correctPath.correctPath)(r);
|
|
101
111
|
}
|
|
102
112
|
async function resolveSafe(n, e = {}) {
|
|
103
113
|
try {
|
|
@@ -118,10 +128,10 @@ async function importModule(n) {
|
|
|
118
128
|
return e && (0, _mlly.interopDefault)(e);
|
|
119
129
|
}
|
|
120
130
|
async function resolvePackage(n, e = {}) {
|
|
121
|
-
let
|
|
122
|
-
return
|
|
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;
|
|
123
133
|
}
|
|
124
134
|
function resolvePackageSync(n, e = {}) {
|
|
125
|
-
let
|
|
126
|
-
return
|
|
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;
|
|
127
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
|
*
|
package/dist/resolve.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getUnique as
|
|
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.
|
|
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,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.
|
|
19
|
-
"@stryke/helpers": "^0.9.
|
|
20
|
-
"@stryke/path": "^0.
|
|
21
|
-
"@stryke/string-format": "^0.12.
|
|
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",
|
|
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.
|
|
30
|
-
"@stryke/type-checks": "^0.3.
|
|
31
|
-
"@stryke/types": "^0.10.
|
|
29
|
+
"@stryke/json": "^0.9.8",
|
|
30
|
+
"@stryke/type-checks": "^0.3.15",
|
|
31
|
+
"@stryke/types": "^0.10.5"
|
|
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": "
|
|
413
|
+
"gitHead": "2c99ef0e654a63299ca75104ec2e8a46d65997cc"
|
|
414
414
|
}
|