@visulima/package 1.3.5 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +22 -14
  3. package/dist/{chunk-EVIAOYPI.js → chunk-5ZQIFU6S.js} +3 -3
  4. package/dist/chunk-5ZQIFU6S.js.map +1 -0
  5. package/dist/chunk-BGBPBHAL.cjs +27 -0
  6. package/dist/chunk-BGBPBHAL.cjs.map +1 -0
  7. package/dist/chunk-F63DY4KL.js +15 -0
  8. package/dist/chunk-F63DY4KL.js.map +1 -0
  9. package/dist/{chunk-S35C7FTW.js → chunk-G767QS5X.js} +3 -3
  10. package/dist/chunk-G767QS5X.js.map +1 -0
  11. package/dist/chunk-L6J2NRQY.cjs +12 -0
  12. package/dist/chunk-L6J2NRQY.cjs.map +1 -0
  13. package/dist/chunk-TM6ZD56C.cjs +16 -0
  14. package/dist/chunk-TM6ZD56C.cjs.map +1 -0
  15. package/dist/chunk-TUN46UZB.js +12 -0
  16. package/dist/chunk-TUN46UZB.js.map +1 -0
  17. package/dist/chunk-VAMRQCZW.cjs +11 -0
  18. package/dist/chunk-VAMRQCZW.cjs.map +1 -0
  19. package/dist/chunk-VQCWTT2B.cjs +22 -0
  20. package/dist/chunk-VQCWTT2B.cjs.map +1 -0
  21. package/dist/{chunk-JUT7NLYV.js → chunk-XKKPPOYW.js} +3 -3
  22. package/dist/chunk-XKKPPOYW.js.map +1 -0
  23. package/dist/index.cjs +34 -18
  24. package/dist/index.d.cts +12 -4
  25. package/dist/index.d.ts +12 -4
  26. package/dist/index.js +5 -5
  27. package/dist/monorepo.cjs +4 -4
  28. package/dist/monorepo.js +3 -3
  29. package/dist/package-json.cjs +6 -6
  30. package/dist/package-json.d.cts +23 -3
  31. package/dist/package-json.d.ts +23 -3
  32. package/dist/package-json.js +1 -1
  33. package/dist/package-manager.cjs +6 -6
  34. package/dist/package-manager.js +2 -2
  35. package/dist/package.cjs +4 -4
  36. package/dist/package.js +3 -3
  37. package/dist/tsconfig.cjs +19 -3
  38. package/dist/tsconfig.d.cts +19 -4
  39. package/dist/tsconfig.d.ts +19 -4
  40. package/dist/tsconfig.js +1 -1
  41. package/dist/types-hoigZ9HA.d.cts +9 -0
  42. package/dist/types-hoigZ9HA.d.ts +9 -0
  43. package/package.json +18 -11
  44. package/dist/chunk-3BB7IH7P.cjs +0 -22
  45. package/dist/chunk-3BB7IH7P.cjs.map +0 -1
  46. package/dist/chunk-EVIAOYPI.js.map +0 -1
  47. package/dist/chunk-JUT7NLYV.js.map +0 -1
  48. package/dist/chunk-KG4KEP7W.cjs +0 -16
  49. package/dist/chunk-KG4KEP7W.cjs.map +0 -1
  50. package/dist/chunk-OIPHYJAS.js +0 -12
  51. package/dist/chunk-OIPHYJAS.js.map +0 -1
  52. package/dist/chunk-QNXGZOH4.js +0 -10
  53. package/dist/chunk-QNXGZOH4.js.map +0 -1
  54. package/dist/chunk-S35C7FTW.js.map +0 -1
  55. package/dist/chunk-WKLGTORJ.cjs +0 -12
  56. package/dist/chunk-WKLGTORJ.cjs.map +0 -1
  57. package/dist/chunk-WOH32CRU.cjs +0 -13
  58. package/dist/chunk-WOH32CRU.cjs.map +0 -1
  59. package/dist/chunk-X65BTKB7.cjs +0 -11
  60. package/dist/chunk-X65BTKB7.cjs.map +0 -1
  61. package/dist/package-json-MvdYC-nU.d.cts +0 -23
  62. package/dist/package-json-MvdYC-nU.d.ts +0 -23
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","dirname","join","findUp","lockFileNames","findLockFile","cwd","filePath","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","parsePackageJson","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"wCAAA,OAAS,YAAAA,MAAgB,qBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,UACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,YAE9B,OAAS,UAAAC,MAAc,eAIvB,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMJ,EAAOC,EAAe,CACzC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaC,EAAqB,MAAOF,GAAsD,CAC3F,IAAMG,EAAY,MAAMN,EACnBO,GAAsB,CACnB,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYZ,EAAWG,EAAKQ,EAAWE,CAAY,CAAC,IACrDD,EAAWT,EAAKQ,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBX,EAAKQ,EAAW,cAAc,EAE1D,GAAIX,EAAWc,CAAmB,GAEVC,EAAiBd,EAAaa,EAAqB,MAAM,CAAC,EAE9D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIP,GAAO,CAAE,IAAAA,CAAI,CACrB,CACJ,EAEA,GAAI,CAACG,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,GAAIA,EAAU,SAAS,cAAc,EAAG,CACpC,IAAMM,EAAcD,EAAiBL,CAAS,EAE9C,GAAIM,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,KAAMf,EAAQQ,CAAS,CAC3B,CAER,CACJ,CAEA,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,OAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,mBAAmB,GAAKA,EAAU,SAAS,qBAAqB,EACnF,MAAO,CACH,eAAgB,MAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,gBAAgB,EACnC,MAAO,CACH,eAAgB,OAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,MAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,MAAM,IAAI,MAAM,0BAA0B,CAC9C,EAQaS,EAA4BC,GAAyBrB,EAAS,GAAGqB,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 { findUp } from \"@visulima/fs\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\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 `URL | string`. 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?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\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 `URL | string`.\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?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory: string) => {\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 = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\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 = parsePackageJson(foundFile);\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 +0,0 @@
1
- {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","dirname","join","findUp","readJson","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"wCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,UACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,YAE9B,OAAS,UAAAC,EAAQ,YAAAC,MAAgB,eAsB1B,IAAMC,EAAmB,MAAOC,GAA8C,CACjF,IAAMC,EAAoB,MAAMJ,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,KAAM,OACN,GAAIG,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAmB,SAAS,YAAY,EAAG,CAC3C,IAAMC,EAAQ,MAAMJ,EAA2DG,CAAiB,EAEhG,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAMP,EAAQM,CAAiB,EAC/B,SAAU,OACd,CAER,CAEA,IAAME,EAAUF,GAAmB,SAAS,YAAY,EAExD,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 { findUp, readJson } from \"@visulima/fs\";\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?: URL | string): Promise<RootMonorepo> => {\n const workspaceFilePath = await findUp([\"lerna.json\", \"turbo.json\"], {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (workspaceFilePath?.endsWith(\"lerna.json\")) {\n const lerna = await readJson<{ packages?: string[]; useWorkspaces?: boolean }>(workspaceFilePath);\n\n if (lerna.useWorkspaces || lerna.packages) {\n return {\n path: dirname(workspaceFilePath),\n strategy: \"lerna\",\n };\n }\n }\n\n const isTurbo = 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,16 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk3BB7IH7P_cjs = require('./chunk-3BB7IH7P.cjs');
4
- var child_process = require('child_process');
5
- var fs$1 = require('fs');
6
- var path = require('path');
7
- var fs = require('@visulima/fs');
8
-
9
- var f=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],y=async a=>{let n=await fs.findUp(f,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},x=async a=>{let n=await fs.findUp(e=>{let t;if(f.forEach(i=>{!t&&fs$1.existsSync(path.join(e,i))&&(t=path.join(e,i));}),t)return t;let r=path.join(e,"package.json");if(fs$1.existsSync(r)&&chunk3BB7IH7P_cjs.e(fs$1.readFileSync(r,"utf8")).packageManager!==void 0)return r},{...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");if(n.endsWith("package.json")){let e=chunk3BB7IH7P_cjs.e(n);if(e.packageManager){let r=["npm","yarn","pnpm","bun"].find(i=>e.packageManager.startsWith(i));if(r)return {packageManager:r,path:path.dirname(n)}}}if(n.endsWith("yarn.lock"))return {packageManager:"yarn",path:path.dirname(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:path.dirname(n)};if(n.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:path.dirname(n)};if(n.endsWith("bun.lockb"))return {packageManager:"bun",path:path.dirname(n)};throw new Error("Could not find lock file")},w=a=>child_process.execSync(`${a} --version`).toString("utf8").trim(),b=async()=>{if(!process.env.npm_config_user_agent)return;let a=process.env.npm_config_user_agent.split(" ")[0],n=a.lastIndexOf("/"),e=a.slice(0,Math.max(0,n));return {name:e==="npminstall"?"cnpm":e,version:a.slice(Math.max(0,n+1))}};
10
-
11
- exports.a = y;
12
- exports.b = x;
13
- exports.c = w;
14
- exports.d = b;
15
- //# sourceMappingURL=out.js.map
16
- //# sourceMappingURL=chunk-KG4KEP7W.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","dirname","join","findUp","lockFileNames","findLockFile","cwd","filePath","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","parsePackageJson","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"yCAAA,OAAS,YAAAA,MAAgB,gBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAE9B,OAAS,UAAAC,MAAc,eAIvB,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMJ,EAAOC,EAAe,CACzC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaC,EAAqB,MAAOF,GAAsD,CAC3F,IAAMG,EAAY,MAAMN,EACnBO,GAAsB,CACnB,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYZ,EAAWG,EAAKQ,EAAWE,CAAY,CAAC,IACrDD,EAAWT,EAAKQ,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBX,EAAKQ,EAAW,cAAc,EAE1D,GAAIX,EAAWc,CAAmB,GAEVC,EAAiBd,EAAaa,EAAqB,MAAM,CAAC,EAE9D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIP,GAAO,CAAE,IAAAA,CAAI,CACrB,CACJ,EAEA,GAAI,CAACG,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,GAAIA,EAAU,SAAS,cAAc,EAAG,CACpC,IAAMM,EAAcD,EAAiBL,CAAS,EAE9C,GAAIM,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,KAAMf,EAAQQ,CAAS,CAC3B,CAER,CACJ,CAEA,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,OAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,mBAAmB,GAAKA,EAAU,SAAS,qBAAqB,EACnF,MAAO,CACH,eAAgB,MAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,gBAAgB,EACnC,MAAO,CACH,eAAgB,OAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,MAChB,KAAMR,EAAQQ,CAAS,CAC3B,EAGJ,MAAM,IAAI,MAAM,0BAA0B,CAC9C,EAQaS,EAA4BC,GAAyBrB,EAAS,GAAGqB,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 { findUp } from \"@visulima/fs\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\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 `URL | string`. 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?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\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 `URL | string`.\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?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory: string) => {\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 = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\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 = parsePackageJson(foundFile);\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,12 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { join } from 'node:path';
3
- import { findUp, readJson, findUpSync, readJsonSync, writeJson, writeJsonSync } from '@visulima/fs';
4
- import { NotFoundError } from '@visulima/fs/error';
5
- import { toPath, parseJson } from '@visulima/fs/utils';
6
- import a from 'normalize-package-data';
7
-
8
- var R=async o=>{let t=await findUp("package.json",{...o&&{cwd:o},type:"file"});if(!t)throw new NotFoundError("Could not find package.json");let n=await readJson(t);return a(n),{packageJson:n,path:t}},O=o=>{let t=findUpSync("package.json",{...o&&{cwd:o},type:"file"});if(!t)throw new NotFoundError("Could not find package.json");let n=readJsonSync(t);return a(n),{packageJson:n,path:t}},S=async(o,t={})=>{let{cwd:n,...s}=t,r=toPath(t.cwd??process.cwd());await writeJson(join(r,"package.json"),o,s);},x=(o,t={})=>{let{cwd:n,...s}=t,r=toPath(t.cwd??process.cwd());writeJsonSync(join(r,"package.json"),o,s);},b=o=>{let t=o!==null&&typeof o=="object"&&!Array.isArray(o);if(!t&&!(typeof o=="string"))throw new TypeError("`packageFile` should be either an `object` or a `string`.");let s=t?structuredClone(o):existsSync(o)?readJsonSync(o):parseJson(o);return a(s),s};
9
-
10
- export { R as a, O as b, S as c, x as d, b as e };
11
- //# sourceMappingURL=out.js.map
12
- //# sourceMappingURL=chunk-OIPHYJAS.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-json.ts"],"names":["existsSync","join","findUp","findUpSync","readJson","readJsonSync","writeJson","writeJsonSync","NotFoundError","parseJson","toPath","normalizeData","findPackageJson","cwd","filePath","packageJson","findPackageJsonSync","writePackageJson","data","options","writeOptions","directory","writePackageJsonSync","parsePackageJson","packageFile","isObject","json"],"mappings":"AAAA,OAAS,cAAAA,MAAkB,UAC3B,OAAS,QAAAC,MAAY,YAGrB,OAAS,UAAAC,EAAQ,cAAAC,EAAY,YAAAC,EAAU,gBAAAC,EAAc,aAAAC,EAAW,iBAAAC,MAAqB,eACrF,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,aAAAC,EAAW,UAAAC,MAAc,qBAElC,OAAOC,MAAmB,yBAkBnB,IAAMC,EAAkB,MAAOC,GAAsD,CACxF,IAAMC,EAAW,MAAMZ,EAAO,eAAgB,CAC1C,GAAIW,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAIN,EAAc,6BAA6B,EAGzD,IAAMO,EAAc,MAAMX,EAASU,CAAQ,EAE3C,OAAAH,EAAcI,CAAoB,EAE3B,CACH,YAAaA,EACb,KAAMD,CACV,CACJ,EAEaE,EAAuBH,GAA6C,CAC7E,IAAMC,EAAWX,EAAW,eAAgB,CACxC,GAAIU,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAIN,EAAc,6BAA6B,EAGzD,IAAMO,EAAcV,EAAaS,CAAQ,EAEzC,OAAAH,EAAcI,CAAoB,EAE3B,CACH,YAAaA,EACb,KAAMD,CACV,CACJ,EAYaG,EAAmB,MAAwBC,EAASC,EAAqD,CAAC,IAAqB,CACxI,GAAM,CAAE,IAAAN,EAAK,GAAGO,CAAa,EAAID,EAC3BE,EAAYX,EAAOS,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErD,MAAMb,EAAUL,EAAKoB,EAAW,cAAc,EAAGH,EAAME,CAAY,CACvE,EAEaE,EAAuB,CAAkBJ,EAASC,EAAqD,CAAC,IAAY,CAC7H,GAAM,CAAE,IAAAN,EAAK,GAAGO,CAAa,EAAID,EAC3BE,EAAYX,EAAOS,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErDZ,EAAcN,EAAKoB,EAAW,cAAc,EAAGH,EAAME,CAAY,CACrE,EAEaG,EAAoBC,GAA4D,CAEzF,IAAMC,EAAWD,IAAgB,MAAQ,OAAOA,GAAgB,UAAY,CAAC,MAAM,QAAQA,CAAW,EAGtG,GAAI,CAACC,GAAY,EAFA,OAAOD,GAAgB,UAGpC,MAAM,IAAI,UAAU,2DAA2D,EAGnF,IAAME,EAAOD,EACP,gBAAgBD,CAAW,EAE3BxB,EAAWwB,CAAqB,EAC9BnB,EAAamB,CAAqB,EAClCf,EAAUe,CAAqB,EAEvC,OAAAb,EAAce,CAAa,EAEpBA,CACX","sourcesContent":["import { existsSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nimport type { WriteJsonOptions } from \"@visulima/fs\";\nimport { findUp, findUpSync, readJson, readJsonSync, writeJson, writeJsonSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { parseJson, toPath } from \"@visulima/fs/utils\";\nimport type { Input } from \"normalize-package-data\";\nimport normalizeData from \"normalize-package-data\";\nimport type { JsonObject } from \"type-fest\";\n\nimport type { NormalizedPackageJson, PackageJson } from \"./types\";\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.\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?: URL | string): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"Could not find package.json\");\n }\n\n const packageJson = await readJson(filePath);\n\n normalizeData(packageJson as Input);\n\n return {\n packageJson: packageJson as NormalizedPackageJson,\n path: filePath,\n };\n};\n\nexport const findPackageJsonSync = (cwd?: URL | string): NormalizedReadResult => {\n const filePath = findUpSync(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"Could not find package.json\");\n }\n\n const packageJson = readJsonSync(filePath);\n\n normalizeData(packageJson as Input);\n\n return {\n packageJson: packageJson as NormalizedPackageJson,\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 `WriteJsonOptions` 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\nexport const writePackageJson = async <T = PackageJson>(data: T, options: WriteJsonOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const { cwd, ...writeOptions } = options;\n const directory = toPath(options.cwd ?? process.cwd());\n\n await writeJson(join(directory, \"package.json\"), data, writeOptions);\n};\n\nexport const writePackageJsonSync = <T = PackageJson>(data: T, options: WriteJsonOptions & { cwd?: URL | string } = {}): void => {\n const { cwd, ...writeOptions } = options;\n const directory = toPath(options.cwd ?? process.cwd());\n\n writeJsonSync(join(directory, \"package.json\"), data, writeOptions);\n};\n\nexport const parsePackageJson = (packageFile: JsonObject | string): NormalizedPackageJson => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const isObject = packageFile !== null && typeof packageFile === \"object\" && !Array.isArray(packageFile);\n const isString = typeof packageFile === \"string\";\n\n if (!isObject && !isString) {\n throw new TypeError(\"`packageFile` should be either an `object` or a `string`.\");\n }\n\n const json = isObject\n ? structuredClone(packageFile)\n : // eslint-disable-next-line security/detect-non-literal-fs-filename\n existsSync(packageFile as string)\n ? readJsonSync(packageFile as string)\n : parseJson(packageFile as string);\n\n normalizeData(json as Input);\n\n return json as NormalizedPackageJson;\n};\n"]}
@@ -1,10 +0,0 @@
1
- import { join } from 'node:path';
2
- import { writeJson } from '@visulima/fs';
3
- import { toPath } from '@visulima/fs/utils';
4
- import { getTsconfig } from 'get-tsconfig';
5
-
6
- var w=async i=>{let o=i===void 0?void 0:toPath(i),n=await getTsconfig(o,"tsconfig.json");if(n===null&&(n=await getTsconfig(o,"jsconfig.json")),n===null)throw new Error("Could not find a tsconfig.json or jsconfig.json file.");return n},u=async(i,o={})=>{let{cwd:n,...r}=o,f=toPath(o.cwd??process.cwd());await writeJson(join(f,"tsconfig.json"),i,r);};
7
-
8
- export { w as a, u as b };
9
- //# sourceMappingURL=out.js.map
10
- //# sourceMappingURL=chunk-QNXGZOH4.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tsconfig.ts"],"names":["join","writeJson","toPath","getTsconfig","findTSConfig","cwd","searchPath","config","writeTSConfig","data","options","writeOptions","directory"],"mappings":"AAAA,OAAS,QAAAA,MAAY,YAGrB,OAAS,aAAAC,MAAiB,eAC1B,OAAS,UAAAC,MAAc,qBAEvB,OAAS,eAAAC,MAAmB,eAYrB,IAAMC,EAAe,MAAOC,GAAgD,CAC/E,IAAMC,EAAaD,IAAQ,OAAY,OAAYH,EAAOG,CAAG,EAIzDE,EAAS,MAAMJ,EAAYG,EAAY,eAAe,EAO1D,GALIC,IAAW,OAEXA,EAAS,MAAMJ,EAAYG,EAAY,eAAe,GAGtDC,IAAW,KACX,MAAM,IAAI,MAAM,uDAAuD,EAG3E,OAAOA,CACX,EAWaC,EAAgB,MAAOC,EAAoBC,EAAqD,CAAC,IAAqB,CAC/H,GAAM,CAAE,IAAAL,EAAK,GAAGM,CAAa,EAAID,EAE3BE,EAAYV,EAAOQ,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErD,MAAMT,EAAUD,EAAKY,EAAW,eAAe,EAAGH,EAAME,CAAY,CACxE","sourcesContent":["import { join } from \"node:path\";\n\nimport type { WriteJsonOptions } from \"@visulima/fs\";\nimport { writeJson } from \"@visulima/fs\";\nimport { toPath } from \"@visulima/fs/utils\";\nimport type { TsConfigJson, TsConfigResult } from \"get-tsconfig\";\nimport { getTsconfig } from \"get-tsconfig\";\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 (data: TsConfigJson, options: WriteJsonOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const { cwd, ...writeOptions } = options;\n\n const directory = toPath(options.cwd ?? process.cwd());\n\n await writeJson(join(directory, \"tsconfig.json\"), data, writeOptions);\n};\n\nexport type { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from \"get-tsconfig\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package.ts"],"names":["dirname","findUp","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath"],"mappings":"wCAAA,OAAS,WAAAA,MAAe,YAExB,OAAS,UAAAC,MAAc,eAgBhB,IAAMC,EAAkB,MAAOC,GAAwC,CAE1E,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,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAON,EAAQA,EAAQM,CAAS,CAAC,EAIrC,IAAMC,EAAW,MAAMN,EAAO,eAAgB,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOP,EAAQO,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { dirname } from \"node:path\";\n\nimport { findUp } from \"@visulima/fs\";\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?: URL | string): 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 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 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,12 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkKG4KEP7W_cjs = require('./chunk-KG4KEP7W.cjs');
4
- var fs$1 = require('fs');
5
- var path = require('path');
6
- var fs = require('@visulima/fs');
7
-
8
- var b=async e=>{let n=await fs.findUp(["lerna.json","turbo.json"],{type:"file",...e&&{cwd:e}});if(n?.endsWith("lerna.json")){let o=await fs.readJson(n);if(o.useWorkspaces||o.packages)return {path:path.dirname(n),strategy:"lerna"}}let s=n?.endsWith("turbo.json");try{let{packageManager:o,path:r}=await chunkKG4KEP7W_cjs.b(e);if(["npm","yarn"].includes(o)){let a=path.join(r,"package.json");if(fs$1.existsSync(a)&&fs$1.readFileSync(path.join(r,"package.json"),"utf8").includes("workspaces"))return {path:r,strategy:s?"turbo":o}}else if(o==="pnpm"){let a=path.join(r,"pnpm-workspace.yaml");if(fs$1.existsSync(a))return {path:r,strategy:s?"turbo":"pnpm"}}}catch(o){if(!o.message.includes("Could not find lock file"))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${e} using lerna, yarn, pnpm, or npm as indicators.`)};
9
-
10
- exports.a = b;
11
- //# sourceMappingURL=out.js.map
12
- //# sourceMappingURL=chunk-WKLGTORJ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","dirname","join","findUp","readJson","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"yCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAE9B,OAAS,UAAAC,EAAQ,YAAAC,MAAgB,eAsB1B,IAAMC,EAAmB,MAAOC,GAA8C,CACjF,IAAMC,EAAoB,MAAMJ,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,KAAM,OACN,GAAIG,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAmB,SAAS,YAAY,EAAG,CAC3C,IAAMC,EAAQ,MAAMJ,EAA2DG,CAAiB,EAEhG,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAMP,EAAQM,CAAiB,EAC/B,SAAU,OACd,CAER,CAEA,IAAME,EAAUF,GAAmB,SAAS,YAAY,EAExD,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 { findUp, readJson } from \"@visulima/fs\";\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?: URL | string): Promise<RootMonorepo> => {\n const workspaceFilePath = await findUp([\"lerna.json\", \"turbo.json\"], {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (workspaceFilePath?.endsWith(\"lerna.json\")) {\n const lerna = await readJson<{ packages?: string[]; useWorkspaces?: boolean }>(workspaceFilePath);\n\n if (lerna.useWorkspaces || lerna.packages) {\n return {\n path: dirname(workspaceFilePath),\n strategy: \"lerna\",\n };\n }\n }\n\n const isTurbo = 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,13 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var fs = require('@visulima/fs');
5
- var utils = require('@visulima/fs/utils');
6
- var getTsconfig = require('get-tsconfig');
7
-
8
- var l=async i=>{let o=i===void 0?void 0:utils.toPath(i),n=await getTsconfig.getTsconfig(o,"tsconfig.json");if(n===null&&(n=await getTsconfig.getTsconfig(o,"jsconfig.json")),n===null)throw new Error("Could not find a tsconfig.json or jsconfig.json file.");return n},w=async(i,o={})=>{let{cwd:n,...r}=o,f=utils.toPath(o.cwd??process.cwd());await fs.writeJson(path.join(f,"tsconfig.json"),i,r);};
9
-
10
- exports.a = l;
11
- exports.b = w;
12
- //# sourceMappingURL=out.js.map
13
- //# sourceMappingURL=chunk-WOH32CRU.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/tsconfig.ts"],"names":["join","writeJson","toPath","getTsconfig","findTSConfig","cwd","searchPath","config","writeTSConfig","data","options","writeOptions","directory"],"mappings":"AAAA,OAAS,QAAAA,MAAY,OAGrB,OAAS,aAAAC,MAAiB,eAC1B,OAAS,UAAAC,MAAc,qBAEvB,OAAS,eAAAC,MAAmB,eAYrB,IAAMC,EAAe,MAAOC,GAAgD,CAC/E,IAAMC,EAAaD,IAAQ,OAAY,OAAYH,EAAOG,CAAG,EAIzDE,EAAS,MAAMJ,EAAYG,EAAY,eAAe,EAO1D,GALIC,IAAW,OAEXA,EAAS,MAAMJ,EAAYG,EAAY,eAAe,GAGtDC,IAAW,KACX,MAAM,IAAI,MAAM,uDAAuD,EAG3E,OAAOA,CACX,EAWaC,EAAgB,MAAOC,EAAoBC,EAAqD,CAAC,IAAqB,CAC/H,GAAM,CAAE,IAAAL,EAAK,GAAGM,CAAa,EAAID,EAE3BE,EAAYV,EAAOQ,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErD,MAAMT,EAAUD,EAAKY,EAAW,eAAe,EAAGH,EAAME,CAAY,CACxE","sourcesContent":["import { join } from \"node:path\";\n\nimport type { WriteJsonOptions } from \"@visulima/fs\";\nimport { writeJson } from \"@visulima/fs\";\nimport { toPath } from \"@visulima/fs/utils\";\nimport type { TsConfigJson, TsConfigResult } from \"get-tsconfig\";\nimport { getTsconfig } from \"get-tsconfig\";\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 (data: TsConfigJson, options: WriteJsonOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const { cwd, ...writeOptions } = options;\n\n const directory = toPath(options.cwd ?? process.cwd());\n\n await writeJson(join(directory, \"tsconfig.json\"), data, writeOptions);\n};\n\nexport type { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from \"get-tsconfig\";\n"]}
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkKG4KEP7W_cjs = require('./chunk-KG4KEP7W.cjs');
4
- var path = require('path');
5
- var fs = require('@visulima/fs');
6
-
7
- var m=async t=>{try{let a=await chunkKG4KEP7W_cjs.a(t);return path.dirname(a)}catch{}let o=await fs.findUp(".git/config",{...t&&{cwd:t},type:"file"});if(o)return path.dirname(path.dirname(o));let r=await fs.findUp("package.json",{...t&&{cwd:t},type:"file"});if(r)return path.dirname(r);throw new Error("Could not find root directory")};
8
-
9
- exports.a = m;
10
- //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-X65BTKB7.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package.ts"],"names":["dirname","findUp","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath"],"mappings":"yCAAA,OAAS,WAAAA,MAAe,OAExB,OAAS,UAAAC,MAAc,eAgBhB,IAAMC,EAAkB,MAAOC,GAAwC,CAE1E,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,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAON,EAAQA,EAAQM,CAAS,CAAC,EAIrC,IAAMC,EAAW,MAAMN,EAAO,eAAgB,CAC1C,GAAIE,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOP,EAAQO,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { dirname } from \"node:path\";\n\nimport { findUp } from \"@visulima/fs\";\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?: URL | string): 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 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 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,23 +0,0 @@
1
- import * as type_fest from 'type-fest';
2
- import { PackageJson as PackageJson$1, JsonObject } from 'type-fest';
3
- import { WriteJsonOptions } from '@visulima/fs';
4
- import { Package } from 'normalize-package-data';
5
-
6
- type NormalizedPackageJson = Package & PackageJson;
7
- type PackageJson = PackageJson$1;
8
-
9
- type NormalizedReadResult = {
10
- packageJson: NormalizedPackageJson;
11
- path: string;
12
- };
13
- declare const findPackageJson: (cwd?: URL | string) => Promise<NormalizedReadResult>;
14
- declare const findPackageJsonSync: (cwd?: URL | string) => NormalizedReadResult;
15
- declare const writePackageJson: <T = type_fest.PackageJson>(data: T, options?: WriteJsonOptions & {
16
- cwd?: URL | string;
17
- }) => Promise<void>;
18
- declare const writePackageJsonSync: <T = type_fest.PackageJson>(data: T, options?: WriteJsonOptions & {
19
- cwd?: URL | string;
20
- }) => void;
21
- declare const parsePackageJson: (packageFile: JsonObject | string) => NormalizedPackageJson;
22
-
23
- export { type NormalizedReadResult as N, type PackageJson as P, findPackageJsonSync as a, writePackageJsonSync as b, type NormalizedPackageJson as c, findPackageJson as f, parsePackageJson as p, writePackageJson as w };
@@ -1,23 +0,0 @@
1
- import * as type_fest from 'type-fest';
2
- import { PackageJson as PackageJson$1, JsonObject } from 'type-fest';
3
- import { WriteJsonOptions } from '@visulima/fs';
4
- import { Package } from 'normalize-package-data';
5
-
6
- type NormalizedPackageJson = Package & PackageJson;
7
- type PackageJson = PackageJson$1;
8
-
9
- type NormalizedReadResult = {
10
- packageJson: NormalizedPackageJson;
11
- path: string;
12
- };
13
- declare const findPackageJson: (cwd?: URL | string) => Promise<NormalizedReadResult>;
14
- declare const findPackageJsonSync: (cwd?: URL | string) => NormalizedReadResult;
15
- declare const writePackageJson: <T = type_fest.PackageJson>(data: T, options?: WriteJsonOptions & {
16
- cwd?: URL | string;
17
- }) => Promise<void>;
18
- declare const writePackageJsonSync: <T = type_fest.PackageJson>(data: T, options?: WriteJsonOptions & {
19
- cwd?: URL | string;
20
- }) => void;
21
- declare const parsePackageJson: (packageFile: JsonObject | string) => NormalizedPackageJson;
22
-
23
- export { type NormalizedReadResult as N, type PackageJson as P, findPackageJsonSync as a, writePackageJsonSync as b, type NormalizedPackageJson as c, findPackageJson as f, parsePackageJson as p, writePackageJson as w };