@visulima/package 1.2.8 → 1.2.10

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## @visulima/package [1.2.10](https://github.com/visulima/visulima/compare/@visulima/package@1.2.9...@visulima/package@1.2.10) (2024-03-11)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **package:** updated get-tsconfig ([d8d3169](https://github.com/visulima/visulima/commit/d8d31691d16b1640019ec20176560f44f903c4cf))
7
+
8
+ ## @visulima/package [1.2.9](https://github.com/visulima/visulima/compare/@visulima/package@1.2.8...@visulima/package@1.2.9) (2024-03-07)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **package:** added missing PackageJson type export ([06e1c50](https://github.com/visulima/visulima/commit/06e1c50c269ba034df7ab319e30b33342a1a810f))
14
+
1
15
  ## @visulima/package [1.2.8](https://github.com/visulima/visulima/compare/@visulima/package@1.2.7...@visulima/package@1.2.8) (2024-03-04)
2
16
 
3
17
 
@@ -1,6 +1,6 @@
1
- import { fileURLToPath } from 'url';
2
- import { existsSync } from 'fs';
3
- import { writeFile, readFile } from 'fs/promises';
1
+ import { fileURLToPath } from 'node:url';
2
+ import { existsSync } from 'node:fs';
3
+ import { writeFile, readFile } from 'node:fs/promises';
4
4
  import m from 'detect-indent';
5
5
 
6
6
  var l=e=>e instanceof URL?fileURLToPath(e):e,w=l;var p=async(e,n)=>{let t=existsSync(e)?await readFile(e,"utf8"):void 0,i=n.indent??(t?m(t).indent:2),r=n.newline===!0?`
@@ -11,4 +11,4 @@ var l=e=>e instanceof URL?fileURLToPath(e):e,w=l;var p=async(e,n)=>{let t=exists
11
11
 
12
12
  export { w as a, v as b };
13
13
  //# sourceMappingURL=out.js.map
14
- //# sourceMappingURL=chunk-C7FQQQI6.js.map
14
+ //# sourceMappingURL=chunk-5CE7NVS2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/to-path.ts","../src/utils/write-json.ts"],"names":["fileURLToPath","toPath","urlOrPath","to_path_default","existsSync","readFile","writeFile","detectIndent","resolveWriteOptions","path","options","file","indent","newline","writeJsonFile","data","resolvedOptions","content"],"mappings":"AAAA,OAAS,iBAAAA,MAAqB,WAE9B,IAAMC,EAAUC,GAAqCA,aAAqB,IAAMF,EAAcE,CAAS,EAAIA,EAEpGC,EAAQF,ECJf,OAAS,cAAAG,MAAkB,UAC3B,OAAS,YAAAC,EAAU,aAAAC,MAAiB,mBAEpC,OAAOC,MAAkB,gBAQzB,IAAMC,EAAsB,MAAOC,EAAcC,IAAyD,CAEtG,IAAMC,EAAOP,EAAWK,CAAI,EAAI,MAAMJ,EAASI,EAAM,MAAM,EAAI,OACzDG,EAASF,EAAQ,SAAWC,EAAOJ,EAAaI,CAAI,EAAE,OAAS,GAC/DE,EAAUH,EAAQ,UAAY,GAAO;AAAA,EAAOA,EAAQ,UAAY,GAAQ,GAAKA,EAAQ,UAAYC,EAAQA,EAAK,SAAS;AAAA,CAAI,EAAI;AAAA,EAAO,GAAM;AAAA,GAElJ,MAAO,CACH,OAAAC,EACA,QAAAC,CACJ,CACJ,EAQaC,EAAgB,MAAOL,EAAcM,EAAyCL,EAAwB,CAAC,IAAqB,CACrI,IAAMM,EAAkB,MAAMR,EAAoBC,EAAMC,CAAO,EAE3DO,EAAU,KAAK,UAAUF,EAAM,OAAWC,EAAgB,MAAM,EACpEC,GAAWD,EAAgB,QAG3B,MAAMV,EAAUG,EAAMQ,CAAO,CACjC","sourcesContent":["import { fileURLToPath } from \"node:url\";\n\nconst toPath = (urlOrPath: URL | string): string => (urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath);\n\nexport default toPath;\n","import { existsSync } from \"node:fs\";\nimport { readFile, writeFile } from \"node:fs/promises\";\n\nimport detectIndent from \"detect-indent\";\nimport type { PackageJson } from \"read-pkg\";\n\ntype ResolvedWriteOptions = {\n indent: number | string;\n newline: string;\n};\n\nconst resolveWriteOptions = async (path: string, options: WriteOptions): Promise<ResolvedWriteOptions> => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const file = existsSync(path) ? await readFile(path, \"utf8\") : undefined;\n const indent = options.indent ?? (file ? detectIndent(file).indent : 2);\n const newline = options.newline === true ? \"\\n\" : options.newline === false ? \"\" : options.newline ?? (file ? (file.endsWith(\"\\n\") ? \"\\n\" : \"\") : \"\\n\");\n\n return {\n indent,\n newline,\n };\n};\n\nexport type WriteOptions = {\n indent?: number | string;\n newline?: boolean | string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const writeJsonFile = async (path: string, data: PackageJson & Record<string, any>, options: WriteOptions = {}): Promise<void> => {\n const resolvedOptions = await resolveWriteOptions(path, options);\n\n let content = JSON.stringify(data, undefined, resolvedOptions.indent);\n content += resolvedOptions.newline;\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await writeFile(path, content);\n};\n"]}
@@ -1,6 +1,6 @@
1
- import { b } from './chunk-IWQKH4TN.js';
2
- import { readFileSync, existsSync } from 'fs';
3
- import { dirname, join } from 'path';
1
+ import { b } from './chunk-ZRX4WIQ4.js';
2
+ import { readFileSync, existsSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
4
  import { findUp } from 'find-up';
5
5
  import l from 'strip-json-comments';
6
6
 
@@ -8,4 +8,4 @@ var j=async e=>{let r=await findUp(["lerna.json","turbo.json"],{allowSymlinks:!1
8
8
 
9
9
  export { j as a };
10
10
  //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-T4PCL5Z7.js.map
11
+ //# sourceMappingURL=chunk-I2QN4KO5.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","dirname","join","findUp","stripJsonComments","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"wCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAG9B,OAAS,UAAAC,MAAc,UACvB,OAAOC,MAAuB,sBAsBvB,IAAMC,EAAmB,MAAOC,GAAgD,CACnF,IAAMC,EAAoB,MAAMJ,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,cAAe,GACf,KAAM,OACN,GAAIG,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAqBA,EAAkB,SAAS,YAAY,EAAG,CAE/D,IAAMC,EAAQ,KAAK,MAAMJ,EAAkBJ,EAAaO,EAAmB,MAAM,CAAC,CAAC,EAEnF,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAMP,EAAQM,CAAiB,EAC/B,SAAU,OACd,CAER,CAEA,IAAME,EAAUF,GAAqBA,EAAkB,SAAS,YAAY,EAE5E,GAAI,CACA,GAAM,CAAE,eAAAG,EAAgB,KAAAC,CAAK,EAAI,MAAMC,EAAmBN,CAAG,EAE7D,GAAI,CAAC,MAAO,MAAM,EAAE,SAASI,CAAc,EAAG,CAC1C,IAAMG,EAAsBX,EAAKS,EAAM,cAAc,EAGrD,GAAIZ,EAAWc,CAAmB,GAEVb,EAAaE,EAAKS,EAAM,cAAc,EAAG,MAAM,EAEnD,SAAS,YAAY,EACjC,MAAO,CACH,KAAAA,EACA,SAAUF,EAAU,QAAWC,CACnC,CAGZ,SAAWA,IAAmB,OAAQ,CAClC,IAAMI,EAAyBZ,EAAKS,EAAM,qBAAqB,EAG/D,GAAIZ,EAAWe,CAAsB,EACjC,MAAO,CACH,KAAAH,EACA,SAAUF,EAAU,QAAU,MAClC,CAER,CAEJ,OAASM,EAAY,CAGjB,GAAI,CAACA,EAAM,QAAQ,SAAS,0BAA0B,EAClD,MAAMA,CAEd,CAEA,MAAM,IAAI,MAAM,8DAA8DT,CAAa,iDAAiD,CAChJ","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport stripJsonComments from \"strip-json-comments\";\n\nimport { findPackageManager } from \"./package-manager\";\n\nexport type Strategy = \"lerna\" | \"npm\" | \"pnpm\" | \"turbo\" | \"yarn\";\n\nexport interface RootMonorepo<T extends Strategy = Strategy> {\n path: string;\n strategy: T;\n}\n\n/**\n * An asynchronous function to find the root directory path and strategy for a monorepo based on\n * the given current working directory (cwd).\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * Default is undefined.\n * @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.\n * The type of the returned promise is `Promise<RootMonorepo>`.\n * @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findMonorepoRoot = async (cwd?: Options[\"cwd\"]): Promise<RootMonorepo> => {\n const workspaceFilePath = await findUp([\"lerna.json\", \"turbo.json\"], {\n allowSymlinks: false,\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (workspaceFilePath && workspaceFilePath.endsWith(\"lerna.json\")) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const lerna = JSON.parse(stripJsonComments(readFileSync(workspaceFilePath, \"utf8\"))) as { packages?: string[]; useWorkspaces?: boolean };\n\n if (lerna.useWorkspaces || lerna.packages) {\n return {\n path: dirname(workspaceFilePath),\n strategy: \"lerna\",\n };\n }\n }\n\n const isTurbo = workspaceFilePath && workspaceFilePath.endsWith(\"turbo.json\");\n\n try {\n const { packageManager, path } = await findPackageManager(cwd);\n\n if ([\"npm\", \"yarn\"].includes(packageManager)) {\n const packageJsonFilePath = join(path, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = readFileSync(join(path, \"package.json\"), \"utf8\");\n\n if (packageJson.includes(\"workspaces\")) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : (packageManager as \"npm\" | \"yarn\"),\n };\n }\n }\n } else if (packageManager === \"pnpm\") {\n const pnpmWorkspacesFilePath = join(path, \"pnpm-workspace.yaml\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(pnpmWorkspacesFilePath)) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : \"pnpm\",\n };\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n // Skip this error to show the error message from the next block\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n if (!error.message.includes(\"Could not find lock file\")) {\n throw error;\n }\n }\n\n throw new Error(`No monorepo root could be found upwards from the directory ${cwd as string} using lerna, yarn, pnpm, or npm as indicators.`);\n};\n"]}
1
+ {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","dirname","join","findUp","stripJsonComments","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"wCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,UACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,YAG9B,OAAS,UAAAC,MAAc,UACvB,OAAOC,MAAuB,sBAsBvB,IAAMC,EAAmB,MAAOC,GAAgD,CACnF,IAAMC,EAAoB,MAAMJ,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,cAAe,GACf,KAAM,OACN,GAAIG,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAqBA,EAAkB,SAAS,YAAY,EAAG,CAE/D,IAAMC,EAAQ,KAAK,MAAMJ,EAAkBJ,EAAaO,EAAmB,MAAM,CAAC,CAAC,EAEnF,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAMP,EAAQM,CAAiB,EAC/B,SAAU,OACd,CAER,CAEA,IAAME,EAAUF,GAAqBA,EAAkB,SAAS,YAAY,EAE5E,GAAI,CACA,GAAM,CAAE,eAAAG,EAAgB,KAAAC,CAAK,EAAI,MAAMC,EAAmBN,CAAG,EAE7D,GAAI,CAAC,MAAO,MAAM,EAAE,SAASI,CAAc,EAAG,CAC1C,IAAMG,EAAsBX,EAAKS,EAAM,cAAc,EAGrD,GAAIZ,EAAWc,CAAmB,GAEVb,EAAaE,EAAKS,EAAM,cAAc,EAAG,MAAM,EAEnD,SAAS,YAAY,EACjC,MAAO,CACH,KAAAA,EACA,SAAUF,EAAU,QAAWC,CACnC,CAGZ,SAAWA,IAAmB,OAAQ,CAClC,IAAMI,EAAyBZ,EAAKS,EAAM,qBAAqB,EAG/D,GAAIZ,EAAWe,CAAsB,EACjC,MAAO,CACH,KAAAH,EACA,SAAUF,EAAU,QAAU,MAClC,CAER,CAEJ,OAASM,EAAY,CAGjB,GAAI,CAACA,EAAM,QAAQ,SAAS,0BAA0B,EAClD,MAAMA,CAEd,CAEA,MAAM,IAAI,MAAM,8DAA8DT,CAAa,iDAAiD,CAChJ","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport stripJsonComments from \"strip-json-comments\";\n\nimport { findPackageManager } from \"./package-manager\";\n\nexport type Strategy = \"lerna\" | \"npm\" | \"pnpm\" | \"turbo\" | \"yarn\";\n\nexport interface RootMonorepo<T extends Strategy = Strategy> {\n path: string;\n strategy: T;\n}\n\n/**\n * An asynchronous function to find the root directory path and strategy for a monorepo based on\n * the given current working directory (cwd).\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * Default is undefined.\n * @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.\n * The type of the returned promise is `Promise<RootMonorepo>`.\n * @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findMonorepoRoot = async (cwd?: Options[\"cwd\"]): Promise<RootMonorepo> => {\n const workspaceFilePath = await findUp([\"lerna.json\", \"turbo.json\"], {\n allowSymlinks: false,\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (workspaceFilePath && workspaceFilePath.endsWith(\"lerna.json\")) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const lerna = JSON.parse(stripJsonComments(readFileSync(workspaceFilePath, \"utf8\"))) as { packages?: string[]; useWorkspaces?: boolean };\n\n if (lerna.useWorkspaces || lerna.packages) {\n return {\n path: dirname(workspaceFilePath),\n strategy: \"lerna\",\n };\n }\n }\n\n const isTurbo = workspaceFilePath && workspaceFilePath.endsWith(\"turbo.json\");\n\n try {\n const { packageManager, path } = await findPackageManager(cwd);\n\n if ([\"npm\", \"yarn\"].includes(packageManager)) {\n const packageJsonFilePath = join(path, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = readFileSync(join(path, \"package.json\"), \"utf8\");\n\n if (packageJson.includes(\"workspaces\")) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : (packageManager as \"npm\" | \"yarn\"),\n };\n }\n }\n } else if (packageManager === \"pnpm\") {\n const pnpmWorkspacesFilePath = join(path, \"pnpm-workspace.yaml\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(pnpmWorkspacesFilePath)) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : \"pnpm\",\n };\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n // Skip this error to show the error message from the next block\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n if (!error.message.includes(\"Could not find lock file\")) {\n throw error;\n }\n }\n\n throw new Error(`No monorepo root could be found upwards from the directory ${cwd as string} using lerna, yarn, pnpm, or npm as indicators.`);\n};\n"]}
@@ -1,9 +1,9 @@
1
- import { a } from './chunk-IWQKH4TN.js';
2
- import { dirname } from 'path';
1
+ import { a } from './chunk-ZRX4WIQ4.js';
2
+ import { dirname } from 'node:path';
3
3
  import { findUp } from 'find-up';
4
4
 
5
5
  var c=async o=>{try{let a$1=await a(o);return dirname(a$1)}catch{}let t=await findUp(".git/config",{...o&&{cwd:o},allowSymlinks:!1,type:"file"});if(t)return dirname(dirname(t));let r=await findUp("package.json",{...o&&{cwd:o},allowSymlinks:!1,type:"file"});if(r)return dirname(r);throw new Error("Could not find root directory")};
6
6
 
7
7
  export { c as a };
8
8
  //# sourceMappingURL=out.js.map
9
- //# sourceMappingURL=chunk-7WLQPGXB.js.map
9
+ //# sourceMappingURL=chunk-LH5BGOWS.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/package.ts"],"names":["dirname","findUp","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath"],"mappings":"wCAAA,OAAS,WAAAA,MAAe,OAGxB,OAAS,UAAAC,MAAc,UAgBhB,IAAMC,EAAkB,MAAOC,GAA0C,CAE5E,GAAI,CACA,IAAMC,EAAW,MAAMC,EAAaF,CAAG,EAEvC,OAAOH,EAAQI,CAAQ,CAC3B,MAAQ,CAER,CAGA,IAAME,EAAY,MAAML,EAAO,cAAe,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAON,EAAQA,EAAQM,CAAS,CAAC,EAIrC,IAAMC,EAAW,MAAMN,EAAO,eAAgB,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOP,EAAQO,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { dirname } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\n\nimport { findLockFile } from \"./package-manager\";\n\n/**\n * An asynchronous function that finds the root directory of a project based on certain lookup criteria.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if the root directory could not be found.\n *\n * @example\n * const rootDirectory = await findPackageRoot();\n * console.log(rootDirectory); // '/path/to/project'\n */\n// eslint-disable-next-line import/prefer-default-export\nexport const findPackageRoot = async (cwd?: Options[\"cwd\"]): Promise<string> => {\n // Lookdown for lockfile\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n // Lookup for .git/config\n const gitConfig = await findUp(\".git/config\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n // Lookdown for package.json\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (filePath) {\n return dirname(filePath);\n }\n\n throw new Error(\"Could not find root directory\");\n};\n"]}
1
+ {"version":3,"sources":["../src/package.ts"],"names":["dirname","findUp","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath"],"mappings":"wCAAA,OAAS,WAAAA,MAAe,YAGxB,OAAS,UAAAC,MAAc,UAgBhB,IAAMC,EAAkB,MAAOC,GAA0C,CAE5E,GAAI,CACA,IAAMC,EAAW,MAAMC,EAAaF,CAAG,EAEvC,OAAOH,EAAQI,CAAQ,CAC3B,MAAQ,CAER,CAGA,IAAME,EAAY,MAAML,EAAO,cAAe,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAON,EAAQA,EAAQM,CAAS,CAAC,EAIrC,IAAMC,EAAW,MAAMN,EAAO,eAAgB,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOP,EAAQO,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { dirname } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\n\nimport { findLockFile } from \"./package-manager\";\n\n/**\n * An asynchronous function that finds the root directory of a project based on certain lookup criteria.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if the root directory could not be found.\n *\n * @example\n * const rootDirectory = await findPackageRoot();\n * console.log(rootDirectory); // '/path/to/project'\n */\n// eslint-disable-next-line import/prefer-default-export\nexport const findPackageRoot = async (cwd?: Options[\"cwd\"]): Promise<string> => {\n // Lookdown for lockfile\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n // Lookup for .git/config\n const gitConfig = await findUp(\".git/config\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n // Lookdown for package.json\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (filePath) {\n return dirname(filePath);\n }\n\n throw new Error(\"Could not find root directory\");\n};\n"]}
@@ -1,7 +1,7 @@
1
- import { a, b } from './chunk-C7FQQQI6.js';
2
- import { readFileSync } from 'fs';
3
- import { mkdir } from 'fs/promises';
4
- import { join } from 'path';
1
+ import { a, b } from './chunk-5CE7NVS2.js';
2
+ import { readFileSync } from 'node:fs';
3
+ import { mkdir } from 'node:fs/promises';
4
+ import { join } from 'node:path';
5
5
  import { findUp } from 'find-up';
6
6
  import { parsePackage } from 'read-pkg';
7
7
  export { parsePackage as c } from 'read-pkg';
@@ -10,4 +10,4 @@ var J=async(e=void 0)=>{let o=await findUp("package.json",{...e&&{cwd:e},allowSy
10
10
 
11
11
  export { J as a, h as b };
12
12
  //# sourceMappingURL=out.js.map
13
- //# sourceMappingURL=chunk-7TF75EA4.js.map
13
+ //# sourceMappingURL=chunk-SET64FVW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package-json.ts"],"names":["readFileSync","mkdir","join","findUp","parsePackage","findPackageJson","cwd","filePath","writePackageJson","data","options","directory","to_path_default","path","writeJsonFile"],"mappings":"0CAAA,OAAS,gBAAAA,MAAoB,UAC7B,OAAS,SAAAC,MAAa,mBACtB,OAAS,QAAAC,MAAY,YAGrB,OAAS,UAAAC,MAAc,UAEvB,OAAS,gBAAAC,MAAoB,WA2D7B,OAAyB,gBAAhBA,MAAwC,WAtC1C,IAAMC,EAAkB,MAAOC,EAAsB,SAA6C,CACrG,IAAMC,EAAW,MAAMJ,EAAO,eAAgB,CAC1C,GAAIG,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,6BAA6B,EAGjD,MAAO,CAEH,YAAaH,EAAaJ,EAAaO,EAAU,MAAM,EAAG,CAAE,UAAW,EAAK,CAAC,EAC7E,KAAMA,CACV,CACJ,EAYaC,EAAmB,MAAOC,EAAyCC,EAAmD,CAAC,IAAqB,CACrJ,IAAMC,EAAYC,EAAOF,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAC/CG,EAAOX,EAAKS,EAAW,cAAc,EAG3C,MAAMV,EAAMU,EAAW,CAAE,UAAW,EAAK,CAAC,EAE1C,MAAMG,EAAcD,EAAMJ,EAAMC,CAAO,CAC3C","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport type { NormalizedPackageJson, PackageJson } from \"read-pkg\";\nimport { parsePackage } from \"read-pkg\";\n\nimport toPath from \"./utils/to-path\";\nimport type { WriteOptions } from \"./utils/write-json\";\nimport { writeJsonFile } from \"./utils/write-json\";\n\nexport type { NormalizedPackageJson } from \"read-pkg\";\n\nexport type NormalizedReadResult = {\n packageJson: NormalizedPackageJson;\n path: string;\n};\n\n/**\n * An asynchronous function to find the package.json file in the specified directory or its parent directories.\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * @returns A `Promise` that resolves to an object containing the parsed package.json data and the file path.\n * The type of the returned promise is `Promise<NormalizedReadResult>`.\n * @throws An `Error` if the package.json file cannot be found.\n */\nexport const findPackageJson = async (cwd: Options[\"cwd\"] = undefined): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (!filePath) {\n throw new Error(\"Could not find package.json\");\n }\n\n return {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n packageJson: parsePackage(readFileSync(filePath, \"utf8\"), { normalize: true }),\n path: filePath,\n };\n};\n\n/**\n * An asynchronous function to write the package.json file with the given data.\n *\n * @param data - The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.\n * @param options - Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.\n * This is an intersection type of `WriteOptions` and a record with an optional `cwd` key which type is `Options[\"cwd\"]`.\n * `cwd` represents the current working directory. If not specified, the default working directory will be used.\n * @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const writePackageJson = async (data: PackageJson & Record<string, any>, options: WriteOptions & { cwd?: Options[\"cwd\"] } = {}): Promise<void> => {\n const directory = toPath(options.cwd ?? process.cwd());\n const path = join(directory, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await mkdir(directory, { recursive: true });\n\n await writeJsonFile(path, data, options);\n};\n\nexport { parsePackage as parsePackageJson } from \"read-pkg\";\n"]}
@@ -1,10 +1,10 @@
1
- import { a, b } from './chunk-C7FQQQI6.js';
2
- import { mkdir } from 'fs/promises';
3
- import { join } from 'path';
1
+ import { a, b } from './chunk-5CE7NVS2.js';
2
+ import { mkdir } from 'node:fs/promises';
3
+ import { join } from 'node:path';
4
4
  import { getTsconfig } from 'get-tsconfig';
5
5
 
6
6
  var w=async t=>{let i=t===void 0?void 0:a(t),o=await getTsconfig(i,"tsconfig.json");if(o===null&&(o=await getTsconfig(i,"jsconfig.json")),o===null)throw new Error("Could not find a tsconfig.json or jsconfig.json file.");return o},C=async(t,i={})=>{let o=a(i.cwd??process.cwd()),e=join(o,"tsconfig.json");await mkdir(o,{recursive:!0}),await b(e,t,i);};
7
7
 
8
8
  export { w as a, C as b };
9
9
  //# sourceMappingURL=out.js.map
10
- //# sourceMappingURL=chunk-QQJUJRI7.js.map
10
+ //# sourceMappingURL=chunk-YMGIEDHF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/tsconfig.ts"],"names":["mkdir","join","getTsconfig","findTSConfig","cwd","searchPath","to_path_default","config","writeTSConfig","tsConfig","options","directory","path","writeJsonFile"],"mappings":"+CAAA,OAAS,SAAAA,MAAa,mBACtB,OAAS,QAAAC,MAAY,YAGrB,OAAS,eAAAC,MAAmB,eAgBrB,IAAMC,EAAe,MAAOC,GAAgD,CAC/E,IAAMC,EAAaD,IAAQ,OAAY,OAAYE,EAAOF,CAAG,EAIzDG,EAAS,MAAML,EAAYG,EAAY,eAAe,EAO1D,GALIE,IAAW,OAEXA,EAAS,MAAML,EAAYG,EAAY,eAAe,GAGtDE,IAAW,KACX,MAAM,IAAI,MAAM,uDAAuD,EAG3E,OAAOA,CACX,EAWaC,EAAgB,MAAOC,EAAwBC,EAAiD,CAAC,IAAqB,CAC/H,IAAMC,EAAYL,EAAOI,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAC/CE,EAAOX,EAAKU,EAAW,eAAe,EAG5C,MAAMX,EAAMW,EAAW,CAAE,UAAW,EAAK,CAAC,EAE1C,MAAME,EAAcD,EAAMH,EAAUC,CAAO,CAC/C","sourcesContent":["import { mkdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport type { TsConfigJson, TsConfigResult } from \"get-tsconfig\";\nimport { getTsconfig } from \"get-tsconfig\";\n\nimport toPath from \"./utils/to-path\";\nimport type { WriteOptions } from \"./utils/write-json\";\nimport { writeJsonFile } from \"./utils/write-json\";\n\n/**\n * An asynchronous function that retrieves the TSConfig by searching for the \"tsconfig.json\" first,\n * second attempt is to look for the \"jsconfig.json\" file from a given current working directory.\n *\n * @param cwd - Optional. The current working directory from which to search for the \"tsconfig.json\" file.\n * The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the TSConfig result object.\n * The return type of the function is `Promise<TsConfigResult>`.\n * @throws An `Error` when the \"tsconfig.json\" file is not found.\n */\nexport const findTSConfig = async (cwd?: URL | string): Promise<TsConfigResult> => {\n const searchPath = cwd === undefined ? undefined : toPath(cwd);\n\n // wrong typing in get-tsconfig\n // eslint-disable-next-line @typescript-eslint/await-thenable\n let config = await getTsconfig(searchPath, \"tsconfig.json\");\n\n if (config === null) {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n config = await getTsconfig(searchPath, \"jsconfig.json\");\n }\n\n if (config === null) {\n throw new Error(\"Could not find a tsconfig.json or jsconfig.json file.\");\n }\n\n return config;\n};\n\n/**\n * An asynchronous function that writes the provided TypeScript configuration object to a tsconfig.json file.\n *\n * @param tsConfig - The TypeScript configuration object to write. The type of `tsConfig` is `TsConfigJson`.\n * @param options - Optional. The write options and the current working directory. The type of `options` is an\n * intersection type of `WriteOptions` and a Record type with an optional `cwd` key of type `string`.\n * @returns A `Promise` that resolves when the tsconfig.json file has been written.\n * The return type of function is `Promise<void>`.\n */\nexport const writeTSConfig = async (tsConfig: TsConfigJson, options: WriteOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const directory = toPath(options.cwd ?? process.cwd());\n const path = join(directory, \"tsconfig.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await mkdir(directory, { recursive: true });\n\n await writeJsonFile(path, tsConfig, options);\n};\n\nexport type { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from \"get-tsconfig\";\n"]}
@@ -1,6 +1,6 @@
1
- import { execSync } from 'child_process';
2
- import { existsSync, readFileSync } from 'fs';
3
- import { join, dirname } from 'path';
1
+ import { execSync } from 'node:child_process';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { join, dirname } from 'node:path';
4
4
  import { findUp } from 'find-up';
5
5
  import { parsePackage, readPackage } from 'read-pkg';
6
6
 
@@ -8,4 +8,4 @@ var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","b
8
8
 
9
9
  export { x as a, b, j as c, S as d };
10
10
  //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-IWQKH4TN.js.map
11
+ //# sourceMappingURL=chunk-ZRX4WIQ4.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","dirname","join","findUp","parsePackage","readPackage","lockFileNames","findLockFile","cwd","filePath","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,gBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAG9B,OAAS,UAAAC,MAAc,UACvB,OAAS,gBAAAC,EAAc,eAAAC,MAAmB,WAE1C,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAA0C,CACzE,IAAMC,EAAW,MAAMN,EAAOG,EAAe,CACzC,cAAe,GACf,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaC,EAAqB,MAAOF,GAAwD,CAC7F,IAAMG,EAAY,MAAMR,EACnBS,GAAc,CACX,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYd,EAAWG,EAAKU,EAAWE,CAAY,CAAC,IACrDD,EAAWX,EAAKU,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBb,EAAKU,EAAW,cAAc,EAE1D,GAAIb,EAAWgB,CAAmB,GAEVX,EAAaJ,EAAae,EAAqB,MAAM,CAAC,EAE1D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIP,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,EACnB,CACJ,EAEA,GAAI,CAACG,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,GAAIA,EAAU,SAAS,cAAc,EAAG,CACpC,IAAMK,EAAc,MAAMX,EAAY,CAAE,IAAKJ,EAAQU,CAAS,EAAG,UAAW,EAAK,CAAC,EAElF,GAAIK,EAAY,eAAgB,CAE5B,IAAMC,EADsB,CAAC,MAAO,OAAQ,OAAQ,KAAK,EACT,KAAMC,GAAYF,EAAY,eAA0B,WAAWE,CAAM,CAAC,EAE1H,GAAID,EACA,MAAO,CACH,eAAgBA,EAChB,KAAMhB,EAAQU,CAAS,CAC3B,CAER,CACJ,CAEA,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,OAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,mBAAmB,GAAKA,EAAU,SAAS,qBAAqB,EACnF,MAAO,CACH,eAAgB,MAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,gBAAgB,EACnC,MAAO,CACH,eAAgB,OAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,MAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,MAAM,IAAI,MAAM,0BAA0B,CAC9C,EAQaQ,EAA4BC,GAAyBtB,EAAS,GAAGsB,CAAI,YAAY,EAAE,SAAS,MAAM,EAAE,KAAK,EAWzGC,EAAmC,SAM3C,CACD,GAAI,CAAC,QAAQ,IAAI,sBACb,OAGJ,IAAMC,EAAS,QAAQ,IAAI,sBAAyB,MAAM,GAAG,EAAE,CAAC,EAC1DC,EAAeD,EAAO,YAAY,GAAG,EACrCF,EAAOE,EAAO,MAAM,EAAG,KAAK,IAAI,EAAGC,CAAY,CAAC,EAEtD,MAAO,CACH,KAAMH,IAAS,aAAe,OAAUA,EACxC,QAASE,EAAO,MAAM,KAAK,IAAI,EAAGC,EAAe,CAAC,CAAC,CACvD,CACJ","sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport { parsePackage, readPackage } from \"read-pkg\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"] as const;\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `Options[\"cwd\"]`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: Options[\"cwd\"]): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n allowSymlinks: false,\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `Options[\"cwd\"]`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findPackageManager = async (cwd?: Options[\"cwd\"]): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackage(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n },\n );\n\n if (!foundFile) {\n throw new Error(\"Could not find lock file\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = await readPackage({ cwd: dirname(foundFile), normalize: true });\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new Error(\"Could not find lock file\");\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
1
+ {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","dirname","join","findUp","parsePackage","readPackage","lockFileNames","findLockFile","cwd","filePath","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,qBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,UACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,YAG9B,OAAS,UAAAC,MAAc,UACvB,OAAS,gBAAAC,EAAc,eAAAC,MAAmB,WAE1C,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAA0C,CACzE,IAAMC,EAAW,MAAMN,EAAOG,EAAe,CACzC,cAAe,GACf,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaC,EAAqB,MAAOF,GAAwD,CAC7F,IAAMG,EAAY,MAAMR,EACnBS,GAAc,CACX,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYd,EAAWG,EAAKU,EAAWE,CAAY,CAAC,IACrDD,EAAWX,EAAKU,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBb,EAAKU,EAAW,cAAc,EAE1D,GAAIb,EAAWgB,CAAmB,GAEVX,EAAaJ,EAAae,EAAqB,MAAM,CAAC,EAE1D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIP,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,EACnB,CACJ,EAEA,GAAI,CAACG,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,GAAIA,EAAU,SAAS,cAAc,EAAG,CACpC,IAAMK,EAAc,MAAMX,EAAY,CAAE,IAAKJ,EAAQU,CAAS,EAAG,UAAW,EAAK,CAAC,EAElF,GAAIK,EAAY,eAAgB,CAE5B,IAAMC,EADsB,CAAC,MAAO,OAAQ,OAAQ,KAAK,EACT,KAAMC,GAAYF,EAAY,eAA0B,WAAWE,CAAM,CAAC,EAE1H,GAAID,EACA,MAAO,CACH,eAAgBA,EAChB,KAAMhB,EAAQU,CAAS,CAC3B,CAER,CACJ,CAEA,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,OAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,mBAAmB,GAAKA,EAAU,SAAS,qBAAqB,EACnF,MAAO,CACH,eAAgB,MAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,gBAAgB,EACnC,MAAO,CACH,eAAgB,OAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,MAChB,KAAMV,EAAQU,CAAS,CAC3B,EAGJ,MAAM,IAAI,MAAM,0BAA0B,CAC9C,EAQaQ,EAA4BC,GAAyBtB,EAAS,GAAGsB,CAAI,YAAY,EAAE,SAAS,MAAM,EAAE,KAAK,EAWzGC,EAAmC,SAM3C,CACD,GAAI,CAAC,QAAQ,IAAI,sBACb,OAGJ,IAAMC,EAAS,QAAQ,IAAI,sBAAyB,MAAM,GAAG,EAAE,CAAC,EAC1DC,EAAeD,EAAO,YAAY,GAAG,EACrCF,EAAOE,EAAO,MAAM,EAAG,KAAK,IAAI,EAAGC,CAAY,CAAC,EAEtD,MAAO,CACH,KAAMH,IAAS,aAAe,OAAUA,EACxC,QAASE,EAAO,MAAM,KAAK,IAAI,EAAGC,EAAe,CAAC,CAAC,CACvD,CACJ","sourcesContent":["import { execSync } from \"node:child_process\";\nimport { existsSync, readFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport { parsePackage, readPackage } from \"read-pkg\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"] as const;\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `Options[\"cwd\"]`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: Options[\"cwd\"]): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n allowSymlinks: false,\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `Options[\"cwd\"]`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findPackageManager = async (cwd?: Options[\"cwd\"]): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackage(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n },\n );\n\n if (!foundFile) {\n throw new Error(\"Could not find lock file\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = await readPackage({ cwd: dirname(foundFile), normalize: true });\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new Error(\"Could not find lock file\");\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { findPackageRoot } from './package.js';
3
3
  export { NormalizedReadResult, findPackageJson, writePackageJson } from './package-json.js';
4
4
  export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
5
5
  export { findTSConfig, writeTSConfig } from './tsconfig.js';
6
- export { NormalizedPackageJson, parsePackage as parsePackageJson } from 'read-pkg';
6
+ export { NormalizedPackageJson, PackageJson, parsePackage as parsePackageJson } from 'read-pkg';
7
7
  export { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from 'get-tsconfig';
8
8
  import 'find-up';
9
9
  import './write-json-EkV5tJMg.js';
package/dist/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export { a as findMonorepoRoot } from './chunk-T4PCL5Z7.js';
2
- export { a as findPackageRoot } from './chunk-7WLQPGXB.js';
3
- export { a as findPackageJson, c as parsePackageJson, b as writePackageJson } from './chunk-7TF75EA4.js';
4
- export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-IWQKH4TN.js';
5
- export { a as findTSConfig, b as writeTSConfig } from './chunk-QQJUJRI7.js';
6
- import './chunk-C7FQQQI6.js';
1
+ export { a as findMonorepoRoot } from './chunk-I2QN4KO5.js';
2
+ export { a as findPackageRoot } from './chunk-LH5BGOWS.js';
3
+ export { a as findPackageJson, c as parsePackageJson, b as writePackageJson } from './chunk-SET64FVW.js';
4
+ export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-ZRX4WIQ4.js';
5
+ export { a as findTSConfig, b as writeTSConfig } from './chunk-YMGIEDHF.js';
6
+ import './chunk-5CE7NVS2.js';
7
7
  //# sourceMappingURL=out.js.map
8
8
  //# sourceMappingURL=index.js.map
package/dist/monorepo.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as findMonorepoRoot } from './chunk-T4PCL5Z7.js';
2
- import './chunk-IWQKH4TN.js';
1
+ export { a as findMonorepoRoot } from './chunk-I2QN4KO5.js';
2
+ import './chunk-ZRX4WIQ4.js';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=monorepo.js.map
@@ -1,4 +1,4 @@
1
- export { a as findPackageJson, c as parsePackageJson, b as writePackageJson } from './chunk-7TF75EA4.js';
2
- import './chunk-C7FQQQI6.js';
1
+ export { a as findPackageJson, c as parsePackageJson, b as writePackageJson } from './chunk-SET64FVW.js';
2
+ import './chunk-5CE7NVS2.js';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=package-json.js.map
@@ -1,3 +1,3 @@
1
- export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-IWQKH4TN.js';
1
+ export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-ZRX4WIQ4.js';
2
2
  //# sourceMappingURL=out.js.map
3
3
  //# sourceMappingURL=package-manager.js.map
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as findPackageRoot } from './chunk-7WLQPGXB.js';
2
- import './chunk-IWQKH4TN.js';
1
+ export { a as findPackageRoot } from './chunk-LH5BGOWS.js';
2
+ import './chunk-ZRX4WIQ4.js';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=package.js.map
package/dist/tsconfig.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as findTSConfig, b as writeTSConfig } from './chunk-QQJUJRI7.js';
2
- import './chunk-C7FQQQI6.js';
1
+ export { a as findTSConfig, b as writeTSConfig } from './chunk-YMGIEDHF.js';
2
+ import './chunk-5CE7NVS2.js';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=tsconfig.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/package",
3
- "version": "1.2.8",
3
+ "version": "1.2.10",
4
4
  "description": "One Package to rule them all, finds your root-dir, monorepo, package manager or tsconfig.json",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -114,7 +114,7 @@
114
114
  "dependencies": {
115
115
  "detect-indent": "^7.0.1",
116
116
  "find-up": "^7.0.0",
117
- "get-tsconfig": "^4.7.2",
117
+ "get-tsconfig": "^4.7.3",
118
118
  "read-pkg": "^9.0.1",
119
119
  "strip-json-comments": "^5.0.1"
120
120
  },
@@ -137,7 +137,7 @@
137
137
  "eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
138
138
  "eslint-plugin-mdx": "^3.1.5",
139
139
  "eslint-plugin-tsdoc": "^0.2.17",
140
- "eslint-plugin-vitest": "^0.3.22",
140
+ "eslint-plugin-vitest": "^0.3.25",
141
141
  "eslint-plugin-vitest-globals": "^1.4.0",
142
142
  "execa": "^8.0.1",
143
143
  "npm": "^10.5.0",
@@ -146,10 +146,10 @@
146
146
  "semantic-release": "^23.0.2",
147
147
  "sort-package-json": "^2.8.0",
148
148
  "tsup": "^8.0.2",
149
- "typescript": "^5.3.3",
149
+ "typescript": "^5.4.2",
150
150
  "vitest": "^1.3.1",
151
151
  "which-pm-runs": "file:",
152
- "yarn": "^1.22.21"
152
+ "yarn": "^1.22.22"
153
153
  },
154
154
  "engines": {
155
155
  "node": ">=18.* <=21.*"
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-json.ts"],"names":["readFileSync","mkdir","join","findUp","parsePackage","findPackageJson","cwd","filePath","writePackageJson","data","options","directory","to_path_default","path","writeJsonFile"],"mappings":"0CAAA,OAAS,gBAAAA,MAAoB,KAC7B,OAAS,SAAAC,MAAa,cACtB,OAAS,QAAAC,MAAY,OAGrB,OAAS,UAAAC,MAAc,UAEvB,OAAS,gBAAAC,MAAoB,WA2D7B,OAAyB,gBAAhBA,MAAwC,WAtC1C,IAAMC,EAAkB,MAAOC,EAAsB,SAA6C,CACrG,IAAMC,EAAW,MAAMJ,EAAO,eAAgB,CAC1C,GAAIG,GAAO,CAAE,IAAAA,CAAI,EACjB,cAAe,GACf,KAAM,MACV,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,6BAA6B,EAGjD,MAAO,CAEH,YAAaH,EAAaJ,EAAaO,EAAU,MAAM,EAAG,CAAE,UAAW,EAAK,CAAC,EAC7E,KAAMA,CACV,CACJ,EAYaC,EAAmB,MAAOC,EAAyCC,EAAmD,CAAC,IAAqB,CACrJ,IAAMC,EAAYC,EAAOF,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAC/CG,EAAOX,EAAKS,EAAW,cAAc,EAG3C,MAAMV,EAAMU,EAAW,CAAE,UAAW,EAAK,CAAC,EAE1C,MAAMG,EAAcD,EAAMJ,EAAMC,CAAO,CAC3C","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { mkdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport type { Options } from \"find-up\";\nimport { findUp } from \"find-up\";\nimport type { NormalizedPackageJson, PackageJson } from \"read-pkg\";\nimport { parsePackage } from \"read-pkg\";\n\nimport toPath from \"./utils/to-path\";\nimport type { WriteOptions } from \"./utils/write-json\";\nimport { writeJsonFile } from \"./utils/write-json\";\n\nexport type { NormalizedPackageJson } from \"read-pkg\";\n\nexport type NormalizedReadResult = {\n packageJson: NormalizedPackageJson;\n path: string;\n};\n\n/**\n * An asynchronous function to find the package.json file in the specified directory or its parent directories.\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * @returns A `Promise` that resolves to an object containing the parsed package.json data and the file path.\n * The type of the returned promise is `Promise<NormalizedReadResult>`.\n * @throws An `Error` if the package.json file cannot be found.\n */\nexport const findPackageJson = async (cwd: Options[\"cwd\"] = undefined): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n allowSymlinks: false,\n type: \"file\",\n });\n\n if (!filePath) {\n throw new Error(\"Could not find package.json\");\n }\n\n return {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n packageJson: parsePackage(readFileSync(filePath, \"utf8\"), { normalize: true }),\n path: filePath,\n };\n};\n\n/**\n * An asynchronous function to write the package.json file with the given data.\n *\n * @param data - The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.\n * @param options - Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.\n * This is an intersection type of `WriteOptions` and a record with an optional `cwd` key which type is `Options[\"cwd\"]`.\n * `cwd` represents the current working directory. If not specified, the default working directory will be used.\n * @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const writePackageJson = async (data: PackageJson & Record<string, any>, options: WriteOptions & { cwd?: Options[\"cwd\"] } = {}): Promise<void> => {\n const directory = toPath(options.cwd ?? process.cwd());\n const path = join(directory, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await mkdir(directory, { recursive: true });\n\n await writeJsonFile(path, data, options);\n};\n\nexport { parsePackage as parsePackageJson } from \"read-pkg\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/utils/to-path.ts","../src/utils/write-json.ts"],"names":["fileURLToPath","toPath","urlOrPath","to_path_default","existsSync","readFile","writeFile","detectIndent","resolveWriteOptions","path","options","file","indent","newline","writeJsonFile","data","resolvedOptions","content"],"mappings":"AAAA,OAAS,iBAAAA,MAAqB,MAE9B,IAAMC,EAAUC,GAAqCA,aAAqB,IAAMF,EAAcE,CAAS,EAAIA,EAEpGC,EAAQF,ECJf,OAAS,cAAAG,MAAkB,KAC3B,OAAS,YAAAC,EAAU,aAAAC,MAAiB,cAEpC,OAAOC,MAAkB,gBAQzB,IAAMC,EAAsB,MAAOC,EAAcC,IAAyD,CAEtG,IAAMC,EAAOP,EAAWK,CAAI,EAAI,MAAMJ,EAASI,EAAM,MAAM,EAAI,OACzDG,EAASF,EAAQ,SAAWC,EAAOJ,EAAaI,CAAI,EAAE,OAAS,GAC/DE,EAAUH,EAAQ,UAAY,GAAO;AAAA,EAAOA,EAAQ,UAAY,GAAQ,GAAKA,EAAQ,UAAYC,EAAQA,EAAK,SAAS;AAAA,CAAI,EAAI;AAAA,EAAO,GAAM;AAAA,GAElJ,MAAO,CACH,OAAAC,EACA,QAAAC,CACJ,CACJ,EAQaC,EAAgB,MAAOL,EAAcM,EAAyCL,EAAwB,CAAC,IAAqB,CACrI,IAAMM,EAAkB,MAAMR,EAAoBC,EAAMC,CAAO,EAE3DO,EAAU,KAAK,UAAUF,EAAM,OAAWC,EAAgB,MAAM,EACpEC,GAAWD,EAAgB,QAG3B,MAAMV,EAAUG,EAAMQ,CAAO,CACjC","sourcesContent":["import { fileURLToPath } from \"node:url\";\n\nconst toPath = (urlOrPath: URL | string): string => (urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath);\n\nexport default toPath;\n","import { existsSync } from \"node:fs\";\nimport { readFile, writeFile } from \"node:fs/promises\";\n\nimport detectIndent from \"detect-indent\";\nimport type { PackageJson } from \"read-pkg\";\n\ntype ResolvedWriteOptions = {\n indent: number | string;\n newline: string;\n};\n\nconst resolveWriteOptions = async (path: string, options: WriteOptions): Promise<ResolvedWriteOptions> => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const file = existsSync(path) ? await readFile(path, \"utf8\") : undefined;\n const indent = options.indent ?? (file ? detectIndent(file).indent : 2);\n const newline = options.newline === true ? \"\\n\" : options.newline === false ? \"\" : options.newline ?? (file ? (file.endsWith(\"\\n\") ? \"\\n\" : \"\") : \"\\n\");\n\n return {\n indent,\n newline,\n };\n};\n\nexport type WriteOptions = {\n indent?: number | string;\n newline?: boolean | string;\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const writeJsonFile = async (path: string, data: PackageJson & Record<string, any>, options: WriteOptions = {}): Promise<void> => {\n const resolvedOptions = await resolveWriteOptions(path, options);\n\n let content = JSON.stringify(data, undefined, resolvedOptions.indent);\n content += resolvedOptions.newline;\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await writeFile(path, content);\n};\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tsconfig.ts"],"names":["mkdir","join","getTsconfig","findTSConfig","cwd","searchPath","to_path_default","config","writeTSConfig","tsConfig","options","directory","path","writeJsonFile"],"mappings":"+CAAA,OAAS,SAAAA,MAAa,cACtB,OAAS,QAAAC,MAAY,OAGrB,OAAS,eAAAC,MAAmB,eAgBrB,IAAMC,EAAe,MAAOC,GAAgD,CAC/E,IAAMC,EAAaD,IAAQ,OAAY,OAAYE,EAAOF,CAAG,EAIzDG,EAAS,MAAML,EAAYG,EAAY,eAAe,EAO1D,GALIE,IAAW,OAEXA,EAAS,MAAML,EAAYG,EAAY,eAAe,GAGtDE,IAAW,KACX,MAAM,IAAI,MAAM,uDAAuD,EAG3E,OAAOA,CACX,EAWaC,EAAgB,MAAOC,EAAwBC,EAAiD,CAAC,IAAqB,CAC/H,IAAMC,EAAYL,EAAOI,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAC/CE,EAAOX,EAAKU,EAAW,eAAe,EAG5C,MAAMX,EAAMW,EAAW,CAAE,UAAW,EAAK,CAAC,EAE1C,MAAME,EAAcD,EAAMH,EAAUC,CAAO,CAC/C","sourcesContent":["import { mkdir } from \"node:fs/promises\";\nimport { join } from \"node:path\";\n\nimport type { TsConfigJson, TsConfigResult } from \"get-tsconfig\";\nimport { getTsconfig } from \"get-tsconfig\";\n\nimport toPath from \"./utils/to-path\";\nimport type { WriteOptions } from \"./utils/write-json\";\nimport { writeJsonFile } from \"./utils/write-json\";\n\n/**\n * An asynchronous function that retrieves the TSConfig by searching for the \"tsconfig.json\" first,\n * second attempt is to look for the \"jsconfig.json\" file from a given current working directory.\n *\n * @param cwd - Optional. The current working directory from which to search for the \"tsconfig.json\" file.\n * The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the TSConfig result object.\n * The return type of the function is `Promise<TsConfigResult>`.\n * @throws An `Error` when the \"tsconfig.json\" file is not found.\n */\nexport const findTSConfig = async (cwd?: URL | string): Promise<TsConfigResult> => {\n const searchPath = cwd === undefined ? undefined : toPath(cwd);\n\n // wrong typing in get-tsconfig\n // eslint-disable-next-line @typescript-eslint/await-thenable\n let config = await getTsconfig(searchPath, \"tsconfig.json\");\n\n if (config === null) {\n // eslint-disable-next-line @typescript-eslint/await-thenable\n config = await getTsconfig(searchPath, \"jsconfig.json\");\n }\n\n if (config === null) {\n throw new Error(\"Could not find a tsconfig.json or jsconfig.json file.\");\n }\n\n return config;\n};\n\n/**\n * An asynchronous function that writes the provided TypeScript configuration object to a tsconfig.json file.\n *\n * @param tsConfig - The TypeScript configuration object to write. The type of `tsConfig` is `TsConfigJson`.\n * @param options - Optional. The write options and the current working directory. The type of `options` is an\n * intersection type of `WriteOptions` and a Record type with an optional `cwd` key of type `string`.\n * @returns A `Promise` that resolves when the tsconfig.json file has been written.\n * The return type of function is `Promise<void>`.\n */\nexport const writeTSConfig = async (tsConfig: TsConfigJson, options: WriteOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const directory = toPath(options.cwd ?? process.cwd());\n const path = join(directory, \"tsconfig.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n await mkdir(directory, { recursive: true });\n\n await writeJsonFile(path, tsConfig, options);\n};\n\nexport type { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from \"get-tsconfig\";\n"]}