functype-os 0.2.0 → 0.4.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/env/Env.d.ts +1 -0
- package/dist/env/Env.js +1 -1
- package/dist/env/Env.js.map +1 -1
- package/dist/errors/errors.d.ts +10 -2
- package/dist/errors/errors.js +1 -1
- package/dist/errors/errors.js.map +1 -1
- package/dist/errors/index.d.ts +2 -2
- package/dist/errors/index.js +1 -1
- package/dist/fs/Fs.d.ts +28 -1
- package/dist/fs/Fs.js +1 -1
- package/dist/fs/Fs.js.map +1 -1
- package/dist/fs/index.d.ts +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1 -1
- package/dist/platform/Platform.d.ts +11 -2
- package/dist/platform/Platform.js +1 -1
- package/dist/platform/Platform.js.map +1 -1
- package/dist/platform/index.d.ts +2 -2
- package/dist/process/Process.d.ts +22 -0
- package/dist/process/Process.js +2 -0
- package/dist/process/Process.js.map +1 -0
- package/dist/process/index.d.ts +2 -0
- package/dist/process/index.js +1 -0
- package/package.json +26 -19
package/dist/env/Env.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ declare const EnvCompanion: {
|
|
|
9
9
|
getOrDefault: (name: string, defaultValue: string) => string;
|
|
10
10
|
has: (name: string) => boolean;
|
|
11
11
|
entries: () => List<readonly [string, string]>;
|
|
12
|
+
parse: <T>(name: string, parser: (value: string) => T) => Either<EnvError, T>;
|
|
12
13
|
};
|
|
13
14
|
declare const Env: typeof EnvConstructor & typeof EnvCompanion;
|
|
14
15
|
//#endregion
|
package/dist/env/Env.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{EnvError as e}from"../errors/errors.js";import{Left as t,List as n,Option as r,Right as i}from"functype";const a=Object.assign(e=>r(process.env[e]),{get:e=>r(process.env[e]),getRequired:n=>{let r=process.env[n];return r===void 0?t(e(n)):i(r)},getOrDefault:(e,t)=>process.env[e]??t,has:e=>process.env[e]!==void 0,entries:()=>n(Object.entries(process.env).filter(e=>e[1]!==void 0).map(([e,t])=>[e,t]))});export{a as Env};
|
|
1
|
+
import{EnvError as e}from"../errors/errors.js";import{Left as t,List as n,Option as r,Right as i}from"functype";const a=Object.assign(e=>r(process.env[e]),{get:e=>r(process.env[e]),getRequired:n=>{let r=process.env[n];return r===void 0?t(e(n)):i(r)},getOrDefault:(e,t)=>process.env[e]??t,has:e=>process.env[e]!==void 0,entries:()=>n(Object.entries(process.env).filter(e=>e[1]!==void 0).map(([e,t])=>[e,t])),parse:(n,r)=>{let a=process.env[n];if(a===void 0)return t(e(n));try{let o=r(a);return typeof o==`number`&&isNaN(o)?t(e(n,`Cannot parse '${a}' as number for '${n}'`)):i(o)}catch(r){return t(e(n,`Failed to parse '${n}': ${r instanceof Error?r.message:String(r)}`))}}});export{a as Env};
|
|
2
2
|
//# sourceMappingURL=Env.js.map
|
package/dist/env/Env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Env.js","names":[],"sources":["../../src/env/Env.ts"],"sourcesContent":["import type { Either } from \"functype\"\nimport { Left, List, Option, Right } from \"functype\"\n\nimport { EnvError } from \"../errors/errors\"\n\nconst EnvConstructor = (name: string): Option<string> => Option(process.env[name])\n\nconst EnvCompanion = {\n get: (name: string): Option<string> => Option(process.env[name]),\n\n getRequired: (name: string): Either<EnvError, string> => {\n const value = process.env[name]\n return value !== undefined ? Right(value) : Left(EnvError(name))\n },\n\n getOrDefault: (name: string, defaultValue: string): string => process.env[name] ?? defaultValue,\n\n has: (name: string): boolean => process.env[name] !== undefined,\n\n entries: (): List<readonly [string, string]> => {\n const pairs: Readonly<Array<readonly [string, string]>> = Object.entries(process.env)\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([k, v]) => [k, v] as const)\n return List(pairs)\n },\n}\n\nexport const Env: typeof EnvConstructor & typeof EnvCompanion = Object.assign(EnvConstructor, EnvCompanion)\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"Env.js","names":[],"sources":["../../src/env/Env.ts"],"sourcesContent":["import type { Either } from \"functype\"\nimport { Left, List, Option, Right } from \"functype\"\n\nimport { EnvError } from \"../errors/errors\"\n\nconst EnvConstructor = (name: string): Option<string> => Option(process.env[name])\n\nconst EnvCompanion = {\n get: (name: string): Option<string> => Option(process.env[name]),\n\n getRequired: (name: string): Either<EnvError, string> => {\n const value = process.env[name]\n return value !== undefined ? Right(value) : Left(EnvError(name))\n },\n\n getOrDefault: (name: string, defaultValue: string): string => process.env[name] ?? defaultValue,\n\n has: (name: string): boolean => process.env[name] !== undefined,\n\n entries: (): List<readonly [string, string]> => {\n const pairs: Readonly<Array<readonly [string, string]>> = Object.entries(process.env)\n .filter((entry): entry is [string, string] => entry[1] !== undefined)\n .map(([k, v]) => [k, v] as const)\n return List(pairs)\n },\n\n parse: <T>(name: string, parser: (value: string) => T): Either<EnvError, T> => {\n const value = process.env[name]\n if (value === undefined) {\n return Left(EnvError(name))\n }\n try {\n const parsed = parser(value)\n if (typeof parsed === \"number\" && isNaN(parsed)) {\n return Left(EnvError(name, `Cannot parse '${value}' as number for '${name}'`))\n }\n return Right(parsed)\n } catch (error) {\n return Left(\n EnvError(name, `Failed to parse '${name}': ${error instanceof Error ? error.message : String(error)}`),\n )\n }\n },\n}\n\nexport const Env: typeof EnvConstructor & typeof EnvCompanion = Object.assign(EnvConstructor, EnvCompanion)\n"],"mappings":"gHA6CA,MAAa,EAAmD,OAAO,OAxC/C,GAAiC,EAAO,QAAQ,IAAI,GAAM,CAE7D,CACnB,IAAM,GAAiC,EAAO,QAAQ,IAAI,GAAM,CAEhE,YAAc,GAA2C,CACvD,IAAM,EAAQ,QAAQ,IAAI,GAC1B,OAAO,IAAU,IAAA,GAA2B,EAAK,EAAS,EAAK,CAAC,CAAnC,EAAM,EAAM,EAG3C,cAAe,EAAc,IAAiC,QAAQ,IAAI,IAAS,EAEnF,IAAM,GAA0B,QAAQ,IAAI,KAAU,IAAA,GAEtD,YAIS,EAHmD,OAAO,QAAQ,QAAQ,IAAI,CAClF,OAAQ,GAAqC,EAAM,KAAO,IAAA,GAAU,CACpE,KAAK,CAAC,EAAG,KAAO,CAAC,EAAG,EAAE,CAAU,CACjB,CAGpB,OAAW,EAAc,IAAsD,CAC7E,IAAM,EAAQ,QAAQ,IAAI,GAC1B,GAAI,IAAU,IAAA,GACZ,OAAO,EAAK,EAAS,EAAK,CAAC,CAE7B,GAAI,CACF,IAAM,EAAS,EAAO,EAAM,CAI5B,OAHI,OAAO,GAAW,UAAY,MAAM,EAAO,CACtC,EAAK,EAAS,EAAM,iBAAiB,EAAM,mBAAmB,EAAK,GAAG,CAAC,CAEzE,EAAM,EAAO,OACb,EAAO,CACd,OAAO,EACL,EAAS,EAAM,oBAAoB,EAAK,KAAK,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,GAAG,CACvG,GAGN,CAE0G"}
|
package/dist/errors/errors.d.ts
CHANGED
|
@@ -22,11 +22,19 @@ type ConfigError = {
|
|
|
22
22
|
readonly candidates: readonly string[];
|
|
23
23
|
readonly message: string;
|
|
24
24
|
};
|
|
25
|
-
type
|
|
25
|
+
type ProcessError = {
|
|
26
|
+
readonly _tag: "ProcessError";
|
|
27
|
+
readonly command: string;
|
|
28
|
+
readonly exitCode: number | null;
|
|
29
|
+
readonly stderr: string;
|
|
30
|
+
readonly message: string;
|
|
31
|
+
};
|
|
32
|
+
type OsError = EnvError | PathError | FsError | ConfigError | ProcessError;
|
|
26
33
|
declare const EnvError: (variable: string, message?: string) => EnvError;
|
|
27
34
|
declare const PathError: (path: string, reason: PathError["reason"], message?: string) => PathError;
|
|
28
35
|
declare const FsError: (path: string, operation: string, cause: Error) => FsError;
|
|
29
36
|
declare const ConfigError: (candidates: readonly string[], message?: string) => ConfigError;
|
|
37
|
+
declare const ProcessError: (command: string, exitCode: number | null, stderr: string, message?: string) => ProcessError;
|
|
30
38
|
//#endregion
|
|
31
|
-
export { ConfigError, EnvError, FsError, OsError, PathError };
|
|
39
|
+
export { ConfigError, EnvError, FsError, OsError, PathError, ProcessError };
|
|
32
40
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors/errors.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=(e,t)=>({_tag:`EnvError`,variable:e,message:t??`Environment variable '${e}' is not set`}),t=(e,t,n)=>({_tag:`PathError`,path:e,reason:t,message:n??(t===`unresolved_variable`?`Unresolved variable in path: ${e}`:`Invalid path: ${e}`)}),n=(e,t,n)=>({_tag:`FsError`,path:e,operation:t,cause:n,message:`${t} failed for '${e}': ${n.message}`}),r=(e,t)=>({_tag:`ConfigError`,candidates:e,message:t??`No config file found among candidates: ${e.join(`, `)}`});export{r as ConfigError,e as EnvError,n as FsError,t as PathError};
|
|
1
|
+
const e=(e,t)=>({_tag:`EnvError`,variable:e,message:t??`Environment variable '${e}' is not set`}),t=(e,t,n)=>({_tag:`PathError`,path:e,reason:t,message:n??(t===`unresolved_variable`?`Unresolved variable in path: ${e}`:`Invalid path: ${e}`)}),n=(e,t,n)=>({_tag:`FsError`,path:e,operation:t,cause:n,message:`${t} failed for '${e}': ${n.message}`}),r=(e,t)=>({_tag:`ConfigError`,candidates:e,message:t??`No config file found among candidates: ${e.join(`, `)}`}),i=(e,t,n,r)=>({_tag:`ProcessError`,command:e,exitCode:t,stderr:n,message:r??`Command '${e}' failed (exit ${t}): ${n}`});export{r as ConfigError,e as EnvError,n as FsError,t as PathError,i as ProcessError};
|
|
2
2
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../../src/errors/errors.ts"],"sourcesContent":["export type EnvError = {\n readonly _tag: \"EnvError\"\n readonly variable: string\n readonly message: string\n}\n\nexport type PathError = {\n readonly _tag: \"PathError\"\n readonly path: string\n readonly reason: \"unresolved_variable\" | \"invalid_path\"\n readonly message: string\n}\n\nexport type FsError = {\n readonly _tag: \"FsError\"\n readonly path: string\n readonly operation: string\n readonly cause: Error\n readonly message: string\n}\n\nexport type ConfigError = {\n readonly _tag: \"ConfigError\"\n readonly candidates: readonly string[]\n readonly message: string\n}\n\nexport type OsError = EnvError | PathError | FsError | ConfigError\n\nexport const EnvError = (variable: string, message?: string): EnvError => ({\n _tag: \"EnvError\",\n variable,\n message: message ?? `Environment variable '${variable}' is not set`,\n})\n\nexport const PathError = (path: string, reason: PathError[\"reason\"], message?: string): PathError => ({\n _tag: \"PathError\",\n path,\n reason,\n message:\n message ?? (reason === \"unresolved_variable\" ? `Unresolved variable in path: ${path}` : `Invalid path: ${path}`),\n})\n\nexport const FsError = (path: string, operation: string, cause: Error): FsError => ({\n _tag: \"FsError\",\n path,\n operation,\n cause,\n message: `${operation} failed for '${path}': ${cause.message}`,\n})\n\nexport const ConfigError = (candidates: readonly string[], message?: string): ConfigError => ({\n _tag: \"ConfigError\",\n candidates,\n message: message ?? `No config file found among candidates: ${candidates.join(\", \")}`,\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../src/errors/errors.ts"],"sourcesContent":["export type EnvError = {\n readonly _tag: \"EnvError\"\n readonly variable: string\n readonly message: string\n}\n\nexport type PathError = {\n readonly _tag: \"PathError\"\n readonly path: string\n readonly reason: \"unresolved_variable\" | \"invalid_path\"\n readonly message: string\n}\n\nexport type FsError = {\n readonly _tag: \"FsError\"\n readonly path: string\n readonly operation: string\n readonly cause: Error\n readonly message: string\n}\n\nexport type ConfigError = {\n readonly _tag: \"ConfigError\"\n readonly candidates: readonly string[]\n readonly message: string\n}\n\nexport type ProcessError = {\n readonly _tag: \"ProcessError\"\n readonly command: string\n readonly exitCode: number | null\n readonly stderr: string\n readonly message: string\n}\n\nexport type OsError = EnvError | PathError | FsError | ConfigError | ProcessError\n\nexport const EnvError = (variable: string, message?: string): EnvError => ({\n _tag: \"EnvError\",\n variable,\n message: message ?? `Environment variable '${variable}' is not set`,\n})\n\nexport const PathError = (path: string, reason: PathError[\"reason\"], message?: string): PathError => ({\n _tag: \"PathError\",\n path,\n reason,\n message:\n message ?? (reason === \"unresolved_variable\" ? `Unresolved variable in path: ${path}` : `Invalid path: ${path}`),\n})\n\nexport const FsError = (path: string, operation: string, cause: Error): FsError => ({\n _tag: \"FsError\",\n path,\n operation,\n cause,\n message: `${operation} failed for '${path}': ${cause.message}`,\n})\n\nexport const ConfigError = (candidates: readonly string[], message?: string): ConfigError => ({\n _tag: \"ConfigError\",\n candidates,\n message: message ?? `No config file found among candidates: ${candidates.join(\", \")}`,\n})\n\nexport const ProcessError = (\n command: string,\n exitCode: number | null,\n stderr: string,\n message?: string,\n): ProcessError => ({\n _tag: \"ProcessError\",\n command,\n exitCode,\n stderr,\n message: message ?? `Command '${command}' failed (exit ${exitCode}): ${stderr}`,\n})\n"],"mappings":"AAqCA,MAAa,GAAY,EAAkB,KAAgC,CACzE,KAAM,WACN,WACA,QAAS,GAAW,yBAAyB,EAAS,cACvD,EAEY,GAAa,EAAc,EAA6B,KAAiC,CACpG,KAAM,YACN,OACA,SACA,QACE,IAAY,IAAW,sBAAwB,gCAAgC,IAAS,iBAAiB,KAC5G,EAEY,GAAW,EAAc,EAAmB,KAA2B,CAClF,KAAM,UACN,OACA,YACA,QACA,QAAS,GAAG,EAAU,eAAe,EAAK,KAAK,EAAM,UACtD,EAEY,GAAe,EAA+B,KAAmC,CAC5F,KAAM,cACN,aACA,QAAS,GAAW,0CAA0C,EAAW,KAAK,KAAK,GACpF,EAEY,GACX,EACA,EACA,EACA,KACkB,CAClB,KAAM,eACN,UACA,WACA,SACA,QAAS,GAAW,YAAY,EAAQ,iBAAiB,EAAS,KAAK,IACxE"}
|
package/dist/errors/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ConfigError, EnvError, FsError, OsError, PathError } from "./errors.js";
|
|
2
|
-
export { ConfigError, EnvError, FsError, type OsError, PathError };
|
|
1
|
+
import { ConfigError, EnvError, FsError, OsError, PathError, ProcessError } from "./errors.js";
|
|
2
|
+
export { ConfigError, EnvError, FsError, type OsError, PathError, ProcessError };
|
package/dist/errors/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ConfigError as e,EnvError as t,FsError as n,PathError as r}from"./errors.js";export{e as ConfigError,t as EnvError,n as FsError,r as PathError};
|
|
1
|
+
import{ConfigError as e,EnvError as t,FsError as n,PathError as r,ProcessError as i}from"./errors.js";export{e as ConfigError,t as EnvError,n as FsError,r as PathError,i as ProcessError};
|
package/dist/fs/Fs.d.ts
CHANGED
|
@@ -2,16 +2,43 @@ import { FsError } from "../errors/errors.js";
|
|
|
2
2
|
import { Either, List, Option, TaskResult } from "functype";
|
|
3
3
|
|
|
4
4
|
//#region src/fs/Fs.d.ts
|
|
5
|
+
type FileInfo = {
|
|
6
|
+
readonly size: number;
|
|
7
|
+
readonly isFile: boolean;
|
|
8
|
+
readonly isDirectory: boolean;
|
|
9
|
+
readonly isSymbolicLink: boolean;
|
|
10
|
+
readonly createdAt: Date;
|
|
11
|
+
readonly modifiedAt: Date;
|
|
12
|
+
readonly accessedAt: Date;
|
|
13
|
+
readonly permissions: number;
|
|
14
|
+
};
|
|
5
15
|
declare const Fs: {
|
|
6
16
|
exists: (p: string) => TaskResult<boolean>;
|
|
7
17
|
readFile: (p: string, encoding?: BufferEncoding) => TaskResult<string>;
|
|
8
18
|
readFileOpt: (p: string, encoding?: BufferEncoding) => TaskResult<Option<string>>;
|
|
19
|
+
stat: (p: string) => TaskResult<FileInfo>;
|
|
20
|
+
copyFile: (src: string, dest: string) => TaskResult<void>;
|
|
21
|
+
rename: (oldPath: string, newPath: string) => TaskResult<void>;
|
|
9
22
|
readdir: (p: string) => TaskResult<List<string>>;
|
|
23
|
+
glob: (dir: string, pattern: string) => TaskResult<List<string>>;
|
|
24
|
+
writeFile: (p: string, data: string, encoding?: BufferEncoding) => TaskResult<void>;
|
|
25
|
+
mkdir: (p: string, options?: {
|
|
26
|
+
recursive?: boolean;
|
|
27
|
+
}) => TaskResult<void>;
|
|
10
28
|
existsSync: (p: string) => boolean;
|
|
11
29
|
readFileSync: (p: string, encoding?: BufferEncoding) => Either<FsError, string>;
|
|
12
30
|
readFileOptSync: (p: string, encoding?: BufferEncoding) => Either<FsError, Option<string>>;
|
|
31
|
+
statSync: (p: string) => Either<FsError, FileInfo>;
|
|
32
|
+
copyFileSync: (src: string, dest: string) => Either<FsError, void>;
|
|
33
|
+
renameSync: (oldPath: string, newPath: string) => Either<FsError, void>;
|
|
13
34
|
readdirSync: (p: string) => Either<FsError, List<string>>;
|
|
35
|
+
writeFileSync: (p: string, data: string, encoding?: BufferEncoding) => Either<FsError, void>;
|
|
36
|
+
mkdirSync: (p: string, options?: {
|
|
37
|
+
recursive?: boolean;
|
|
38
|
+
}) => Either<FsError, void>;
|
|
39
|
+
unlink: (p: string) => TaskResult<void>;
|
|
40
|
+
unlinkSync: (p: string) => Either<FsError, void>;
|
|
14
41
|
};
|
|
15
42
|
//#endregion
|
|
16
|
-
export { Fs };
|
|
43
|
+
export { FileInfo, Fs };
|
|
17
44
|
//# sourceMappingURL=Fs.d.ts.map
|
package/dist/fs/Fs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{FsError as e}from"../errors/errors.js";import{Err as t,Left as n,List as r,Ok as i,Option as a,Right as o}from"functype";import*as s from"node:fs";import*as c from"node:fs/promises";const l=(t,n,r)=>e(t,n,r instanceof Error?r:Error(String(r))),
|
|
1
|
+
import{FsError as e}from"../errors/errors.js";import{Err as t,Left as n,List as r,Ok as i,Option as a,Right as o}from"functype";import*as s from"node:fs";import*as c from"node:fs/promises";const l=e=>({size:e.size,isFile:e.isFile(),isDirectory:e.isDirectory(),isSymbolicLink:e.isSymbolicLink(),createdAt:e.birthtime,modifiedAt:e.mtime,accessedAt:e.atime,permissions:e.mode}),u=(t,n,r)=>e(t,n,r instanceof Error?r:Error(String(r))),d=(e,t)=>{let n=t.replace(/\./g,`\\.`).replace(/\*\*\//g,`{{GLOBSTAR}}`).replace(/\*\*/g,`{{GLOBSTAR}}`).replace(/\*/g,`[^/]*`).replace(/\{\{GLOBSTAR\}\}/g,`(?:.*/)?`);return RegExp(`^${n}$`).test(e)},f={exists:async e=>{try{return await c.access(e),i(!0)}catch{return i(!1)}},readFile:async(e,n=`utf8`)=>{try{return i(await c.readFile(e,{encoding:n}))}catch(n){return t(u(e,`readFile`,n))}},readFileOpt:async(e,n=`utf8`)=>{try{return i(a(await c.readFile(e,{encoding:n})))}catch(n){return n instanceof Error&&`code`in n&&n.code===`ENOENT`?i(a(void 0)):t(u(e,`readFile`,n))}},stat:async e=>{try{return i(l(await c.stat(e)))}catch(n){return t(u(e,`stat`,n))}},copyFile:async(e,n)=>{try{return await c.copyFile(e,n),i(void 0)}catch(n){return t(u(e,`copyFile`,n))}},rename:async(e,n)=>{try{return await c.rename(e,n),i(void 0)}catch(n){return t(u(e,`rename`,n))}},readdir:async e=>{try{return i(r(await c.readdir(e)))}catch(n){return t(u(e,`readdir`,n))}},glob:async(e,n)=>{try{return i(r((await c.readdir(e,{recursive:!0,encoding:`utf8`})).filter(e=>d(e,n))))}catch(n){return t(u(e,`glob`,n))}},writeFile:async(e,n,r=`utf8`)=>{try{return await c.writeFile(e,n,{encoding:r}),i(void 0)}catch(n){return t(u(e,`writeFile`,n))}},mkdir:async(e,n)=>{try{return await c.mkdir(e,n),i(void 0)}catch(n){return t(u(e,`mkdir`,n))}},existsSync:e=>{try{return s.accessSync(e),!0}catch{return!1}},readFileSync:(e,t=`utf8`)=>{try{return o(s.readFileSync(e,{encoding:t}))}catch(t){return n(u(e,`readFileSync`,t))}},readFileOptSync:(e,t=`utf8`)=>{try{return o(a(s.readFileSync(e,{encoding:t})))}catch(t){return t instanceof Error&&`code`in t&&t.code===`ENOENT`?o(a(void 0)):n(u(e,`readFileOptSync`,t))}},statSync:e=>{try{return o(l(s.statSync(e)))}catch(t){return n(u(e,`statSync`,t))}},copyFileSync:(e,t)=>{try{return s.copyFileSync(e,t),o(void 0)}catch(t){return n(u(e,`copyFileSync`,t))}},renameSync:(e,t)=>{try{return s.renameSync(e,t),o(void 0)}catch(t){return n(u(e,`renameSync`,t))}},readdirSync:e=>{try{return o(r(s.readdirSync(e)))}catch(t){return n(u(e,`readdirSync`,t))}},writeFileSync:(e,t,r=`utf8`)=>{try{return s.writeFileSync(e,t,{encoding:r}),o(void 0)}catch(t){return n(u(e,`writeFileSync`,t))}},mkdirSync:(e,t)=>{try{return s.mkdirSync(e,t),o(void 0)}catch(t){return n(u(e,`mkdirSync`,t))}},unlink:async e=>{try{return await c.unlink(e),i(void 0)}catch(n){return t(u(e,`unlink`,n))}},unlinkSync:e=>{try{return s.unlinkSync(e),o(void 0)}catch(t){return n(u(e,`unlinkSync`,t))}}};export{f as Fs};
|
|
2
2
|
//# sourceMappingURL=Fs.js.map
|
package/dist/fs/Fs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fs.js","names":[],"sources":["../../src/fs/Fs.ts"],"sourcesContent":["import * as fsSync from \"node:fs\"\nimport * as fs from \"node:fs/promises\"\n\nimport type { Either, TaskResult } from \"functype\"\nimport { Err, Left, List, Ok, Option, Right } from \"functype\"\n\nimport { FsError } from \"../errors/errors\"\n\nconst toFsError = (p: string, op: string, error: unknown): FsError =>\n FsError(p, op, error instanceof Error ? error : new Error(String(error)))\n\nexport const Fs = {\n // Async methods — return TaskResult<T>\n\n exists: async (p: string): TaskResult<boolean> => {\n try {\n await fs.access(p)\n return Ok(true)\n } catch {\n return Ok(false)\n }\n },\n\n readFile: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<string> => {\n try {\n return Ok(await fs.readFile(p, { encoding }))\n } catch (error) {\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n readFileOpt: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<Option<string>> => {\n try {\n return Ok(Option(await fs.readFile(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Ok(Option<string>(undefined))\n }\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n readdir: async (p: string): TaskResult<List<string>> => {\n try {\n return Ok(List(await fs.readdir(p)))\n } catch (error) {\n return Err(toFsError(p, \"readdir\", error))\n }\n },\n\n // Sync methods — return Either<FsError, T>\n\n existsSync: (p: string): boolean => {\n try {\n fsSync.accessSync(p)\n return true\n } catch {\n return false\n }\n },\n\n readFileSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, string> => {\n try {\n return Right(fsSync.readFileSync(p, { encoding }))\n } catch (error) {\n return Left(toFsError(p, \"readFileSync\", error))\n }\n },\n\n readFileOptSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, Option<string>> => {\n try {\n return Right(Option(fsSync.readFileSync(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Right(Option<string>(undefined))\n }\n return Left(toFsError(p, \"readFileOptSync\", error))\n }\n },\n\n readdirSync: (p: string): Either<FsError, List<string>> => {\n try {\n return Right(List(fsSync.readdirSync(p)))\n } catch (error) {\n return Left(toFsError(p, \"readdirSync\", error))\n }\n },\n}\n"],"mappings":"6LAQA,MAAM,GAAa,EAAW,EAAY,IACxC,EAAQ,EAAG,EAAI,aAAiB,MAAQ,EAAY,MAAM,OAAO,EAAM,CAAC,CAAC,CAE9D,EAAK,CAGhB,OAAQ,KAAO,IAAmC,CAChD,GAAI,CAEF,OADA,MAAM,EAAG,OAAO,EAAE,CACX,EAAG,GAAK,MACT,CACN,OAAO,EAAG,GAAM,GAIpB,SAAU,MAAO,EAAW,EAA2B,SAA+B,CACpF,GAAI,CACF,OAAO,EAAG,MAAM,EAAG,SAAS,EAAG,CAAE,WAAU,CAAC,CAAC,OACtC,EAAO,CACd,OAAO,EAAI,EAAU,EAAG,WAAY,EAAM,CAAC,GAI/C,YAAa,MAAO,EAAW,EAA2B,SAAuC,CAC/F,GAAI,CACF,OAAO,EAAG,EAAO,MAAM,EAAG,SAAS,EAAG,CAAE,WAAU,CAAC,CAAC,CAAC,OAC9C,EAAO,CAId,OAHI,aAAiB,OAAS,SAAU,GAAS,EAAM,OAAS,SACvD,EAAG,EAAe,IAAA,GAAU,CAAC,CAE/B,EAAI,EAAU,EAAG,WAAY,EAAM,CAAC,GAI/C,QAAS,KAAO,IAAwC,CACtD,GAAI,CACF,OAAO,EAAG,EAAK,MAAM,EAAG,QAAQ,EAAE,CAAC,CAAC,OAC7B,EAAO,CACd,OAAO,EAAI,EAAU,EAAG,UAAW,EAAM,CAAC,GAM9C,WAAa,GAAuB,CAClC,GAAI,CAEF,OADA,EAAO,WAAW,EAAE,CACb,QACD,CACN,MAAO,KAIX,cAAe,EAAW,EAA2B,SAAoC,CACvF,GAAI,CACF,OAAO,EAAM,EAAO,aAAa,EAAG,CAAE,WAAU,CAAC,CAAC,OAC3C,EAAO,CACd,OAAO,EAAK,EAAU,EAAG,eAAgB,EAAM,CAAC,GAIpD,iBAAkB,EAAW,EAA2B,SAA4C,CAClG,GAAI,CACF,OAAO,EAAM,EAAO,EAAO,aAAa,EAAG,CAAE,WAAU,CAAC,CAAC,CAAC,OACnD,EAAO,CAId,OAHI,aAAiB,OAAS,SAAU,GAAS,EAAM,OAAS,SACvD,EAAM,EAAe,IAAA,GAAU,CAAC,CAElC,EAAK,EAAU,EAAG,kBAAmB,EAAM,CAAC,GAIvD,YAAc,GAA6C,CACzD,GAAI,CACF,OAAO,EAAM,EAAK,EAAO,YAAY,EAAE,CAAC,CAAC,OAClC,EAAO,CACd,OAAO,EAAK,EAAU,EAAG,cAAe,EAAM,CAAC,GAGpD"}
|
|
1
|
+
{"version":3,"file":"Fs.js","names":[],"sources":["../../src/fs/Fs.ts"],"sourcesContent":["import * as fsSync from \"node:fs\"\nimport * as fs from \"node:fs/promises\"\n\nimport type { Either, TaskResult } from \"functype\"\nimport { Err, Left, List, Ok, Option, Right } from \"functype\"\n\nimport { FsError } from \"../errors/errors\"\n\nexport type FileInfo = {\n readonly size: number\n readonly isFile: boolean\n readonly isDirectory: boolean\n readonly isSymbolicLink: boolean\n readonly createdAt: Date\n readonly modifiedAt: Date\n readonly accessedAt: Date\n readonly permissions: number\n}\n\nconst toFileInfo = (stats: fsSync.Stats): FileInfo => ({\n size: stats.size,\n isFile: stats.isFile(),\n isDirectory: stats.isDirectory(),\n isSymbolicLink: stats.isSymbolicLink(),\n createdAt: stats.birthtime,\n modifiedAt: stats.mtime,\n accessedAt: stats.atime,\n permissions: stats.mode,\n})\n\nconst toFsError = (p: string, op: string, error: unknown): FsError =>\n FsError(p, op, error instanceof Error ? error : new Error(String(error)))\n\nconst matchGlob = (filePath: string, pattern: string): boolean => {\n const regex = pattern\n .replace(/\\./g, \"\\\\.\")\n .replace(/\\*\\*\\//g, \"{{GLOBSTAR}}\")\n .replace(/\\*\\*/g, \"{{GLOBSTAR}}\")\n .replace(/\\*/g, \"[^/]*\")\n .replace(/\\{\\{GLOBSTAR\\}\\}/g, \"(?:.*/)?\")\n return new RegExp(`^${regex}$`).test(filePath)\n}\n\nexport const Fs = {\n // Async methods — return TaskResult<T>\n\n exists: async (p: string): TaskResult<boolean> => {\n try {\n await fs.access(p)\n return Ok(true)\n } catch {\n return Ok(false)\n }\n },\n\n readFile: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<string> => {\n try {\n return Ok(await fs.readFile(p, { encoding }))\n } catch (error) {\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n readFileOpt: async (p: string, encoding: BufferEncoding = \"utf8\"): TaskResult<Option<string>> => {\n try {\n return Ok(Option(await fs.readFile(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Ok(Option<string>(undefined))\n }\n return Err(toFsError(p, \"readFile\", error))\n }\n },\n\n stat: async (p: string): TaskResult<FileInfo> => {\n try {\n return Ok(toFileInfo(await fs.stat(p)))\n } catch (error) {\n return Err(toFsError(p, \"stat\", error))\n }\n },\n\n copyFile: async (src: string, dest: string): TaskResult<void> => {\n try {\n await fs.copyFile(src, dest)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(src, \"copyFile\", error))\n }\n },\n\n rename: async (oldPath: string, newPath: string): TaskResult<void> => {\n try {\n await fs.rename(oldPath, newPath)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(oldPath, \"rename\", error))\n }\n },\n\n readdir: async (p: string): TaskResult<List<string>> => {\n try {\n return Ok(List(await fs.readdir(p)))\n } catch (error) {\n return Err(toFsError(p, \"readdir\", error))\n }\n },\n\n glob: async (dir: string, pattern: string): TaskResult<List<string>> => {\n try {\n const entries = await fs.readdir(dir, { recursive: true, encoding: \"utf8\" })\n const matched = entries.filter((entry) => matchGlob(entry, pattern))\n return Ok(List(matched))\n } catch (error) {\n return Err(toFsError(dir, \"glob\", error))\n }\n },\n\n writeFile: async (p: string, data: string, encoding: BufferEncoding = \"utf8\"): TaskResult<void> => {\n try {\n await fs.writeFile(p, data, { encoding })\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(p, \"writeFile\", error))\n }\n },\n\n mkdir: async (p: string, options?: { recursive?: boolean }): TaskResult<void> => {\n try {\n await fs.mkdir(p, options)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(p, \"mkdir\", error))\n }\n },\n\n // Sync methods — return Either<FsError, T>\n\n existsSync: (p: string): boolean => {\n try {\n fsSync.accessSync(p)\n return true\n } catch {\n return false\n }\n },\n\n readFileSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, string> => {\n try {\n return Right(fsSync.readFileSync(p, { encoding }))\n } catch (error) {\n return Left(toFsError(p, \"readFileSync\", error))\n }\n },\n\n readFileOptSync: (p: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, Option<string>> => {\n try {\n return Right(Option(fsSync.readFileSync(p, { encoding })))\n } catch (error) {\n if (error instanceof Error && \"code\" in error && error.code === \"ENOENT\") {\n return Right(Option<string>(undefined))\n }\n return Left(toFsError(p, \"readFileOptSync\", error))\n }\n },\n\n statSync: (p: string): Either<FsError, FileInfo> => {\n try {\n return Right(toFileInfo(fsSync.statSync(p)))\n } catch (error) {\n return Left(toFsError(p, \"statSync\", error))\n }\n },\n\n copyFileSync: (src: string, dest: string): Either<FsError, void> => {\n try {\n fsSync.copyFileSync(src, dest)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(src, \"copyFileSync\", error))\n }\n },\n\n renameSync: (oldPath: string, newPath: string): Either<FsError, void> => {\n try {\n fsSync.renameSync(oldPath, newPath)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(oldPath, \"renameSync\", error))\n }\n },\n\n readdirSync: (p: string): Either<FsError, List<string>> => {\n try {\n return Right(List(fsSync.readdirSync(p)))\n } catch (error) {\n return Left(toFsError(p, \"readdirSync\", error))\n }\n },\n\n writeFileSync: (p: string, data: string, encoding: BufferEncoding = \"utf8\"): Either<FsError, void> => {\n try {\n fsSync.writeFileSync(p, data, { encoding })\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(p, \"writeFileSync\", error))\n }\n },\n\n mkdirSync: (p: string, options?: { recursive?: boolean }): Either<FsError, void> => {\n try {\n fsSync.mkdirSync(p, options)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(p, \"mkdirSync\", error))\n }\n },\n\n unlink: async (p: string): TaskResult<void> => {\n try {\n await fs.unlink(p)\n return Ok(undefined as void)\n } catch (error) {\n return Err(toFsError(p, \"unlink\", error))\n }\n },\n\n unlinkSync: (p: string): Either<FsError, void> => {\n try {\n fsSync.unlinkSync(p)\n return Right(undefined as void)\n } catch (error) {\n return Left(toFsError(p, \"unlinkSync\", error))\n }\n },\n}\n"],"mappings":"6LAmBA,MAAM,EAAc,IAAmC,CACrD,KAAM,EAAM,KACZ,OAAQ,EAAM,QAAQ,CACtB,YAAa,EAAM,aAAa,CAChC,eAAgB,EAAM,gBAAgB,CACtC,UAAW,EAAM,UACjB,WAAY,EAAM,MAClB,WAAY,EAAM,MAClB,YAAa,EAAM,KACpB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I,CAEF,OADA,MAAM,EAAG,OAAO,EAAE,CACX,EAAG,IAAA,GAAkB,OACrB,EAAO,CACd,OAAO,EAAI,EAAU,EAAG,SAAU,EAAM,CAAC,GAI7C,WAAa,GAAqC,CAChD,GAAI,CAEF,OADA,EAAO,WAAW,EAAE,CACb,EAAM,IAAA,GAAkB,OACxB,EAAO,CACd,OAAO,EAAK,EAAU,EAAG,aAAc,EAAM,CAAC,GAGnD"}
|
package/dist/fs/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Fs } from "./Fs.js";
|
|
2
|
-
export { Fs };
|
|
1
|
+
import { FileInfo, Fs } from "./Fs.js";
|
|
2
|
+
export { type FileInfo, Fs };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { ConfigError, EnvError, FsError, OsError, PathError } from "./errors/errors.js";
|
|
1
|
+
import { ConfigError, EnvError, FsError, OsError, PathError, ProcessError } from "./errors/errors.js";
|
|
2
2
|
import { ConfigResolver } from "./config/ConfigResolver.js";
|
|
3
3
|
import { Env } from "./env/Env.js";
|
|
4
|
-
import { Fs } from "./fs/Fs.js";
|
|
4
|
+
import { FileInfo, Fs } from "./fs/Fs.js";
|
|
5
5
|
import { Path, expandPath, expandTilde, expandVars } from "./path/PathExpander.js";
|
|
6
|
-
import { Platform, UserInfo } from "./platform/Platform.js";
|
|
7
|
-
|
|
6
|
+
import { CloudProvider, CloudStorageDir, Platform, UserInfo } from "./platform/Platform.js";
|
|
7
|
+
import { ExecResult, Process } from "./process/Process.js";
|
|
8
|
+
export { type CloudProvider, type CloudStorageDir, ConfigError, ConfigResolver, Env, EnvError, type ExecResult, type FileInfo, Fs, FsError, type OsError, Path, PathError, Platform, Process, ProcessError, type UserInfo, expandPath, expandTilde, expandVars };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ConfigError as e,EnvError as t,FsError as n,PathError as r}from"./errors/errors.js";import{Fs as
|
|
1
|
+
import{ConfigError as e,EnvError as t,FsError as n,PathError as r,ProcessError as i}from"./errors/errors.js";import{Fs as a}from"./fs/Fs.js";import{Path as o,expandPath as s,expandTilde as c,expandVars as l}from"./path/PathExpander.js";import{ConfigResolver as u}from"./config/ConfigResolver.js";import"./config/index.js";import{Env as d}from"./env/Env.js";import"./env/index.js";import"./fs/index.js";import"./path/index.js";import{Platform as f}from"./platform/Platform.js";import"./platform/index.js";import{Process as p}from"./process/Process.js";import"./process/index.js";export{e as ConfigError,u as ConfigResolver,d as Env,t as EnvError,a as Fs,n as FsError,o as Path,r as PathError,f as Platform,p as Process,i as ProcessError,s as expandPath,c as expandTilde,l as expandVars};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Option } from "functype";
|
|
1
|
+
import { List, Option } from "functype";
|
|
2
2
|
|
|
3
3
|
//#region src/platform/Platform.d.ts
|
|
4
4
|
type UserInfo = {
|
|
@@ -8,6 +8,12 @@ type UserInfo = {
|
|
|
8
8
|
readonly shell: string | null;
|
|
9
9
|
readonly homedir: string;
|
|
10
10
|
};
|
|
11
|
+
type CloudProvider = "onedrive" | "gdrive" | "dropbox" | "icloud";
|
|
12
|
+
type CloudStorageDir = {
|
|
13
|
+
readonly provider: CloudProvider;
|
|
14
|
+
readonly path: string;
|
|
15
|
+
readonly label: string;
|
|
16
|
+
};
|
|
11
17
|
declare const Platform: {
|
|
12
18
|
os: () => "darwin" | "linux" | "win32" | string;
|
|
13
19
|
arch: () => string;
|
|
@@ -25,7 +31,10 @@ declare const Platform: {
|
|
|
25
31
|
isWSL: () => boolean;
|
|
26
32
|
isCI: () => boolean;
|
|
27
33
|
isContainer: () => boolean;
|
|
34
|
+
windowsHomeDir: () => Option<string>;
|
|
35
|
+
homeDirs: () => List<string>;
|
|
36
|
+
cloudStorageDirs: (home?: string) => List<CloudStorageDir>;
|
|
28
37
|
};
|
|
29
38
|
//#endregion
|
|
30
|
-
export { Platform, UserInfo };
|
|
39
|
+
export { CloudProvider, CloudStorageDir, Platform, UserInfo };
|
|
31
40
|
//# sourceMappingURL=Platform.d.ts.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{Option as
|
|
1
|
+
import{List as e,Option as t}from"functype";import*as n from"node:fs";import*as r from"node:os";import*as i from"node:path";import{execSync as a}from"node:child_process";const o=()=>{try{return n.statSync(`/.dockerenv`),!0}catch{return!1}},s=()=>{try{return n.readFileSync(`/proc/self/cgroup`,`utf8`).includes(`docker`)}catch{return!1}},c=e=>{let t={};return()=>(`value`in t||(t.value=e()),t.value)},l=c(()=>o()||s()),u=c(()=>{try{return n.readFileSync(`/proc/self/cgroup`,`utf8`).includes(`kube`)}catch{return!1}}),d=c(()=>{try{let e=n.readFileSync(`/proc/version`,`utf8`);return e.includes(`Microsoft`)||e.includes(`WSL`)}catch{return!1}}),f=c(()=>process.env.CI!==void 0||process.env.GITHUB_ACTIONS!==void 0||process.env.GITLAB_CI!==void 0||process.env.CIRCLECI!==void 0||process.env.JENKINS_URL!==void 0||process.env.TRAVIS!==void 0||process.env.BUILDKITE!==void 0),p=new Set([`all users`,`default`,`default user`,`public`]),m=e=>{let t=e.toLowerCase();return!!(p.has(t)||t.startsWith(`defaultuser`)||t.startsWith(`desktop.`)||t.startsWith(`wsiaccount`))},h=e=>{try{return n.statSync(e).isDirectory()}catch{return!1}},g=e=>{try{return n.readdirSync(e).filter(t=>!m(t)&&h(i.join(e,t)))}catch{return}},_=(e,n)=>{try{let e=a(`cmd.exe /c echo %USERPROFILE%`,{timeout:3e3,encoding:`utf8`}).trim().match(/^([A-Za-z]):\\(.*)$/);if(e){let n=`/mnt/${e[1].toLowerCase()}/${e[2].replace(/\\/g,`/`)}`;if(h(n))return t(n)}}catch{}return t(n)},v=c(()=>{if(!d())return t(void 0);let e=`/mnt/c/Users`,n=g(e);return n===void 0?t(void 0):n.length===1?t(i.join(e,n[0])):n.length>1?_(e,i.join(e,n[0])):t(void 0)}),y=e=>{if(e===`OneDrive`||e.startsWith(`OneDrive `)||e.startsWith(`OneDrive-`))return{provider:`onedrive`,label:e};if(e===`Google Drive`)return{provider:`gdrive`,label:e};if(e===`Dropbox`)return{provider:`dropbox`,label:e}},b=e=>{let t=[];try{let r=n.readdirSync(e);for(let n of r){let r=i.join(e,n),a=y(n);a&&h(r)&&t.push({provider:a.provider,path:r,label:a.label})}}catch{}let r=i.join(e,`Library`,`CloudStorage`);try{let e=n.readdirSync(r);for(let n of e){let e=i.join(r,n);h(e)&&(n.startsWith(`OneDrive`)?t.push({provider:`onedrive`,path:e,label:n}):n.startsWith(`GoogleDrive`)&&t.push({provider:`gdrive`,path:e,label:n}))}}catch{}let a=i.join(e,`Library`,`Mobile Documents`,`com~apple~CloudDocs`);return h(a)&&t.push({provider:`icloud`,path:a,label:`iCloud Drive`}),t},x={os:()=>process.platform,arch:()=>process.arch,homeDir:()=>r.homedir(),tmpDir:()=>r.tmpdir(),hostname:()=>r.hostname(),eol:()=>r.EOL,pathSep:()=>i.sep,isWindows:()=>process.platform===`win32`,isMac:()=>process.platform===`darwin`,isLinux:()=>process.platform===`linux`,userInfo:()=>{try{let e=r.userInfo();return t({username:e.username,uid:e.uid,gid:e.gid,shell:e.shell,homedir:e.homedir})}catch{return t(void 0)}},isDocker:()=>l(),isKubernetes:()=>u(),isWSL:()=>d(),isCI:()=>f(),isContainer:()=>x.isDocker()||x.isKubernetes(),windowsHomeDir:()=>v(),homeDirs:()=>{let t=[r.homedir()];return x.windowsHomeDir().forEach(e=>{e!==r.homedir()&&t.push(e)}),e(t)},cloudStorageDirs:t=>{if(t!==void 0)return e(b(t));let n=[],r=new Set;return x.homeDirs().forEach(e=>{for(let t of b(e))r.has(t.path)||(r.add(t.path),n.push(t))}),e(n)}};export{x as Platform};
|
|
2
2
|
//# sourceMappingURL=Platform.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Platform.js","names":[],"sources":["../../src/platform/Platform.ts"],"sourcesContent":["import * as fs from \"node:fs\"\nimport * as os from \"node:os\"\nimport * as path from \"node:path\"\n\nimport { Option } from \"functype\"\n\nexport type UserInfo = {\n readonly username: string\n readonly uid: number\n readonly gid: number\n readonly shell: string | null\n readonly homedir: string\n}\n\nconst hasDockerEnv = (): boolean => {\n try {\n fs.statSync(\"/.dockerenv\")\n return true\n } catch {\n return false\n }\n}\nconst hasDockerCGroup = (): boolean => {\n try {\n return fs.readFileSync(\"/proc/self/cgroup\", \"utf8\").includes(\"docker\")\n } catch {\n return false\n }\n}\n\nconst memo = <T>(fn: () => T): (() => T) => {\n const cache: { value?: T } = {}\n return () => {\n if (!(\"value\" in cache)) {\n cache.value = fn()\n }\n return cache.value as T\n }\n}\n\nconst cachedIsDocker = memo(() => hasDockerEnv() || hasDockerCGroup())\nconst cachedIsKube = memo(() => {\n try {\n return fs.readFileSync(\"/proc/self/cgroup\", \"utf8\").includes(\"kube\")\n } catch {\n return false\n }\n})\nconst cachedIsWSL = memo(() => {\n try {\n const version = fs.readFileSync(\"/proc/version\", \"utf8\")\n return version.includes(\"Microsoft\") || version.includes(\"WSL\")\n } catch {\n return false\n }\n})\nconst cachedIsCI = memo(\n () =>\n process.env[\"CI\"] !== undefined ||\n process.env[\"GITHUB_ACTIONS\"] !== undefined ||\n process.env[\"GITLAB_CI\"] !== undefined ||\n process.env[\"CIRCLECI\"] !== undefined ||\n process.env[\"JENKINS_URL\"] !== undefined ||\n process.env[\"TRAVIS\"] !== undefined ||\n process.env[\"BUILDKITE\"] !== undefined,\n)\n\nexport const Platform = {\n os: (): \"darwin\" | \"linux\" | \"win32\" | string => process.platform,\n arch: (): string => process.arch,\n homeDir: (): string => os.homedir(),\n tmpDir: (): string => os.tmpdir(),\n hostname: (): string => os.hostname(),\n eol: (): string => os.EOL,\n pathSep: (): string => path.sep,\n\n isWindows: (): boolean => process.platform === \"win32\",\n isMac: (): boolean => process.platform === \"darwin\",\n isLinux: (): boolean => process.platform === \"linux\",\n\n userInfo: (): Option<UserInfo> => {\n try {\n const info = os.userInfo()\n return Option({\n username: info.username,\n uid: info.uid,\n gid: info.gid,\n shell: info.shell,\n homedir: info.homedir,\n })\n } catch {\n return Option<UserInfo>(undefined)\n }\n },\n\n isDocker: (): boolean => cachedIsDocker(),\n isKubernetes: (): boolean => cachedIsKube(),\n isWSL: (): boolean => cachedIsWSL(),\n isCI: (): boolean => cachedIsCI(),\n\n isContainer: (): boolean => Platform.isDocker() || Platform.isKubernetes(),\n}\n"],"mappings":"kHAcA,MAAM,MAA8B,CAClC,GAAI,CAEF,OADA,EAAG,SAAS,cAAc,CACnB,QACD,CACN,MAAO,KAGL,MAAiC,CACrC,GAAI,CACF,OAAO,EAAG,aAAa,oBAAqB,OAAO,CAAC,SAAS,SAAS,MAChE,CACN,MAAO,KAIL,EAAW,GAA2B,CAC1C,IAAM,EAAuB,EAAE,CAC/B,WACQ,UAAW,IACf,EAAM,MAAQ,GAAI,EAEb,EAAM,QAIX,EAAiB,MAAW,GAAc,EAAI,GAAiB,CAAC,CAChE,EAAe,MAAW,CAC9B,GAAI,CACF,OAAO,EAAG,aAAa,oBAAqB,OAAO,CAAC,SAAS,OAAO,MAC9D,CACN,MAAO,KAET,CACI,EAAc,MAAW,CAC7B,GAAI,CACF,IAAM,EAAU,EAAG,aAAa,gBAAiB,OAAO,CACxD,OAAO,EAAQ,SAAS,YAAY,EAAI,EAAQ,SAAS,MAAM,MACzD,CACN,MAAO,KAET,CACI,EAAa,MAEf,QAAQ,IAAI,KAAU,IAAA,IACtB,QAAQ,IAAI,iBAAsB,IAAA,IAClC,QAAQ,IAAI,YAAiB,IAAA,IAC7B,QAAQ,IAAI,WAAgB,IAAA,IAC5B,QAAQ,IAAI,cAAmB,IAAA,IAC/B,QAAQ,IAAI,SAAc,IAAA,IAC1B,QAAQ,IAAI,YAAiB,IAAA,GAChC,CAEY,EAAW,CACtB,OAAiD,QAAQ,SACzD,SAAoB,QAAQ,KAC5B,YAAuB,EAAG,SAAS,CACnC,WAAsB,EAAG,QAAQ,CACjC,aAAwB,EAAG,UAAU,CACrC,QAAmB,EAAG,IACtB,YAAuB,EAAK,IAE5B,cAA0B,QAAQ,WAAa,QAC/C,UAAsB,QAAQ,WAAa,SAC3C,YAAwB,QAAQ,WAAa,QAE7C,aAAkC,CAChC,GAAI,CACF,IAAM,EAAO,EAAG,UAAU,CAC1B,OAAO,EAAO,CACZ,SAAU,EAAK,SACf,IAAK,EAAK,IACV,IAAK,EAAK,IACV,MAAO,EAAK,MACZ,QAAS,EAAK,QACf,CAAC,MACI,CACN,OAAO,EAAiB,IAAA,GAAU,GAItC,aAAyB,GAAgB,CACzC,iBAA6B,GAAc,CAC3C,UAAsB,GAAa,CACnC,SAAqB,GAAY,CAEjC,gBAA4B,EAAS,UAAU,EAAI,EAAS,cAAc,CAC3E"}
|
|
1
|
+
{"version":3,"file":"Platform.js","names":[],"sources":["../../src/platform/Platform.ts"],"sourcesContent":["import { execSync } from \"node:child_process\"\nimport * as fs from \"node:fs\"\nimport * as os from \"node:os\"\nimport * as path from \"node:path\"\n\nimport { List, Option } from \"functype\"\n\nexport type UserInfo = {\n readonly username: string\n readonly uid: number\n readonly gid: number\n readonly shell: string | null\n readonly homedir: string\n}\n\nexport type CloudProvider = \"onedrive\" | \"gdrive\" | \"dropbox\" | \"icloud\"\n\nexport type CloudStorageDir = {\n readonly provider: CloudProvider\n readonly path: string\n readonly label: string\n}\n\nconst hasDockerEnv = (): boolean => {\n try {\n fs.statSync(\"/.dockerenv\")\n return true\n } catch {\n return false\n }\n}\nconst hasDockerCGroup = (): boolean => {\n try {\n return fs.readFileSync(\"/proc/self/cgroup\", \"utf8\").includes(\"docker\")\n } catch {\n return false\n }\n}\n\nconst memo = <T>(fn: () => T): (() => T) => {\n const cache: { value?: T } = {}\n return () => {\n if (!(\"value\" in cache)) {\n cache.value = fn()\n }\n return cache.value as T\n }\n}\n\nconst cachedIsDocker = memo(() => hasDockerEnv() || hasDockerCGroup())\nconst cachedIsKube = memo(() => {\n try {\n return fs.readFileSync(\"/proc/self/cgroup\", \"utf8\").includes(\"kube\")\n } catch {\n return false\n }\n})\nconst cachedIsWSL = memo(() => {\n try {\n const version = fs.readFileSync(\"/proc/version\", \"utf8\")\n return version.includes(\"Microsoft\") || version.includes(\"WSL\")\n } catch {\n return false\n }\n})\nconst cachedIsCI = memo(\n () =>\n process.env[\"CI\"] !== undefined ||\n process.env[\"GITHUB_ACTIONS\"] !== undefined ||\n process.env[\"GITLAB_CI\"] !== undefined ||\n process.env[\"CIRCLECI\"] !== undefined ||\n process.env[\"JENKINS_URL\"] !== undefined ||\n process.env[\"TRAVIS\"] !== undefined ||\n process.env[\"BUILDKITE\"] !== undefined,\n)\n\nconst SYSTEM_ACCOUNTS = new Set([\"all users\", \"default\", \"default user\", \"public\"])\n\nconst isSystemAccount = (name: string): boolean => {\n const lower = name.toLowerCase()\n if (SYSTEM_ACCOUNTS.has(lower)) return true\n if (lower.startsWith(\"defaultuser\") || lower.startsWith(\"desktop.\") || lower.startsWith(\"wsiaccount\")) return true\n return false\n}\n\nconst isDirectory = (p: string): boolean => {\n try {\n return fs.statSync(p).isDirectory()\n } catch {\n return false\n }\n}\n\nconst readRealUsers = (usersDir: string): readonly string[] | undefined => {\n try {\n const entries = fs.readdirSync(usersDir)\n return entries.filter((name) => !isSystemAccount(name) && isDirectory(path.join(usersDir, name)))\n } catch {\n return undefined\n }\n}\n\nconst resolveViaCmdExe = (usersDir: string, fallback: string): Option<string> => {\n try {\n const raw = execSync(\"cmd.exe /c echo %USERPROFILE%\", { timeout: 3000, encoding: \"utf8\" }).trim()\n // Convert Windows path C:\\Users\\foo → /mnt/c/Users/foo\n const match = raw.match(/^([A-Za-z]):\\\\(.*)$/)\n if (match) {\n const drive = match[1].toLowerCase()\n const rest = match[2].replace(/\\\\/g, \"/\")\n const wslPath = `/mnt/${drive}/${rest}`\n if (isDirectory(wslPath)) {\n return Option(wslPath)\n }\n }\n } catch {\n // cmd.exe failed, fall through to best guess\n }\n return Option(fallback)\n}\n\nconst resolveWindowsHome = (): Option<string> => {\n if (!cachedIsWSL()) return Option<string>(undefined)\n\n const usersDir = \"/mnt/c/Users\"\n const realUsers = readRealUsers(usersDir)\n if (realUsers === undefined) return Option<string>(undefined)\n\n if (realUsers.length === 1) {\n return Option(path.join(usersDir, realUsers[0]))\n }\n\n if (realUsers.length > 1) {\n return resolveViaCmdExe(usersDir, path.join(usersDir, realUsers[0]))\n }\n\n return Option<string>(undefined)\n}\n\nconst cachedWindowsHome = memo(resolveWindowsHome)\n\nconst detectCloudProvider = (name: string): { provider: CloudProvider; label: string } | undefined => {\n if (name === \"OneDrive\" || name.startsWith(\"OneDrive \") || name.startsWith(\"OneDrive-\")) {\n return { provider: \"onedrive\", label: name }\n }\n if (name === \"Google Drive\") {\n return { provider: \"gdrive\", label: name }\n }\n if (name === \"Dropbox\") {\n return { provider: \"dropbox\", label: name }\n }\n return undefined\n}\n\nconst scanCloudStorageDirs = (home: string): CloudStorageDir[] => {\n const results: CloudStorageDir[] = []\n\n // Direct home children\n try {\n const entries = fs.readdirSync(home)\n for (const name of entries) {\n const fullPath = path.join(home, name)\n const detection = detectCloudProvider(name)\n if (detection && isDirectory(fullPath)) {\n results.push({ provider: detection.provider, path: fullPath, label: detection.label })\n }\n }\n } catch {\n // home dir may not exist or be readable\n }\n\n // macOS Library/CloudStorage children\n const cloudStoragePath = path.join(home, \"Library\", \"CloudStorage\")\n try {\n const entries = fs.readdirSync(cloudStoragePath)\n for (const name of entries) {\n const fullPath = path.join(cloudStoragePath, name)\n if (!isDirectory(fullPath)) continue\n if (name.startsWith(\"OneDrive\")) {\n results.push({ provider: \"onedrive\", path: fullPath, label: name })\n } else if (name.startsWith(\"GoogleDrive\")) {\n results.push({ provider: \"gdrive\", path: fullPath, label: name })\n }\n }\n } catch {\n // Library/CloudStorage may not exist\n }\n\n // macOS iCloud fixed path\n const icloudPath = path.join(home, \"Library\", \"Mobile Documents\", \"com~apple~CloudDocs\")\n if (isDirectory(icloudPath)) {\n results.push({ provider: \"icloud\", path: icloudPath, label: \"iCloud Drive\" })\n }\n\n return results\n}\n\nexport const Platform = {\n os: (): \"darwin\" | \"linux\" | \"win32\" | string => process.platform,\n arch: (): string => process.arch,\n homeDir: (): string => os.homedir(),\n tmpDir: (): string => os.tmpdir(),\n hostname: (): string => os.hostname(),\n eol: (): string => os.EOL,\n pathSep: (): string => path.sep,\n\n isWindows: (): boolean => process.platform === \"win32\",\n isMac: (): boolean => process.platform === \"darwin\",\n isLinux: (): boolean => process.platform === \"linux\",\n\n userInfo: (): Option<UserInfo> => {\n try {\n const info = os.userInfo()\n return Option({\n username: info.username,\n uid: info.uid,\n gid: info.gid,\n shell: info.shell,\n homedir: info.homedir,\n })\n } catch {\n return Option<UserInfo>(undefined)\n }\n },\n\n isDocker: (): boolean => cachedIsDocker(),\n isKubernetes: (): boolean => cachedIsKube(),\n isWSL: (): boolean => cachedIsWSL(),\n isCI: (): boolean => cachedIsCI(),\n\n isContainer: (): boolean => Platform.isDocker() || Platform.isKubernetes(),\n\n windowsHomeDir: (): Option<string> => cachedWindowsHome(),\n\n homeDirs: (): List<string> => {\n const homes: string[] = [os.homedir()]\n Platform.windowsHomeDir().forEach((winHome) => {\n if (winHome !== os.homedir()) {\n homes.push(winHome)\n }\n })\n return List(homes)\n },\n\n cloudStorageDirs: (home?: string): List<CloudStorageDir> => {\n if (home !== undefined) {\n return List(scanCloudStorageDirs(home))\n }\n const allDirs: CloudStorageDir[] = []\n const seenPaths = new Set<string>()\n Platform.homeDirs().forEach((h) => {\n for (const dir of scanCloudStorageDirs(h)) {\n if (!seenPaths.has(dir.path)) {\n seenPaths.add(dir.path)\n allDirs.push(dir)\n }\n }\n })\n return List(allDirs)\n },\n}\n"],"mappings":"0KAuBA,MAAM,MAA8B,CAClC,GAAI,CAEF,OADA,EAAG,SAAS,cAAc,CACnB,QACD,CACN,MAAO,KAGL,MAAiC,CACrC,GAAI,CACF,OAAO,EAAG,aAAa,oBAAqB,OAAO,CAAC,SAAS,SAAS,MAChE,CACN,MAAO,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,EAGpB,iBAAmB,GAAyC,CAC1D,GAAI,IAAS,IAAA,GACX,OAAO,EAAK,EAAqB,EAAK,CAAC,CAEzC,IAAM,EAA6B,EAAE,CAC/B,EAAY,IAAI,IAStB,OARA,EAAS,UAAU,CAAC,QAAS,GAAM,CACjC,IAAK,IAAM,KAAO,EAAqB,EAAE,CAClC,EAAU,IAAI,EAAI,KAAK,GAC1B,EAAU,IAAI,EAAI,KAAK,CACvB,EAAQ,KAAK,EAAI,GAGrB,CACK,EAAK,EAAQ,EAEvB"}
|
package/dist/platform/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Platform, UserInfo } from "./Platform.js";
|
|
2
|
-
export { Platform, type UserInfo };
|
|
1
|
+
import { CloudProvider, CloudStorageDir, Platform, UserInfo } from "./Platform.js";
|
|
2
|
+
export { type CloudProvider, type CloudStorageDir, Platform, type UserInfo };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ProcessError } from "../errors/errors.js";
|
|
2
|
+
import { Either, TaskResult } from "functype";
|
|
3
|
+
|
|
4
|
+
//#region src/process/Process.d.ts
|
|
5
|
+
type ExecResult = {
|
|
6
|
+
readonly stdout: string;
|
|
7
|
+
readonly stderr: string;
|
|
8
|
+
readonly exitCode: number;
|
|
9
|
+
};
|
|
10
|
+
declare const Process: {
|
|
11
|
+
exec: (command: string, options?: {
|
|
12
|
+
timeout?: number;
|
|
13
|
+
cwd?: string;
|
|
14
|
+
}) => TaskResult<ExecResult>;
|
|
15
|
+
execSync: (command: string, options?: {
|
|
16
|
+
timeout?: number;
|
|
17
|
+
cwd?: string;
|
|
18
|
+
}) => Either<ProcessError, ExecResult>;
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { ExecResult, Process };
|
|
22
|
+
//# sourceMappingURL=Process.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{ProcessError as e}from"../errors/errors.js";import{Err as t,Left as n,Ok as r,Right as i}from"functype";import{exec as a,execSync as o}from"node:child_process";const s={exec:(n,i)=>new Promise(o=>{a(n,{timeout:i?.timeout,cwd:i?.cwd},(i,a,s)=>{o(i?t(e(n,typeof i.code==`number`?i.code:null,String(s))):r({stdout:String(a),stderr:String(s),exitCode:0}))})}),execSync:(t,r)=>{try{let e=o(t,{timeout:r?.timeout,cwd:r?.cwd,encoding:`utf8`,stdio:[`pipe`,`pipe`,`pipe`]});return i({stdout:String(e),stderr:``,exitCode:0})}catch(r){if(r instanceof Error&&`status`in r&&`stderr`in r){let i=r;return n(e(t,i.status,String(i.stderr)))}return n(e(t,null,``,r instanceof Error?r.message:String(r)))}}};export{s as Process};
|
|
2
|
+
//# sourceMappingURL=Process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Process.js","names":["nodeExecSync"],"sources":["../../src/process/Process.ts"],"sourcesContent":["import { exec as execCb, execSync as nodeExecSync } from \"node:child_process\"\n\nimport type { Either, TaskResult } from \"functype\"\nimport { Err, Left, Ok, Right } from \"functype\"\n\nimport { ProcessError } from \"../errors/errors\"\n\nexport type ExecResult = {\n readonly stdout: string\n readonly stderr: string\n readonly exitCode: number\n}\n\nexport const Process = {\n exec: (command: string, options?: { timeout?: number; cwd?: string }): TaskResult<ExecResult> => {\n return new Promise((resolve) => {\n execCb(command, { timeout: options?.timeout, cwd: options?.cwd }, (error, stdout, stderr) => {\n if (error) {\n // exec callback error has `code` as exit code (number) — distinct from Node errno `code` (string)\n const exitCode = typeof error.code === \"number\" ? error.code : null\n resolve(Err(ProcessError(command, exitCode, String(stderr))))\n } else {\n resolve(Ok({ stdout: String(stdout), stderr: String(stderr), exitCode: 0 }))\n }\n })\n })\n },\n\n execSync: (command: string, options?: { timeout?: number; cwd?: string }): Either<ProcessError, ExecResult> => {\n try {\n const stdout = nodeExecSync(command, {\n timeout: options?.timeout,\n cwd: options?.cwd,\n encoding: \"utf8\",\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n })\n return Right({ stdout: String(stdout), stderr: \"\", exitCode: 0 })\n } catch (error) {\n if (error instanceof Error && \"status\" in error && \"stderr\" in error) {\n const execError = error as Error & { status: number; stderr: string }\n return Left(ProcessError(command, execError.status, String(execError.stderr)))\n }\n return Left(ProcessError(command, null, \"\", error instanceof Error ? error.message : String(error)))\n }\n },\n}\n"],"mappings":"uKAaA,MAAa,EAAU,CACrB,MAAO,EAAiB,IACf,IAAI,QAAS,GAAY,CAC9B,EAAO,EAAS,CAAE,QAAS,GAAS,QAAS,IAAK,GAAS,IAAK,EAAG,EAAO,EAAQ,IAAW,CAIzF,EAHE,EAGM,EAAI,EAAa,EADR,OAAO,EAAM,MAAS,SAAW,EAAM,KAAO,KACnB,OAAO,EAAO,CAAC,CAAC,CAEpD,EAAG,CAAE,OAAQ,OAAO,EAAO,CAAE,OAAQ,OAAO,EAAO,CAAE,SAAU,EAAG,CAAC,CAAC,EAE9E,EACF,CAGJ,UAAW,EAAiB,IAAmF,CAC7G,GAAI,CACF,IAAM,EAASA,EAAa,EAAS,CACnC,QAAS,GAAS,QAClB,IAAK,GAAS,IACd,SAAU,OACV,MAAO,CAAC,OAAQ,OAAQ,OAAO,CAChC,CAAC,CACF,OAAO,EAAM,CAAE,OAAQ,OAAO,EAAO,CAAE,OAAQ,GAAI,SAAU,EAAG,CAAC,OAC1D,EAAO,CACd,GAAI,aAAiB,OAAS,WAAY,GAAS,WAAY,EAAO,CACpE,IAAM,EAAY,EAClB,OAAO,EAAK,EAAa,EAAS,EAAU,OAAQ,OAAO,EAAU,OAAO,CAAC,CAAC,CAEhF,OAAO,EAAK,EAAa,EAAS,KAAM,GAAI,aAAiB,MAAQ,EAAM,QAAU,OAAO,EAAM,CAAC,CAAC,GAGzG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Process as e}from"./Process.js";export{e as Process};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "functype-os",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Functional OS utilities using functype data structures — env vars, path expansion, file ops, platform detection",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"functype",
|
|
@@ -18,16 +18,30 @@
|
|
|
18
18
|
"type": "git",
|
|
19
19
|
"url": "https://github.com/jordanburke/functype-os"
|
|
20
20
|
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"validate": "ts-builds validate",
|
|
23
|
+
"format": "ts-builds format",
|
|
24
|
+
"format:check": "ts-builds format:check",
|
|
25
|
+
"lint": "ts-builds lint",
|
|
26
|
+
"lint:check": "ts-builds lint:check",
|
|
27
|
+
"typecheck": "ts-builds typecheck",
|
|
28
|
+
"test": "ts-builds test",
|
|
29
|
+
"test:watch": "ts-builds test:watch",
|
|
30
|
+
"test:coverage": "ts-builds test:coverage",
|
|
31
|
+
"build": "ts-builds build",
|
|
32
|
+
"dev": "ts-builds dev",
|
|
33
|
+
"prepublishOnly": "pnpm validate"
|
|
34
|
+
},
|
|
21
35
|
"peerDependencies": {
|
|
22
36
|
"functype": ">=0.49.0"
|
|
23
37
|
},
|
|
24
38
|
"devDependencies": {
|
|
25
|
-
"@types/node": "^24.
|
|
39
|
+
"@types/node": "^24.12.0",
|
|
26
40
|
"eslint-config-prettier": "^10.1.8",
|
|
27
41
|
"functype": "^0.49.0",
|
|
28
|
-
"ts-builds": "^2.5.
|
|
42
|
+
"ts-builds": "^2.5.2",
|
|
29
43
|
"tsdown": "^0.20.3",
|
|
30
|
-
"vitest": "^4.0
|
|
44
|
+
"vitest": "^4.1.0"
|
|
31
45
|
},
|
|
32
46
|
"type": "module",
|
|
33
47
|
"main": "./dist/index.js",
|
|
@@ -68,6 +82,11 @@
|
|
|
68
82
|
"types": "./dist/errors/index.d.ts",
|
|
69
83
|
"import": "./dist/errors/index.js",
|
|
70
84
|
"default": "./dist/errors/index.js"
|
|
85
|
+
},
|
|
86
|
+
"./process": {
|
|
87
|
+
"types": "./dist/process/index.d.ts",
|
|
88
|
+
"import": "./dist/process/index.js",
|
|
89
|
+
"default": "./dist/process/index.js"
|
|
71
90
|
}
|
|
72
91
|
},
|
|
73
92
|
"files": [
|
|
@@ -75,20 +94,8 @@
|
|
|
75
94
|
"dist"
|
|
76
95
|
],
|
|
77
96
|
"prettier": "ts-builds/prettier",
|
|
97
|
+
"packageManager": "pnpm@10.32.1+sha512.a706938f0e89ac1456b6563eab4edf1d1faf3368d1191fc5c59790e96dc918e4456ab2e67d613de1043d2e8c81f87303e6b40d4ffeca9df15ef1ad567348f2be",
|
|
78
98
|
"engines": {
|
|
79
|
-
"node": ">=18.
|
|
80
|
-
},
|
|
81
|
-
"scripts": {
|
|
82
|
-
"validate": "ts-builds validate",
|
|
83
|
-
"format": "ts-builds format",
|
|
84
|
-
"format:check": "ts-builds format:check",
|
|
85
|
-
"lint": "ts-builds lint",
|
|
86
|
-
"lint:check": "ts-builds lint:check",
|
|
87
|
-
"typecheck": "ts-builds typecheck",
|
|
88
|
-
"test": "ts-builds test",
|
|
89
|
-
"test:watch": "ts-builds test:watch",
|
|
90
|
-
"test:coverage": "ts-builds test:coverage",
|
|
91
|
-
"build": "ts-builds build",
|
|
92
|
-
"dev": "ts-builds dev"
|
|
99
|
+
"node": ">=18.17.0"
|
|
93
100
|
}
|
|
94
|
-
}
|
|
101
|
+
}
|