@stryke/fs 0.20.0 → 0.20.2
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/package-fns.cjs +29 -42
- package/dist/package-fns.d.ts +2 -16
- package/dist/package-fns.mjs +1 -1
- package/dist/tsconfig.cjs +9 -7
- package/dist/tsconfig.mjs +1 -1
- package/package.json +3 -2
package/dist/package-fns.cjs
CHANGED
|
@@ -4,19 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getPackageInfo = getPackageInfo;
|
|
7
|
-
exports.getPackageInfoSync = getPackageInfoSync;
|
|
8
7
|
exports.getPackageManager = getPackageManager;
|
|
9
8
|
exports.isPackageExists = isPackageExists;
|
|
10
9
|
exports.isPackageListed = isPackageListed;
|
|
11
|
-
exports.
|
|
12
|
-
var _stormJson = require("@stryke/json/storm-json");
|
|
10
|
+
exports.loadPackageJson = loadPackageJson;
|
|
13
11
|
var _path = require("@stryke/path");
|
|
14
12
|
var _getParentPath = require("@stryke/path/get-parent-path");
|
|
15
13
|
var _getWorkspaceRoot = require("@stryke/path/get-workspace-root");
|
|
16
14
|
var _resolve = require("@stryke/path/resolve");
|
|
15
|
+
var _nodeFs = require("node:fs");
|
|
17
16
|
var _readFile = require("./read-file.cjs");
|
|
18
|
-
function getPackageManager(
|
|
19
|
-
const n = (0, _getParentPath.getParentPath)(["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lock"],
|
|
17
|
+
function getPackageManager(a = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
18
|
+
const n = (0, _getParentPath.getParentPath)(["package-lock.json", "yarn.lock", "pnpm-lock.yaml", "bun.lock"], a);
|
|
20
19
|
if (!n) return "pnpm";
|
|
21
20
|
switch ((0, _path.findFileName)(n)) {
|
|
22
21
|
case "yarn.lock":
|
|
@@ -29,56 +28,44 @@ function getPackageManager(e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
|
29
28
|
return "npm";
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
|
-
async function
|
|
31
|
+
async function f(a) {
|
|
33
32
|
let n;
|
|
34
33
|
for (;;) {
|
|
35
|
-
if (!
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
if (
|
|
34
|
+
if (!a) return;
|
|
35
|
+
const e = (0, _path.findFilePath)(a);
|
|
36
|
+
if (e === a) return;
|
|
37
|
+
if (a = e, n = (0, _path.joinPaths)(a, "package.json"), await (0, _path.exists)(n)) break;
|
|
39
38
|
}
|
|
40
39
|
return n;
|
|
41
40
|
}
|
|
42
|
-
async function
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
41
|
+
async function u(a, n = {}) {
|
|
42
|
+
const e = await (0, _resolve.resolvePackage)(a, n);
|
|
43
|
+
if (e) return f(e);
|
|
45
44
|
}
|
|
46
|
-
async function getPackageInfo(
|
|
47
|
-
const
|
|
48
|
-
if (!
|
|
49
|
-
const t =
|
|
45
|
+
async function getPackageInfo(a, n = {}) {
|
|
46
|
+
const e = await u(a, n);
|
|
47
|
+
if (!e) return;
|
|
48
|
+
const t = await (0, _readFile.readJsonFile)(e);
|
|
50
49
|
return {
|
|
51
|
-
name:
|
|
50
|
+
name: a,
|
|
52
51
|
version: t.version,
|
|
53
|
-
rootPath: (0, _path.findFilePath)(
|
|
54
|
-
packageJsonPath:
|
|
52
|
+
rootPath: (0, _path.findFilePath)(e),
|
|
53
|
+
packageJsonPath: e,
|
|
55
54
|
packageJson: t
|
|
56
55
|
};
|
|
57
56
|
}
|
|
58
|
-
async function
|
|
59
|
-
const
|
|
60
|
-
if (!a) return;
|
|
61
|
-
const t = _stormJson.StormJSON.parse(await (0, _readFile.readFile)(a));
|
|
62
|
-
return {
|
|
63
|
-
name: e,
|
|
64
|
-
version: t.version,
|
|
65
|
-
rootPath: (0, _path.findFilePath)(a),
|
|
66
|
-
packageJsonPath: a,
|
|
67
|
-
packageJson: t
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
async function loadPackageJSON(e = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
71
|
-
const n = (0, _getParentPath.getParentPath)("package.json", e, {
|
|
57
|
+
async function loadPackageJson(a = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
|
|
58
|
+
const n = (0, _getParentPath.getParentPath)("package.json", a, {
|
|
72
59
|
skipCwd: !1
|
|
73
60
|
});
|
|
74
|
-
return !n || !(
|
|
61
|
+
return !n || !(0, _nodeFs.existsSync)(n) ? null : (0, _readFile.readJsonFile)(n);
|
|
75
62
|
}
|
|
76
|
-
async function isPackageListed(
|
|
77
|
-
let
|
|
78
|
-
|
|
79
|
-
const t = (await
|
|
80
|
-
return
|
|
63
|
+
async function isPackageListed(a, n) {
|
|
64
|
+
let e = a;
|
|
65
|
+
e.includes("@") && (e = !e.startsWith("@") || e.lastIndexOf("@") > 0 ? e.slice(0, e.lastIndexOf("@")) : e);
|
|
66
|
+
const t = (await loadPackageJson(n)) ?? {};
|
|
67
|
+
return e in (t.dependencies ?? {}) || e in (t.devDependencies ?? {});
|
|
81
68
|
}
|
|
82
|
-
function isPackageExists(
|
|
83
|
-
return !!(0, _resolve.resolvePackage)(
|
|
69
|
+
function isPackageExists(a, n = {}) {
|
|
70
|
+
return !!(0, _resolve.resolvePackage)(a, n);
|
|
84
71
|
}
|
package/dist/package-fns.d.ts
CHANGED
|
@@ -19,21 +19,7 @@ export declare function getPackageInfo(name: string, options?: PackageResolvingO
|
|
|
19
19
|
version: any;
|
|
20
20
|
rootPath: any;
|
|
21
21
|
packageJsonPath: any;
|
|
22
|
-
packageJson:
|
|
23
|
-
} | undefined>;
|
|
24
|
-
/**
|
|
25
|
-
* Get package info synchronously
|
|
26
|
-
*
|
|
27
|
-
* @param name - The name of the package
|
|
28
|
-
* @param options - The options to use when resolving the package
|
|
29
|
-
* @returns The package info
|
|
30
|
-
*/
|
|
31
|
-
export declare function getPackageInfoSync(name: string, options?: PackageResolvingOptions): Promise<{
|
|
32
|
-
name: string;
|
|
33
|
-
version: any;
|
|
34
|
-
rootPath: any;
|
|
35
|
-
packageJsonPath: any;
|
|
36
|
-
packageJson: any;
|
|
22
|
+
packageJson: PackageJson;
|
|
37
23
|
} | undefined>;
|
|
38
24
|
/**
|
|
39
25
|
* Get the package info from the package.json file
|
|
@@ -41,7 +27,7 @@ export declare function getPackageInfoSync(name: string, options?: PackageResolv
|
|
|
41
27
|
* @param cwd - The current working directory
|
|
42
28
|
* @returns The package info
|
|
43
29
|
*/
|
|
44
|
-
export declare function
|
|
30
|
+
export declare function loadPackageJson(cwd?: any): Promise<PackageJson | null>;
|
|
45
31
|
/**
|
|
46
32
|
* Check if a package is listed in the package.json file
|
|
47
33
|
*
|
package/dist/package-fns.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{exists as p,findFileName as g,findFilePath as o,joinPaths as k}from"@stryke/path";import{getParentPath as r}from"@stryke/path/get-parent-path";import{getWorkspaceRoot as s}from"@stryke/path/get-workspace-root";import{resolvePackage as i}from"@stryke/path/resolve";import{existsSync as l}from"node:fs";import{readJsonFile as c}from"./read-file";export function getPackageManager(a=s()){const n=r(["package-lock.json","yarn.lock","pnpm-lock.yaml","bun.lock"],a);if(!n)return"pnpm";switch(g(n)){case"yarn.lock":return"yarn";case"pnpm-lock.yaml":return"pnpm";case"bun.lock":return"bun";default:return"npm"}}async function f(a){let n;for(;;){if(!a)return;const e=o(a);if(e===a)return;if(a=e,n=k(a,"package.json"),await p(n))break}return n}async function u(a,n={}){const e=await i(a,n);if(e)return f(e)}export async function getPackageInfo(a,n={}){const e=await u(a,n);if(!e)return;const t=await c(e);return{name:a,version:t.version,rootPath:o(e),packageJsonPath:e,packageJson:t}}export async function loadPackageJson(a=s()){const n=r("package.json",a,{skipCwd:!1});return!n||!l(n)?null:c(n)}export async function isPackageListed(a,n){let e=a;e.includes("@")&&(e=!e.startsWith("@")||e.lastIndexOf("@")>0?e.slice(0,e.lastIndexOf("@")):e);const t=await loadPackageJson(n)??{};return e in(t.dependencies??{})||e in(t.devDependencies??{})}export function isPackageExists(a,n={}){return!!i(a,n)}
|
package/dist/tsconfig.cjs
CHANGED
|
@@ -4,22 +4,24 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.loadTsConfig = loadTsConfig;
|
|
7
|
-
var _path = require("@stryke/path");
|
|
8
7
|
var _exists = require("@stryke/path/exists");
|
|
9
8
|
var _filePathFns = require("@stryke/path/file-path-fns");
|
|
10
9
|
var _joinPaths = require("@stryke/path/join-paths");
|
|
11
10
|
var _defu = _interopRequireDefault(require("defu"));
|
|
11
|
+
var _mlly = require("mlly");
|
|
12
12
|
var _readFile = require("./read-file.cjs");
|
|
13
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
async function loadTsConfig(e = process.cwd()) {
|
|
15
|
-
|
|
16
|
-
if (!(0, _exists.existsSync)(s)
|
|
15
|
+
let s = e.endsWith(".json") ? e : (0, _joinPaths.joinPaths)(e, "tsconfig.json");
|
|
16
|
+
if (!(0, _exists.existsSync)(s) && (s = await (0, _mlly.resolvePath)(e, {
|
|
17
|
+
url: require('url').pathToFileURL(__filename).toString()
|
|
18
|
+
}), !(0, _exists.existsSync)(s))) throw new Error(`tsconfig.json not found at ${s}. Please ensure the file exists.`);
|
|
17
19
|
let o = await (0, _readFile.readJsonFile)(s);
|
|
18
20
|
if (o?.compilerOptions?.baseUrl && (o.compilerOptions.baseUrl = (0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(s), o.compilerOptions.baseUrl)), o?.extends) {
|
|
19
|
-
const
|
|
20
|
-
for (const
|
|
21
|
-
const
|
|
22
|
-
|
|
21
|
+
const f = Array.isArray(o.extends) ? o.extends : [o.extends];
|
|
22
|
+
for (const m of f) {
|
|
23
|
+
const n = await loadTsConfig((0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(s), m));
|
|
24
|
+
n && (o = (0, _defu.default)(o, n ?? {}));
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
return o.extends = void 0, o;
|
package/dist/tsconfig.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{existsSync as i}from"@stryke/path/exists";import{findFilePath as r}from"@stryke/path/file-path-fns";import{joinPaths as t}from"@stryke/path/join-paths";import a from"defu";import{resolvePath as p}from"mlly";import{readJsonFile as c}from"./read-file";export async function loadTsConfig(e=process.cwd()){let s=e.endsWith(".json")?e:t(e,"tsconfig.json");if(!i(s)&&(s=await p(e,{url:import.meta.url}),!i(s)))throw new Error(`tsconfig.json not found at ${s}. Please ensure the file exists.`);let o=await c(s);if(o?.compilerOptions?.baseUrl&&(o.compilerOptions.baseUrl=t(r(s),o.compilerOptions.baseUrl)),o?.extends){const f=Array.isArray(o.extends)?o.extends:[o.extends];for(const m of f){const n=await loadTsConfig(t(r(s),m));n&&(o=a(o,n??{}))}}return o.extends=void 0,o}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/fs",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.2",
|
|
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": {
|
|
@@ -20,9 +20,10 @@
|
|
|
20
20
|
"chalk": "^5.4.1",
|
|
21
21
|
"defu": "^6.1.4",
|
|
22
22
|
"glob": "^11.0.1",
|
|
23
|
+
"mlly": "1.7.4",
|
|
23
24
|
"nanotar": "^0.2.0",
|
|
24
25
|
"semver": "7.7.1",
|
|
25
|
-
"@stryke/json": "^0.
|
|
26
|
+
"@stryke/json": "^0.9.0",
|
|
26
27
|
"@stryke/type-checks": "^0.3.3",
|
|
27
28
|
"@stryke/types": "^0.8.3"
|
|
28
29
|
},
|