@stryke/fs 0.18.0 → 0.20.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/tsconfig.cjs CHANGED
@@ -8,91 +8,19 @@ var _path = require("@stryke/path");
8
8
  var _exists = require("@stryke/path/exists");
9
9
  var _filePathFns = require("@stryke/path/file-path-fns");
10
10
  var _joinPaths = require("@stryke/path/join-paths");
11
- var _base = require("@stryke/types/base");
12
11
  var _defu = _interopRequireDefault(require("defu"));
13
- var _nodeModule = require("node:module");
14
12
  var _readFile = require("./read-file.cjs");
15
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
- const h = Symbol("singleComment"),
17
- F = Symbol("multiComment"),
18
- R = () => "",
19
- k = (e, t, n) => e.slice(t, n).replace(/\S/g, " "),
20
- L = (e, t) => {
21
- let n = t - 1,
22
- f = 0;
23
- for (; e[n] === "\\";) n -= 1, f += 1;
24
- return !!(f % 2);
25
- },
26
- $ = (e, {
27
- whitespace: t = !0,
28
- trailingCommas: n = !1
29
- } = {}) => {
30
- if (typeof e != "string") throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);
31
- const f = t ? k : R;
32
- let o = !1,
33
- i = !1,
34
- r = 0,
35
- l = "",
36
- u = "",
37
- a = -1;
38
- for (let s = 0; s < e.length; s++) {
39
- const c = e[s],
40
- m = e[s + 1];
41
- !i && c === '"' && (L(e, s) || (o = !o)), !o && (!i && c + (m ?? _base.EMPTY_STRING) === "//" ? (l += e.slice(r, s), r = s, i = h, s++) : i === h && c + (m ?? _base.EMPTY_STRING) === `\r
42
- ` ? (s++, i = !1, l += f(e, r, s), r = s) : i === h && c === `
43
- ` ? (i = !1, l += f(e, r, s), r = s) : !i && c + (m ?? _base.EMPTY_STRING) === "/*" ? (l += e.slice(r, s), r = s, i = F, s++) : i === F && c + (m ?? _base.EMPTY_STRING) === "*/" ? (s++, i = !1, l += f(e, r, s + 1), r = s + 1) : n && !i && (a !== -1 ? c === "}" || c === "]" ? (l += e.slice(r, s), u += f(l, 0, 1) + l.slice(1), l = "", r = s, a = -1) : c !== " " && c !== " " && c !== "\r" && c !== `
44
- ` && (l += e.slice(r, s), r = s, a = -1) : c === "," && (u += l + e.slice(r, s), l = "", r = s, a = s)));
45
- }
46
- return u + l + (i ? f(e.slice(r)) : e.slice(r));
47
- },
48
- v = e => {
49
- try {
50
- return new Function(`return ${$(e).trim()}`)();
51
- } catch {
52
- return {};
53
- }
54
- },
55
- A = (0, _nodeModule.createRequire)(require('url').pathToFileURL(__filename).toString());
56
- function J(e, t) {
57
- if ((0, _path.isAbsolutePath)(t)) return (0, _exists.existsSync)(t) ? t : null;
58
- const n = t.endsWith(".json") ? t : `${t}.json`;
59
- return (0, _exists.existsSync)((0, _joinPaths.joinPaths)(e, n)) ? (0, _joinPaths.joinPaths)(e, n) : (0, _path.getParentPath)(n, e, {
60
- ignoreCase: !0,
61
- skipCwd: !0,
62
- targetType: "file"
63
- });
64
- }
65
- function O(e, t) {
66
- if ((0, _path.isAbsolutePath)(t)) return (0, _exists.existsSync)(t) ? t : null;
67
- const n = t.endsWith(".json") ? t : `${t}.json`;
68
- return (0, _exists.existsSync)((0, _joinPaths.joinPaths)(e, n)) ? (0, _joinPaths.joinPaths)(e, n) : n.startsWith(".") ? (0, _path.getParentPath)((0, _filePathFns.findFileName)(n), e, {
69
- ignoreCase: !0,
70
- skipCwd: !1,
71
- targetType: "file"
72
- }) : A.resolve(t, {
73
- paths: [e]
74
- });
75
- }
76
- function W(e, t, n = !1) {
77
- const f = n ? O((0, _path.slash)(e), t) : J((0, _path.slash)(e), t);
78
- if (!f) return null;
79
- let o = v((0, _readFile.readFileSync)(f));
80
- const i = (0, _filePathFns.findFilePath)(f);
81
- o?.compilerOptions?.baseUrl && (o.compilerOptions.baseUrl = (0, _joinPaths.joinPaths)(i, o.compilerOptions.baseUrl));
82
- const r = [];
83
- if (o.extends) {
84
- const l = Array.isArray(o.extends) ? o.extends : [o.extends];
85
- for (const u of l) {
86
- const a = W(i, u, !0);
87
- a && (o = (0, _defu.default)(o, a.data ?? {}), r.push(...a.files));
14
+ async function loadTsConfig(e = process.cwd()) {
15
+ const s = (0, _path.isFile)(e) ? e : (0, _joinPaths.joinPaths)(e, "tsconfig.json");
16
+ if (!(0, _exists.existsSync)(s)) throw new Error(`tsconfig.json not found at ${s}. Please ensure the file exists.`);
17
+ let o = await (0, _readFile.readJsonFile)(s);
18
+ if (o?.compilerOptions?.baseUrl && (o.compilerOptions.baseUrl = (0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(s), o.compilerOptions.baseUrl)), o?.extends) {
19
+ const r = Array.isArray(o.extends) ? o.extends : [o.extends];
20
+ for (const f of r) {
21
+ const t = await loadTsConfig((0, _joinPaths.joinPaths)((0, _filePathFns.findFilePath)(s), f));
22
+ t && (o = (0, _defu.default)(o, t ?? {}));
88
23
  }
89
24
  }
90
- return o.extends = void 0, {
91
- path: f,
92
- data: o,
93
- files: [...r, f]
94
- };
95
- }
96
- function loadTsConfig(e, t) {
97
- return W((0, _filePathFns.findFilePath)(e) ? (0, _filePathFns.findFilePath)(e) : process.cwd(), t ? (0, _filePathFns.findFileName)(t) : "tsconfig.json");
25
+ return o.extends = void 0, o;
98
26
  }
@@ -1,14 +1,8 @@
1
1
  import type { TsConfigJson } from "@stryke/types/tsconfig";
2
- export interface LoadTsConfigResult {
3
- path: string;
4
- data: TsConfigJson;
5
- files: string[];
6
- }
7
2
  /**
8
3
  * Loads a tsconfig.json file and returns the parsed JSON object.
9
4
  *
10
5
  * @param filePath - The directory to start searching for the tsconfig.json file.
11
- * @param fileName - The name of the tsconfig.json file.
12
- * @returns The parsed JSON object.
6
+ * @returns The parsed tsconfig.json object or null if not found.
13
7
  */
14
- export declare function loadTsConfig(filePath: string, fileName?: string): LoadTsConfigResult | null;
8
+ export declare function loadTsConfig(filePath?: string): Promise<TsConfigJson>;
package/dist/tsconfig.mjs CHANGED
@@ -1,4 +1 @@
1
- import{getParentPath as y,isAbsolutePath as b,slash as T}from"@stryke/path";import{existsSync as g}from"@stryke/path/exists";import{findFileName as x,findFilePath as C}from"@stryke/path/file-path-fns";import{joinPaths as p}from"@stryke/path/join-paths";import{EMPTY_STRING as d}from"@stryke/types/base";import P from"defu";import{createRequire as E}from"node:module";import{readFileSync as I}from"./read-file";const h=Symbol("singleComment"),F=Symbol("multiComment"),R=()=>"",k=(e,t,n)=>e.slice(t,n).replace(/\S/g," "),L=(e,t)=>{let n=t-1,f=0;for(;e[n]==="\\";)n-=1,f+=1;return!!(f%2)},$=(e,{whitespace:t=!0,trailingCommas:n=!1}={})=>{if(typeof e!="string")throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);const f=t?k:R;let o=!1,i=!1,r=0,l="",u="",a=-1;for(let s=0;s<e.length;s++){const c=e[s],m=e[s+1];!i&&c==='"'&&(L(e,s)||(o=!o)),!o&&(!i&&c+(m??d)==="//"?(l+=e.slice(r,s),r=s,i=h,s++):i===h&&c+(m??d)===`\r
2
- `?(s++,i=!1,l+=f(e,r,s),r=s):i===h&&c===`
3
- `?(i=!1,l+=f(e,r,s),r=s):!i&&c+(m??d)==="/*"?(l+=e.slice(r,s),r=s,i=F,s++):i===F&&c+(m??d)==="*/"?(s++,i=!1,l+=f(e,r,s+1),r=s+1):n&&!i&&(a!==-1?c==="}"||c==="]"?(l+=e.slice(r,s),u+=f(l,0,1)+l.slice(1),l="",r=s,a=-1):c!==" "&&c!==" "&&c!=="\r"&&c!==`
4
- `&&(l+=e.slice(r,s),r=s,a=-1):c===","&&(u+=l+e.slice(r,s),l="",r=s,a=s)))}return u+l+(i?f(e.slice(r)):e.slice(r))},v=e=>{try{return new Function(`return ${$(e).trim()}`)()}catch{return{}}},A=E(import.meta.url);function J(e,t){if(b(t))return g(t)?t:null;const n=t.endsWith(".json")?t:`${t}.json`;return g(p(e,n))?p(e,n):y(n,e,{ignoreCase:!0,skipCwd:!0,targetType:"file"})}function O(e,t){if(b(t))return g(t)?t:null;const n=t.endsWith(".json")?t:`${t}.json`;return g(p(e,n))?p(e,n):n.startsWith(".")?y(x(n),e,{ignoreCase:!0,skipCwd:!1,targetType:"file"}):A.resolve(t,{paths:[e]})}function W(e,t,n=!1){const f=n?O(T(e),t):J(T(e),t);if(!f)return null;let o=v(I(f));const i=C(f);o?.compilerOptions?.baseUrl&&(o.compilerOptions.baseUrl=p(i,o.compilerOptions.baseUrl));const r=[];if(o.extends){const l=Array.isArray(o.extends)?o.extends:[o.extends];for(const u of l){const a=W(i,u,!0);a&&(o=P(o,a.data??{}),r.push(...a.files))}}return o.extends=void 0,{path:f,data:o,files:[...r,f]}}export function loadTsConfig(e,t){return W(C(e)?C(e):process.cwd(),t?x(t):"tsconfig.json")}
1
+ import{isFile as m}from"@stryke/path";import{existsSync as p}from"@stryke/path/exists";import{findFilePath as i}from"@stryke/path/file-path-fns";import{joinPaths as n}from"@stryke/path/join-paths";import a from"defu";import{readJsonFile as c}from"./read-file";export async function loadTsConfig(e=process.cwd()){const s=m(e)?e:n(e,"tsconfig.json");if(!p(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=n(i(s),o.compilerOptions.baseUrl)),o?.extends){const r=Array.isArray(o.extends)?o.extends:[o.extends];for(const f of r){const t=await loadTsConfig(n(i(s),f));t&&(o=a(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.18.0",
3
+ "version": "0.20.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": {