@stryke/fs 0.0.1

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.
Files changed (45) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +63 -0
  3. package/dist/files/chmod-x.cjs +57 -0
  4. package/dist/files/chmod-x.d.ts +40 -0
  5. package/dist/files/chmod-x.mjs +1 -0
  6. package/dist/files/constants.cjs +1 -0
  7. package/dist/files/constants.d.ts +1 -0
  8. package/dist/files/constants.mjs +0 -0
  9. package/dist/files/copy-files.cjs +15 -0
  10. package/dist/files/copy-files.d.ts +18 -0
  11. package/dist/files/copy-files.mjs +1 -0
  12. package/dist/files/helpers.cjs +37 -0
  13. package/dist/files/helpers.d.ts +32 -0
  14. package/dist/files/helpers.mjs +1 -0
  15. package/dist/files/index.cjs +82 -0
  16. package/dist/files/index.d.ts +7 -0
  17. package/dist/files/index.mjs +1 -0
  18. package/dist/files/read-file.cjs +83 -0
  19. package/dist/files/read-file.d.ts +72 -0
  20. package/dist/files/read-file.mjs +1 -0
  21. package/dist/files/remove-file.cjs +18 -0
  22. package/dist/files/remove-file.d.ts +15 -0
  23. package/dist/files/remove-file.mjs +1 -0
  24. package/dist/files/write-file.cjs +34 -0
  25. package/dist/files/write-file.d.ts +47 -0
  26. package/dist/files/write-file.mjs +3 -0
  27. package/dist/index.cjs +27 -0
  28. package/dist/index.d.ts +10 -0
  29. package/dist/index.mjs +1 -0
  30. package/dist/package/get-tsconfig.cjs +110 -0
  31. package/dist/package/get-tsconfig.d.ts +23 -0
  32. package/dist/package/get-tsconfig.mjs +4 -0
  33. package/dist/package/index.cjs +49 -0
  34. package/dist/package/index.d.ts +4 -0
  35. package/dist/package/index.mjs +1 -0
  36. package/dist/package/install.cjs +21 -0
  37. package/dist/package/install.d.ts +0 -0
  38. package/dist/package/install.mjs +1 -0
  39. package/dist/package/package-fns.cjs +83 -0
  40. package/dist/package/package-fns.d.ts +61 -0
  41. package/dist/package/package-fns.mjs +1 -0
  42. package/dist/package/semver-fns.cjs +22 -0
  43. package/dist/package/semver-fns.d.ts +4 -0
  44. package/dist/package/semver-fns.mjs +1 -0
  45. package/package.json +301 -0
@@ -0,0 +1,72 @@
1
+ import type { JsonParseOptions } from "@stryke/json/types";
2
+ /**
3
+ * Read the given content to the given file path
4
+ *
5
+ * @param filePath - The file path to write to
6
+ */
7
+ export declare const readFileSync: (filePath: string) => string;
8
+ /**
9
+ * Read the given content to the given file path
10
+ *
11
+ * @param filePath - The file path to read to
12
+ */
13
+ export declare const readFile: (filePath: string) => Promise<string>;
14
+ export interface JsonReadOptions extends JsonParseOptions {
15
+ /**
16
+ * mutable field recording whether JSON ends with new line
17
+ *
18
+ * @defaultValue false
19
+ */
20
+ endsWithNewline?: boolean;
21
+ }
22
+ /**
23
+ * Reads a JSON file and returns the object the JSON content represents.
24
+ *
25
+ * @param path - A path to a file.
26
+ * @param options - JSON parse options
27
+ * @returns Object the JSON content of the file represents
28
+ */
29
+ export declare function readJsonFileSync<T extends object = any>(path: string, options?: JsonReadOptions): T;
30
+ /**
31
+ * Reads a JSON file and returns the object the JSON content represents.
32
+ *
33
+ * @param path - A path to a file.
34
+ * @param options - JSON parse options
35
+ * @returns Object the JSON content of the file represents
36
+ */
37
+ export declare function readJsonFile<T extends object = any>(path: string, options?: JsonReadOptions): Promise<T>;
38
+ interface YamlReadOptions {
39
+ /**
40
+ * Compatibility with JSON.parse behavior. If true, then duplicate keys in a mapping will override values rather than throwing an error.
41
+ */
42
+ json?: boolean;
43
+ }
44
+ /**
45
+ * Reads a YAML file and returns the object the YAML content represents.
46
+ *
47
+ * @param path - A path to a file.
48
+ * @returns
49
+ */
50
+ export declare function readYamlFileSync<T extends object = any>(path: string, options?: YamlReadOptions): T;
51
+ /**
52
+ * Reads a YAML file and returns the object the YAML content represents.
53
+ *
54
+ * @param path - A path to a file.
55
+ * @returns
56
+ */
57
+ export declare function readYamlFile<T extends object = any>(path: string, options?: YamlReadOptions): Promise<T>;
58
+ /**
59
+ * Reads a file if it exists, otherwise returns an empty string.
60
+ *
61
+ * @param path - The path to the file to read.
62
+ * @returns The content of the file if it exists, otherwise an empty string.
63
+ */
64
+ export declare function readFileIfExistingSync(path: string): string;
65
+ /**
66
+ * Reads a file if it exists, otherwise returns an empty string.
67
+ *
68
+ * @param path - The path to the file to read.
69
+ * @returns The content of the file if it exists, otherwise an empty string.
70
+ */
71
+ export declare function readFileIfExisting(path: string): Promise<string> | "";
72
+ export {};
@@ -0,0 +1 @@
1
+ import{StormJSON as o}from"@stryke/json/storm-json";import{isError as i}from"@stryke/types/type-checks/is-error";import{existsSync as s,readFileSync as a}from"node:fs";import{readFile as c}from"node:fs/promises";export const readFileSync=e=>{try{if(!e)throw new Error("No file path provided to read data");return a(e,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}},readFile=e=>{try{if(!e)throw new Error("No file path provided to read data");return c(e,{encoding:"utf8"})}catch{throw new Error("An error occurred writing data to file")}};export function readJsonFileSync(e,n){const t=readFileSync(e);n&&(n.endsWithNewline=t.codePointAt(t.length-1)===10);try{return o.parseJson(t,n)}catch(r){throw i(r)?(r.message=r.message.replace("JSON",e),r):new Error(`Failed to parse JSON: ${e}`)}}export async function readJsonFile(e,n){const t=await readFile(e);n&&(n.endsWithNewline=t.codePointAt(t.length-1)===10);try{return o.parseJson(t,n)}catch(r){throw i(r)?(r.message=r.message.replace("JSON",e),r):new Error(`Failed to parse JSON: ${e}`)}}export function readYamlFileSync(e,n){const t=readFileSync(e),{load:r}=require("@zkochan/js-yaml");return r(t,{...n,filename:e})}export async function readYamlFile(e,n){const t=await readFile(e),{load:r}=require("@zkochan/js-yaml");return r(t,{...n,filename:e})}export function readFileIfExistingSync(e){return s(e)?readFileSync(e):""}export function readFileIfExisting(e){return s(e)?readFile(e):""}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.removeFileSync = exports.removeFile = void 0;
7
+ var _nodeFs = require("node:fs");
8
+ var _promises = require("node:fs/promises");
9
+ const removeFileSync = r => {
10
+ if (!r || !(0, _nodeFs.existsSync)(r)) throw new Error("Invalid file path provided to remove data");
11
+ (0, _nodeFs.rmSync)(r);
12
+ },
13
+ removeFile = r => {
14
+ if (!r || !(0, _nodeFs.existsSync)(r)) throw new Error("Invalid file path provided to remove data");
15
+ return (0, _promises.rm)(r);
16
+ };
17
+ exports.removeFile = removeFile;
18
+ exports.removeFileSync = removeFileSync;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Remove the given content to the given file path
3
+ *
4
+ * @param filePath - The file path to remove to
5
+ * @param content - The content to remove to the file
6
+ */
7
+ export declare const removeFileSync: (filePath: string) => void;
8
+ /**
9
+ * Remove the given content to the given file path
10
+ *
11
+ * @param filePath - The file path to read to
12
+ * @param content - The content to remove to the file
13
+ * @returns The content of the file
14
+ */
15
+ export declare const removeFile: (filePath: string) => Promise<void>;
@@ -0,0 +1 @@
1
+ import{existsSync as o,rmSync as e}from"node:fs";import{rm as i}from"node:fs/promises";export const removeFileSync=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");e(r)},removeFile=r=>{if(!r||!o(r))throw new Error("Invalid file path provided to remove data");return i(r)};
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.writeFileSync = exports.writeFile = void 0;
7
+ exports.writeJsonFile = writeJsonFile;
8
+ exports.writeJsonFileSync = writeJsonFileSync;
9
+ var _stormJson = require("@stryke/json/storm-json");
10
+ var _nodeFs = require("node:fs");
11
+ var _promises = require("node:fs/promises");
12
+ var _helpers = require("./helpers.cjs");
13
+ const writeFileSync = (e, t, o) => {
14
+ if (!e) throw new Error("No file path provided to write data");
15
+ (0, _nodeFs.writeFileSync)(e, t ?? "", o);
16
+ },
17
+ writeFile = (e, t, o) => {
18
+ if (!e) throw new Error("No file path provided to read data");
19
+ return (0, _promises.writeFile)(e, t ?? "", o);
20
+ };
21
+ exports.writeFile = writeFile;
22
+ exports.writeFileSync = writeFileSync;
23
+ function writeJsonFileSync(e, t, o) {
24
+ (0, _helpers.createDirectorySync)(e);
25
+ const n = _stormJson.StormJSON.stringifyJson(t, o);
26
+ return writeFileSync(e, o?.appendNewLine ? `${n}
27
+ ` : n);
28
+ }
29
+ async function writeJsonFile(e, t, o) {
30
+ await (0, _helpers.createDirectory)(e);
31
+ const n = _stormJson.StormJSON.stringifyJson(t, o);
32
+ return writeFile(e, o?.appendNewLine ? `${n}
33
+ ` : n);
34
+ }
@@ -0,0 +1,47 @@
1
+ import type { JsonSerializeOptions } from "@stryke/json/types";
2
+ import type { Abortable } from "node:events";
3
+ import { type Mode, type ObjectEncodingOptions, type OpenMode, type WriteFileOptions } from "node:fs";
4
+ import type { Encoding } from "./constants";
5
+ /**
6
+ * Write the given content to the given file path
7
+ *
8
+ * @param filePath - The file path to write to
9
+ * @param content - The content to write to the file
10
+ */
11
+ export declare const writeFileSync: (filePath: string, content?: any, options?: WriteFileOptions) => void;
12
+ /**
13
+ * Read the given content to the given file path
14
+ *
15
+ * @param filePath - The file path to read to
16
+ * @param content - The content to write to the file
17
+ * @returns The content of the file
18
+ */
19
+ export declare const writeFile: (filePath: string, content?: any, options?: (ObjectEncodingOptions & {
20
+ mode?: Mode | undefined;
21
+ flag?: OpenMode | undefined;
22
+ flush?: boolean | undefined;
23
+ } & Abortable) | Encoding | null) => Promise<void>;
24
+ export interface JsonWriteOptions extends JsonSerializeOptions {
25
+ /**
26
+ * whether to append new line at the end of JSON file
27
+ *
28
+ * @defaultValue false
29
+ */
30
+ appendNewLine?: boolean;
31
+ }
32
+ /**
33
+ * Serializes the given data to JSON and writes it to a file.
34
+ *
35
+ * @param path - A path to a file.
36
+ * @param data - data which should be serialized to JSON and written to the file
37
+ * @param options - JSON serialize options
38
+ */
39
+ export declare function writeJsonFileSync<T extends object = object>(path: string, data: T, options?: JsonWriteOptions): void;
40
+ /**
41
+ * Serializes the given data to JSON and writes it to a file asynchronously.
42
+ *
43
+ * @param path - A path to a file.
44
+ * @param data - data which should be serialized to JSON and written to the file
45
+ * @param options - JSON serialize options
46
+ */
47
+ export declare function writeJsonFile<T extends object = object>(path: string, data: T, options?: JsonWriteOptions): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import{StormJSON as i}from"@stryke/json/storm-json";import{writeFileSync as r}from"node:fs";import{writeFile as s}from"node:fs/promises";import{createDirectory as p,createDirectorySync as d}from"./helpers";export const writeFileSync=(e,t,o)=>{if(!e)throw new Error("No file path provided to write data");r(e,t??"",o)},writeFile=(e,t,o)=>{if(!e)throw new Error("No file path provided to read data");return s(e,t??"",o)};export function writeJsonFileSync(e,t,o){d(e);const n=i.stringifyJson(t,o);return writeFileSync(e,o?.appendNewLine?`${n}
2
+ `:n)}export async function writeJsonFile(e,t,o){await p(e);const n=i.stringifyJson(t,o);return writeFile(e,o?.appendNewLine?`${n}
3
+ `:n)}
package/dist/index.cjs ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _files = require("./files/index.cjs");
7
+ Object.keys(_files).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _files[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _files[key];
14
+ }
15
+ });
16
+ });
17
+ var _package = require("./package/index.cjs");
18
+ Object.keys(_package).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _package[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _package[key];
25
+ }
26
+ });
27
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The fs library used by Storm Software for building NodeJS applications.
3
+ *
4
+ * @remarks
5
+ * A package containing various file system utilities that expand the functionality of NodeJs's `fs` module
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export * from "./files";
10
+ export * from "./package";
package/dist/index.mjs ADDED
@@ -0,0 +1 @@
1
+ export*from"./files";export*from"./package";
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.loadTsConfigFile = exports.loadTsConfig = void 0;
7
+ var _filePathFns = require("@stryke/path/utilities/file-path-fns");
8
+ var _base = require("@stryke/types/utility-types/base");
9
+ var _nodeFs = _interopRequireDefault(require("node:fs"));
10
+ var _nodeModule = require("node:module");
11
+ var _nodePath = _interopRequireDefault(require("node:path"));
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ const h = Symbol("singleComment"),
14
+ y = Symbol("multiComment"),
15
+ T = () => "",
16
+ W = (e, i, c) => e.slice(i, c).replace(/\S/g, " "),
17
+ E = (e, i) => {
18
+ let c = i - 1,
19
+ l = 0;
20
+ for (; e[c] === "\\";) c -= 1, l += 1;
21
+ return !!(l % 2);
22
+ },
23
+ w = (e, {
24
+ whitespace: i = !0,
25
+ trailingCommas: c = !1
26
+ } = {}) => {
27
+ if (typeof e != "string") throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);
28
+ const l = i ? W : T;
29
+ let f = !1,
30
+ o = !1,
31
+ n = 0,
32
+ s = "",
33
+ m = "",
34
+ p = -1;
35
+ for (let t = 0; t < e.length; t++) {
36
+ const r = e[t],
37
+ d = e[t + 1];
38
+ !o && r === '"' && (E(e, t) || (f = !f)), !f && (!o && r + (d ?? _base.EMPTY_STRING) === "//" ? (s += e.slice(n, t), n = t, o = h, t++) : o === h && r + (d ?? _base.EMPTY_STRING) === `\r
39
+ ` ? (t++, o = !1, s += l(e, n, t), n = t) : o === h && r === `
40
+ ` ? (o = !1, s += l(e, n, t), n = t) : !o && r + (d ?? _base.EMPTY_STRING) === "/*" ? (s += e.slice(n, t), n = t, o = y, t++) : o === y && r + (d ?? _base.EMPTY_STRING) === "*/" ? (t++, o = !1, s += l(e, n, t + 1), n = t + 1) : c && !o && (p !== -1 ? r === "}" || r === "]" ? (s += e.slice(n, t), m += l(s, 0, 1) + s.slice(1), s = "", n = t, p = -1) : r !== " " && r !== " " && r !== "\r" && r !== `
41
+ ` && (s += e.slice(n, t), n = t, p = -1) : r === "," && (m += s + e.slice(n, t), s = "", n = t, p = t)));
42
+ }
43
+ return m + s + (o ? l(e.slice(n)) : e.slice(n));
44
+ },
45
+ I = e => {
46
+ try {
47
+ return new Function(`return ${w(e).trim()}`)();
48
+ } catch {
49
+ return {};
50
+ }
51
+ },
52
+ A = (0, _nodeModule.createRequire)(require('url').pathToFileURL(__filename).toString()),
53
+ g = (e, i, c = _nodePath.default.parse(i).root) => {
54
+ let l = i;
55
+ for (; l !== c;) {
56
+ const f = _nodePath.default.join(l, e);
57
+ if (_nodeFs.default.existsSync(f)) return f;
58
+ if (!f.endsWith(".json")) {
59
+ const o = `${f}.json`;
60
+ if (_nodeFs.default.existsSync(o)) return o;
61
+ }
62
+ l = _nodePath.default.dirname(l);
63
+ }
64
+ return null;
65
+ },
66
+ U = (e, i) => _nodePath.default.isAbsolute(i) ? _nodeFs.default.existsSync(i) ? i : null : g(i, e),
67
+ P = (e, i) => _nodePath.default.isAbsolute(i) ? _nodeFs.default.existsSync(i) ? i : null : i.startsWith(".") ? g(i, e) : A.resolve(i, {
68
+ paths: [e]
69
+ }),
70
+ C = (e = process.cwd(), i = "tsconfig.json", c = !1) => {
71
+ let l, f;
72
+ const o = _nodePath.default.resolve(e),
73
+ n = c ? P(o, i) : U(o, i);
74
+ if (!n) return null;
75
+ const s = I(_nodeFs.default.readFileSync(n, "utf8")),
76
+ m = _nodePath.default.dirname(n);
77
+ (l = s.compilerOptions) !== null && l.baseUrl && (s.compilerOptions.baseUrl = _nodePath.default.join(m, s.compilerOptions.baseUrl));
78
+ const p = [];
79
+ if (s.extends) {
80
+ const t = Array.isArray(s.extends) ? s.extends : [s.extends],
81
+ r = {};
82
+ for (const d of t) {
83
+ const u = C(m, d, !0);
84
+ u && (Object.assign(r, {
85
+ ...(u === null ? void 0 : u.data),
86
+ compilerOptions: {
87
+ ...r.compilerOptions,
88
+ ...((f = u === null ? void 0 : u.data) === null ? void 0 : f.compilerOptions)
89
+ }
90
+ }), p.push(...u.files));
91
+ }
92
+ Object.assign(s, {
93
+ ...r,
94
+ ...s,
95
+ compilerOptions: {
96
+ ...r.compilerOptions,
97
+ ...s.compilerOptions
98
+ }
99
+ });
100
+ }
101
+ return s.extends = void 0, {
102
+ path: n,
103
+ data: s,
104
+ files: [...p, n]
105
+ };
106
+ };
107
+ const loadTsConfig = (e, i = "tsconfig.json") => C(e, i),
108
+ loadTsConfigFile = e => loadTsConfig((0, _filePathFns.findFilePath)(e), (0, _filePathFns.findFileName)(e));
109
+ exports.loadTsConfigFile = loadTsConfigFile;
110
+ exports.loadTsConfig = loadTsConfig;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Loads a tsconfig.json file and returns the parsed JSON object.
3
+ *
4
+ * @param dir - The directory to start searching for the tsconfig.json file.
5
+ * @param name - The name of the tsconfig.json file.
6
+ * @returns The parsed JSON object.
7
+ */
8
+ export declare const loadTsConfig: (dir: string, name?: string) => {
9
+ path: any;
10
+ data: any;
11
+ files: any[];
12
+ } | null;
13
+ /**
14
+ * Loads a tsconfig.json file and returns the parsed JSON object.
15
+ *
16
+ * @param name - The name/path of the tsconfig.json file.
17
+ * @returns The parsed JSON object.
18
+ */
19
+ export declare const loadTsConfigFile: (file: string) => {
20
+ path: any;
21
+ data: any;
22
+ files: any[];
23
+ } | null;
@@ -0,0 +1,4 @@
1
+ import{findFileName as O,findFilePath as F}from"@stryke/path/utilities/file-path-fns";import{EMPTY_STRING as b}from"@stryke/types/utility-types/base";import x from"node:fs";import{createRequire as v}from"node:module";import a from"node:path";const h=Symbol("singleComment"),y=Symbol("multiComment"),T=()=>"",W=(e,i,c)=>e.slice(i,c).replace(/\S/g," "),E=(e,i)=>{let c=i-1,l=0;for(;e[c]==="\\";)c-=1,l+=1;return!!(l%2)},w=(e,{whitespace:i=!0,trailingCommas:c=!1}={})=>{if(typeof e!="string")throw new TypeError(`Expected argument \`jsonString\` to be a \`string\`, got \`${typeof e}\``);const l=i?W:T;let f=!1,o=!1,n=0,s="",m="",p=-1;for(let t=0;t<e.length;t++){const r=e[t],d=e[t+1];!o&&r==='"'&&(E(e,t)||(f=!f)),!f&&(!o&&r+(d??b)==="//"?(s+=e.slice(n,t),n=t,o=h,t++):o===h&&r+(d??b)===`\r
2
+ `?(t++,o=!1,s+=l(e,n,t),n=t):o===h&&r===`
3
+ `?(o=!1,s+=l(e,n,t),n=t):!o&&r+(d??b)==="/*"?(s+=e.slice(n,t),n=t,o=y,t++):o===y&&r+(d??b)==="*/"?(t++,o=!1,s+=l(e,n,t+1),n=t+1):c&&!o&&(p!==-1?r==="}"||r==="]"?(s+=e.slice(n,t),m+=l(s,0,1)+s.slice(1),s="",n=t,p=-1):r!==" "&&r!==" "&&r!=="\r"&&r!==`
4
+ `&&(s+=e.slice(n,t),n=t,p=-1):r===","&&(m+=s+e.slice(n,t),s="",n=t,p=t)))}return m+s+(o?l(e.slice(n)):e.slice(n))},I=e=>{try{return new Function(`return ${w(e).trim()}`)()}catch{return{}}},A=v(import.meta.url),g=(e,i,c=a.parse(i).root)=>{let l=i;for(;l!==c;){const f=a.join(l,e);if(x.existsSync(f))return f;if(!f.endsWith(".json")){const o=`${f}.json`;if(x.existsSync(o))return o}l=a.dirname(l)}return null},U=(e,i)=>a.isAbsolute(i)?x.existsSync(i)?i:null:g(i,e),P=(e,i)=>a.isAbsolute(i)?x.existsSync(i)?i:null:i.startsWith(".")?g(i,e):A.resolve(i,{paths:[e]}),C=(e=process.cwd(),i="tsconfig.json",c=!1)=>{let l,f;const o=a.resolve(e),n=c?P(o,i):U(o,i);if(!n)return null;const s=I(x.readFileSync(n,"utf8")),m=a.dirname(n);(l=s.compilerOptions)!==null&&l.baseUrl&&(s.compilerOptions.baseUrl=a.join(m,s.compilerOptions.baseUrl));const p=[];if(s.extends){const t=Array.isArray(s.extends)?s.extends:[s.extends],r={};for(const d of t){const u=C(m,d,!0);u&&(Object.assign(r,{...u===null?void 0:u.data,compilerOptions:{...r.compilerOptions,...(f=u===null?void 0:u.data)===null?void 0:f.compilerOptions}}),p.push(...u.files))}Object.assign(s,{...r,...s,compilerOptions:{...r.compilerOptions,...s.compilerOptions}})}return s.extends=void 0,{path:n,data:s,files:[...p,n]}};export const loadTsConfig=(e,i="tsconfig.json")=>C(e,i),loadTsConfigFile=e=>loadTsConfig(F(e),O(e));
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _getTsconfig = require("./get-tsconfig.cjs");
7
+ Object.keys(_getTsconfig).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _getTsconfig[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _getTsconfig[key];
14
+ }
15
+ });
16
+ });
17
+ var _install = require("./install.cjs");
18
+ Object.keys(_install).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _install[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _install[key];
25
+ }
26
+ });
27
+ });
28
+ var _packageFns = require("./package-fns.cjs");
29
+ Object.keys(_packageFns).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _packageFns[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _packageFns[key];
36
+ }
37
+ });
38
+ });
39
+ var _semverFns = require("./semver-fns.cjs");
40
+ Object.keys(_semverFns).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _semverFns[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _semverFns[key];
47
+ }
48
+ });
49
+ });
@@ -0,0 +1,4 @@
1
+ export * from "./get-tsconfig";
2
+ export * from "./install";
3
+ export * from "./package-fns";
4
+ export * from "./semver-fns";
@@ -0,0 +1 @@
1
+ export*from"./get-tsconfig";export*from"./install";export*from"./package-fns";export*from"./semver-fns";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.packageExists = exports.install = void 0;
7
+ var _installPkg = require("@antfu/install-pkg");
8
+ var _resolve = require("@stryke/path/resolve/resolve");
9
+ const install = (t, s) => (0, _installPkg.installPackage)(t, s),
10
+ packageExists = async (t, s) => {
11
+ const r = await (0, _resolve.resolve)(s?.cwd || process.cwd());
12
+ try {
13
+ (0, _resolve.resolve)(t, {
14
+ paths: [r]
15
+ });
16
+ } catch {
17
+ install(t, s);
18
+ }
19
+ };
20
+ exports.packageExists = packageExists;
21
+ exports.install = install;
File without changes
@@ -0,0 +1 @@
1
+ import{installPackage as c}from"@antfu/install-pkg";import{resolve as a}from"@stryke/path/resolve/resolve";export const install=(t,s)=>c(t,s),packageExists=async(t,s)=>{const r=await a(s?.cwd||process.cwd());try{a(t,{paths:[r]})}catch{install(t,s)}};
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPackageInfo = getPackageInfo;
7
+ exports.getPackageInfoSync = getPackageInfoSync;
8
+ exports.getPackageManager = getPackageManager;
9
+ exports.isPackageExists = isPackageExists;
10
+ exports.isPackageListed = isPackageListed;
11
+ exports.loadPackageJSON = loadPackageJSON;
12
+ var _stormJson = require("@stryke/json/storm-json");
13
+ var _resolve = require("@stryke/path/resolve");
14
+ var _utilities = require("@stryke/path/utilities");
15
+ var _getParentPath = require("@stryke/path/utilities/get-parent-path");
16
+ var _getWorkspaceRoot = require("@stryke/path/workspace/get-workspace-root");
17
+ var _packageManager = require("@stryke/types/utility-types/package-manager");
18
+ var _promises = require("node:fs/promises");
19
+ function getPackageManager(a = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
20
+ const e = (0, _getParentPath.getParentPath)([_packageManager.PackageManagerLockFiles.NPM, _packageManager.PackageManagerLockFiles.YARN, _packageManager.PackageManagerLockFiles.PNPM, _packageManager.PackageManagerLockFiles.BUN], a);
21
+ if (!e) return _packageManager.PackageManagers.PNPM;
22
+ switch ((0, _utilities.findFileName)(e)) {
23
+ case _packageManager.PackageManagerLockFiles.YARN:
24
+ return _packageManager.PackageManagers.YARN;
25
+ case _packageManager.PackageManagerLockFiles.PNPM:
26
+ return _packageManager.PackageManagers.PNPM;
27
+ case _packageManager.PackageManagerLockFiles.BUN:
28
+ return _packageManager.PackageManagers.BUN;
29
+ default:
30
+ return _packageManager.PackageManagers.NPM;
31
+ }
32
+ }
33
+ async function m(a) {
34
+ let e;
35
+ for (;;) {
36
+ if (!a) return;
37
+ const t = (0, _utilities.findFilePath)(a);
38
+ if (t === a) return;
39
+ if (a = t, e = (0, _utilities.joinPaths)(a, "package.json"), await (0, _utilities.exists)(e)) break;
40
+ }
41
+ return e;
42
+ }
43
+ async function u(a, e = {}) {
44
+ const t = await (0, _resolve.resolvePackage)(a, e);
45
+ if (t) return m(t);
46
+ }
47
+ async function getPackageInfo(a, e = {}) {
48
+ const t = await u(a, e);
49
+ if (!t) return;
50
+ const r = _stormJson.StormJSON.parse(await (0, _promises.readFile)(t, "utf8"));
51
+ return {
52
+ name: a,
53
+ version: r.version,
54
+ rootPath: (0, _utilities.findFilePath)(t),
55
+ packageJsonPath: t,
56
+ packageJson: r
57
+ };
58
+ }
59
+ async function getPackageInfoSync(a, e = {}) {
60
+ const t = await u(a, e);
61
+ if (!t) return;
62
+ const r = _stormJson.StormJSON.parse(await (0, _promises.readFile)(t, "utf8"));
63
+ return {
64
+ name: a,
65
+ version: r.version,
66
+ rootPath: (0, _utilities.findFilePath)(t),
67
+ packageJsonPath: t,
68
+ packageJson: r
69
+ };
70
+ }
71
+ async function loadPackageJSON(a = (0, _getWorkspaceRoot.getWorkspaceRoot)()) {
72
+ let e = (0, _getParentPath.getParentPath)("package.json", a, {
73
+ skipCwd: !1
74
+ });
75
+ return !e || !(await (0, _utilities.exists)(e)) ? null : _stormJson.StormJSON.parse(await (0, _promises.readFile)(e, "utf8"));
76
+ }
77
+ async function isPackageListed(a, e) {
78
+ const t = (await loadPackageJSON(e)) ?? {};
79
+ return a in (t.dependencies ?? {}) || a in (t.devDependencies ?? {});
80
+ }
81
+ function isPackageExists(a, e = {}) {
82
+ return !!(0, _resolve.resolvePackage)(a, e);
83
+ }
@@ -0,0 +1,61 @@
1
+ import { type PackageResolvingOptions } from "@stryke/path/resolve";
2
+ import type { PackageJson } from "@stryke/types/utility-types/package-json";
3
+ import { PackageManagers } from "@stryke/types/utility-types/package-manager";
4
+ /**
5
+ * Get the package manager used in the project
6
+ * @param dir - The path to the project
7
+ * @returns The package manager used in the project
8
+ */
9
+ export declare function getPackageManager(dir?: any): PackageManagers;
10
+ /**
11
+ * Get package info
12
+ *
13
+ * @param name - The name of the package
14
+ * @param options - The options to use when resolving the package
15
+ * @returns The package info
16
+ */
17
+ export declare function getPackageInfo(name: string, options?: PackageResolvingOptions): Promise<{
18
+ name: string;
19
+ version: any;
20
+ rootPath: any;
21
+ packageJsonPath: any;
22
+ packageJson: any;
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;
37
+ } | undefined>;
38
+ /**
39
+ * Get the package info from the package.json file
40
+ *
41
+ * @param name - The name of the package
42
+ * @param options - The options to use when resolving the package
43
+ * @returns The package info
44
+ */
45
+ export declare function loadPackageJSON(cwd?: any): Promise<PackageJson | null>;
46
+ /**
47
+ * Check if a package is listed in the package.json file
48
+ *
49
+ * @param name - The name of the package
50
+ * @param cwd - The current working directory
51
+ * @returns An indicator specifying if the package is listed
52
+ */
53
+ export declare function isPackageListed(name: string, cwd?: string): Promise<boolean>;
54
+ /**
55
+ * Check if a package exists
56
+ *
57
+ * @param name - The name of the package
58
+ * @param options - The options to use when resolving the package
59
+ * @returns An indicator specifying if the package exists
60
+ */
61
+ export declare function isPackageExists(name: string, options?: PackageResolvingOptions): boolean;
@@ -0,0 +1 @@
1
+ import{StormJSON as s}from"@stryke/json/storm-json";import{resolvePackage as g}from"@stryke/path/resolve";import{exists as P,findFileName as f,findFilePath as i,joinPaths as l}from"@stryke/path/utilities";import{getParentPath as p}from"@stryke/path/utilities/get-parent-path";import{getWorkspaceRoot as k}from"@stryke/path/workspace/get-workspace-root";import{PackageManagerLockFiles as n,PackageManagers as o}from"@stryke/types/utility-types/package-manager";import{readFile as c}from"node:fs/promises";export function getPackageManager(a=k()){const e=p([n.NPM,n.YARN,n.PNPM,n.BUN],a);if(!e)return o.PNPM;switch(f(e)){case n.YARN:return o.YARN;case n.PNPM:return o.PNPM;case n.BUN:return o.BUN;default:return o.NPM}}async function m(a){let e;for(;;){if(!a)return;const t=i(a);if(t===a)return;if(a=t,e=l(a,"package.json"),await P(e))break}return e}async function u(a,e={}){const t=await g(a,e);if(t)return m(t)}export async function getPackageInfo(a,e={}){const t=await u(a,e);if(!t)return;const r=s.parse(await c(t,"utf8"));return{name:a,version:r.version,rootPath:i(t),packageJsonPath:t,packageJson:r}}export async function getPackageInfoSync(a,e={}){const t=await u(a,e);if(!t)return;const r=s.parse(await c(t,"utf8"));return{name:a,version:r.version,rootPath:i(t),packageJsonPath:t,packageJson:r}}export async function loadPackageJSON(a=k()){let e=p("package.json",a,{skipCwd:!1});return!e||!await P(e)?null:s.parse(await c(e,"utf8"))}export async function isPackageListed(a,e){const t=await loadPackageJSON(e)??{};return a in(t.dependencies??{})||a in(t.devDependencies??{})}export function isPackageExists(a,e={}){return!!g(a,e)}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.parseVersion = exports.isRelativeVersionKeyword = exports.deriveNewSemverVersion = void 0;
7
+ var _semver = require("semver");
8
+ const parseVersion = e => (0, _semver.parse)(e),
9
+ isRelativeVersionKeyword = e => _semver.RELEASE_TYPES.includes(e),
10
+ deriveNewSemverVersion = (e, r, n) => {
11
+ if (!(0, _semver.valid)(e)) throw new Error(`Invalid semver version "${e}" provided.`);
12
+ let o = r;
13
+ if (isRelativeVersionKeyword(r)) {
14
+ const i = (0, _semver.inc)(e, r, n);
15
+ if (!i) throw new Error(`Unable to derive new version from current version "${e}" and version specifier "${r}"`);
16
+ o = i;
17
+ } else if (!(0, _semver.valid)(r)) throw new Error(`Invalid semver version specifier "${r}" provided. Please provide either a valid semver version or a valid semver version keyword.`);
18
+ return o;
19
+ };
20
+ exports.deriveNewSemverVersion = deriveNewSemverVersion;
21
+ exports.isRelativeVersionKeyword = isRelativeVersionKeyword;
22
+ exports.parseVersion = parseVersion;
@@ -0,0 +1,4 @@
1
+ import { type ReleaseType } from "semver";
2
+ export declare const parseVersion: (semver: string) => any;
3
+ export declare const isRelativeVersionKeyword: (val: string) => val is ReleaseType;
4
+ export declare const deriveNewSemverVersion: (currentSemverVersion: string, semverSpecifier: string, preid?: string) => string;