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