@visulima/package 1.4.3 → 1.5.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 (53) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +1 -0
  3. package/dist/chunk-45ZLUVBF.cjs +13 -0
  4. package/dist/chunk-45ZLUVBF.cjs.map +1 -0
  5. package/dist/chunk-6KT7465D.cjs +22 -0
  6. package/dist/chunk-6KT7465D.cjs.map +1 -0
  7. package/dist/chunk-BBGTIP2U.js +10 -0
  8. package/dist/chunk-BBGTIP2U.js.map +1 -0
  9. package/dist/chunk-DCD4MOHC.cjs +13 -0
  10. package/dist/chunk-DCD4MOHC.cjs.map +1 -0
  11. package/dist/chunk-IRDIZG2L.cjs +18 -0
  12. package/dist/chunk-IRDIZG2L.cjs.map +1 -0
  13. package/dist/chunk-QYGSOB5F.js +11 -0
  14. package/dist/chunk-QYGSOB5F.js.map +1 -0
  15. package/dist/chunk-SUN6RRMM.js +12 -0
  16. package/dist/chunk-SUN6RRMM.js.map +1 -0
  17. package/dist/chunk-U4YVB3GU.js +12 -0
  18. package/dist/chunk-U4YVB3GU.js.map +1 -0
  19. package/dist/index.cjs +26 -16
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +9 -2
  22. package/dist/index.d.ts +9 -2
  23. package/dist/index.js +13 -4
  24. package/dist/index.js.map +1 -1
  25. package/dist/monorepo.cjs +4 -4
  26. package/dist/monorepo.js +3 -3
  27. package/dist/package-json.cjs +6 -6
  28. package/dist/package-json.js +1 -1
  29. package/dist/package-manager.cjs +10 -6
  30. package/dist/package-manager.d.cts +2 -1
  31. package/dist/package-manager.d.ts +2 -1
  32. package/dist/package-manager.js +2 -2
  33. package/dist/package.cjs +8 -4
  34. package/dist/package.d.cts +2 -1
  35. package/dist/package.d.ts +2 -1
  36. package/dist/package.js +3 -3
  37. package/package.json +24 -16
  38. package/dist/chunk-3IWUMNBO.cjs +0 -16
  39. package/dist/chunk-3IWUMNBO.cjs.map +0 -1
  40. package/dist/chunk-4I4DRNVT.cjs +0 -22
  41. package/dist/chunk-4I4DRNVT.cjs.map +0 -1
  42. package/dist/chunk-6KVF4I2Q.js +0 -11
  43. package/dist/chunk-6KVF4I2Q.js.map +0 -1
  44. package/dist/chunk-GA54FVOU.js +0 -12
  45. package/dist/chunk-GA54FVOU.js.map +0 -1
  46. package/dist/chunk-GAZI4NM6.cjs +0 -11
  47. package/dist/chunk-GAZI4NM6.cjs.map +0 -1
  48. package/dist/chunk-M4MWM246.js +0 -9
  49. package/dist/chunk-M4MWM246.js.map +0 -1
  50. package/dist/chunk-PUY4M2BR.js +0 -10
  51. package/dist/chunk-PUY4M2BR.js.map +0 -1
  52. package/dist/chunk-XMGJIRS7.cjs +0 -12
  53. package/dist/chunk-XMGJIRS7.cjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ ## @visulima/package [1.5.1](https://github.com/visulima/visulima/compare/@visulima/package@1.5.0...@visulima/package@1.5.1) (2024-03-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * added missing os key to package.json ([4ad1268](https://github.com/visulima/visulima/commit/4ad1268ed12cbdcf60aeb46d4c052ed1696bc150))
7
+
8
+
9
+
10
+ ### Dependencies
11
+
12
+ * **@visulima/fs:** upgraded to 2.0.2
13
+
14
+ ## @visulima/package [1.5.0](https://github.com/visulima/visulima/compare/@visulima/package@1.4.3...@visulima/package@1.5.0) (2024-03-25)
15
+
16
+
17
+ ### Features
18
+
19
+ * **package:** added findCacheDirectory, findCacheDirectorySync and findPackageRootSync ([#366](https://github.com/visulima/visulima/issues/366)) ([b96f8bf](https://github.com/visulima/visulima/commit/b96f8bf66540dc88b4479dae9e9dfbd1e21296ca))
20
+
1
21
  ## @visulima/package [1.4.3](https://github.com/visulima/visulima/compare/@visulima/package@1.4.2...@visulima/package@1.4.3) (2024-03-24)
2
22
 
3
23
 
package/README.md CHANGED
@@ -184,6 +184,7 @@ If you would like to help take a look at the [list of issues](https://github.com
184
184
 
185
185
  - [get-tsconfig](https://github.com/privatenumber/get-tsconfig) - Get the TypeScript configuration from a project.
186
186
  - [read-pkg](https://github.com/sindresorhus/read-pkg) - Read a package.json file.
187
+ - [find-cache-dir](https://github.com/sindresorhus/find-cache-dir) - Find the cache directory.
187
188
 
188
189
  ## License
189
190
 
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var chunkIRDIZG2L_cjs = require('./chunk-IRDIZG2L.cjs');
4
+ var fs$1 = require('fs');
5
+ var fs = require('@visulima/fs');
6
+ var pathe = require('pathe');
7
+
8
+ var g=t=>{if(fs$1.existsSync(pathe.join(t,"package.json"))){let n=fs.readJsonSync(pathe.join(t,"package.json"));if(n.name&&n.private!==!0)return "package.json"}},h=async t=>{try{let i=await chunkIRDIZG2L_cjs.a(t);return pathe.dirname(i)}catch{}let n=await fs.findUp(".git/config",{...t&&{cwd:t},type:"file"});if(n)return pathe.dirname(pathe.dirname(n));let r=await fs.findUp(g,{...t&&{cwd:t},type:"file"});if(r)return pathe.dirname(r);throw new Error("Could not find root directory")},P=t=>{try{let i=chunkIRDIZG2L_cjs.b(t);return pathe.dirname(i)}catch{}let n=fs.findUpSync(".git/config",{...t&&{cwd:t},type:"file"});if(n)return pathe.dirname(pathe.dirname(n));let r=fs.findUpSync(g,{...t&&{cwd:t},type:"file"});if(r)return pathe.dirname(r);throw new Error("Could not find root directory")};
9
+
10
+ exports.a = h;
11
+ exports.b = P;
12
+ //# sourceMappingURL=out.js.map
13
+ //# sourceMappingURL=chunk-45ZLUVBF.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package.ts"],"names":["existsSync","findUp","findUpSync","readJsonSync","dirname","join","packageJsonMatcher","directory","packageJson","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath","findPackageRootSync","findLockFileSync"],"mappings":"gDAAA,OAAS,cAAAA,MAAkB,KAE3B,OAAS,UAAAC,EAAQ,cAAAC,EAAY,gBAAAC,MAAoB,eACjD,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAK9B,IAAMC,EAAsBC,GAAsB,CAE9C,GAAIP,EAAWK,EAAKE,EAAW,cAAc,CAAC,EAAG,CAC7C,IAAMC,EAAcL,EAA0BE,EAAKE,EAAW,cAAc,CAAC,EAE7E,GAAIC,EAAY,MAAQA,EAAY,UAAY,GAC5C,MAAO,cAEf,CAGJ,EAaaC,EAAkB,MAAOC,GAAwC,CAC1E,GAAI,CACA,IAAMC,EAAW,MAAMC,EAAaF,CAAG,EAEvC,OAAON,EAAQO,CAAQ,CAC3B,MAAQ,CAER,CAEA,IAAME,EAAY,MAAMZ,EAAO,cAAe,CAC1C,GAAIS,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAOT,EAAQA,EAAQS,CAAS,CAAC,EAGrC,IAAMC,EAAW,MAAMb,EAAOK,EAAoB,CAC9C,GAAII,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOV,EAAQU,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD,EAEaC,EAAuBL,GAA+B,CAC/D,GAAI,CACA,IAAMC,EAAWK,EAAiBN,CAAG,EAErC,OAAON,EAAQO,CAAQ,CAC3B,MAAQ,CAER,CAEA,IAAME,EAAYX,EAAW,cAAe,CACxC,GAAIQ,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAOT,EAAQA,EAAQS,CAAS,CAAC,EAGrC,IAAMC,EAAWZ,EAAWI,EAAoB,CAC5C,GAAII,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOV,EAAQU,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { existsSync } from \"node:fs\";\n\nimport { findUp, findUpSync, readJsonSync } from \"@visulima/fs\";\nimport { dirname, join } from \"pathe\";\n\nimport { findLockFile, findLockFileSync } from \"./package-manager\";\nimport type { PackageJson } from \"./types\";\n\nconst packageJsonMatcher = (directory: string) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(join(directory, \"package.json\"))) {\n const packageJson = readJsonSync<PackageJson>(join(directory, \"package.json\"));\n\n if (packageJson.name && packageJson.private !== true) {\n return \"package.json\";\n }\n }\n\n return undefined;\n};\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 */\nexport const findPackageRoot = async (cwd?: URL | string): Promise<string> => {\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\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 const filePath = await findUp(packageJsonMatcher, {\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\nexport const findPackageRootSync = (cwd?: URL | string): string => {\n try {\n const lockFile = findLockFileSync(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n const gitConfig = findUpSync(\".git/config\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n const filePath = findUpSync(packageJsonMatcher, {\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,22 @@
1
+ 'use strict';
2
+
3
+ var fs$1 = require('fs');
4
+ var fs = require('@visulima/fs');
5
+ var error = require('@visulima/fs/error');
6
+ var utils = require('@visulima/fs/utils');
7
+ var n = require('normalize-package-data');
8
+ var pathe = require('pathe');
9
+
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var n__default = /*#__PURE__*/_interopDefault(n);
13
+
14
+ var m=new Map,O=async(e,o={})=>{let t=await fs.findUp("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new error.NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=await fs.readJson(t);n__default.default(s);let r={packageJson:s,path:t};return a.set(t,r),r},b=(e,o={})=>{let t=fs.findUpSync("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new error.NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=fs.readJsonSync(t);n__default.default(s);let r={packageJson:s,path:t};return a.set(t,r),r},S=async(e,o={})=>{let{cwd:t,...a}=o,s=utils.toPath(o.cwd??process.cwd());await fs.writeJson(pathe.join(s,"package.json"),e,a);},x=(e,o={})=>{let{cwd:t,...a}=o,s=utils.toPath(o.cwd??process.cwd());fs.writeJsonSync(pathe.join(s,"package.json"),e,a);},U=e=>{let o=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!o&&!(typeof e=="string"))throw new TypeError("`packageFile` should be either an `object` or a `string`.");let a=o?structuredClone(e):fs$1.existsSync(e)?fs.readJsonSync(e):utils.parseJson(e);return n__default.default(a),a};
15
+
16
+ exports.a = O;
17
+ exports.b = b;
18
+ exports.c = S;
19
+ exports.d = x;
20
+ exports.e = U;
21
+ //# sourceMappingURL=out.js.map
22
+ //# sourceMappingURL=chunk-6KT7465D.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package-json.ts"],"names":["existsSync","findUp","findUpSync","readJson","readJsonSync","writeJson","writeJsonSync","NotFoundError","parseJson","toPath","normalizeData","join","PackageJsonFileCache","findPackageJson","cwd","options","filePath","cache","packageJson","output","findPackageJsonSync","writePackageJson","data","writeOptions","directory","writePackageJsonSync","parsePackageJson","packageFile","isObject","json"],"mappings":"AAAA,OAAS,cAAAA,MAAkB,KAG3B,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,yBAC1B,OAAS,QAAAC,MAAY,QASrB,IAAMC,EAAuB,IAAI,IAepBC,EAAkB,MAAOC,EAAoBC,EAAuB,CAAC,IAAqC,CACnH,IAAMC,EAAW,MAAMf,EAAO,eAAgB,CAC1C,GAAIa,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIT,EAAc,oDAAoD,EAGhF,IAAMU,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAc,MAAMf,EAASa,CAAQ,EAE3CN,EAAcQ,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EACb,KAAMF,CACV,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAEaC,EAAsB,CAACN,EAAoBC,EAAuB,CAAC,IAA4B,CACxG,IAAMC,EAAWd,EAAW,eAAgB,CACxC,GAAIY,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIT,EAAc,oDAAoD,EAGhF,IAAMU,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAcd,EAAaY,CAAQ,EAEzCN,EAAcQ,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EACb,KAAMF,CACV,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAYaE,EAAmB,MAAwBC,EAASP,EAAqD,CAAC,IAAqB,CACxI,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYf,EAAOM,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErD,MAAMV,EAAUM,EAAKa,EAAW,cAAc,EAAGF,EAAMC,CAAY,CACvE,EAEaE,EAAuB,CAAkBH,EAASP,EAAqD,CAAC,IAAY,CAC7H,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYf,EAAOM,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErDT,EAAcK,EAAKa,EAAW,cAAc,EAAGF,EAAMC,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,EAE3B3B,EAAW2B,CAAqB,EAC9BvB,EAAauB,CAAqB,EAClCnB,EAAUmB,CAAqB,EAEvC,OAAAjB,EAAcmB,CAAa,EAEpBA,CACX","sourcesContent":["import { existsSync } from \"node:fs\";\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 { join } from \"pathe\";\nimport type { JsonObject } from \"type-fest\";\n\nimport type { Cache, NormalizedPackageJson, PackageJson } from \"./types\";\n\ntype ReadOptions = {\n cache?: Cache<NormalizedReadResult> | boolean;\n};\n\nconst PackageJsonFileCache = new Map<string, NormalizedReadResult>();\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, options: ReadOptions = {}): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = await readJson(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n path: filePath,\n };\n\n cache.set(filePath, output);\n\n return output;\n};\n\nexport const findPackageJsonSync = (cwd?: URL | string, options: ReadOptions = {}): NormalizedReadResult => {\n const filePath = findUpSync(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = readJsonSync(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n path: filePath,\n };\n\n cache.set(filePath, output);\n\n return output;\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 { a, b } from './chunk-SUN6RRMM.js';
2
+ import { existsSync } from 'node:fs';
3
+ import { findUp, findUpSync, readJsonSync } from '@visulima/fs';
4
+ import { dirname, join } from 'pathe';
5
+
6
+ var g=t=>{if(existsSync(join(t,"package.json"))){let n=readJsonSync(join(t,"package.json"));if(n.name&&n.private!==!0)return "package.json"}},P=async t=>{try{let i=await a(t);return dirname(i)}catch{}let n=await findUp(".git/config",{...t&&{cwd:t},type:"file"});if(n)return dirname(dirname(n));let r=await findUp(g,{...t&&{cwd:t},type:"file"});if(r)return dirname(r);throw new Error("Could not find root directory")},J=t=>{try{let i=b(t);return dirname(i)}catch{}let n=findUpSync(".git/config",{...t&&{cwd:t},type:"file"});if(n)return dirname(dirname(n));let r=findUpSync(g,{...t&&{cwd:t},type:"file"});if(r)return dirname(r);throw new Error("Could not find root directory")};
7
+
8
+ export { P as a, J as b };
9
+ //# sourceMappingURL=out.js.map
10
+ //# sourceMappingURL=chunk-BBGTIP2U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package.ts"],"names":["existsSync","findUp","findUpSync","readJsonSync","dirname","join","packageJsonMatcher","directory","packageJson","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath","findPackageRootSync","findLockFileSync"],"mappings":"+CAAA,OAAS,cAAAA,MAAkB,UAE3B,OAAS,UAAAC,EAAQ,cAAAC,EAAY,gBAAAC,MAAoB,eACjD,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAK9B,IAAMC,EAAsBC,GAAsB,CAE9C,GAAIP,EAAWK,EAAKE,EAAW,cAAc,CAAC,EAAG,CAC7C,IAAMC,EAAcL,EAA0BE,EAAKE,EAAW,cAAc,CAAC,EAE7E,GAAIC,EAAY,MAAQA,EAAY,UAAY,GAC5C,MAAO,cAEf,CAGJ,EAaaC,EAAkB,MAAOC,GAAwC,CAC1E,GAAI,CACA,IAAMC,EAAW,MAAMC,EAAaF,CAAG,EAEvC,OAAON,EAAQO,CAAQ,CAC3B,MAAQ,CAER,CAEA,IAAME,EAAY,MAAMZ,EAAO,cAAe,CAC1C,GAAIS,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAOT,EAAQA,EAAQS,CAAS,CAAC,EAGrC,IAAMC,EAAW,MAAMb,EAAOK,EAAoB,CAC9C,GAAII,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOV,EAAQU,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD,EAEaC,EAAuBL,GAA+B,CAC/D,GAAI,CACA,IAAMC,EAAWK,EAAiBN,CAAG,EAErC,OAAON,EAAQO,CAAQ,CAC3B,MAAQ,CAER,CAEA,IAAME,EAAYX,EAAW,cAAe,CACxC,GAAIQ,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAOT,EAAQA,EAAQS,CAAS,CAAC,EAGrC,IAAMC,EAAWZ,EAAWI,EAAoB,CAC5C,GAAII,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAOV,EAAQU,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { existsSync } from \"node:fs\";\n\nimport { findUp, findUpSync, readJsonSync } from \"@visulima/fs\";\nimport { dirname, join } from \"pathe\";\n\nimport { findLockFile, findLockFileSync } from \"./package-manager\";\nimport type { PackageJson } from \"./types\";\n\nconst packageJsonMatcher = (directory: string) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(join(directory, \"package.json\"))) {\n const packageJson = readJsonSync<PackageJson>(join(directory, \"package.json\"));\n\n if (packageJson.name && packageJson.private !== true) {\n return \"package.json\";\n }\n }\n\n return undefined;\n};\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 */\nexport const findPackageRoot = async (cwd?: URL | string): Promise<string> => {\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\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 const filePath = await findUp(packageJsonMatcher, {\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\nexport const findPackageRootSync = (cwd?: URL | string): string => {\n try {\n const lockFile = findLockFileSync(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n const gitConfig = findUpSync(\".git/config\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n const filePath = findUpSync(packageJsonMatcher, {\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,13 @@
1
+ 'use strict';
2
+
3
+ var chunkIRDIZG2L_cjs = require('./chunk-IRDIZG2L.cjs');
4
+ var fs$1 = require('fs');
5
+ var fs = require('@visulima/fs');
6
+ var error = require('@visulima/fs/error');
7
+ var pathe = require('pathe');
8
+
9
+ var w=async n=>{let a=await fs.findUp(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(a?.endsWith("lerna.json")){let o=await fs.readJson(a);if(o.useWorkspaces||o.packages)return {path:pathe.dirname(a),strategy:"lerna"}}let s=a?.endsWith("turbo.json");try{let{packageManager:o,path:r}=await chunkIRDIZG2L_cjs.c(n);if(["npm","yarn"].includes(o)){let t=pathe.join(r,"package.json");if(fs$1.existsSync(t)&&fs$1.readFileSync(pathe.join(r,"package.json"),"utf8").includes("workspaces"))return {path:r,strategy:s?"turbo":o}}else if(o==="pnpm"){let t=pathe.join(r,"pnpm-workspace.yaml");if(fs$1.existsSync(t))return {path:r,strategy:s?"turbo":"pnpm"}}}catch(o){if(!(o instanceof error.NotFoundError))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${n} using lerna, yarn, pnpm, or npm as indicators.`)};
10
+
11
+ exports.a = w;
12
+ //# sourceMappingURL=out.js.map
13
+ //# sourceMappingURL=chunk-DCD4MOHC.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","findUp","readJson","NotFoundError","dirname","join","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"yCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,KAEzC,OAAS,UAAAC,EAAQ,YAAAC,MAAgB,eACjC,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAsBvB,IAAMC,EAAmB,MAAOC,GAA8C,CACjF,IAAMC,EAAoB,MAAMP,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,KAAM,OACN,GAAIM,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAmB,SAAS,YAAY,EAAG,CAC3C,IAAMC,EAAQ,MAAMP,EAA2DM,CAAiB,EAEhG,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAML,EAAQI,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,EAAsBT,EAAKO,EAAM,cAAc,EAGrD,GAAIb,EAAWe,CAAmB,GAEVd,EAAaK,EAAKO,EAAM,cAAc,EAAG,MAAM,EAEnD,SAAS,YAAY,EACjC,MAAO,CACH,KAAAA,EACA,SAAUF,EAAU,QAAWC,CACnC,CAGZ,SAAWA,IAAmB,OAAQ,CAClC,IAAMI,EAAyBV,EAAKO,EAAM,qBAAqB,EAG/D,GAAIb,EAAWgB,CAAsB,EACjC,MAAO,CACH,KAAAH,EACA,SAAUF,EAAU,QAAU,MAClC,CAER,CAEJ,OAASM,EAAY,CAEjB,GAAI,EAAEA,aAAiBb,GACnB,MAAMa,CAEd,CAEA,MAAM,IAAI,MAAM,8DAA8DT,CAAa,iDAAiD,CAChJ","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\n\nimport { findUp, readJson } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\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 if (!(error instanceof NotFoundError)) {\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,18 @@
1
+ 'use strict';
2
+
3
+ var chunk6KT7465D_cjs = require('./chunk-6KT7465D.cjs');
4
+ var child_process = require('child_process');
5
+ var fs$1 = require('fs');
6
+ var fs = require('@visulima/fs');
7
+ var error = require('@visulima/fs/error');
8
+ var pathe = require('pathe');
9
+
10
+ var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],b=async a=>{let n=await fs.findUp(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},j=a=>{let n=fs.findUpSync(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},F=async a=>{let n=await fs.findUp(e=>{let t;if(g.forEach(o=>{!t&&fs$1.existsSync(pathe.join(e,o))&&(t=pathe.join(e,o));}),t)return t;let r=pathe.join(e,"package.json");if(fs$1.existsSync(r)&&chunk6KT7465D_cjs.e(fs$1.readFileSync(r,"utf8")).packageManager!==void 0)return r},{...a&&{cwd:a}});if(!n)throw new error.NotFoundError("Could not find a package manager");if(n.endsWith("package.json")){let e=chunk6KT7465D_cjs.e(n);if(e.packageManager){let r=["npm","yarn","pnpm","bun"].find(o=>e.packageManager.startsWith(o));if(r)return {packageManager:r,path:pathe.dirname(n)}}}if(n.endsWith("yarn.lock"))return {packageManager:"yarn",path:pathe.dirname(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:pathe.dirname(n)};if(n.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:pathe.dirname(n)};if(n.endsWith("bun.lockb"))return {packageManager:"bun",path:pathe.dirname(n)};throw new Error("Could not find a package manager")},S=a=>child_process.execSync(`${a} --version`).toString("utf8").trim(),W=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))}};
11
+
12
+ exports.a = b;
13
+ exports.b = j;
14
+ exports.c = F;
15
+ exports.d = S;
16
+ exports.e = W;
17
+ //# sourceMappingURL=out.js.map
18
+ //# sourceMappingURL=chunk-IRDIZG2L.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","findUpSync","NotFoundError","dirname","join","lockFileNames","findLockFile","cwd","filePath","findLockFileSync","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,KAEzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,eACnC,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAI9B,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMR,EAAOK,EAAe,CACzC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAEaC,EAAoBF,GAA+B,CAC5D,IAAMC,EAAWP,EAAWI,EAAe,CACvC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaE,EAAqB,MAAOH,GAAsD,CAC3F,IAAMI,EAAY,MAAMX,EACnBY,GAAsB,CACnB,IAAIC,EASJ,GAPAR,EAAc,QAASS,GAAiB,CAEhC,CAACD,GAAYf,EAAWM,EAAKQ,EAAWE,CAAY,CAAC,IACrDD,EAAWT,EAAKQ,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBX,EAAKQ,EAAW,cAAc,EAE1D,GAAId,EAAWiB,CAAmB,GAEVC,EAAiBjB,EAAagB,EAAqB,MAAM,CAAC,EAE9D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIR,GAAO,CAAE,IAAAA,CAAI,CACrB,CACJ,EAEA,GAAI,CAACI,EACD,MAAM,IAAIT,EAAc,kCAAkC,EAG9D,GAAIS,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,kCAAkC,CACtD,EAQaS,EAA4BC,GAAyBxB,EAAS,GAAGwB,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\";\n\nimport { findUp, findUpSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\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 const findLockFileSync = (cwd?: URL | string): string => {\n const filePath = findUpSync(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 NotFoundError(\"Could not find a package manager\");\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 a package manager\");\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,11 @@
1
+ import { c } from './chunk-SUN6RRMM.js';
2
+ import { existsSync, readFileSync } from 'node:fs';
3
+ import { findUp, readJson } from '@visulima/fs';
4
+ import { NotFoundError } from '@visulima/fs/error';
5
+ import { dirname, join } from 'pathe';
6
+
7
+ var x=async n=>{let a=await findUp(["lerna.json","turbo.json"],{type:"file",...n&&{cwd:n}});if(a?.endsWith("lerna.json")){let o=await readJson(a);if(o.useWorkspaces||o.packages)return {path:dirname(a),strategy:"lerna"}}let s=a?.endsWith("turbo.json");try{let{packageManager:o,path:r}=await c(n);if(["npm","yarn"].includes(o)){let t=join(r,"package.json");if(existsSync(t)&&readFileSync(join(r,"package.json"),"utf8").includes("workspaces"))return {path:r,strategy:s?"turbo":o}}else if(o==="pnpm"){let t=join(r,"pnpm-workspace.yaml");if(existsSync(t))return {path:r,strategy:s?"turbo":"pnpm"}}}catch(o){if(!(o instanceof NotFoundError))throw o}throw new Error(`No monorepo root could be found upwards from the directory ${n} using lerna, yarn, pnpm, or npm as indicators.`)};
8
+
9
+ export { x as a };
10
+ //# sourceMappingURL=out.js.map
11
+ //# sourceMappingURL=chunk-QYGSOB5F.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","findUp","readJson","NotFoundError","dirname","join","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"wCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,UAEzC,OAAS,UAAAC,EAAQ,YAAAC,MAAgB,eACjC,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAsBvB,IAAMC,EAAmB,MAAOC,GAA8C,CACjF,IAAMC,EAAoB,MAAMP,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,KAAM,OACN,GAAIM,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAmB,SAAS,YAAY,EAAG,CAC3C,IAAMC,EAAQ,MAAMP,EAA2DM,CAAiB,EAEhG,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAML,EAAQI,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,EAAsBT,EAAKO,EAAM,cAAc,EAGrD,GAAIb,EAAWe,CAAmB,GAEVd,EAAaK,EAAKO,EAAM,cAAc,EAAG,MAAM,EAEnD,SAAS,YAAY,EACjC,MAAO,CACH,KAAAA,EACA,SAAUF,EAAU,QAAWC,CACnC,CAGZ,SAAWA,IAAmB,OAAQ,CAClC,IAAMI,EAAyBV,EAAKO,EAAM,qBAAqB,EAG/D,GAAIb,EAAWgB,CAAsB,EACjC,MAAO,CACH,KAAAH,EACA,SAAUF,EAAU,QAAU,MAClC,CAER,CAEJ,OAASM,EAAY,CAEjB,GAAI,EAAEA,aAAiBb,GACnB,MAAMa,CAEd,CAEA,MAAM,IAAI,MAAM,8DAA8DT,CAAa,iDAAiD,CAChJ","sourcesContent":["import { existsSync, readFileSync } from \"node:fs\";\n\nimport { findUp, readJson } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\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 if (!(error instanceof NotFoundError)) {\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,12 @@
1
+ import { e } from './chunk-U4YVB3GU.js';
2
+ import { execSync } from 'node:child_process';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { findUp, findUpSync } from '@visulima/fs';
5
+ import { NotFoundError } from '@visulima/fs/error';
6
+ import { join, dirname } from 'pathe';
7
+
8
+ var g=["yarn.lock","package-lock.json","pnpm-lock.yaml","npm-shrinkwrap.json","bun.lockb"],j=async a=>{let n=await findUp(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},F=a=>{let n=findUpSync(g,{type:"file",...a&&{cwd:a}});if(!n)throw new Error("Could not find lock file");return n},S=async a=>{let n=await findUp(e$1=>{let t;if(g.forEach(o=>{!t&&existsSync(join(e$1,o))&&(t=join(e$1,o));}),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 NotFoundError("Could not find a package manager");if(n.endsWith("package.json")){let e$1=e(n);if(e$1.packageManager){let r=["npm","yarn","pnpm","bun"].find(o=>e$1.packageManager.startsWith(o));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 a package manager")},W=a=>execSync(`${a} --version`).toString("utf8").trim(),_=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))}};
9
+
10
+ export { j as a, F as b, S as c, W as d, _ as e };
11
+ //# sourceMappingURL=out.js.map
12
+ //# sourceMappingURL=chunk-SUN6RRMM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","findUpSync","NotFoundError","dirname","join","lockFileNames","findLockFile","cwd","filePath","findLockFileSync","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,UAEzC,OAAS,UAAAC,EAAQ,cAAAC,MAAkB,eACnC,OAAS,iBAAAC,MAAqB,qBAC9B,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAI9B,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMR,EAAOK,EAAe,CACzC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAEaC,EAAoBF,GAA+B,CAC5D,IAAMC,EAAWP,EAAWI,EAAe,CACvC,KAAM,OACN,GAAIE,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAI,CAACC,EACD,MAAM,IAAI,MAAM,0BAA0B,EAG9C,OAAOA,CACX,EAqBaE,EAAqB,MAAOH,GAAsD,CAC3F,IAAMI,EAAY,MAAMX,EACnBY,GAAsB,CACnB,IAAIC,EASJ,GAPAR,EAAc,QAASS,GAAiB,CAEhC,CAACD,GAAYf,EAAWM,EAAKQ,EAAWE,CAAY,CAAC,IACrDD,EAAWT,EAAKQ,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBX,EAAKQ,EAAW,cAAc,EAE1D,GAAId,EAAWiB,CAAmB,GAEVC,EAAiBjB,EAAagB,EAAqB,MAAM,CAAC,EAE9D,iBAAmB,OAC/B,OAAOA,CAKnB,EACA,CACI,GAAIR,GAAO,CAAE,IAAAA,CAAI,CACrB,CACJ,EAEA,GAAI,CAACI,EACD,MAAM,IAAIT,EAAc,kCAAkC,EAG9D,GAAIS,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,kCAAkC,CACtD,EAQaS,EAA4BC,GAAyBxB,EAAS,GAAGwB,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\";\n\nimport { findUp, findUpSync } from \"@visulima/fs\";\nimport { NotFoundError } from \"@visulima/fs/error\";\nimport { dirname, join } from \"pathe\";\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 const findLockFileSync = (cwd?: URL | string): string => {\n const filePath = findUpSync(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 NotFoundError(\"Could not find a package manager\");\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 a package manager\");\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 { findUp, readJson, findUpSync, readJsonSync, writeJson, writeJsonSync } from '@visulima/fs';
3
+ import { NotFoundError } from '@visulima/fs/error';
4
+ import { toPath, parseJson } from '@visulima/fs/utils';
5
+ import n from 'normalize-package-data';
6
+ import { join } from 'pathe';
7
+
8
+ var m=new Map,b=async(e,o={})=>{let t=await findUp("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=await readJson(t);n(s);let r={packageJson:s,path:t};return a.set(t,r),r},S=(e,o={})=>{let t=findUpSync("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=readJsonSync(t);n(s);let r={packageJson:s,path:t};return a.set(t,r),r},x=async(e,o={})=>{let{cwd:t,...a}=o,s=toPath(o.cwd??process.cwd());await writeJson(join(s,"package.json"),e,a);},U=(e,o={})=>{let{cwd:t,...a}=o,s=toPath(o.cwd??process.cwd());writeJsonSync(join(s,"package.json"),e,a);},T=e=>{let o=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!o&&!(typeof e=="string"))throw new TypeError("`packageFile` should be either an `object` or a `string`.");let a=o?structuredClone(e):existsSync(e)?readJsonSync(e):parseJson(e);return n(a),a};
9
+
10
+ export { b as a, S as b, x as c, U as d, T as e };
11
+ //# sourceMappingURL=out.js.map
12
+ //# sourceMappingURL=chunk-U4YVB3GU.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/package-json.ts"],"names":["existsSync","findUp","findUpSync","readJson","readJsonSync","writeJson","writeJsonSync","NotFoundError","parseJson","toPath","normalizeData","join","PackageJsonFileCache","findPackageJson","cwd","options","filePath","cache","packageJson","output","findPackageJsonSync","writePackageJson","data","writeOptions","directory","writePackageJsonSync","parsePackageJson","packageFile","isObject","json"],"mappings":"AAAA,OAAS,cAAAA,MAAkB,UAG3B,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,yBAC1B,OAAS,QAAAC,MAAY,QASrB,IAAMC,EAAuB,IAAI,IAepBC,EAAkB,MAAOC,EAAoBC,EAAuB,CAAC,IAAqC,CACnH,IAAMC,EAAW,MAAMf,EAAO,eAAgB,CAC1C,GAAIa,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIT,EAAc,oDAAoD,EAGhF,IAAMU,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAc,MAAMf,EAASa,CAAQ,EAE3CN,EAAcQ,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EACb,KAAMF,CACV,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAEaC,EAAsB,CAACN,EAAoBC,EAAuB,CAAC,IAA4B,CACxG,IAAMC,EAAWd,EAAW,eAAgB,CACxC,GAAIY,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIT,EAAc,oDAAoD,EAGhF,IAAMU,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAcd,EAAaY,CAAQ,EAEzCN,EAAcQ,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EACb,KAAMF,CACV,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAYaE,EAAmB,MAAwBC,EAASP,EAAqD,CAAC,IAAqB,CACxI,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYf,EAAOM,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErD,MAAMV,EAAUM,EAAKa,EAAW,cAAc,EAAGF,EAAMC,CAAY,CACvE,EAEaE,EAAuB,CAAkBH,EAASP,EAAqD,CAAC,IAAY,CAC7H,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYf,EAAOM,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErDT,EAAcK,EAAKa,EAAW,cAAc,EAAGF,EAAMC,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,EAE3B3B,EAAW2B,CAAqB,EAC9BvB,EAAauB,CAAqB,EAClCnB,EAAUmB,CAAqB,EAEvC,OAAAjB,EAAcmB,CAAa,EAEpBA,CACX","sourcesContent":["import { existsSync } from \"node:fs\";\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 { join } from \"pathe\";\nimport type { JsonObject } from \"type-fest\";\n\nimport type { Cache, NormalizedPackageJson, PackageJson } from \"./types\";\n\ntype ReadOptions = {\n cache?: Cache<NormalizedReadResult> | boolean;\n};\n\nconst PackageJsonFileCache = new Map<string, NormalizedReadResult>();\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, options: ReadOptions = {}): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = await readJson(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n path: filePath,\n };\n\n cache.set(filePath, output);\n\n return output;\n};\n\nexport const findPackageJsonSync = (cwd?: URL | string, options: ReadOptions = {}): NormalizedReadResult => {\n const filePath = findUpSync(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = readJsonSync(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n path: filePath,\n };\n\n cache.set(filePath, output);\n\n return output;\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"]}
package/dist/index.cjs CHANGED
@@ -1,56 +1,64 @@
1
1
  'use strict';
2
2
 
3
- var chunkXMGJIRS7_cjs = require('./chunk-XMGJIRS7.cjs');
4
- var chunkGAZI4NM6_cjs = require('./chunk-GAZI4NM6.cjs');
5
- var chunk3IWUMNBO_cjs = require('./chunk-3IWUMNBO.cjs');
6
- var chunk4I4DRNVT_cjs = require('./chunk-4I4DRNVT.cjs');
3
+ var chunkDCD4MOHC_cjs = require('./chunk-DCD4MOHC.cjs');
4
+ var chunk45ZLUVBF_cjs = require('./chunk-45ZLUVBF.cjs');
5
+ var chunkIRDIZG2L_cjs = require('./chunk-IRDIZG2L.cjs');
6
+ var chunk6KT7465D_cjs = require('./chunk-6KT7465D.cjs');
7
7
  var chunk4K7XWYTT_cjs = require('./chunk-4K7XWYTT.cjs');
8
+ var fs = require('fs');
9
+ var process = require('process');
10
+ var fs$1 = require('@visulima/fs');
11
+ var pathe = require('pathe');
8
12
 
9
-
13
+ var d=(r,e)=>(e?.create&&fs$1.ensureDirSync(r),r),O=async(r,e)=>{if(process.env.CACHE_DIR&&!["0","1","false","true"].includes(process.env.CACHE_DIR))return d(pathe.join(process.env.CACHE_DIR,r),e);let s=await chunk45ZLUVBF_cjs.a(e?.cwd??process.cwd());if(!s)return;let o=pathe.join(s,"node_modules"),t=pathe.join(o,".cache"),i=pathe.join(t,r);if(!(fs.existsSync(i)&&!await fs$1.isAccessible(i,fs$1.W_OK))&&!(fs.existsSync(t)&&!await fs$1.isAccessible(t,fs$1.W_OK))&&!(fs.existsSync(o)&&!await fs$1.isAccessible(o,fs$1.W_OK)))return d(i,e)},N=(r,e)=>{if(process.env.CACHE_DIR&&!["0","1","false","true"].includes(process.env.CACHE_DIR))return d(pathe.join(process.env.CACHE_DIR,r),e);let s=chunk45ZLUVBF_cjs.b(e?.cwd??process.cwd());if(!s)return;let o=pathe.join(s,"node_modules"),t=pathe.join(o,".cache"),i=pathe.join(t,r);if(!(fs.existsSync(i)&&!fs$1.isAccessibleSync(i,fs$1.W_OK))&&!(fs.existsSync(t)&&!fs$1.isAccessibleSync(t,fs$1.W_OK))&&!(fs.existsSync(o)&&!fs$1.isAccessibleSync(o,fs$1.W_OK)))return d(i,e)};
10
14
 
11
15
  Object.defineProperty(exports, 'findMonorepoRoot', {
12
16
  enumerable: true,
13
- get: function () { return chunkXMGJIRS7_cjs.a; }
17
+ get: function () { return chunkDCD4MOHC_cjs.a; }
14
18
  });
15
19
  Object.defineProperty(exports, 'findPackageRoot', {
16
20
  enumerable: true,
17
- get: function () { return chunkGAZI4NM6_cjs.a; }
21
+ get: function () { return chunk45ZLUVBF_cjs.a; }
22
+ });
23
+ Object.defineProperty(exports, 'findPackageRootSync', {
24
+ enumerable: true,
25
+ get: function () { return chunk45ZLUVBF_cjs.b; }
18
26
  });
19
27
  Object.defineProperty(exports, 'findLockFile', {
20
28
  enumerable: true,
21
- get: function () { return chunk3IWUMNBO_cjs.a; }
29
+ get: function () { return chunkIRDIZG2L_cjs.a; }
22
30
  });
23
31
  Object.defineProperty(exports, 'findPackageManager', {
24
32
  enumerable: true,
25
- get: function () { return chunk3IWUMNBO_cjs.b; }
33
+ get: function () { return chunkIRDIZG2L_cjs.c; }
26
34
  });
27
35
  Object.defineProperty(exports, 'getPackageManagerVersion', {
28
36
  enumerable: true,
29
- get: function () { return chunk3IWUMNBO_cjs.c; }
37
+ get: function () { return chunkIRDIZG2L_cjs.d; }
30
38
  });
31
39
  Object.defineProperty(exports, 'identifyInitiatingPackageManager', {
32
40
  enumerable: true,
33
- get: function () { return chunk3IWUMNBO_cjs.d; }
41
+ get: function () { return chunkIRDIZG2L_cjs.e; }
34
42
  });
35
43
  Object.defineProperty(exports, 'findPackageJson', {
36
44
  enumerable: true,
37
- get: function () { return chunk4I4DRNVT_cjs.a; }
45
+ get: function () { return chunk6KT7465D_cjs.a; }
38
46
  });
39
47
  Object.defineProperty(exports, 'findPackageJsonSync', {
40
48
  enumerable: true,
41
- get: function () { return chunk4I4DRNVT_cjs.b; }
49
+ get: function () { return chunk6KT7465D_cjs.b; }
42
50
  });
43
51
  Object.defineProperty(exports, 'parsePackageJson', {
44
52
  enumerable: true,
45
- get: function () { return chunk4I4DRNVT_cjs.e; }
53
+ get: function () { return chunk6KT7465D_cjs.e; }
46
54
  });
47
55
  Object.defineProperty(exports, 'writePackageJson', {
48
56
  enumerable: true,
49
- get: function () { return chunk4I4DRNVT_cjs.c; }
57
+ get: function () { return chunk6KT7465D_cjs.c; }
50
58
  });
51
59
  Object.defineProperty(exports, 'writePackageJsonSync', {
52
60
  enumerable: true,
53
- get: function () { return chunk4I4DRNVT_cjs.d; }
61
+ get: function () { return chunk6KT7465D_cjs.d; }
54
62
  });
55
63
  Object.defineProperty(exports, 'findTSConfig', {
56
64
  enumerable: true,
@@ -76,5 +84,7 @@ Object.defineProperty(exports, 'writeTSConfig', {
76
84
  enumerable: true,
77
85
  get: function () { return chunk4K7XWYTT_cjs.g; }
78
86
  });
87
+ exports.findCacheDirectory = O;
88
+ exports.findCacheDirectorySync = N;
79
89
  //# sourceMappingURL=out.js.map
80
90
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../src/find-cache-dir.ts"],"names":["existsSync","cwd","env","ensureDirSync","isAccessible","isAccessibleSync","W_OK","join","useDirectory","directory","options","findCacheDirectory","name","rootDirectory","findPackageRoot","nodeModulesDirectory","cacheDirectory","cacheNameDirectory","findCacheDirectorySync","findPackageRootSync"],"mappings":"wSACA,OAAS,cAAAA,MAAkB,KAC3B,OAAS,OAAAC,EAAK,OAAAC,MAAW,UAEzB,OAAS,iBAAAC,EAAe,gBAAAC,EAAc,oBAAAC,EAAkB,QAAAC,MAAY,eACpE,OAAS,QAAAC,MAAY,QASrB,IAAMC,EAAe,CAACC,EAAmBC,KACjCA,GAAS,QACTP,EAAcM,CAAS,EAGpBA,GAGEE,EAAqB,MAAOC,EAAcF,IAAmD,CACtG,GAAIR,EAAI,WAAgB,CAAC,CAAC,IAAK,IAAK,QAAS,MAAM,EAAE,SAASA,EAAI,SAAY,EAC1E,OAAOM,EAAaD,EAAKL,EAAI,UAAcU,CAAI,EAAGF,CAAO,EAG7D,IAAMG,EAAgB,MAAMC,EAAgBJ,GAAS,KAAOT,EAAI,CAAC,EAEjE,GAAI,CAACY,EACD,OAGJ,IAAME,EAAuBR,EAAKM,EAAe,cAAc,EACzDG,EAAiBT,EAAKQ,EAAsB,QAAQ,EACpDE,EAAqBV,EAAKS,EAAgBJ,CAAI,EAMpD,GAAI,EAAAZ,EAAWiB,CAAkB,GAAK,CAAE,MAAMb,EAAaa,EAAoBX,CAAI,IAK/E,EAAAN,EAAWgB,CAAc,GAAK,CAAE,MAAMZ,EAAaY,EAAgBV,CAAI,IAKvE,EAAAN,EAAWe,CAAoB,GAAK,CAAE,MAAMX,EAAaW,EAAsBT,CAAI,GAIvF,OAAOE,EAAaS,EAAoBP,CAAO,CACnD,EAEaQ,EAAyB,CAACN,EAAcF,IAA0C,CAC3F,GAAIR,EAAI,WAAgB,CAAC,CAAC,IAAK,IAAK,QAAS,MAAM,EAAE,SAASA,EAAI,SAAY,EAC1E,OAAOM,EAAaD,EAAKL,EAAI,UAAcU,CAAI,EAAGF,CAAO,EAG7D,IAAMG,EAAgBM,EAAoBT,GAAS,KAAOT,EAAI,CAAC,EAE/D,GAAI,CAACY,EACD,OAGJ,IAAME,EAAuBR,EAAKM,EAAe,cAAc,EACzDG,EAAiBT,EAAKQ,EAAsB,QAAQ,EACpDE,EAAqBV,EAAKS,EAAgBJ,CAAI,EAMpD,GAAI,EAAAZ,EAAWiB,CAAkB,GAAK,CAACZ,EAAiBY,EAAoBX,CAAI,IAK5E,EAAAN,EAAWgB,CAAc,GAAK,CAACX,EAAiBW,EAAgBV,CAAI,IAKpE,EAAAN,EAAWe,CAAoB,GAAK,CAACV,EAAiBU,EAAsBT,CAAI,GAIpF,OAAOE,EAAaS,EAAoBP,CAAO,CACnD","sourcesContent":["// eslint-disable-next-line unicorn/prevent-abbreviations\nimport { existsSync } from \"node:fs\";\nimport { cwd, env } from \"node:process\";\n\nimport { ensureDirSync, isAccessible, isAccessibleSync, W_OK } from \"@visulima/fs\";\nimport { join } from \"pathe\";\n\nimport { findPackageRoot, findPackageRootSync } from \"./package\";\n\ntype Options = {\n create?: boolean;\n cwd?: URL | string;\n};\n\nconst useDirectory = (directory: string, options?: Options): string => {\n if (options?.create) {\n ensureDirSync(directory);\n }\n\n return directory;\n};\n\nexport const findCacheDirectory = async (name: string, options?: Options): Promise<string | undefined> => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = await findPackageRoot(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !(await isAccessible(cacheNameDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !(await isAccessible(cacheDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !(await isAccessible(nodeModulesDirectory, W_OK))) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n\nexport const findCacheDirectorySync = (name: string, options?: Options): string | undefined => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = findPackageRootSync(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !isAccessibleSync(cacheNameDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !isAccessibleSync(cacheDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !isAccessibleSync(nodeModulesDirectory, W_OK)) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.cjs';
2
- export { findPackageRoot } from './package.cjs';
2
+ export { findPackageRoot, findPackageRootSync } from './package.cjs';
3
3
  export { NormalizedReadResult, findPackageJson, findPackageJsonSync, parsePackageJson, writePackageJson, writePackageJsonSync } from './package-json.cjs';
4
4
  export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.cjs';
5
5
  import { T as TsConfigJsonResolved } from './types-hoigZ9HA.cjs';
@@ -9,9 +9,16 @@ export { TsConfigJson } from 'type-fest';
9
9
  import '@visulima/fs';
10
10
  import 'normalize-package-data';
11
11
 
12
+ type Options$1 = {
13
+ create?: boolean;
14
+ cwd?: URL | string;
15
+ };
16
+ declare const findCacheDirectory: (name: string, options?: Options$1) => Promise<string | undefined>;
17
+ declare const findCacheDirectorySync: (name: string, options?: Options$1) => string | undefined;
18
+
12
19
  type Options = {
13
20
  tscCompatible?: boolean;
14
21
  };
15
22
  declare const readTsConfig: (tsconfigPath: string, options?: Options) => TsConfigJsonResolved;
16
23
 
17
- export { TsConfigJsonResolved, readTsConfig };
24
+ export { TsConfigJsonResolved, findCacheDirectory, findCacheDirectorySync, readTsConfig };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { RootMonorepo, Strategy, findMonorepoRoot } from './monorepo.js';
2
- export { findPackageRoot } from './package.js';
2
+ export { findPackageRoot, findPackageRootSync } from './package.js';
3
3
  export { NormalizedReadResult, findPackageJson, findPackageJsonSync, parsePackageJson, writePackageJson, writePackageJsonSync } from './package-json.js';
4
4
  export { PackageManager, PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager } from './package-manager.js';
5
5
  import { T as TsConfigJsonResolved } from './types-hoigZ9HA.js';
@@ -9,9 +9,16 @@ export { TsConfigJson } from 'type-fest';
9
9
  import '@visulima/fs';
10
10
  import 'normalize-package-data';
11
11
 
12
+ type Options$1 = {
13
+ create?: boolean;
14
+ cwd?: URL | string;
15
+ };
16
+ declare const findCacheDirectory: (name: string, options?: Options$1) => Promise<string | undefined>;
17
+ declare const findCacheDirectorySync: (name: string, options?: Options$1) => string | undefined;
18
+
12
19
  type Options = {
13
20
  tscCompatible?: boolean;
14
21
  };
15
22
  declare const readTsConfig: (tsconfigPath: string, options?: Options) => TsConfigJsonResolved;
16
23
 
17
- export { TsConfigJsonResolved, readTsConfig };
24
+ export { TsConfigJsonResolved, findCacheDirectory, findCacheDirectorySync, readTsConfig };
package/dist/index.js CHANGED
@@ -1,7 +1,16 @@
1
- export { a as findMonorepoRoot } from './chunk-PUY4M2BR.js';
2
- export { a as findPackageRoot } from './chunk-M4MWM246.js';
3
- export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-6KVF4I2Q.js';
4
- export { a as findPackageJson, b as findPackageJsonSync, e as parsePackageJson, c as writePackageJson, d as writePackageJsonSync } from './chunk-GA54FVOU.js';
1
+ export { a as findMonorepoRoot } from './chunk-QYGSOB5F.js';
2
+ import { a, b as b$1 } from './chunk-BBGTIP2U.js';
3
+ export { a as findPackageRoot, b as findPackageRootSync } from './chunk-BBGTIP2U.js';
4
+ export { a as findLockFile, c as findPackageManager, d as getPackageManagerVersion, e as identifyInitiatingPackageManager } from './chunk-SUN6RRMM.js';
5
+ export { a as findPackageJson, b as findPackageJsonSync, e as parsePackageJson, c as writePackageJson, d as writePackageJsonSync } from './chunk-U4YVB3GU.js';
5
6
  export { c as findTSConfig, e as findTSConfigSync, b as findTsConfig, d as findTsConfigSync, a as readTsConfig, g as writeTSConfig } from './chunk-OQ2PTROP.js';
7
+ import { existsSync } from 'node:fs';
8
+ import { env, cwd } from 'node:process';
9
+ import { isAccessible, W_OK, isAccessibleSync, ensureDirSync } from '@visulima/fs';
10
+ import { join } from 'pathe';
11
+
12
+ var d=(r,e)=>(e?.create&&ensureDirSync(r),r),N=async(r,e)=>{if(env.CACHE_DIR&&!["0","1","false","true"].includes(env.CACHE_DIR))return d(join(env.CACHE_DIR,r),e);let s=await a(e?.cwd??cwd());if(!s)return;let o=join(s,"node_modules"),t=join(o,".cache"),i=join(t,r);if(!(existsSync(i)&&!await isAccessible(i,W_OK))&&!(existsSync(t)&&!await isAccessible(t,W_OK))&&!(existsSync(o)&&!await isAccessible(o,W_OK)))return d(i,e)},b=(r,e)=>{if(env.CACHE_DIR&&!["0","1","false","true"].includes(env.CACHE_DIR))return d(join(env.CACHE_DIR,r),e);let s=b$1(e?.cwd??cwd());if(!s)return;let o=join(s,"node_modules"),t=join(o,".cache"),i=join(t,r);if(!(existsSync(i)&&!isAccessibleSync(i,W_OK))&&!(existsSync(t)&&!isAccessibleSync(t,W_OK))&&!(existsSync(o)&&!isAccessibleSync(o,W_OK)))return d(i,e)};
13
+
14
+ export { N as findCacheDirectory, b as findCacheDirectorySync };
6
15
  //# sourceMappingURL=out.js.map
7
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../src/find-cache-dir.ts"],"names":["existsSync","cwd","env","ensureDirSync","isAccessible","isAccessibleSync","W_OK","join","useDirectory","directory","options","findCacheDirectory","name","rootDirectory","findPackageRoot","nodeModulesDirectory","cacheDirectory","cacheNameDirectory","findCacheDirectorySync","findPackageRootSync"],"mappings":"mSACA,OAAS,cAAAA,MAAkB,UAC3B,OAAS,OAAAC,EAAK,OAAAC,MAAW,eAEzB,OAAS,iBAAAC,EAAe,gBAAAC,EAAc,oBAAAC,EAAkB,QAAAC,MAAY,eACpE,OAAS,QAAAC,MAAY,QASrB,IAAMC,EAAe,CAACC,EAAmBC,KACjCA,GAAS,QACTP,EAAcM,CAAS,EAGpBA,GAGEE,EAAqB,MAAOC,EAAcF,IAAmD,CACtG,GAAIR,EAAI,WAAgB,CAAC,CAAC,IAAK,IAAK,QAAS,MAAM,EAAE,SAASA,EAAI,SAAY,EAC1E,OAAOM,EAAaD,EAAKL,EAAI,UAAcU,CAAI,EAAGF,CAAO,EAG7D,IAAMG,EAAgB,MAAMC,EAAgBJ,GAAS,KAAOT,EAAI,CAAC,EAEjE,GAAI,CAACY,EACD,OAGJ,IAAME,EAAuBR,EAAKM,EAAe,cAAc,EACzDG,EAAiBT,EAAKQ,EAAsB,QAAQ,EACpDE,EAAqBV,EAAKS,EAAgBJ,CAAI,EAMpD,GAAI,EAAAZ,EAAWiB,CAAkB,GAAK,CAAE,MAAMb,EAAaa,EAAoBX,CAAI,IAK/E,EAAAN,EAAWgB,CAAc,GAAK,CAAE,MAAMZ,EAAaY,EAAgBV,CAAI,IAKvE,EAAAN,EAAWe,CAAoB,GAAK,CAAE,MAAMX,EAAaW,EAAsBT,CAAI,GAIvF,OAAOE,EAAaS,EAAoBP,CAAO,CACnD,EAEaQ,EAAyB,CAACN,EAAcF,IAA0C,CAC3F,GAAIR,EAAI,WAAgB,CAAC,CAAC,IAAK,IAAK,QAAS,MAAM,EAAE,SAASA,EAAI,SAAY,EAC1E,OAAOM,EAAaD,EAAKL,EAAI,UAAcU,CAAI,EAAGF,CAAO,EAG7D,IAAMG,EAAgBM,EAAoBT,GAAS,KAAOT,EAAI,CAAC,EAE/D,GAAI,CAACY,EACD,OAGJ,IAAME,EAAuBR,EAAKM,EAAe,cAAc,EACzDG,EAAiBT,EAAKQ,EAAsB,QAAQ,EACpDE,EAAqBV,EAAKS,EAAgBJ,CAAI,EAMpD,GAAI,EAAAZ,EAAWiB,CAAkB,GAAK,CAACZ,EAAiBY,EAAoBX,CAAI,IAK5E,EAAAN,EAAWgB,CAAc,GAAK,CAACX,EAAiBW,EAAgBV,CAAI,IAKpE,EAAAN,EAAWe,CAAoB,GAAK,CAACV,EAAiBU,EAAsBT,CAAI,GAIpF,OAAOE,EAAaS,EAAoBP,CAAO,CACnD","sourcesContent":["// eslint-disable-next-line unicorn/prevent-abbreviations\nimport { existsSync } from \"node:fs\";\nimport { cwd, env } from \"node:process\";\n\nimport { ensureDirSync, isAccessible, isAccessibleSync, W_OK } from \"@visulima/fs\";\nimport { join } from \"pathe\";\n\nimport { findPackageRoot, findPackageRootSync } from \"./package\";\n\ntype Options = {\n create?: boolean;\n cwd?: URL | string;\n};\n\nconst useDirectory = (directory: string, options?: Options): string => {\n if (options?.create) {\n ensureDirSync(directory);\n }\n\n return directory;\n};\n\nexport const findCacheDirectory = async (name: string, options?: Options): Promise<string | undefined> => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = await findPackageRoot(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !(await isAccessible(cacheNameDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !(await isAccessible(cacheDirectory, W_OK))) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !(await isAccessible(nodeModulesDirectory, W_OK))) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n\nexport const findCacheDirectorySync = (name: string, options?: Options): string | undefined => {\n if (env[\"CACHE_DIR\"] && ![\"0\", \"1\", \"false\", \"true\"].includes(env[\"CACHE_DIR\"])) {\n return useDirectory(join(env[\"CACHE_DIR\"], name), options);\n }\n\n const rootDirectory = findPackageRootSync(options?.cwd ?? cwd());\n\n if (!rootDirectory) {\n return undefined;\n }\n\n const nodeModulesDirectory = join(rootDirectory, \"node_modules\");\n const cacheDirectory = join(nodeModulesDirectory, \".cache\");\n const cacheNameDirectory = join(cacheDirectory, name);\n\n // If node_modules/.cache/${name} exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise, if node_modules/.cache exists: If it is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // Otherwise: If node_modules is writeable, return node_modules/.cache/${name}, otherwise return undefined\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheNameDirectory) && !isAccessibleSync(cacheNameDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(cacheDirectory) && !isAccessibleSync(cacheDirectory, W_OK)) {\n return undefined;\n }\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(nodeModulesDirectory) && !isAccessibleSync(nodeModulesDirectory, W_OK)) {\n return undefined;\n }\n\n return useDirectory(cacheNameDirectory, options);\n};\n"]}
package/dist/monorepo.cjs CHANGED
@@ -1,14 +1,14 @@
1
1
  'use strict';
2
2
 
3
- var chunkXMGJIRS7_cjs = require('./chunk-XMGJIRS7.cjs');
4
- require('./chunk-3IWUMNBO.cjs');
5
- require('./chunk-4I4DRNVT.cjs');
3
+ var chunkDCD4MOHC_cjs = require('./chunk-DCD4MOHC.cjs');
4
+ require('./chunk-IRDIZG2L.cjs');
5
+ require('./chunk-6KT7465D.cjs');
6
6
 
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'findMonorepoRoot', {
10
10
  enumerable: true,
11
- get: function () { return chunkXMGJIRS7_cjs.a; }
11
+ get: function () { return chunkDCD4MOHC_cjs.a; }
12
12
  });
13
13
  //# sourceMappingURL=out.js.map
14
14
  //# sourceMappingURL=monorepo.cjs.map
package/dist/monorepo.js CHANGED
@@ -1,5 +1,5 @@
1
- export { a as findMonorepoRoot } from './chunk-PUY4M2BR.js';
2
- import './chunk-6KVF4I2Q.js';
3
- import './chunk-GA54FVOU.js';
1
+ export { a as findMonorepoRoot } from './chunk-QYGSOB5F.js';
2
+ import './chunk-SUN6RRMM.js';
3
+ import './chunk-U4YVB3GU.js';
4
4
  //# sourceMappingURL=out.js.map
5
5
  //# sourceMappingURL=monorepo.js.map
@@ -1,28 +1,28 @@
1
1
  'use strict';
2
2
 
3
- var chunk4I4DRNVT_cjs = require('./chunk-4I4DRNVT.cjs');
3
+ var chunk6KT7465D_cjs = require('./chunk-6KT7465D.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, 'findPackageJson', {
8
8
  enumerable: true,
9
- get: function () { return chunk4I4DRNVT_cjs.a; }
9
+ get: function () { return chunk6KT7465D_cjs.a; }
10
10
  });
11
11
  Object.defineProperty(exports, 'findPackageJsonSync', {
12
12
  enumerable: true,
13
- get: function () { return chunk4I4DRNVT_cjs.b; }
13
+ get: function () { return chunk6KT7465D_cjs.b; }
14
14
  });
15
15
  Object.defineProperty(exports, 'parsePackageJson', {
16
16
  enumerable: true,
17
- get: function () { return chunk4I4DRNVT_cjs.e; }
17
+ get: function () { return chunk6KT7465D_cjs.e; }
18
18
  });
19
19
  Object.defineProperty(exports, 'writePackageJson', {
20
20
  enumerable: true,
21
- get: function () { return chunk4I4DRNVT_cjs.c; }
21
+ get: function () { return chunk6KT7465D_cjs.c; }
22
22
  });
23
23
  Object.defineProperty(exports, 'writePackageJsonSync', {
24
24
  enumerable: true,
25
- get: function () { return chunk4I4DRNVT_cjs.d; }
25
+ get: function () { return chunk6KT7465D_cjs.d; }
26
26
  });
27
27
  //# sourceMappingURL=out.js.map
28
28
  //# sourceMappingURL=package-json.cjs.map
@@ -1,3 +1,3 @@
1
- export { a as findPackageJson, b as findPackageJsonSync, e as parsePackageJson, c as writePackageJson, d as writePackageJsonSync } from './chunk-GA54FVOU.js';
1
+ export { a as findPackageJson, b as findPackageJsonSync, e as parsePackageJson, c as writePackageJson, d as writePackageJsonSync } from './chunk-U4YVB3GU.js';
2
2
  //# sourceMappingURL=out.js.map
3
3
  //# sourceMappingURL=package-json.js.map
@@ -1,25 +1,29 @@
1
1
  'use strict';
2
2
 
3
- var chunk3IWUMNBO_cjs = require('./chunk-3IWUMNBO.cjs');
4
- require('./chunk-4I4DRNVT.cjs');
3
+ var chunkIRDIZG2L_cjs = require('./chunk-IRDIZG2L.cjs');
4
+ require('./chunk-6KT7465D.cjs');
5
5
 
6
6
 
7
7
 
8
8
  Object.defineProperty(exports, 'findLockFile', {
9
9
  enumerable: true,
10
- get: function () { return chunk3IWUMNBO_cjs.a; }
10
+ get: function () { return chunkIRDIZG2L_cjs.a; }
11
+ });
12
+ Object.defineProperty(exports, 'findLockFileSync', {
13
+ enumerable: true,
14
+ get: function () { return chunkIRDIZG2L_cjs.b; }
11
15
  });
12
16
  Object.defineProperty(exports, 'findPackageManager', {
13
17
  enumerable: true,
14
- get: function () { return chunk3IWUMNBO_cjs.b; }
18
+ get: function () { return chunkIRDIZG2L_cjs.c; }
15
19
  });
16
20
  Object.defineProperty(exports, 'getPackageManagerVersion', {
17
21
  enumerable: true,
18
- get: function () { return chunk3IWUMNBO_cjs.c; }
22
+ get: function () { return chunkIRDIZG2L_cjs.d; }
19
23
  });
20
24
  Object.defineProperty(exports, 'identifyInitiatingPackageManager', {
21
25
  enumerable: true,
22
- get: function () { return chunk3IWUMNBO_cjs.d; }
26
+ get: function () { return chunkIRDIZG2L_cjs.e; }
23
27
  });
24
28
  //# sourceMappingURL=out.js.map
25
29
  //# sourceMappingURL=package-manager.cjs.map
@@ -1,4 +1,5 @@
1
1
  declare const findLockFile: (cwd?: URL | string) => Promise<string>;
2
+ declare const findLockFileSync: (cwd?: URL | string) => string;
2
3
  type PackageManager = "bun" | "npm" | "pnpm" | "yarn";
3
4
  type PackageManagerResult = {
4
5
  packageManager: PackageManager;
@@ -11,4 +12,4 @@ declare const identifyInitiatingPackageManager: () => Promise<{
11
12
  version: string;
12
13
  } | undefined>;
13
14
 
14
- export { type PackageManager, type PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
15
+ export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
@@ -1,4 +1,5 @@
1
1
  declare const findLockFile: (cwd?: URL | string) => Promise<string>;
2
+ declare const findLockFileSync: (cwd?: URL | string) => string;
2
3
  type PackageManager = "bun" | "npm" | "pnpm" | "yarn";
3
4
  type PackageManagerResult = {
4
5
  packageManager: PackageManager;
@@ -11,4 +12,4 @@ declare const identifyInitiatingPackageManager: () => Promise<{
11
12
  version: string;
12
13
  } | undefined>;
13
14
 
14
- export { type PackageManager, type PackageManagerResult, findLockFile, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
15
+ export { type PackageManager, type PackageManagerResult, findLockFile, findLockFileSync, findPackageManager, getPackageManagerVersion, identifyInitiatingPackageManager };
@@ -1,4 +1,4 @@
1
- export { a as findLockFile, b as findPackageManager, c as getPackageManagerVersion, d as identifyInitiatingPackageManager } from './chunk-6KVF4I2Q.js';
2
- import './chunk-GA54FVOU.js';
1
+ export { a as findLockFile, b as findLockFileSync, c as findPackageManager, d as getPackageManagerVersion, e as identifyInitiatingPackageManager } from './chunk-SUN6RRMM.js';
2
+ import './chunk-U4YVB3GU.js';
3
3
  //# sourceMappingURL=out.js.map
4
4
  //# sourceMappingURL=package-manager.js.map
package/dist/package.cjs CHANGED
@@ -1,14 +1,18 @@
1
1
  'use strict';
2
2
 
3
- var chunkGAZI4NM6_cjs = require('./chunk-GAZI4NM6.cjs');
4
- require('./chunk-3IWUMNBO.cjs');
5
- require('./chunk-4I4DRNVT.cjs');
3
+ var chunk45ZLUVBF_cjs = require('./chunk-45ZLUVBF.cjs');
4
+ require('./chunk-IRDIZG2L.cjs');
5
+ require('./chunk-6KT7465D.cjs');
6
6
 
7
7
 
8
8
 
9
9
  Object.defineProperty(exports, 'findPackageRoot', {
10
10
  enumerable: true,
11
- get: function () { return chunkGAZI4NM6_cjs.a; }
11
+ get: function () { return chunk45ZLUVBF_cjs.a; }
12
+ });
13
+ Object.defineProperty(exports, 'findPackageRootSync', {
14
+ enumerable: true,
15
+ get: function () { return chunk45ZLUVBF_cjs.b; }
12
16
  });
13
17
  //# sourceMappingURL=out.js.map
14
18
  //# sourceMappingURL=package.cjs.map
@@ -1,3 +1,4 @@
1
1
  declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
2
+ declare const findPackageRootSync: (cwd?: URL | string) => string;
2
3
 
3
- export { findPackageRoot };
4
+ export { findPackageRoot, findPackageRootSync };
package/dist/package.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  declare const findPackageRoot: (cwd?: URL | string) => Promise<string>;
2
+ declare const findPackageRootSync: (cwd?: URL | string) => string;
2
3
 
3
- export { findPackageRoot };
4
+ export { findPackageRoot, findPackageRootSync };
package/dist/package.js CHANGED
@@ -1,5 +1,5 @@
1
- export { a as findPackageRoot } from './chunk-M4MWM246.js';
2
- import './chunk-6KVF4I2Q.js';
3
- import './chunk-GA54FVOU.js';
1
+ export { a as findPackageRoot, b as findPackageRootSync } from './chunk-BBGTIP2U.js';
2
+ import './chunk-SUN6RRMM.js';
3
+ import './chunk-U4YVB3GU.js';
4
4
  //# sourceMappingURL=out.js.map
5
5
  //# sourceMappingURL=package.js.map
package/package.json CHANGED
@@ -1,30 +1,33 @@
1
1
  {
2
2
  "name": "@visulima/package",
3
- "version": "1.4.3",
3
+ "version": "1.5.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",
7
- "package",
8
- "pkg-types",
7
+ "find",
8
+ "find-cache",
9
+ "find-cache-dir",
10
+ "find-cache-directory",
11
+ "find-monorepo-root",
9
12
  "find-up-pkg",
10
- "read-pkg",
11
- "read-pkg-up",
12
- "read-tsconfig",
13
- "tsconfig",
14
13
  "get-tsconfig",
15
- "find-monorepo-root",
16
- "pkg-up",
17
- "pkg-dir",
14
+ "mono-repo",
15
+ "monorepo",
16
+ "package",
18
17
  "package-json",
18
+ "package-manager",
19
19
  "package.json",
20
- "tsconfig.json",
21
20
  "packages",
22
- "monorepo",
23
- "mono-repo",
21
+ "pkg-dir",
24
22
  "pkg-manager",
25
- "package-manager",
26
- "find",
23
+ "pkg-types",
24
+ "pkg-up",
25
+ "read-pkg",
26
+ "read-pkg-up",
27
+ "read-tsconfig",
27
28
  "root",
29
+ "tsconfig",
30
+ "tsconfig.json",
28
31
  "visulima"
29
32
  ],
30
33
  "homepage": "https://www.visulima.com/docs/package/package",
@@ -139,7 +142,7 @@
139
142
  "test:watch": "vitest"
140
143
  },
141
144
  "dependencies": {
142
- "@visulima/fs": "2.0.1",
145
+ "@visulima/fs": "2.0.2",
143
146
  "jsonc-parser": "^3.2.1",
144
147
  "normalize-package-data": "^6.0.0",
145
148
  "pathe": "^1.1.2",
@@ -183,6 +186,11 @@
183
186
  "engines": {
184
187
  "node": ">=18.* <=21.*"
185
188
  },
189
+ "os": [
190
+ "darwin",
191
+ "linux",
192
+ "win32"
193
+ ],
186
194
  "publishConfig": {
187
195
  "access": "public",
188
196
  "provenance": true
@@ -1,16 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk4I4DRNVT_cjs = require('./chunk-4I4DRNVT.cjs');
4
- var child_process = require('child_process');
5
- var fs$1 = require('fs');
6
- var fs = require('@visulima/fs');
7
- var pathe = require('pathe');
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(pathe.join(e,i))&&(t=pathe.join(e,i));}),t)return t;let r=pathe.join(e,"package.json");if(fs$1.existsSync(r)&&chunk4I4DRNVT_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=chunk4I4DRNVT_cjs.e(n);if(e.packageManager){let r=["npm","yarn","pnpm","bun"].find(i=>e.packageManager.startsWith(i));if(r)return {packageManager:r,path:pathe.dirname(n)}}}if(n.endsWith("yarn.lock"))return {packageManager:"yarn",path:pathe.dirname(n)};if(n.endsWith("package-lock.json")||n.endsWith("npm-shrinkwrap.json"))return {packageManager:"npm",path:pathe.dirname(n)};if(n.endsWith("pnpm-lock.yaml"))return {packageManager:"pnpm",path:pathe.dirname(n)};if(n.endsWith("bun.lockb"))return {packageManager:"bun",path:pathe.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-3IWUMNBO.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","dirname","join","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,KAEzC,OAAS,UAAAC,MAAc,eACvB,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAI9B,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMN,EAAOG,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,MAAMR,EACnBS,GAAsB,CACnB,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYZ,EAAWI,EAAKO,EAAWE,CAAY,CAAC,IACrDD,EAAWR,EAAKO,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBV,EAAKO,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,KAAMd,EAAQO,CAAS,CAC3B,CAER,CACJ,CAEA,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,OAChB,KAAMP,EAAQO,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,mBAAmB,GAAKA,EAAU,SAAS,qBAAqB,EACnF,MAAO,CACH,eAAgB,MAChB,KAAMP,EAAQO,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,gBAAgB,EACnC,MAAO,CACH,eAAgB,OAChB,KAAMP,EAAQO,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,MAChB,KAAMP,EAAQO,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\";\n\nimport { findUp } from \"@visulima/fs\";\nimport { dirname, join } from \"pathe\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `URL | string`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory: string) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\n },\n );\n\n if (!foundFile) {\n throw new Error(\"Could not find lock file\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = parsePackageJson(foundFile);\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new Error(\"Could not find lock file\");\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
@@ -1,22 +0,0 @@
1
- 'use strict';
2
-
3
- var fs$1 = require('fs');
4
- var fs = require('@visulima/fs');
5
- var error = require('@visulima/fs/error');
6
- var utils = require('@visulima/fs/utils');
7
- var n = require('normalize-package-data');
8
- var pathe = require('pathe');
9
-
10
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
-
12
- var n__default = /*#__PURE__*/_interopDefault(n);
13
-
14
- var m=new Map,b=async(e,o={})=>{let t=await fs.findUp("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new error.NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=await fs.readJson(t);n__default.default(s);let r={packageJson:s,path:pathe.normalize(t)};return a.set(t,r),r},S=(e,o={})=>{let t=fs.findUpSync("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new error.NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=fs.readJsonSync(t);n__default.default(s);let r={packageJson:s,path:t};return a.set(t,r),r},x=async(e,o={})=>{let{cwd:t,...a}=o,s=utils.toPath(o.cwd??process.cwd());await fs.writeJson(pathe.join(s,"package.json"),e,a);},U=(e,o={})=>{let{cwd:t,...a}=o,s=utils.toPath(o.cwd??process.cwd());fs.writeJsonSync(pathe.join(s,"package.json"),e,a);},T=e=>{let o=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!o&&!(typeof e=="string"))throw new TypeError("`packageFile` should be either an `object` or a `string`.");let a=o?structuredClone(e):fs$1.existsSync(e)?fs.readJsonSync(e):utils.parseJson(e);return n__default.default(a),a};
15
-
16
- exports.a = b;
17
- exports.b = S;
18
- exports.c = x;
19
- exports.d = U;
20
- exports.e = T;
21
- //# sourceMappingURL=out.js.map
22
- //# sourceMappingURL=chunk-4I4DRNVT.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-json.ts"],"names":["existsSync","findUp","findUpSync","readJson","readJsonSync","writeJson","writeJsonSync","NotFoundError","parseJson","toPath","normalizeData","join","normalize","PackageJsonFileCache","findPackageJson","cwd","options","filePath","cache","packageJson","output","findPackageJsonSync","writePackageJson","data","writeOptions","directory","writePackageJsonSync","parsePackageJson","packageFile","isObject","json"],"mappings":"AAAA,OAAS,cAAAA,MAAkB,KAG3B,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,yBAC1B,OAAS,QAAAC,EAAM,aAAAC,MAAiB,QAShC,IAAMC,EAAuB,IAAI,IAepBC,EAAkB,MAAOC,EAAoBC,EAAuB,CAAC,IAAqC,CACnH,IAAMC,EAAW,MAAMhB,EAAO,eAAgB,CAC1C,GAAIc,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIV,EAAc,oDAAoD,EAGhF,IAAMW,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAc,MAAMhB,EAASc,CAAQ,EAE3CP,EAAcS,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EAEb,KAAMP,EAAUK,CAAQ,CAC5B,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAEaC,EAAsB,CAACN,EAAoBC,EAAuB,CAAC,IAA4B,CACxG,IAAMC,EAAWf,EAAW,eAAgB,CACxC,GAAIa,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIV,EAAc,oDAAoD,EAGhF,IAAMW,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAcf,EAAaa,CAAQ,EAEzCP,EAAcS,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EACb,KAAMF,CACV,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAYaE,EAAmB,MAAwBC,EAASP,EAAqD,CAAC,IAAqB,CACxI,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYhB,EAAOO,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErD,MAAMX,EAAUM,EAAKc,EAAW,cAAc,EAAGF,EAAMC,CAAY,CACvE,EAEaE,EAAuB,CAAkBH,EAASP,EAAqD,CAAC,IAAY,CAC7H,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYhB,EAAOO,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErDV,EAAcK,EAAKc,EAAW,cAAc,EAAGF,EAAMC,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,EAE3B5B,EAAW4B,CAAqB,EAC9BxB,EAAawB,CAAqB,EAClCpB,EAAUoB,CAAqB,EAEvC,OAAAlB,EAAcoB,CAAa,EAEpBA,CACX","sourcesContent":["import { existsSync } from \"node:fs\";\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 { join, normalize } from \"pathe\";\nimport type { JsonObject } from \"type-fest\";\n\nimport type { Cache, NormalizedPackageJson, PackageJson } from \"./types\";\n\ntype ReadOptions = {\n cache?: Cache<NormalizedReadResult> | boolean;\n};\n\nconst PackageJsonFileCache = new Map<string, NormalizedReadResult>();\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, options: ReadOptions = {}): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = await readJson(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n // @TODO Remove this after @visulima/fs use pathe\n path: normalize(filePath),\n };\n\n cache.set(filePath, output);\n\n return output;\n};\n\nexport const findPackageJsonSync = (cwd?: URL | string, options: ReadOptions = {}): NormalizedReadResult => {\n const filePath = findUpSync(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = readJsonSync(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n path: filePath,\n };\n\n cache.set(filePath, output);\n\n return output;\n};\n\n/**\n * An asynchronous function to write the package.json file with the given data.\n *\n * @param data - The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.\n * @param options - Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.\n * This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options[\"cwd\"]`.\n * `cwd` represents the current working directory. If not specified, the default working directory will be used.\n * @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.\n */\n\nexport const writePackageJson = async <T = PackageJson>(data: T, options: WriteJsonOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const { cwd, ...writeOptions } = options;\n const directory = toPath(options.cwd ?? process.cwd());\n\n await writeJson(join(directory, \"package.json\"), data, writeOptions);\n};\n\nexport const writePackageJsonSync = <T = PackageJson>(data: T, options: WriteJsonOptions & { cwd?: URL | string } = {}): void => {\n const { cwd, ...writeOptions } = options;\n const directory = toPath(options.cwd ?? process.cwd());\n\n writeJsonSync(join(directory, \"package.json\"), data, writeOptions);\n};\n\nexport const parsePackageJson = (packageFile: JsonObject | string): NormalizedPackageJson => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const isObject = packageFile !== null && typeof packageFile === \"object\" && !Array.isArray(packageFile);\n const isString = typeof packageFile === \"string\";\n\n if (!isObject && !isString) {\n throw new TypeError(\"`packageFile` should be either an `object` or a `string`.\");\n }\n\n const json = isObject\n ? structuredClone(packageFile)\n : // eslint-disable-next-line security/detect-non-literal-fs-filename\n existsSync(packageFile as string)\n ? readJsonSync(packageFile as string)\n : parseJson(packageFile as string);\n\n normalizeData(json as Input);\n\n return json as NormalizedPackageJson;\n};\n"]}
@@ -1,11 +0,0 @@
1
- import { e } from './chunk-GA54FVOU.js';
2
- import { execSync } from 'node:child_process';
3
- import { existsSync, readFileSync } from 'node:fs';
4
- import { findUp } from '@visulima/fs';
5
- import { join, dirname } from 'pathe';
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-6KVF4I2Q.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-manager.ts"],"names":["execSync","existsSync","readFileSync","findUp","dirname","join","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,UAEzC,OAAS,UAAAC,MAAc,eACvB,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAI9B,IAAMC,EAAgB,CAAC,YAAa,oBAAqB,iBAAkB,sBAAuB,WAAW,EAWhGC,EAAe,MAAOC,GAAwC,CACvE,IAAMC,EAAW,MAAMN,EAAOG,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,MAAMR,EACnBS,GAAsB,CACnB,IAAIC,EASJ,GAPAP,EAAc,QAASQ,GAAiB,CAEhC,CAACD,GAAYZ,EAAWI,EAAKO,EAAWE,CAAY,CAAC,IACrDD,EAAWR,EAAKO,EAAWE,CAAY,EAE/C,CAAC,EAEGD,EACA,OAAOA,EAGX,IAAME,EAAsBV,EAAKO,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,KAAMd,EAAQO,CAAS,CAC3B,CAER,CACJ,CAEA,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,OAChB,KAAMP,EAAQO,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,mBAAmB,GAAKA,EAAU,SAAS,qBAAqB,EACnF,MAAO,CACH,eAAgB,MAChB,KAAMP,EAAQO,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,gBAAgB,EACnC,MAAO,CACH,eAAgB,OAChB,KAAMP,EAAQO,CAAS,CAC3B,EAGJ,GAAIA,EAAU,SAAS,WAAW,EAC9B,MAAO,CACH,eAAgB,MAChB,KAAMP,EAAQO,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\";\n\nimport { findUp } from \"@visulima/fs\";\nimport { dirname, join } from \"pathe\";\n\nimport { parsePackageJson } from \"./package-json\";\n\nconst lockFileNames = [\"yarn.lock\", \"package-lock.json\", \"pnpm-lock.yaml\", \"npm-shrinkwrap.json\", \"bun.lockb\"];\n\n/**\n * An asynchronous function that finds a lock file in the specified directory or any of its parent directories.\n *\n * @param cwd - Optional. The directory path to start the search from. The type of `cwd` is part of an `Options` type,\n * specifically `URL | string`. Defaults to the current working directory.\n * @returns A `Promise` that resolves with the path of the found lock file.\n * The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if no lock file is found.\n */\nexport const findLockFile = async (cwd?: URL | string): Promise<string> => {\n const filePath = await findUp(lockFileNames, {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (!filePath) {\n throw new Error(\"Could not find lock file\");\n }\n\n return filePath;\n};\n\nexport type PackageManager = \"bun\" | \"npm\" | \"pnpm\" | \"yarn\";\n\nexport type PackageManagerResult = {\n packageManager: PackageManager;\n path: string;\n};\n\n/**\n * An asynchronous function that finds the package manager used in a project based on the presence of lock files\n * or package.json configuration. If found, it returns the package manager and the path to the lock file or package.json.\n * Throws an error if no lock file or package.json is found.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is part of an `Options`\n * type, specifically `URL | string`.\n * @returns A `Promise` that resolves to an object containing the package manager and path.\n * The return type of the function is `Promise<PackageManagerResult>`.\n * @throws An `Error` if no lock file or package.json is found.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(\n (directory: string) => {\n let lockFile: string | undefined;\n\n lockFileNames.forEach((lockFileName) => {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (!lockFile && existsSync(join(directory, lockFileName))) {\n lockFile = join(directory, lockFileName);\n }\n });\n\n if (lockFile) {\n return lockFile;\n }\n\n const packageJsonFilePath = join(directory, \"package.json\");\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = parsePackageJson(readFileSync(packageJsonFilePath, \"utf8\"));\n\n if (packageJson.packageManager !== undefined) {\n return packageJsonFilePath;\n }\n }\n\n return undefined;\n },\n {\n ...(cwd && { cwd }),\n },\n );\n\n if (!foundFile) {\n throw new Error(\"Could not find lock file\");\n }\n\n if (foundFile.endsWith(\"package.json\")) {\n const packageJson = parsePackageJson(foundFile);\n\n if (packageJson.packageManager) {\n const packageManagerNames = [\"npm\", \"yarn\", \"pnpm\", \"bun\"] as const;\n const foundPackageManager = packageManagerNames.find((prefix) => (packageJson.packageManager as string).startsWith(prefix));\n\n if (foundPackageManager) {\n return {\n packageManager: foundPackageManager,\n path: dirname(foundFile),\n };\n }\n }\n }\n\n if (foundFile.endsWith(\"yarn.lock\")) {\n return {\n packageManager: \"yarn\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"package-lock.json\") || foundFile.endsWith(\"npm-shrinkwrap.json\")) {\n return {\n packageManager: \"npm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"pnpm-lock.yaml\")) {\n return {\n packageManager: \"pnpm\",\n path: dirname(foundFile),\n };\n }\n\n if (foundFile.endsWith(\"bun.lockb\")) {\n return {\n packageManager: \"bun\",\n path: dirname(foundFile),\n };\n }\n\n throw new Error(\"Could not find lock file\");\n};\n\n/**\n * Function that retrieves the version of the specified package manager.\n *\n * @param name - The name of the package manager. The type of `name` is `string`.\n * @returns The version of the package manager. The return type of the function is `string`.\n */\nexport const getPackageManagerVersion = (name: string): string => execSync(`${name} --version`).toString(\"utf8\").trim();\n\n/**\n * An asynchronous function that detects what package manager executes the process.\n *\n * Supports npm, pnpm, Yarn, cnpm, and bun. And also any other package manager that sets the npm_config_user_agent env variable.\n *\n * @returns A `Promise` that resolves to an object containing the name and version of the package manager,\n * or undefined if the package manager information cannot be determined. The return type of the function\n * is `Promise<{ name: PackageManager | \"cnpm\"; version: string } | undefined>`.\n */\nexport const identifyInitiatingPackageManager = async (): Promise<\n | {\n name: PackageManager | \"cnpm\";\n version: string;\n }\n | undefined\n> => {\n if (!process.env[\"npm_config_user_agent\"]) {\n return undefined;\n }\n\n const pmSpec = process.env[\"npm_config_user_agent\"].split(\" \")[0] as string;\n const separatorPos = pmSpec.lastIndexOf(\"/\");\n const name = pmSpec.slice(0, Math.max(0, separatorPos));\n\n return {\n name: name === \"npminstall\" ? \"cnpm\" : (name as PackageManager),\n version: pmSpec.slice(Math.max(0, separatorPos + 1)),\n };\n};\n"]}
@@ -1,12 +0,0 @@
1
- import { existsSync } from 'node:fs';
2
- import { findUp, readJson, findUpSync, readJsonSync, writeJson, writeJsonSync } from '@visulima/fs';
3
- import { NotFoundError } from '@visulima/fs/error';
4
- import { toPath, parseJson } from '@visulima/fs/utils';
5
- import n from 'normalize-package-data';
6
- import { normalize, join } from 'pathe';
7
-
8
- var m=new Map,S=async(e,o={})=>{let t=await findUp("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=await readJson(t);n(s);let r={packageJson:s,path:normalize(t)};return a.set(t,r),r},x=(e,o={})=>{let t=findUpSync("package.json",{...e&&{cwd:e},type:"file"});if(!t)throw new NotFoundError("No such file or directory, for package.json found.");let a=o.cache&&typeof o.cache!="boolean"?o.cache:m;if(o.cache&&a.has(t))return a.get(t);let s=readJsonSync(t);n(s);let r={packageJson:s,path:t};return a.set(t,r),r},U=async(e,o={})=>{let{cwd:t,...a}=o,s=toPath(o.cwd??process.cwd());await writeJson(join(s,"package.json"),e,a);},T=(e,o={})=>{let{cwd:t,...a}=o,s=toPath(o.cwd??process.cwd());writeJsonSync(join(s,"package.json"),e,a);},C=e=>{let o=e!==null&&typeof e=="object"&&!Array.isArray(e);if(!o&&!(typeof e=="string"))throw new TypeError("`packageFile` should be either an `object` or a `string`.");let a=o?structuredClone(e):existsSync(e)?readJsonSync(e):parseJson(e);return n(a),a};
9
-
10
- export { S as a, x as b, U as c, T as d, C as e };
11
- //# sourceMappingURL=out.js.map
12
- //# sourceMappingURL=chunk-GA54FVOU.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-json.ts"],"names":["existsSync","findUp","findUpSync","readJson","readJsonSync","writeJson","writeJsonSync","NotFoundError","parseJson","toPath","normalizeData","join","normalize","PackageJsonFileCache","findPackageJson","cwd","options","filePath","cache","packageJson","output","findPackageJsonSync","writePackageJson","data","writeOptions","directory","writePackageJsonSync","parsePackageJson","packageFile","isObject","json"],"mappings":"AAAA,OAAS,cAAAA,MAAkB,UAG3B,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,yBAC1B,OAAS,QAAAC,EAAM,aAAAC,MAAiB,QAShC,IAAMC,EAAuB,IAAI,IAepBC,EAAkB,MAAOC,EAAoBC,EAAuB,CAAC,IAAqC,CACnH,IAAMC,EAAW,MAAMhB,EAAO,eAAgB,CAC1C,GAAIc,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIV,EAAc,oDAAoD,EAGhF,IAAMW,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAc,MAAMhB,EAASc,CAAQ,EAE3CP,EAAcS,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EAEb,KAAMP,EAAUK,CAAQ,CAC5B,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAEaC,EAAsB,CAACN,EAAoBC,EAAuB,CAAC,IAA4B,CACxG,IAAMC,EAAWf,EAAW,eAAgB,CACxC,GAAIa,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAI,CAACE,EACD,MAAM,IAAIV,EAAc,oDAAoD,EAGhF,IAAMW,EAAQF,EAAQ,OAAS,OAAOA,EAAQ,OAAU,UAAYA,EAAQ,MAAQH,EAEpF,GAAIG,EAAQ,OAASE,EAAM,IAAID,CAAQ,EACnC,OAAOC,EAAM,IAAID,CAAQ,EAG7B,IAAME,EAAcf,EAAaa,CAAQ,EAEzCP,EAAcS,CAAoB,EAElC,IAAMC,EAAS,CACX,YAAaD,EACb,KAAMF,CACV,EAEA,OAAAC,EAAM,IAAID,EAAUG,CAAM,EAEnBA,CACX,EAYaE,EAAmB,MAAwBC,EAASP,EAAqD,CAAC,IAAqB,CACxI,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYhB,EAAOO,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErD,MAAMX,EAAUM,EAAKc,EAAW,cAAc,EAAGF,EAAMC,CAAY,CACvE,EAEaE,EAAuB,CAAkBH,EAASP,EAAqD,CAAC,IAAY,CAC7H,GAAM,CAAE,IAAAD,EAAK,GAAGS,CAAa,EAAIR,EAC3BS,EAAYhB,EAAOO,EAAQ,KAAO,QAAQ,IAAI,CAAC,EAErDV,EAAcK,EAAKc,EAAW,cAAc,EAAGF,EAAMC,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,EAE3B5B,EAAW4B,CAAqB,EAC9BxB,EAAawB,CAAqB,EAClCpB,EAAUoB,CAAqB,EAEvC,OAAAlB,EAAcoB,CAAa,EAEpBA,CACX","sourcesContent":["import { existsSync } from \"node:fs\";\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 { join, normalize } from \"pathe\";\nimport type { JsonObject } from \"type-fest\";\n\nimport type { Cache, NormalizedPackageJson, PackageJson } from \"./types\";\n\ntype ReadOptions = {\n cache?: Cache<NormalizedReadResult> | boolean;\n};\n\nconst PackageJsonFileCache = new Map<string, NormalizedReadResult>();\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, options: ReadOptions = {}): Promise<NormalizedReadResult> => {\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = await readJson(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n // @TODO Remove this after @visulima/fs use pathe\n path: normalize(filePath),\n };\n\n cache.set(filePath, output);\n\n return output;\n};\n\nexport const findPackageJsonSync = (cwd?: URL | string, options: ReadOptions = {}): NormalizedReadResult => {\n const filePath = findUpSync(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (!filePath) {\n throw new NotFoundError(\"No such file or directory, for package.json found.\");\n }\n\n const cache = options.cache && typeof options.cache !== \"boolean\" ? options.cache : PackageJsonFileCache;\n\n if (options.cache && cache.has(filePath)) {\n return cache.get(filePath) as NormalizedReadResult;\n }\n\n const packageJson = readJsonSync(filePath);\n\n normalizeData(packageJson as Input);\n\n const output = {\n packageJson: packageJson as NormalizedPackageJson,\n path: filePath,\n };\n\n cache.set(filePath, output);\n\n return output;\n};\n\n/**\n * An asynchronous function to write the package.json file with the given data.\n *\n * @param data - The package.json data to write. The data is an intersection type of `PackageJson` and a record where keys are `string` and values can be any type.\n * @param options - Optional. The options for writing the package.json. If not provided, an empty object will be used `{}`.\n * This is an intersection type of `WriteJsonOptions` and a record with an optional `cwd` key which type is `Options[\"cwd\"]`.\n * `cwd` represents the current working directory. If not specified, the default working directory will be used.\n * @returns A `Promise` that resolves once the package.json file has been written. The type of the returned promise is `Promise<void>`.\n */\n\nexport const writePackageJson = async <T = PackageJson>(data: T, options: WriteJsonOptions & { cwd?: URL | string } = {}): Promise<void> => {\n const { cwd, ...writeOptions } = options;\n const directory = toPath(options.cwd ?? process.cwd());\n\n await writeJson(join(directory, \"package.json\"), data, writeOptions);\n};\n\nexport const writePackageJsonSync = <T = PackageJson>(data: T, options: WriteJsonOptions & { cwd?: URL | string } = {}): void => {\n const { cwd, ...writeOptions } = options;\n const directory = toPath(options.cwd ?? process.cwd());\n\n writeJsonSync(join(directory, \"package.json\"), data, writeOptions);\n};\n\nexport const parsePackageJson = (packageFile: JsonObject | string): NormalizedPackageJson => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n const isObject = packageFile !== null && typeof packageFile === \"object\" && !Array.isArray(packageFile);\n const isString = typeof packageFile === \"string\";\n\n if (!isObject && !isString) {\n throw new TypeError(\"`packageFile` should be either an `object` or a `string`.\");\n }\n\n const json = isObject\n ? structuredClone(packageFile)\n : // eslint-disable-next-line security/detect-non-literal-fs-filename\n existsSync(packageFile as string)\n ? readJsonSync(packageFile as string)\n : parseJson(packageFile as string);\n\n normalizeData(json as Input);\n\n return json as NormalizedPackageJson;\n};\n"]}
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk3IWUMNBO_cjs = require('./chunk-3IWUMNBO.cjs');
4
- var fs = require('@visulima/fs');
5
- var pathe = require('pathe');
6
-
7
- var m=async t=>{try{let a=await chunk3IWUMNBO_cjs.a(t);return pathe.dirname(a)}catch{}let o=await fs.findUp(".git/config",{...t&&{cwd:t},type:"file"});if(o)return pathe.dirname(pathe.dirname(o));let r=await fs.findUp("package.json",{...t&&{cwd:t},type:"file"});if(r)return pathe.dirname(r);throw new Error("Could not find root directory")};
8
-
9
- exports.a = m;
10
- //# sourceMappingURL=out.js.map
11
- //# sourceMappingURL=chunk-GAZI4NM6.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package.ts"],"names":["findUp","dirname","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath"],"mappings":"yCAAA,OAAS,UAAAA,MAAc,eACvB,OAAS,WAAAC,MAAe,QAgBjB,IAAMC,EAAkB,MAAOC,GAAwC,CAE1E,GAAI,CACA,IAAMC,EAAW,MAAMC,EAAaF,CAAG,EAEvC,OAAOF,EAAQG,CAAQ,CAC3B,MAAQ,CAER,CAGA,IAAME,EAAY,MAAMN,EAAO,cAAe,CAC1C,GAAIG,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAOL,EAAQA,EAAQK,CAAS,CAAC,EAIrC,IAAMC,EAAW,MAAMP,EAAO,eAAgB,CAC1C,GAAIG,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAON,EAAQM,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { findUp } from \"@visulima/fs\";\nimport { dirname } from \"pathe\";\n\nimport { findLockFile } from \"./package-manager\";\n\n/**\n * An asynchronous function that finds the root directory of a project based on certain lookup criteria.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if the root directory could not be found.\n *\n * @example\n * const rootDirectory = await findPackageRoot();\n * console.log(rootDirectory); // '/path/to/project'\n */\n// eslint-disable-next-line import/prefer-default-export\nexport const findPackageRoot = async (cwd?: URL | string): Promise<string> => {\n // Lookdown for lockfile\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n // Lookup for .git/config\n const gitConfig = await findUp(\".git/config\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n // Lookdown for package.json\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (filePath) {\n return dirname(filePath);\n }\n\n throw new Error(\"Could not find root directory\");\n};\n"]}
@@ -1,9 +0,0 @@
1
- import { a } from './chunk-6KVF4I2Q.js';
2
- import { findUp } from '@visulima/fs';
3
- import { dirname } from 'pathe';
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-M4MWM246.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package.ts"],"names":["findUp","dirname","findPackageRoot","cwd","lockFile","findLockFile","gitConfig","filePath"],"mappings":"wCAAA,OAAS,UAAAA,MAAc,eACvB,OAAS,WAAAC,MAAe,QAgBjB,IAAMC,EAAkB,MAAOC,GAAwC,CAE1E,GAAI,CACA,IAAMC,EAAW,MAAMC,EAAaF,CAAG,EAEvC,OAAOF,EAAQG,CAAQ,CAC3B,MAAQ,CAER,CAGA,IAAME,EAAY,MAAMN,EAAO,cAAe,CAC1C,GAAIG,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAIG,EACA,OAAOL,EAAQA,EAAQK,CAAS,CAAC,EAIrC,IAAMC,EAAW,MAAMP,EAAO,eAAgB,CAC1C,GAAIG,GAAO,CAAE,IAAAA,CAAI,EACjB,KAAM,MACV,CAAC,EAED,GAAII,EACA,OAAON,EAAQM,CAAQ,EAG3B,MAAM,IAAI,MAAM,+BAA+B,CACnD","sourcesContent":["import { findUp } from \"@visulima/fs\";\nimport { dirname } from \"pathe\";\n\nimport { findLockFile } from \"./package-manager\";\n\n/**\n * An asynchronous function that finds the root directory of a project based on certain lookup criteria.\n *\n * @param cwd - Optional. The current working directory to start the search from. The type of `cwd` is `string`.\n * @returns A `Promise` that resolves to the path of the root directory. The type of the returned promise is `Promise<string>`.\n * @throws An `Error` if the root directory could not be found.\n *\n * @example\n * const rootDirectory = await findPackageRoot();\n * console.log(rootDirectory); // '/path/to/project'\n */\n// eslint-disable-next-line import/prefer-default-export\nexport const findPackageRoot = async (cwd?: URL | string): Promise<string> => {\n // Lookdown for lockfile\n try {\n const lockFile = await findLockFile(cwd);\n\n return dirname(lockFile);\n } catch {\n /* empty */\n }\n\n // Lookup for .git/config\n const gitConfig = await findUp(\".git/config\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (gitConfig) {\n return dirname(dirname(gitConfig));\n }\n\n // Lookdown for package.json\n const filePath = await findUp(\"package.json\", {\n ...(cwd && { cwd }),\n type: \"file\",\n });\n\n if (filePath) {\n return dirname(filePath);\n }\n\n throw new Error(\"Could not find root directory\");\n};\n"]}
@@ -1,10 +0,0 @@
1
- import { b } from './chunk-6KVF4I2Q.js';
2
- import { existsSync, readFileSync } from 'node:fs';
3
- import { findUp, readJson } from '@visulima/fs';
4
- import { dirname, join } from 'pathe';
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-PUY4M2BR.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","findUp","readJson","dirname","join","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"wCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,UAEzC,OAAS,UAAAC,EAAQ,YAAAC,MAAgB,eACjC,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAsBvB,IAAMC,EAAmB,MAAOC,GAA8C,CACjF,IAAMC,EAAoB,MAAMN,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,KAAM,OACN,GAAIK,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAmB,SAAS,YAAY,EAAG,CAC3C,IAAMC,EAAQ,MAAMN,EAA2DK,CAAiB,EAEhG,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAML,EAAQI,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,EAAsBT,EAAKO,EAAM,cAAc,EAGrD,GAAIZ,EAAWc,CAAmB,GAEVb,EAAaI,EAAKO,EAAM,cAAc,EAAG,MAAM,EAEnD,SAAS,YAAY,EACjC,MAAO,CACH,KAAAA,EACA,SAAUF,EAAU,QAAWC,CACnC,CAGZ,SAAWA,IAAmB,OAAQ,CAClC,IAAMI,EAAyBV,EAAKO,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\";\n\nimport { findUp, readJson } from \"@visulima/fs\";\nimport { dirname, join } from \"pathe\";\n\nimport { findPackageManager } from \"./package-manager\";\n\nexport type Strategy = \"lerna\" | \"npm\" | \"pnpm\" | \"turbo\" | \"yarn\";\n\nexport interface RootMonorepo<T extends Strategy = Strategy> {\n path: string;\n strategy: T;\n}\n\n/**\n * An asynchronous function to find the root directory path and strategy for a monorepo based on\n * the given current working directory (cwd).\n *\n * @param cwd - The current working directory. The type of `cwd` is part of an `Options` type, specifically `Options[\"cwd\"]`.\n * Default is undefined.\n * @returns A `Promise` that resolves to the root directory path and strategy for the monorepo.\n * The type of the returned promise is `Promise<RootMonorepo>`.\n * @throws An `Error` if no monorepo root can be found using lerna, yarn, pnpm, or npm as indicators.\n */\n// eslint-disable-next-line sonarjs/cognitive-complexity\nexport const findMonorepoRoot = async (cwd?: URL | string): Promise<RootMonorepo> => {\n const workspaceFilePath = await findUp([\"lerna.json\", \"turbo.json\"], {\n type: \"file\",\n ...(cwd && { cwd }),\n });\n\n if (workspaceFilePath?.endsWith(\"lerna.json\")) {\n const lerna = await readJson<{ packages?: string[]; useWorkspaces?: boolean }>(workspaceFilePath);\n\n if (lerna.useWorkspaces || lerna.packages) {\n return {\n path: dirname(workspaceFilePath),\n strategy: \"lerna\",\n };\n }\n }\n\n const isTurbo = workspaceFilePath?.endsWith(\"turbo.json\");\n\n try {\n const { packageManager, path } = await findPackageManager(cwd);\n\n if ([\"npm\", \"yarn\"].includes(packageManager)) {\n const packageJsonFilePath = join(path, \"package.json\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(packageJsonFilePath)) {\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n const packageJson = readFileSync(join(path, \"package.json\"), \"utf8\");\n\n if (packageJson.includes(\"workspaces\")) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : (packageManager as \"npm\" | \"yarn\"),\n };\n }\n }\n } else if (packageManager === \"pnpm\") {\n const pnpmWorkspacesFilePath = join(path, \"pnpm-workspace.yaml\");\n\n // eslint-disable-next-line security/detect-non-literal-fs-filename\n if (existsSync(pnpmWorkspacesFilePath)) {\n return {\n path,\n strategy: isTurbo ? \"turbo\" : \"pnpm\",\n };\n }\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n // Skip this error to show the error message from the next block\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access\n if (!error.message.includes(\"Could not find lock file\")) {\n throw error;\n }\n }\n\n throw new Error(`No monorepo root could be found upwards from the directory ${cwd as string} using lerna, yarn, pnpm, or npm as indicators.`);\n};\n"]}
@@ -1,12 +0,0 @@
1
- 'use strict';
2
-
3
- var chunk3IWUMNBO_cjs = require('./chunk-3IWUMNBO.cjs');
4
- var fs$1 = require('fs');
5
- var fs = require('@visulima/fs');
6
- var pathe = require('pathe');
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:pathe.dirname(n),strategy:"lerna"}}let s=n?.endsWith("turbo.json");try{let{packageManager:o,path:r}=await chunk3IWUMNBO_cjs.b(e);if(["npm","yarn"].includes(o)){let a=pathe.join(r,"package.json");if(fs$1.existsSync(a)&&fs$1.readFileSync(pathe.join(r,"package.json"),"utf8").includes("workspaces"))return {path:r,strategy:s?"turbo":o}}else if(o==="pnpm"){let a=pathe.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-XMGJIRS7.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/monorepo.ts"],"names":["existsSync","readFileSync","findUp","readJson","dirname","join","findMonorepoRoot","cwd","workspaceFilePath","lerna","isTurbo","packageManager","path","findPackageManager","packageJsonFilePath","pnpmWorkspacesFilePath","error"],"mappings":"yCAAA,OAAS,cAAAA,EAAY,gBAAAC,MAAoB,KAEzC,OAAS,UAAAC,EAAQ,YAAAC,MAAgB,eACjC,OAAS,WAAAC,EAAS,QAAAC,MAAY,QAsBvB,IAAMC,EAAmB,MAAOC,GAA8C,CACjF,IAAMC,EAAoB,MAAMN,EAAO,CAAC,aAAc,YAAY,EAAG,CACjE,KAAM,OACN,GAAIK,GAAO,CAAE,IAAAA,CAAI,CACrB,CAAC,EAED,GAAIC,GAAmB,SAAS,YAAY,EAAG,CAC3C,IAAMC,EAAQ,MAAMN,EAA2DK,CAAiB,EAEhG,GAAIC,EAAM,eAAiBA,EAAM,SAC7B,MAAO,CACH,KAAML,EAAQI,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,EAAsBT,EAAKO,EAAM,cAAc,EAGrD,GAAIZ,EAAWc,CAAmB,GAEVb,EAAaI,EAAKO,EAAM,cAAc,EAAG,MAAM,EAEnD,SAAS,YAAY,EACjC,MAAO,CACH,KAAAA,EACA,SAAUF,EAAU,QAAWC,CACnC,CAGZ,SAAWA,IAAmB,OAAQ,CAClC,IAAMI,EAAyBV,EAAKO,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\";\n\nimport { findUp, readJson } from \"@visulima/fs\";\nimport { dirname, join } from \"pathe\";\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"]}