@visulima/package 1.2.10 → 1.3.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 (67) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/chunk-3BB7IH7P.cjs +22 -0
  3. package/dist/chunk-3BB7IH7P.cjs.map +1 -0
  4. package/dist/chunk-EVIAOYPI.js +11 -0
  5. package/dist/chunk-EVIAOYPI.js.map +1 -0
  6. package/dist/chunk-JUT7NLYV.js +10 -0
  7. package/dist/chunk-JUT7NLYV.js.map +1 -0
  8. package/dist/chunk-KG4KEP7W.cjs +16 -0
  9. package/dist/chunk-KG4KEP7W.cjs.map +1 -0
  10. package/dist/chunk-OIPHYJAS.js +12 -0
  11. package/dist/chunk-OIPHYJAS.js.map +1 -0
  12. package/dist/chunk-QNXGZOH4.js +10 -0
  13. package/dist/chunk-QNXGZOH4.js.map +1 -0
  14. package/dist/chunk-S35C7FTW.js +9 -0
  15. package/dist/chunk-S35C7FTW.js.map +1 -0
  16. package/dist/chunk-WKLGTORJ.cjs +12 -0
  17. package/dist/chunk-WKLGTORJ.cjs.map +1 -0
  18. package/dist/chunk-WOH32CRU.cjs +13 -0
  19. package/dist/chunk-WOH32CRU.cjs.map +1 -0
  20. package/dist/chunk-X65BTKB7.cjs +11 -0
  21. package/dist/chunk-X65BTKB7.cjs.map +1 -0
  22. package/dist/index.cjs +64 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +9 -0
  25. package/dist/index.d.ts +4 -4
  26. package/dist/index.js +5 -6
  27. package/dist/monorepo.cjs +14 -0
  28. package/dist/monorepo.cjs.map +1 -0
  29. package/dist/monorepo.d.cts +8 -0
  30. package/dist/monorepo.d.ts +1 -3
  31. package/dist/monorepo.js +3 -2
  32. package/dist/package-json-MvdYC-nU.d.cts +23 -0
  33. package/dist/package-json-MvdYC-nU.d.ts +23 -0
  34. package/dist/package-json.cjs +28 -0
  35. package/dist/package-json.cjs.map +1 -0
  36. package/dist/package-json.d.cts +4 -0
  37. package/dist/package-json.d.ts +4 -15
  38. package/dist/package-json.js +1 -2
  39. package/dist/package-manager.cjs +25 -0
  40. package/dist/package-manager.cjs.map +1 -0
  41. package/dist/package-manager.d.cts +14 -0
  42. package/dist/package-manager.d.ts +2 -4
  43. package/dist/package-manager.js +2 -1
  44. package/dist/package.cjs +14 -0
  45. package/dist/package.cjs.map +1 -0
  46. package/dist/package.d.cts +3 -0
  47. package/dist/package.d.ts +1 -3
  48. package/dist/package.js +3 -2
  49. package/dist/tsconfig.cjs +16 -0
  50. package/dist/tsconfig.cjs.map +1 -0
  51. package/dist/tsconfig.d.cts +10 -0
  52. package/dist/tsconfig.d.ts +2 -2
  53. package/dist/tsconfig.js +1 -2
  54. package/package.json +36 -11
  55. package/dist/chunk-5CE7NVS2.js +0 -14
  56. package/dist/chunk-5CE7NVS2.js.map +0 -1
  57. package/dist/chunk-I2QN4KO5.js +0 -11
  58. package/dist/chunk-I2QN4KO5.js.map +0 -1
  59. package/dist/chunk-LH5BGOWS.js +0 -9
  60. package/dist/chunk-LH5BGOWS.js.map +0 -1
  61. package/dist/chunk-SET64FVW.js +0 -13
  62. package/dist/chunk-SET64FVW.js.map +0 -1
  63. package/dist/chunk-YMGIEDHF.js +0 -10
  64. package/dist/chunk-YMGIEDHF.js.map +0 -1
  65. package/dist/chunk-ZRX4WIQ4.js +0 -11
  66. package/dist/chunk-ZRX4WIQ4.js.map +0 -1
  67. package/dist/write-json-EkV5tJMg.d.ts +0 -6
package/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ## @visulima/package [1.3.1](https://github.com/visulima/visulima/compare/@visulima/package@1.3.0...@visulima/package@1.3.1) (2024-03-16)
2
+
3
+
4
+
5
+ ### Dependencies
6
+
7
+ * **@visulima/fs:** upgraded to 1.7.1
8
+
9
+ ## @visulima/package [1.3.0](https://github.com/visulima/visulima/compare/@visulima/package@1.2.10...@visulima/package@1.3.0) (2024-03-16)
10
+
11
+
12
+ ### Features
13
+
14
+ * **package:** added cjs and esm export ([#335](https://github.com/visulima/visulima/issues/335)) ([62b873a](https://github.com/visulima/visulima/commit/62b873a76d2a5356e7596d3a7e299d8e51eb2fcd))
15
+
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * **@visulima/fs:** upgraded to 1.7.0
21
+
1
22
  ## @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
23
 
3
24
 
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ var fs$1 = require('fs');
4
+ var path = require('path');
5
+ var fs = require('@visulima/fs');
6
+ var error = require('@visulima/fs/error');
7
+ var utils = require('@visulima/fs/utils');
8
+ var a = require('normalize-package-data');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var a__default = /*#__PURE__*/_interopDefault(a);
13
+
14
+ var N=async o=>{let t=await fs.findUp("package.json",{...o&&{cwd:o},type:"file"});if(!t)throw new error.NotFoundError("Could not find package.json");let n=await fs.readJson(t);return a__default.default(n),{packageJson:n,path:t}},R=o=>{let t=fs.findUpSync("package.json",{...o&&{cwd:o},type:"file"});if(!t)throw new error.NotFoundError("Could not find package.json");let n=fs.readJsonSync(t);return a__default.default(n),{packageJson:n,path:t}},O=async(o,t={})=>{let{cwd:n,...s}=t,r=utils.toPath(t.cwd??process.cwd());await fs.writeJson(path.join(r,"package.json"),o,s);},S=(o,t={})=>{let{cwd:n,...s}=t,r=utils.toPath(t.cwd??process.cwd());fs.writeJsonSync(path.join(r,"package.json"),o,s);},x=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):fs$1.existsSync(o)?fs.readJsonSync(o):utils.parseJson(o);return a__default.default(s),s};
15
+
16
+ exports.a = N;
17
+ exports.b = R;
18
+ exports.c = O;
19
+ exports.d = S;
20
+ exports.e = x;
21
+ //# sourceMappingURL=out.js.map
22
+ //# sourceMappingURL=chunk-3BB7IH7P.cjs.map
@@ -0,0 +1 @@
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,KAC3B,OAAS,QAAAC,MAAY,OAGrB,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"]}
@@ -0,0 +1,11 @@
1
+ import { e } from './chunk-OIPHYJAS.js';
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { join, dirname } from 'node:path';
5
+ import { findUp } from '@visulima/fs';
6
+
7
+ var f=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],x=async a=>{let n=await findUp(f,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},w=async a=>{let n=await findUp(e$1=>{let t;if(f.forEach(i=>{!t&&existsSync(join(e$1,i))&&(t=join(e$1,i));}),t)return t;let r=join(e$1,"package.json");if(existsSync(r)&&e(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$1=e(n);if(e$1.packageManager){let r=["npm","yarn","pnpm","bun"].find(i=>e$1.packageManager.startsWith(i));if(r)return {packageManager:r,path:dirname(n)}}}if(n.endsWith("yarn.lock"))return {packageManager:"yarn",path:dirname(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:dirname(n)};if(n.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:dirname(n)};if(n.endsWith("bun.lockb"))return {packageManager:"bun",path:dirname(n)};throw new Error("Could not find lock file")},b=a=>execSync(`${a} --version`).toString("utf8").trim(),j=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))}};
8
+
9
+ export { x as a, w as b, b as c, j as d };
10
+ //# sourceMappingURL=out.js.map
11
+ //# sourceMappingURL=chunk-EVIAOYPI.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,10 @@
1
+ import { b } from './chunk-EVIAOYPI.js';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { findUp, readJson } from '@visulima/fs';
5
+
6
+ var j=async e=>{let n=await findUp(["lerna.json","turbo.json"],{type:"file",...e&&{cwd:e}});if(n?.endsWith("lerna.json")){let o=await readJson(n);if(o.useWorkspaces||o.packages)return {path:dirname(n),strategy:"lerna"}}let s=n?.endsWith("turbo.json");try{let{packageManager:o,path:r}=await b(e);if(["npm","yarn"].includes(o)){let a=join(r,"package.json");if(existsSync(a)&&readFileSync(join(r,"package.json"),"utf8").includes("workspaces"))return {path:r,strategy:s?"turbo":o}}else if(o==="pnpm"){let a=join(r,"pnpm-workspace.yaml");if(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.`)};
7
+
8
+ export { j as a };
9
+ //# sourceMappingURL=out.js.map
10
+ //# sourceMappingURL=chunk-JUT7NLYV.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,16 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,12 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,10 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,9 @@
1
+ import { a } from './chunk-EVIAOYPI.js';
2
+ import { dirname } from 'node:path';
3
+ import { findUp } from '@visulima/fs';
4
+
5
+ var p=async t=>{try{let a$1=await a(t);return dirname(a$1)}catch{}let o=await findUp(".git/config",{...t&&{cwd:t},type:"file"});if(o)return dirname(dirname(o));let r=await findUp("package.json",{...t&&{cwd:t},type:"file"});if(r)return dirname(r);throw new Error("Could not find root directory")};
6
+
7
+ export { p as a };
8
+ //# sourceMappingURL=out.js.map
9
+ //# sourceMappingURL=chunk-S35C7FTW.js.map
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,12 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,13 @@
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
@@ -0,0 +1 @@
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"]}
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ var chunkWKLGTORJ_cjs = require('./chunk-WKLGTORJ.cjs');
4
+ var chunkX65BTKB7_cjs = require('./chunk-X65BTKB7.cjs');
5
+ var chunkKG4KEP7W_cjs = require('./chunk-KG4KEP7W.cjs');
6
+ var chunk3BB7IH7P_cjs = require('./chunk-3BB7IH7P.cjs');
7
+ var chunkWOH32CRU_cjs = require('./chunk-WOH32CRU.cjs');
8
+
9
+
10
+
11
+ Object.defineProperty(exports, 'findMonorepoRoot', {
12
+ enumerable: true,
13
+ get: function () { return chunkWKLGTORJ_cjs.a; }
14
+ });
15
+ Object.defineProperty(exports, 'findPackageRoot', {
16
+ enumerable: true,
17
+ get: function () { return chunkX65BTKB7_cjs.a; }
18
+ });
19
+ Object.defineProperty(exports, 'findLockFile', {
20
+ enumerable: true,
21
+ get: function () { return chunkKG4KEP7W_cjs.a; }
22
+ });
23
+ Object.defineProperty(exports, 'findPackageManager', {
24
+ enumerable: true,
25
+ get: function () { return chunkKG4KEP7W_cjs.b; }
26
+ });
27
+ Object.defineProperty(exports, 'getPackageManagerVersion', {
28
+ enumerable: true,
29
+ get: function () { return chunkKG4KEP7W_cjs.c; }
30
+ });
31
+ Object.defineProperty(exports, 'identifyInitiatingPackageManager', {
32
+ enumerable: true,
33
+ get: function () { return chunkKG4KEP7W_cjs.d; }
34
+ });
35
+ Object.defineProperty(exports, 'findPackageJson', {
36
+ enumerable: true,
37
+ get: function () { return chunk3BB7IH7P_cjs.a; }
38
+ });
39
+ Object.defineProperty(exports, 'findPackageJsonSync', {
40
+ enumerable: true,
41
+ get: function () { return chunk3BB7IH7P_cjs.b; }
42
+ });
43
+ Object.defineProperty(exports, 'parsePackageJson', {
44
+ enumerable: true,
45
+ get: function () { return chunk3BB7IH7P_cjs.e; }
46
+ });
47
+ Object.defineProperty(exports, 'writePackageJson', {
48
+ enumerable: true,
49
+ get: function () { return chunk3BB7IH7P_cjs.c; }
50
+ });
51
+ Object.defineProperty(exports, 'writePackageJsonSync', {
52
+ enumerable: true,
53
+ get: function () { return chunk3BB7IH7P_cjs.d; }
54
+ });
55
+ Object.defineProperty(exports, 'findTSConfig', {
56
+ enumerable: true,
57
+ get: function () { return chunkWOH32CRU_cjs.a; }
58
+ });
59
+ Object.defineProperty(exports, 'writeTSConfig', {
60
+ enumerable: true,
61
+ get: function () { return chunkWOH32CRU_cjs.b; }
62
+ });
63
+ //# sourceMappingURL=out.js.map
64
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.cjs';
2
+ export { findPackageRoot } from './package.cjs';
3
+ export { c as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, f as findPackageJson, a as findPackageJsonSync, p as parsePackageJson, w as writePackageJson, b as writePackageJsonSync } from './package-json-MvdYC-nU.cjs';
4
+ export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.cjs';
5
+ export { findTSConfig, writeTSConfig } from './tsconfig.cjs';
6
+ export { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from 'get-tsconfig';
7
+ import 'type-fest';
8
+ import '@visulima/fs';
9
+ import 'normalize-package-data';
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.js';
2
2
  export { findPackageRoot } from './package.js';
3
- export { NormalizedReadResult, findPackageJson, writePackageJson } from './package-json.js';
3
+ export { c as NormalizedPackageJson, N as NormalizedReadResult, P as PackageJson, f as findPackageJson, a as findPackageJsonSync, p as parsePackageJson, w as writePackageJson, b as writePackageJsonSync } from './package-json-MvdYC-nU.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, PackageJson, parsePackage as parsePackageJson } from 'read-pkg';
7
6
  export { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from 'get-tsconfig';
8
- import 'find-up';
9
- import './write-json-EkV5tJMg.js';
7
+ import 'type-fest';
8
+ import '@visulima/fs';
9
+ import 'normalize-package-data';
package/dist/index.js CHANGED
@@ -1,8 +1,7 @@
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';
1
+ export { a as findMonorepoRoot } from './chunk-JUT7NLYV.js';
2
+ export { a as findPackageRoot } from './chunk-S35C7FTW.js';
3
+ export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-EVIAOYPI.js';
4
+ export { a as findPackageJson, b as findPackageJsonSync, e as parsePackageJson, c as writePackageJson, d as writePackageJsonSync } from './chunk-OIPHYJAS.js';
5
+ export { a as findTSConfig, b as writeTSConfig } from './chunk-QNXGZOH4.js';
7
6
  //# sourceMappingURL=out.js.map
8
7
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var chunkWKLGTORJ_cjs = require('./chunk-WKLGTORJ.cjs');
4
+ require('./chunk-KG4KEP7W.cjs');
5
+ require('./chunk-3BB7IH7P.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, 'findMonorepoRoot', {
10
+ enumerable: true,
11
+ get: function () { return chunkWKLGTORJ_cjs.a; }
12
+ });
13
+ //# sourceMappingURL=out.js.map
14
+ //# sourceMappingURL=monorepo.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ type Strategy = "lerna" | "npm" | "pnpm" | "turbo" | "yarn";
2
+ interface RootMonorepo<T extends Strategy = Strategy> {
3
+ path: string;
4
+ strategy: T;
5
+ }
6
+ declare const findMonorepoRoot: (cwd?: URL | string) => Promise<RootMonorepo>;
7
+
8
+ export { type RootMonorepo, type Strategy, findMonorepoRoot };
@@ -1,10 +1,8 @@
1
- import { Options } from 'find-up';
2
-
3
1
  type Strategy = "lerna" | "npm" | "pnpm" | "turbo" | "yarn";
4
2
  interface RootMonorepo<T extends Strategy = Strategy> {
5
3
  path: string;
6
4
  strategy: T;
7
5
  }
8
- declare const findMonorepoRoot: (cwd?: Options["cwd"]) => Promise<RootMonorepo>;
6
+ declare const findMonorepoRoot: (cwd?: URL | string) => Promise<RootMonorepo>;
9
7
 
10
8
  export { type RootMonorepo, type Strategy, findMonorepoRoot };
package/dist/monorepo.js CHANGED
@@ -1,4 +1,5 @@
1
- export { a as findMonorepoRoot } from './chunk-I2QN4KO5.js';
2
- import './chunk-ZRX4WIQ4.js';
1
+ export { a as findMonorepoRoot } from './chunk-JUT7NLYV.js';
2
+ import './chunk-EVIAOYPI.js';
3
+ import './chunk-OIPHYJAS.js';
3
4
  //# sourceMappingURL=out.js.map
4
5
  //# sourceMappingURL=monorepo.js.map
@@ -0,0 +1,23 @@
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 };
@@ -0,0 +1,23 @@
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 };
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var chunk3BB7IH7P_cjs = require('./chunk-3BB7IH7P.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, 'findPackageJson', {
8
+ enumerable: true,
9
+ get: function () { return chunk3BB7IH7P_cjs.a; }
10
+ });
11
+ Object.defineProperty(exports, 'findPackageJsonSync', {
12
+ enumerable: true,
13
+ get: function () { return chunk3BB7IH7P_cjs.b; }
14
+ });
15
+ Object.defineProperty(exports, 'parsePackageJson', {
16
+ enumerable: true,
17
+ get: function () { return chunk3BB7IH7P_cjs.e; }
18
+ });
19
+ Object.defineProperty(exports, 'writePackageJson', {
20
+ enumerable: true,
21
+ get: function () { return chunk3BB7IH7P_cjs.c; }
22
+ });
23
+ Object.defineProperty(exports, 'writePackageJsonSync', {
24
+ enumerable: true,
25
+ get: function () { return chunk3BB7IH7P_cjs.d; }
26
+ });
27
+ //# sourceMappingURL=out.js.map
28
+ //# sourceMappingURL=package-json.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,4 @@
1
+ import 'type-fest';
2
+ import '@visulima/fs';
3
+ export { N as NormalizedReadResult, f as findPackageJson, a as findPackageJsonSync, p as parsePackageJson, w as writePackageJson, b as writePackageJsonSync } from './package-json-MvdYC-nU.cjs';
4
+ import 'normalize-package-data';
@@ -1,15 +1,4 @@
1
- import { Options } from 'find-up';
2
- import { NormalizedPackageJson, PackageJson } from 'read-pkg';
3
- export { NormalizedPackageJson, parsePackage as parsePackageJson } from 'read-pkg';
4
- import { W as WriteOptions } from './write-json-EkV5tJMg.js';
5
-
6
- type NormalizedReadResult = {
7
- packageJson: NormalizedPackageJson;
8
- path: string;
9
- };
10
- declare const findPackageJson: (cwd?: Options["cwd"]) => Promise<NormalizedReadResult>;
11
- declare const writePackageJson: (data: PackageJson & Record<string, any>, options?: WriteOptions & {
12
- cwd?: Options["cwd"];
13
- }) => Promise<void>;
14
-
15
- export { type NormalizedReadResult, findPackageJson, writePackageJson };
1
+ import 'type-fest';
2
+ import '@visulima/fs';
3
+ export { N as NormalizedReadResult, f as findPackageJson, a as findPackageJsonSync, p as parsePackageJson, w as writePackageJson, b as writePackageJsonSync } from './package-json-MvdYC-nU.js';
4
+ import 'normalize-package-data';
@@ -1,4 +1,3 @@
1
- export { a as findPackageJson, c as parsePackageJson, b as writePackageJson } from './chunk-SET64FVW.js';
2
- import './chunk-5CE7NVS2.js';
1
+ export { a as findPackageJson, b as findPackageJsonSync, e as parsePackageJson, c as writePackageJson, d as writePackageJsonSync } from './chunk-OIPHYJAS.js';
3
2
  //# sourceMappingURL=out.js.map
4
3
  //# sourceMappingURL=package-json.js.map
@@ -0,0 +1,25 @@
1
+ 'use strict';
2
+
3
+ var chunkKG4KEP7W_cjs = require('./chunk-KG4KEP7W.cjs');
4
+ require('./chunk-3BB7IH7P.cjs');
5
+
6
+
7
+
8
+ Object.defineProperty(exports, 'findLockFile', {
9
+ enumerable: true,
10
+ get: function () { return chunkKG4KEP7W_cjs.a; }
11
+ });
12
+ Object.defineProperty(exports, 'findPackageManager', {
13
+ enumerable: true,
14
+ get: function () { return chunkKG4KEP7W_cjs.b; }
15
+ });
16
+ Object.defineProperty(exports, 'getPackageManagerVersion', {
17
+ enumerable: true,
18
+ get: function () { return chunkKG4KEP7W_cjs.c; }
19
+ });
20
+ Object.defineProperty(exports, 'identifyInitiatingPackageManager', {
21
+ enumerable: true,
22
+ get: function () { return chunkKG4KEP7W_cjs.d; }
23
+ });
24
+ //# sourceMappingURL=out.js.map
25
+ //# sourceMappingURL=package-manager.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ declare const findLockFile: (cwd?: URL | string) => Promise<string>;
2
+ type PackageManager = "bun" | "npm" | "pnpm" | "yarn";
3
+ type PackageManagerResult = {
4
+ packageManager: PackageManager;
5
+ path: string;
6
+ };
7
+ declare const findPackageManager: (cwd?: URL | string) => Promise<PackageManagerResult>;
8
+ declare const getPackageManagerVersion: (name: string) => string;
9
+ declare const identifyInitiatingPackageManager: () => Promise<{
10
+ name: PackageManager | "cnpm";
11
+ version: string;
12
+ } | undefined>;
13
+
14
+ export { type PackageManager, type PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
@@ -1,12 +1,10 @@
1
- import { Options } from 'find-up';
2
-
3
- declare const findLockFile: (cwd?: Options["cwd"]) => Promise<string>;
1
+ declare const findLockFile: (cwd?: URL | string) => Promise<string>;
4
2
  type PackageManager = "bun" | "npm" | "pnpm" | "yarn";
5
3
  type PackageManagerResult = {
6
4
  packageManager: PackageManager;
7
5
  path: string;
8
6
  };
9
- declare const findPackageManager: (cwd?: Options["cwd"]) => Promise<PackageManagerResult>;
7
+ declare const findPackageManager: (cwd?: URL | string) => Promise<PackageManagerResult>;
10
8
  declare const getPackageManagerVersion: (name: string) => string;
11
9
  declare const identifyInitiatingPackageManager: () => Promise<{
12
10
  name: PackageManager | "cnpm";
@@ -1,3 +1,4 @@
1
- export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-ZRX4WIQ4.js';
1
+ export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-EVIAOYPI.js';
2
+ import './chunk-OIPHYJAS.js';
2
3
  //# sourceMappingURL=out.js.map
3
4
  //# sourceMappingURL=package-manager.js.map
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var chunkX65BTKB7_cjs = require('./chunk-X65BTKB7.cjs');
4
+ require('./chunk-KG4KEP7W.cjs');
5
+ require('./chunk-3BB7IH7P.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, 'findPackageRoot', {
10
+ enumerable: true,
11
+ get: function () { return chunkX65BTKB7_cjs.a; }
12
+ });
13
+ //# sourceMappingURL=out.js.map
14
+ //# sourceMappingURL=package.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
2
+
3
+ export { findPackageRoot };
package/dist/package.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { Options } from 'find-up';
2
-
3
- declare const findPackageRoot: (cwd?: Options["cwd"]) => Promise<string>;
1
+ declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
4
2
 
5
3
  export { findPackageRoot };
package/dist/package.js CHANGED
@@ -1,4 +1,5 @@
1
- export { a as findPackageRoot } from './chunk-LH5BGOWS.js';
2
- import './chunk-ZRX4WIQ4.js';
1
+ export { a as findPackageRoot } from './chunk-S35C7FTW.js';
2
+ import './chunk-EVIAOYPI.js';
3
+ import './chunk-OIPHYJAS.js';
3
4
  //# sourceMappingURL=out.js.map
4
5
  //# sourceMappingURL=package.js.map
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var chunkWOH32CRU_cjs = require('./chunk-WOH32CRU.cjs');
4
+
5
+
6
+
7
+ Object.defineProperty(exports, 'findTSConfig', {
8
+ enumerable: true,
9
+ get: function () { return chunkWOH32CRU_cjs.a; }
10
+ });
11
+ Object.defineProperty(exports, 'writeTSConfig', {
12
+ enumerable: true,
13
+ get: function () { return chunkWOH32CRU_cjs.b; }
14
+ });
15
+ //# sourceMappingURL=out.js.map
16
+ //# sourceMappingURL=tsconfig.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,10 @@
1
+ import { WriteJsonOptions } from '@visulima/fs';
2
+ import { TsConfigResult, TsConfigJson } from 'get-tsconfig';
3
+ export { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from 'get-tsconfig';
4
+
5
+ declare const findTSConfig: (cwd?: URL | string) => Promise<TsConfigResult>;
6
+ declare const writeTSConfig: (data: TsConfigJson, options?: WriteJsonOptions & {
7
+ cwd?: URL | string;
8
+ }) => Promise<void>;
9
+
10
+ export { findTSConfig, writeTSConfig };
@@ -1,9 +1,9 @@
1
+ import { WriteJsonOptions } from '@visulima/fs';
1
2
  import { TsConfigResult, TsConfigJson } from 'get-tsconfig';
2
3
  export { TsConfigJson, TsConfigJsonResolved, TsConfigResult } from 'get-tsconfig';
3
- import { W as WriteOptions } from './write-json-EkV5tJMg.js';
4
4
 
5
5
  declare const findTSConfig: (cwd?: URL | string) => Promise<TsConfigResult>;
6
- declare const writeTSConfig: (tsConfig: TsConfigJson, options?: WriteOptions & {
6
+ declare const writeTSConfig: (data: TsConfigJson, options?: WriteJsonOptions & {
7
7
  cwd?: URL | string;
8
8
  }) => Promise<void>;
9
9
 
package/dist/tsconfig.js CHANGED
@@ -1,4 +1,3 @@
1
- export { a as findTSConfig, b as writeTSConfig } from './chunk-YMGIEDHF.js';
2
- import './chunk-5CE7NVS2.js';
1
+ export { a as findTSConfig, b as writeTSConfig } from './chunk-QNXGZOH4.js';
3
2
  //# sourceMappingURL=out.js.map
4
3
  //# sourceMappingURL=tsconfig.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/package",
3
- "version": "1.2.10",
3
+ "version": "1.3.1",
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",
@@ -50,36 +50,60 @@
50
50
  "type": "module",
51
51
  "exports": {
52
52
  ".": {
53
+ "require": {
54
+ "types": "./dist/index.d.cts",
55
+ "default": "./dist/index.cjs"
56
+ },
53
57
  "import": {
54
58
  "types": "./dist/index.d.ts",
55
59
  "default": "./dist/index.js"
56
60
  }
57
61
  },
58
62
  "./monorepo": {
63
+ "require": {
64
+ "types": "./dist/monorepo.d.cts",
65
+ "default": "./dist/monorepo.cjs"
66
+ },
59
67
  "import": {
60
68
  "types": "./dist/monorepo.d.ts",
61
69
  "default": "./dist/monorepo.js"
62
70
  }
63
71
  },
64
72
  "./package": {
73
+ "require": {
74
+ "types": "./dist/package.d.cts",
75
+ "default": "./dist/package.cjs"
76
+ },
65
77
  "import": {
66
78
  "types": "./dist/package.d.ts",
67
79
  "default": "./dist/package.js"
68
80
  }
69
81
  },
70
82
  "./package-json": {
83
+ "require": {
84
+ "types": "./dist/package-json.d.cts",
85
+ "default": "./dist/package-json.cjs"
86
+ },
71
87
  "import": {
72
88
  "types": "./dist/package-json.d.ts",
73
89
  "default": "./dist/package-json.js"
74
90
  }
75
91
  },
76
92
  "./package-manager": {
93
+ "require": {
94
+ "types": "./dist/package-manager.d.cts",
95
+ "default": "./dist/package-manager.cjs"
96
+ },
77
97
  "import": {
78
98
  "types": "./dist/package-manager.d.ts",
79
99
  "default": "./dist/package-manager.js"
80
100
  }
81
101
  },
82
102
  "./tsconfig": {
103
+ "require": {
104
+ "types": "./dist/tsconfig.d.cts",
105
+ "default": "./dist/tsconfig.cjs"
106
+ },
83
107
  "import": {
84
108
  "types": "./dist/tsconfig.d.ts",
85
109
  "default": "./dist/tsconfig.js"
@@ -87,6 +111,7 @@
87
111
  },
88
112
  "./package.json": "./package.json"
89
113
  },
114
+ "main": "dist/index.cjs",
90
115
  "module": "dist/index.js",
91
116
  "types": "dist/index.d.ts",
92
117
  "files": [
@@ -112,11 +137,10 @@
112
137
  "test:watch": "vitest"
113
138
  },
114
139
  "dependencies": {
115
- "detect-indent": "^7.0.1",
116
- "find-up": "^7.0.0",
140
+ "@visulima/fs": "1.7.1",
117
141
  "get-tsconfig": "^4.7.3",
118
- "read-pkg": "^9.0.1",
119
- "strip-json-comments": "^5.0.1"
142
+ "normalize-package-data": "^6.0.0",
143
+ "type-fest": "^4.12.0"
120
144
  },
121
145
  "devDependencies": {
122
146
  "@anolilab/eslint-config": "^15.0.3",
@@ -127,8 +151,8 @@
127
151
  "@rushstack/eslint-plugin-security": "^0.8.1",
128
152
  "@total-typescript/ts-reset": "^0.5.1",
129
153
  "@types/node": "18.18.14",
130
- "@vitest/coverage-v8": "^1.3.1",
131
- "@vitest/ui": "^1.3.1",
154
+ "@vitest/coverage-v8": "^1.4.0",
155
+ "@vitest/ui": "^1.4.0",
132
156
  "cnpm": "^9.4.0",
133
157
  "cross-env": "^7.0.3",
134
158
  "eslint": "^8.57.0",
@@ -137,17 +161,18 @@
137
161
  "eslint-plugin-import": "npm:eslint-plugin-i@^2.29.1",
138
162
  "eslint-plugin-mdx": "^3.1.5",
139
163
  "eslint-plugin-tsdoc": "^0.2.17",
140
- "eslint-plugin-vitest": "^0.3.25",
141
- "eslint-plugin-vitest-globals": "^1.4.0",
164
+ "eslint-plugin-vitest": "^0.3.26",
165
+ "eslint-plugin-vitest-globals": "^1.5.0",
142
166
  "execa": "^8.0.1",
143
167
  "npm": "^10.5.0",
144
168
  "prettier": "^3.2.5",
145
169
  "rimraf": "^5.0.5",
146
- "semantic-release": "^23.0.2",
170
+ "semantic-release": "^23.0.4",
147
171
  "sort-package-json": "^2.8.0",
172
+ "tempy": "^3.1.0",
148
173
  "tsup": "^8.0.2",
149
174
  "typescript": "^5.4.2",
150
- "vitest": "^1.3.1",
175
+ "vitest": "^1.4.0",
151
176
  "which-pm-runs": "file:",
152
177
  "yarn": "^1.22.22"
153
178
  },
@@ -1,14 +0,0 @@
1
- import { fileURLToPath } from 'node:url';
2
- import { existsSync } from 'node:fs';
3
- import { writeFile, readFile } from 'node:fs/promises';
4
- import m from 'detect-indent';
5
-
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?`
7
- `:n.newline===!1?"":n.newline??(t?t.endsWith(`
8
- `)?`
9
- `:"":`
10
- `);return {indent:i,newline:r}},v=async(e,n,t={})=>{let i=await p(e,t),r=JSON.stringify(n,void 0,i.indent);r+=i.newline,await writeFile(e,r);};
11
-
12
- export { w as a, v as b };
13
- //# sourceMappingURL=out.js.map
14
- //# sourceMappingURL=chunk-5CE7NVS2.js.map
@@ -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,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,11 +0,0 @@
1
- import { b } from './chunk-ZRX4WIQ4.js';
2
- import { readFileSync, existsSync } from 'node:fs';
3
- import { dirname, join } from 'node:path';
4
- import { findUp } from 'find-up';
5
- import l from 'strip-json-comments';
6
-
7
- var j=async e=>{let r=await findUp(["lerna.json","turbo.json"],{allowSymlinks:!1,type:"file",...e&&{cwd:e}});if(r&&r.endsWith("lerna.json")){let o=JSON.parse(l(readFileSync(r,"utf8")));if(o.useWorkspaces||o.packages)return {path:dirname(r),strategy:"lerna"}}let s=r&&r.endsWith("turbo.json");try{let{packageManager:o,path:n}=await b(e);if(["npm","yarn"].includes(o)){let t=join(n,"package.json");if(existsSync(t)&&readFileSync(join(n,"package.json"),"utf8").includes("workspaces"))return {path:n,strategy:s?"turbo":o}}else if(o==="pnpm"){let t=join(n,"pnpm-workspace.yaml");if(existsSync(t))return {path:n,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.`)};
8
-
9
- export { j as a };
10
- //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-I2QN4KO5.js.map
@@ -1 +0,0 @@
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 +0,0 @@
1
- import { a } from './chunk-ZRX4WIQ4.js';
2
- import { dirname } from 'node:path';
3
- import { findUp } from 'find-up';
4
-
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
-
7
- export { c as a };
8
- //# sourceMappingURL=out.js.map
9
- //# sourceMappingURL=chunk-LH5BGOWS.js.map
@@ -1 +0,0 @@
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,13 +0,0 @@
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
- import { findUp } from 'find-up';
6
- import { parsePackage } from 'read-pkg';
7
- export { parsePackage as c } from 'read-pkg';
8
-
9
- var J=async(e=void 0)=>{let o=await findUp("package.json",{...e&&{cwd:e},allowSymlinks:!1,type:"file"});if(!o)throw new Error("Could not find package.json");return {packageJson:parsePackage(readFileSync(o,"utf8"),{normalize:!0}),path:o}},h=async(e,o={})=>{let r=a(o.cwd??process.cwd()),i=join(r,"package.json");await mkdir(r,{recursive:!0}),await b(i,e,o);};
10
-
11
- export { J as a, h as b };
12
- //# sourceMappingURL=out.js.map
13
- //# sourceMappingURL=chunk-SET64FVW.js.map
@@ -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,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 +0,0 @@
1
- import { a, b } from './chunk-5CE7NVS2.js';
2
- import { mkdir } from 'node:fs/promises';
3
- import { join } from 'node:path';
4
- import { getTsconfig } from 'get-tsconfig';
5
-
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
-
8
- export { w as a, C as b };
9
- //# sourceMappingURL=out.js.map
10
- //# sourceMappingURL=chunk-YMGIEDHF.js.map
@@ -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,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,11 +0,0 @@
1
- import { execSync } from 'node:child_process';
2
- import { existsSync, readFileSync } from 'node:fs';
3
- import { join, dirname } from 'node:path';
4
- import { findUp } from 'find-up';
5
- import { parsePackage, readPackage } from 'read-pkg';
6
-
7
- var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],x=async n=>{let a=await findUp(g,{allowSymlinks:!1,type:"file",...n&&{cwd:n}});if(!a)throw new Error("Could not find lock file");return a},b=async n=>{let a=await findUp(e=>{let o;if(g.forEach(i=>{!o&&existsSync(join(e,i))&&(o=join(e,i));}),o)return o;let r=join(e,"package.json");if(existsSync(r)&&parsePackage(readFileSync(r,"utf8")).packageManager!==void 0)return r},{...n&&{cwd:n},allowSymlinks:!1});if(!a)throw new Error("Could not find lock file");if(a.endsWith("package.json")){let e=await readPackage({cwd:dirname(a),normalize:!0});if(e.packageManager){let r=["npm","yarn","pnpm","bun"].find(i=>e.packageManager.startsWith(i));if(r)return {packageManager:r,path:dirname(a)}}}if(a.endsWith("yarn.lock"))return {packageManager:"yarn",path:dirname(a)};if(a.endsWith("package-lock.json")||a.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:dirname(a)};if(a.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:dirname(a)};if(a.endsWith("bun.lockb"))return {packageManager:"bun",path:dirname(a)};throw new Error("Could not find lock file")},j=n=>execSync(`${n} --version`).toString("utf8").trim(),S=async()=>{if(!process.env.npm_config_user_agent)return;let n=process.env.npm_config_user_agent.split(" ")[0],a=n.lastIndexOf("/"),e=n.slice(0,Math.max(0,a));return {name:e==="npminstall"?"cnpm":e,version:n.slice(Math.max(0,a+1))}};
8
-
9
- export { x as a, b, j as c, S as d };
10
- //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-ZRX4WIQ4.js.map
@@ -1 +0,0 @@
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"]}
@@ -1,6 +0,0 @@
1
- type WriteOptions = {
2
- indent?: number | string;
3
- newline?: boolean | string;
4
- };
5
-
6
- export type { WriteOptions as W };