@stryke/fs 0.33.1 → 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 +61 -83
- package/dist/resolve.d.ts +7 -0
- package/dist/resolve.mjs +5 -1
- package/dist/tsconfig.cjs +10 -11
- package/dist/tsconfig.mjs +1 -1
- package/package.json +9 -9
package/dist/resolve.cjs
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.DEFAULT_EXTENSIONS = void 0;
|
|
7
|
+
exports.getNodeModulesPaths = getNodeModulesPaths;
|
|
7
8
|
exports.getResolutionCombinations = getResolutionCombinations;
|
|
8
9
|
exports.getResolutionPaths = getResolutionPaths;
|
|
9
10
|
exports.importModule = importModule;
|
|
@@ -21,117 +22,94 @@ var _filePathFns = require("@stryke/path/file-path-fns");
|
|
|
21
22
|
var _isType = require("@stryke/path/is-type");
|
|
22
23
|
var _joinPaths = require("@stryke/path/join-paths");
|
|
23
24
|
var _mlly = require("mlly");
|
|
25
|
+
var _exists = require("./exists.cjs");
|
|
24
26
|
var _getWorkspaceRoot = require("./get-workspace-root.cjs");
|
|
25
27
|
const DEFAULT_EXTENSIONS = exports.DEFAULT_EXTENSIONS = ["js", "jsx", "mjs", "cjs", "ts", "tsx", "mts", "cts", "json", "jsonc", "json5", "node"];
|
|
26
28
|
function getResolutionPaths(n = []) {
|
|
27
|
-
let
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
})),
|
|
29
|
+
let r = n;
|
|
30
|
+
r.includes((0, _cwd.cwd)()) || r.push((0, _cwd.cwd)());
|
|
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, 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
|
+
})), s), [])), r;
|
|
33
35
|
}
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
function getNodeModulesPaths(n = []) {
|
|
37
|
+
return (0, _getUnique.getUnique)(n.reduce((r, e) => ((0, _filePathFns.findFolderName)(e) === "node_modules" && r.push((0, _correctPath.correctPath)(e)), (0, _exists.existsSync)((0, _joinPaths.joinPaths)(e, "node_modules")) && r.push((0, _correctPath.correctPath)((0, _joinPaths.joinPaths)(e, "node_modules"))), r), []));
|
|
38
|
+
}
|
|
39
|
+
function getResolutionCombinations(n, r = {}) {
|
|
40
|
+
let e = getResolutionPaths(r.paths);
|
|
41
|
+
(0, _isType.isNpmScopedPackage)(n) ? e = getNodeModulesPaths(e) : e.push(...getNodeModulesPaths(e));
|
|
42
|
+
const s = r.extensions ?? DEFAULT_EXTENSIONS;
|
|
43
|
+
let t = e.map(o => (0, _joinPaths.joinPaths)(n, o));
|
|
38
44
|
return (0, _filePathFns.findFileName)(n, {
|
|
39
45
|
withExtension: !1
|
|
40
|
-
}) !== "index" && (
|
|
41
|
-
|
|
42
|
-
}),
|
|
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));
|
|
43
49
|
}
|
|
44
|
-
async function resolve(n,
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
async function resolve(n, r = {}) {
|
|
51
|
+
let e = getResolutionPaths(r.paths);
|
|
52
|
+
(0, _isType.isNpmScopedPackage)(n) ? e = getNodeModulesPaths(e) : e.push(...getNodeModulesPaths(e));
|
|
53
|
+
let s, t;
|
|
47
54
|
try {
|
|
48
|
-
|
|
49
|
-
url:
|
|
50
|
-
extensions:
|
|
51
|
-
conditions:
|
|
52
|
-
});
|
|
53
|
-
} catch (s) {
|
|
54
|
-
i = s;
|
|
55
|
-
}
|
|
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
|
|
55
|
+
s = await (0, _mlly.resolvePath)(n, {
|
|
56
|
+
url: e,
|
|
57
|
+
extensions: r.extensions ?? DEFAULT_EXTENSIONS,
|
|
58
|
+
conditions: r.conditions
|
|
61
59
|
});
|
|
62
60
|
} catch (o) {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
if (!r && (0, _filePathFns.findFileName)(n, {
|
|
66
|
-
withExtension: !1
|
|
67
|
-
}) !== "index") try {
|
|
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;
|
|
61
|
+
t = o;
|
|
74
62
|
}
|
|
75
|
-
if (!
|
|
76
|
-
|
|
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
|
+
});
|
|
68
|
+
return (0, _correctPath.correctPath)(s);
|
|
77
69
|
}
|
|
78
|
-
function resolveSync(n,
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
function resolveSync(n, r = {}) {
|
|
71
|
+
let e = getResolutionPaths(r.paths);
|
|
72
|
+
(0, _isType.isNpmScopedPackage)(n) ? e = getNodeModulesPaths(e) : e.push(...getNodeModulesPaths(e));
|
|
73
|
+
let s, t;
|
|
81
74
|
try {
|
|
82
|
-
|
|
83
|
-
url:
|
|
84
|
-
extensions:
|
|
85
|
-
conditions:
|
|
86
|
-
});
|
|
87
|
-
} catch (s) {
|
|
88
|
-
i = s;
|
|
89
|
-
}
|
|
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
|
|
75
|
+
s = (0, _mlly.resolvePathSync)(n, {
|
|
76
|
+
url: e,
|
|
77
|
+
extensions: r.extensions ?? DEFAULT_EXTENSIONS,
|
|
78
|
+
conditions: r.conditions
|
|
95
79
|
});
|
|
96
80
|
} catch (o) {
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
if (!r && (0, _filePathFns.findFileName)(n, {
|
|
100
|
-
withExtension: !1
|
|
101
|
-
}) !== "index") try {
|
|
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;
|
|
81
|
+
t = o;
|
|
108
82
|
}
|
|
109
|
-
if (!
|
|
110
|
-
|
|
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
|
+
});
|
|
88
|
+
return (0, _correctPath.correctPath)(s);
|
|
111
89
|
}
|
|
112
|
-
async function resolveSafe(n,
|
|
90
|
+
async function resolveSafe(n, r = {}) {
|
|
113
91
|
try {
|
|
114
|
-
return await resolve(n,
|
|
92
|
+
return await resolve(n, r);
|
|
115
93
|
} catch {
|
|
116
94
|
return;
|
|
117
95
|
}
|
|
118
96
|
}
|
|
119
|
-
function resolveSafeSync(n,
|
|
97
|
+
function resolveSafeSync(n, r = {}) {
|
|
120
98
|
try {
|
|
121
|
-
return resolveSync(n,
|
|
99
|
+
return resolveSync(n, r);
|
|
122
100
|
} catch {
|
|
123
101
|
return;
|
|
124
102
|
}
|
|
125
103
|
}
|
|
126
104
|
async function importModule(n) {
|
|
127
|
-
const
|
|
128
|
-
return
|
|
105
|
+
const r = await Promise.resolve(`${n}`).then(s => require(s));
|
|
106
|
+
return r && (0, _mlly.interopDefault)(r);
|
|
129
107
|
}
|
|
130
|
-
async function resolvePackage(n,
|
|
131
|
-
let
|
|
132
|
-
return
|
|
108
|
+
async function resolvePackage(n, r = {}) {
|
|
109
|
+
let e = await resolveSafe((0, _joinPaths.joinPaths)(n, "package.json"), r);
|
|
110
|
+
return e || (e = await resolveSafe((0, _joinPaths.joinPaths)(n, "index.js"), r), e || (e = await resolveSafe(n, r))), e ? (0, _filePathFns.findFilePath)(e) : void 0;
|
|
133
111
|
}
|
|
134
|
-
function resolvePackageSync(n,
|
|
135
|
-
let
|
|
136
|
-
return
|
|
112
|
+
function resolvePackageSync(n, r = {}) {
|
|
113
|
+
let e = resolveSafeSync((0, _joinPaths.joinPaths)(n, "package.json"), r);
|
|
114
|
+
return e || (e = resolveSafeSync((0, _joinPaths.joinPaths)(n, "index.js"), r), e || (e = resolveSafeSync(n, r))), e ? (0, _filePathFns.findFilePath)(e) : void 0;
|
|
137
115
|
}
|
package/dist/resolve.d.ts
CHANGED
|
@@ -25,6 +25,13 @@ export interface ResolveOptions {
|
|
|
25
25
|
* @returns An array of unique, corrected resolution paths.
|
|
26
26
|
*/
|
|
27
27
|
export declare function getResolutionPaths(paths?: string[]): string[];
|
|
28
|
+
/**
|
|
29
|
+
* Get the node_modules resolution paths based on the provided paths.
|
|
30
|
+
*
|
|
31
|
+
* @param paths - An array of paths to include in the resolution.
|
|
32
|
+
* @returns An array of unique, corrected node_modules resolution paths.
|
|
33
|
+
*/
|
|
34
|
+
export declare function getNodeModulesPaths(paths?: string[]): any;
|
|
28
35
|
/**
|
|
29
36
|
* Get all combinations of resolution paths for a given path and options.
|
|
30
37
|
*
|
package/dist/resolve.mjs
CHANGED
|
@@ -1 +1,5 @@
|
|
|
1
|
-
import{getUnique as
|
|
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/dist/tsconfig.cjs
CHANGED
|
@@ -4,26 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.loadTsConfig = loadTsConfig;
|
|
7
|
+
var _toArray = require("@stryke/convert/to-array");
|
|
7
8
|
var _cwd = require("@stryke/path/cwd");
|
|
8
9
|
var _filePathFns = require("@stryke/path/file-path-fns");
|
|
10
|
+
var _isType = require("@stryke/path/is-type");
|
|
9
11
|
var _joinPaths = require("@stryke/path/join-paths");
|
|
10
12
|
var _defu = _interopRequireDefault(require("defu"));
|
|
11
13
|
var _exists = require("./exists.cjs");
|
|
12
14
|
var _json = require("./json.cjs");
|
|
13
15
|
var _resolve = require("./resolve.cjs");
|
|
14
16
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
async function loadTsConfig(
|
|
16
|
-
let
|
|
17
|
-
if (!(0, _exists.existsSync)(
|
|
17
|
+
async function loadTsConfig(n = (0, _cwd.cwd)()) {
|
|
18
|
+
let i = (0, _filePathFns.findFileExtension)(n) === "json" ? n : (0, _joinPaths.joinPaths)(n, "tsconfig.json");
|
|
19
|
+
if (!(0, _exists.existsSync)(i) && (i = await (0, _resolve.resolve)(n, {
|
|
18
20
|
extensions: ["json"]
|
|
19
|
-
}), !(0, _exists.existsSync)(
|
|
20
|
-
let o = await (0, _json.readJsonFile)(
|
|
21
|
-
if (o?.compilerOptions?.baseUrl && (o.compilerOptions.baseUrl = (0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const i = await loadTsConfig((0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(n), m));
|
|
25
|
-
i && (o = (0, _defu.default)(o, i ?? {}));
|
|
26
|
-
}
|
|
21
|
+
}), !(0, _exists.existsSync)(i))) throw new Error(`tsconfig.json not found at ${i}. Please ensure the file exists.`);
|
|
22
|
+
let o = await (0, _json.readJsonFile)(i);
|
|
23
|
+
if (o?.compilerOptions?.baseUrl && (o.compilerOptions.baseUrl = (0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(i), o.compilerOptions.baseUrl)), o?.extends) for (const e of (0, _toArray.toArray)(o.extends)) {
|
|
24
|
+
const t = await loadTsConfig((0, _isType.isNpmScopedPackage)(e) ? e : (0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(i), e));
|
|
25
|
+
t && (o = (0, _defu.default)(o, t ?? {}));
|
|
27
26
|
}
|
|
28
27
|
return o.extends = void 0, o;
|
|
29
28
|
}
|
package/dist/tsconfig.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cwd as
|
|
1
|
+
import{toArray as m}from"@stryke/convert/to-array";import{cwd as p}from"@stryke/path/cwd";import{findFileExtension as a,findFilePath as r}from"@stryke/path/file-path-fns";import{isNpmScopedPackage as c}from"@stryke/path/is-type";import{joinPaths as s}from"@stryke/path/join-paths";import d from"defu";import{existsSync as f}from"./exists";import{readJsonFile as l}from"./json";import{resolve as g}from"./resolve";export async function loadTsConfig(n=p()){let i=a(n)==="json"?n:s(n,"tsconfig.json");if(!f(i)&&(i=await g(n,{extensions:["json"]}),!f(i)))throw new Error(`tsconfig.json not found at ${i}. Please ensure the file exists.`);let o=await l(i);if(o?.compilerOptions?.baseUrl&&(o.compilerOptions.baseUrl=s(r(i),o.compilerOptions.baseUrl)),o?.extends)for(const e of m(o.extends)){const t=await loadTsConfig(c(e)?e:s(r(i),e));t&&(o=d(o,t??{}))}return o.extends=void 0,o}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/fs",
|
|
3
|
-
"version": "0.33.
|
|
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.
|
|
19
|
-
"@stryke/helpers": "^0.9.
|
|
20
|
-
"@stryke/path": "^0.
|
|
21
|
-
"@stryke/string-format": "^0.12.
|
|
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.
|
|
30
|
-
"@stryke/type-checks": "^0.3.
|
|
31
|
-
"@stryke/types": "^0.10.
|
|
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": "
|
|
413
|
+
"gitHead": "3e25bbb29dbc40028763147139a99c437e48426b"
|
|
414
414
|
}
|