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