@visulima/package 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ## @visulima/package [1.1.0](https://github.com/visulima/visulima/compare/@visulima/package@1.0.0...@visulima/package@1.1.0) (2023-10-17)
2
+
3
+
4
+ ### Features
5
+
6
+ * added new function that identify the initiating package-manager ([0c89c6a](https://github.com/visulima/visulima/commit/0c89c6ae32641f13ad8ac818f69ebc18d6d17f0e))
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * removed bun from the dev deps of the package lib ([95c790f](https://github.com/visulima/visulima/commit/95c790f15bc66d6ff0d4b559f4890bb896ff018e))
12
+
1
13
  ## @visulima/package 1.0.0 (2023-10-15)
2
14
 
3
15
 
@@ -1,4 +1,4 @@
1
- import { a } from './chunk-KWZ4YGPC.js';
1
+ import { a } from './chunk-IWQKH4TN.js';
2
2
  import { dirname } from 'path';
3
3
  import { findUp } from 'find-up';
4
4
 
@@ -6,4 +6,4 @@ var c=async o=>{try{let a$1=await a(o);return dirname(a$1)}catch{}let t=await fi
6
6
 
7
7
  export { c as a };
8
8
  //# sourceMappingURL=out.js.map
9
- //# sourceMappingURL=chunk-MYRZ7SEG.js.map
9
+ //# sourceMappingURL=chunk-7WLQPGXB.js.map
@@ -4,8 +4,8 @@ import { join, dirname } from 'path';
4
4
  import { findUp } from 'find-up';
5
5
  import { parsePackage, readPackage } from 'read-pkg';
6
6
 
7
- var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],b=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},j=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")},x=n=>execSync(`${n} --version`).toString("utf8").trim();
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
8
 
9
- export { b as a, j as b, x as c };
9
+ export { x as a, b, j as c, S as d };
10
10
  //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-KWZ4YGPC.js.map
11
+ //# sourceMappingURL=chunk-IWQKH4TN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","dirname","join","findUp","parsePackage","readPackage","lockFileNames","findLockFile","cwd","filePath","findPackageManager","foundFile","directory","lockFile","lockFileName","packageJsonFilePath","packageJson","foundPackageManager","prefix","getPackageManagerVersion","name","identifyInitiatingPackageManager","pmSpec","separatorPos"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,gBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAG9B,OAAS,UAAAC,MAAc,UACvB,OAAS,gBAAAC,EAAc,eAAAC,MAAmB,WAE1C,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAA0C,CACzE,IAAMC,EAAW,MAAMN,EAAOG,EAAe,CACzC,cAAe,GACf,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaC,EAAqB,MAAOF,GAAwD,CAC7F,IAAMG,EAAY,MAAMR,EACnBS,GAAc,CACX,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYd,EAAWG,EAAKU,EAAWE,CAAY,CAAC,IACrDD,EAAWX,EAAKU,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsB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C,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,4 +1,4 @@
1
- import { b } from './chunk-KWZ4YGPC.js';
1
+ import { b } from './chunk-IWQKH4TN.js';
2
2
  import { readFileSync, existsSync } from 'fs';
3
3
  import { dirname, join } from 'path';
4
4
  import { findUp } from 'find-up';
@@ -8,4 +8,4 @@ var j=async e=>{let r=await findUp(["lerna.json","turbo.json"],{allowSymlinks:!1
8
8
 
9
9
  export { j as a };
10
10
  //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-HSXXY5E3.js.map
11
+ //# sourceMappingURL=chunk-T4PCL5Z7.js.map
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.js';
2
2
  export { findPackageRoot } from './package.js';
3
3
  export { NormalizedReadResult, findPackageJson, writePackageJson } from './package-json.js';
4
- export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion } from './package-manager.js';
4
+ export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
5
5
  export { findTSConfig, writeTSConfig } from './tsconfig.js';
6
6
  export { NormalizedPackageJson, parsePackage as parsePackageJson } from 'read-pkg';
7
7
  export { TsConfigJson, TsConfigJsonResolved } from 'get-tsconfig';
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- export { a as findMonorepoRoot } from './chunk-HSXXY5E3.js';
2
- export { a as findPackageRoot } from './chunk-MYRZ7SEG.js';
1
+ export { a as findMonorepoRoot } from './chunk-T4PCL5Z7.js';
2
+ export { a as findPackageRoot } from './chunk-7WLQPGXB.js';
3
3
  export { a as findPackageJson, c as parsePackageJson, b as writePackageJson } from './chunk-7TF75EA4.js';
4
- export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion } from './chunk-KWZ4YGPC.js';
4
+ export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-IWQKH4TN.js';
5
5
  export { a as findTSConfig, b as writeTSConfig } from './chunk-HN5TULBQ.js';
6
6
  import './chunk-C7FQQQI6.js';
7
7
  //# sourceMappingURL=out.js.map
package/dist/monorepo.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as findMonorepoRoot } from './chunk-HSXXY5E3.js';
2
- import './chunk-KWZ4YGPC.js';
1
+ export { a as findMonorepoRoot } from './chunk-T4PCL5Z7.js';
2
+ import './chunk-IWQKH4TN.js';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=monorepo.js.map
@@ -8,5 +8,9 @@ type PackageManagerResult = {
8
8
  };
9
9
  declare const findPackageManager: (cwd?: Options["cwd"]) => Promise<PackageManagerResult>;
10
10
  declare const getPackageManagerVersion: (name: string) => string;
11
+ declare const identifyInitiatingPackageManager: () => Promise<{
12
+ name: PackageManager | "cnpm";
13
+ version: string;
14
+ } | undefined>;
11
15
 
12
- export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion };
16
+ export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
@@ -1,3 +1,3 @@
1
- export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion } from './chunk-KWZ4YGPC.js';
1
+ export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-IWQKH4TN.js';
2
2
  //# sourceMappingURL=out.js.map
3
3
  //# sourceMappingURL=package-manager.js.map
package/dist/package.js CHANGED
@@ -1,4 +1,4 @@
1
- export { a as findPackageRoot } from './chunk-MYRZ7SEG.js';
2
- import './chunk-KWZ4YGPC.js';
1
+ export { a as findPackageRoot } from './chunk-7WLQPGXB.js';
2
+ import './chunk-IWQKH4TN.js';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=package.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/package",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
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",
@@ -122,10 +122,12 @@
122
122
  "@anolilab/prettier-config": "^5.0.11",
123
123
  "@anolilab/semantic-release-preset": "^8.0.0",
124
124
  "@babel/core": "^7.23.2",
125
+ "@pnpm/exe": "^8.6.12",
125
126
  "@rushstack/eslint-plugin-security": "^0.7.1",
126
127
  "@total-typescript/ts-reset": "^0.5.1",
127
- "@types/node": "18.17.12",
128
+ "@types/node": "18.18.5",
128
129
  "@vitest/coverage-v8": "^0.34.6",
130
+ "cnpm": "^7.1.1",
129
131
  "cross-env": "^7.0.3",
130
132
  "eslint": "^8.51.0",
131
133
  "eslint-plugin-deprecation": "^2.0.0",
@@ -135,13 +137,17 @@
135
137
  "eslint-plugin-tsdoc": "^0.2.17",
136
138
  "eslint-plugin-vitest": "^0.3.2",
137
139
  "eslint-plugin-vitest-globals": "^1.4.0",
140
+ "execa": "^5.1.1",
141
+ "npm": "^8.2.0",
138
142
  "prettier": "^3.0.3",
139
143
  "rimraf": "^5.0.5",
140
144
  "semantic-release": "^22.0.5",
141
145
  "sort-package-json": "^2.6.0",
142
146
  "tsup": "^7.2.0",
143
147
  "typescript": "^5.2.2",
144
- "vitest": "^0.34.6"
148
+ "vitest": "^0.34.6",
149
+ "which-pm-runs": "file:",
150
+ "yarn": "^1.22.17"
145
151
  },
146
152
  "engines": {
147
153
  "node": ">=18.* <=20.*"
@@ -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"],"mappings":"AAAA,OAAS,YAAAA,MAAgB,gBACzB,OAAS,cAAAC,EAAY,gBAAAC,MAAoB,KACzC,OAAS,WAAAC,EAAS,QAAAC,MAAY,OAG9B,OAAS,UAAAC,MAAc,UACvB,OAAS,gBAAAC,EAAc,eAAAC,MAAmB,WAE1C,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAA0C,CACzE,IAAMC,EAAW,MAAMN,EAAOG,EAAe,CACzC,cAAe,GACf,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaC,EAAqB,MAAOF,GAAwD,CAC7F,IAAMG,EAAY,MAAMR,EACnBS,GAAc,CACX,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYd,EAAWG,EAAKU,EAAWE,CAAY,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, 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"]}