@visulima/package 1.8.1 → 1.8.2

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 (66) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/chunk-5UU4RIJA.js +11 -0
  3. package/dist/chunk-5UU4RIJA.js.map +1 -0
  4. package/dist/chunk-BGVUNBLL.js +12 -0
  5. package/dist/chunk-BGVUNBLL.js.map +1 -0
  6. package/dist/chunk-BHDWBI3F.cjs +22 -0
  7. package/dist/chunk-BHDWBI3F.cjs.map +1 -0
  8. package/dist/chunk-C36BYRSZ.cjs +19 -0
  9. package/dist/chunk-C36BYRSZ.cjs.map +1 -0
  10. package/dist/chunk-EY5KVLRL.js +10 -0
  11. package/dist/chunk-EY5KVLRL.js.map +1 -0
  12. package/dist/chunk-HGV2BL7M.js +12 -0
  13. package/dist/chunk-HGV2BL7M.js.map +1 -0
  14. package/dist/chunk-I3EKI236.cjs +13 -0
  15. package/dist/chunk-I3EKI236.cjs.map +1 -0
  16. package/dist/chunk-J5ERILYG.cjs +9 -0
  17. package/dist/chunk-J5ERILYG.cjs.map +1 -0
  18. package/dist/chunk-KMWIKANF.js +7 -0
  19. package/dist/chunk-KMWIKANF.js.map +1 -0
  20. package/dist/chunk-RETLQXQB.cjs +13 -0
  21. package/dist/chunk-RETLQXQB.cjs.map +1 -0
  22. package/dist/chunk-W3Z24XII.js +14 -0
  23. package/dist/chunk-W3Z24XII.js.map +1 -0
  24. package/dist/chunk-W7A6C74U.cjs +27 -0
  25. package/dist/chunk-W7A6C74U.cjs.map +1 -0
  26. package/dist/error.cjs +5 -5
  27. package/dist/error.js +3 -3
  28. package/dist/index.cjs +54 -103
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.js +10 -59
  31. package/dist/index.js.map +1 -1
  32. package/dist/monorepo.cjs +5 -5
  33. package/dist/monorepo.js +3 -3
  34. package/dist/package-json.cjs +11 -11
  35. package/dist/package-json.js +1 -1
  36. package/dist/package-manager.cjs +14 -14
  37. package/dist/package-manager.js +2 -2
  38. package/dist/package.cjs +7 -7
  39. package/dist/package.js +3 -3
  40. package/dist/tsconfig.cjs +15 -15
  41. package/dist/tsconfig.js +1 -1
  42. package/package.json +8 -8
  43. package/dist/chunk-5VO6NTKJ.js +0 -361
  44. package/dist/chunk-5VO6NTKJ.js.map +0 -1
  45. package/dist/chunk-7IOK6YPW.cjs +0 -52
  46. package/dist/chunk-7IOK6YPW.cjs.map +0 -1
  47. package/dist/chunk-CVVFWSMT.cjs +0 -65
  48. package/dist/chunk-CVVFWSMT.cjs.map +0 -1
  49. package/dist/chunk-E2PKJX3Q.js +0 -54
  50. package/dist/chunk-E2PKJX3Q.js.map +0 -1
  51. package/dist/chunk-EYMR7Z2I.js +0 -62
  52. package/dist/chunk-EYMR7Z2I.js.map +0 -1
  53. package/dist/chunk-G3SI24AJ.cjs +0 -88
  54. package/dist/chunk-G3SI24AJ.cjs.map +0 -1
  55. package/dist/chunk-IIYQBLPC.js +0 -119
  56. package/dist/chunk-IIYQBLPC.js.map +0 -1
  57. package/dist/chunk-IK5YSYLX.cjs +0 -126
  58. package/dist/chunk-IK5YSYLX.cjs.map +0 -1
  59. package/dist/chunk-UZ2FN6C5.js +0 -78
  60. package/dist/chunk-UZ2FN6C5.js.map +0 -1
  61. package/dist/chunk-WXFZK4G3.cjs +0 -374
  62. package/dist/chunk-WXFZK4G3.cjs.map +0 -1
  63. package/dist/chunk-YLCN7EVV.js +0 -50
  64. package/dist/chunk-YLCN7EVV.js.map +0 -1
  65. package/dist/chunk-YOQXHFU3.cjs +0 -56
  66. package/dist/chunk-YOQXHFU3.cjs.map +0 -1
@@ -1,65 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkIK5YSYLX_cjs = require('./chunk-IK5YSYLX.cjs');
4
- var fs$1 = require('fs');
5
- var fs = require('@visulima/fs');
6
- var pathe = require('pathe');
7
-
8
- var packageJsonMatcher = (directory) => {
9
- if (fs$1.existsSync(pathe.join(directory, "package.json"))) {
10
- const packageJson = fs.readJsonSync(pathe.join(directory, "package.json"));
11
- if (packageJson.name && packageJson.private !== true) {
12
- return "package.json";
13
- }
14
- }
15
- return void 0;
16
- };
17
- var findPackageRoot = async (cwd) => {
18
- try {
19
- const lockFile = await chunkIK5YSYLX_cjs.findLockFile(cwd);
20
- return pathe.dirname(lockFile);
21
- } catch {
22
- }
23
- const gitConfig = await fs.findUp(".git/config", {
24
- ...cwd && { cwd },
25
- type: "file"
26
- });
27
- if (gitConfig) {
28
- return pathe.dirname(pathe.dirname(gitConfig));
29
- }
30
- const filePath = await fs.findUp(packageJsonMatcher, {
31
- ...cwd && { cwd },
32
- type: "file"
33
- });
34
- if (filePath) {
35
- return pathe.dirname(filePath);
36
- }
37
- throw new Error("Could not find root directory");
38
- };
39
- var findPackageRootSync = (cwd) => {
40
- try {
41
- const lockFile = chunkIK5YSYLX_cjs.findLockFileSync(cwd);
42
- return pathe.dirname(lockFile);
43
- } catch {
44
- }
45
- const gitConfig = fs.findUpSync(".git/config", {
46
- ...cwd && { cwd },
47
- type: "file"
48
- });
49
- if (gitConfig) {
50
- return pathe.dirname(pathe.dirname(gitConfig));
51
- }
52
- const filePath = fs.findUpSync(packageJsonMatcher, {
53
- ...cwd && { cwd },
54
- type: "file"
55
- });
56
- if (filePath) {
57
- return pathe.dirname(filePath);
58
- }
59
- throw new Error("Could not find root directory");
60
- };
61
-
62
- exports.findPackageRoot = findPackageRoot;
63
- exports.findPackageRootSync = findPackageRootSync;
64
- //# sourceMappingURL=out.js.map
65
- //# sourceMappingURL=chunk-CVVFWSMT.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,kBAAkB;AAE3B,SAAS,QAAQ,YAAY,oBAAoB;AACjD,SAAS,SAAS,YAAY;AAK9B,IAAM,qBAAqB,CAAC,cAAsB;AAE9C,MAAI,WAAW,KAAK,WAAW,cAAc,CAAC,GAAG;AAC7C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\";\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"]}
@@ -1,54 +0,0 @@
1
- import { findPackageManager } from './chunk-IIYQBLPC.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 findMonorepoRoot = async (cwd) => {
8
- const workspaceFilePath = await findUp(["lerna.json", "turbo.json"], {
9
- type: "file",
10
- ...cwd && { cwd }
11
- });
12
- if (workspaceFilePath?.endsWith("lerna.json")) {
13
- const lerna = await readJson(workspaceFilePath);
14
- if (lerna.useWorkspaces || lerna.packages) {
15
- return {
16
- path: dirname(workspaceFilePath),
17
- strategy: "lerna"
18
- };
19
- }
20
- }
21
- const isTurbo = workspaceFilePath?.endsWith("turbo.json");
22
- try {
23
- const { packageManager, path } = await findPackageManager(cwd);
24
- if (["npm", "yarn"].includes(packageManager)) {
25
- const packageJsonFilePath = join(path, "package.json");
26
- if (existsSync(packageJsonFilePath)) {
27
- const packageJson = readFileSync(join(path, "package.json"), "utf8");
28
- if (packageJson.includes("workspaces")) {
29
- return {
30
- path,
31
- strategy: isTurbo ? "turbo" : packageManager
32
- };
33
- }
34
- }
35
- } else if (packageManager === "pnpm") {
36
- const pnpmWorkspacesFilePath = join(path, "pnpm-workspace.yaml");
37
- if (existsSync(pnpmWorkspacesFilePath)) {
38
- return {
39
- path,
40
- strategy: isTurbo ? "turbo" : "pnpm"
41
- };
42
- }
43
- }
44
- } catch (error) {
45
- if (!(error instanceof NotFoundError)) {
46
- throw error;
47
- }
48
- }
49
- throw new Error(`No monorepo root could be found upwards from the directory ${cwd} using lerna, yarn, pnpm, or npm as indicators.`);
50
- };
51
-
52
- export { findMonorepoRoot };
53
- //# sourceMappingURL=out.js.map
54
- //# sourceMappingURL=chunk-E2PKJX3Q.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/monorepo.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAY,oBAAoB;AAEzC,SAAS,QAAQ,gBAAgB;AACjC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAsBvB,IAAM,mBAAmB,OAAO,QAA8C;AACjF,QAAM,oBAAoB,MAAM,OAAO,CAAC,cAAc,YAAY,GAAG;AAAA,IACjE,MAAM;AAAA,IACN,GAAI,OAAO,EAAE,IAAI;AAAA,EACrB,CAAC;AAED,MAAI,mBAAmB,SAAS,YAAY,GAAG;AAC3C,UAAM,QAAQ,MAAM,SAA2D,iBAAiB;AAEhG,QAAI,MAAM,iBAAiB,MAAM,UAAU;AACvC,aAAO;AAAA,QACH,MAAM,QAAQ,iBAAiB;AAAA,QAC/B,UAAU;AAAA,MACd;AAAA,IACJ;AAAA,EACJ;AAEA,QAAM,UAAU,mBAAmB,SAAS,YAAY;AAExD,MAAI;AACA,UAAM,EAAE,gBAAgB,KAAK,IAAI,MAAM,mBAAmB,GAAG;AAE7D,QAAI,CAAC,OAAO,MAAM,EAAE,SAAS,cAAc,GAAG;AAC1C,YAAM,sBAAsB,KAAK,MAAM,cAAc;AAGrD,UAAI,WAAW,mBAAmB,GAAG;AAEjC,cAAM,cAAc,aAAa,KAAK,MAAM,cAAc,GAAG,MAAM;AAEnE,YAAI,YAAY,SAAS,YAAY,GAAG;AACpC,iBAAO;AAAA,YACH;AAAA,YACA,UAAU,UAAU,UAAW;AAAA,UACnC;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ,WAAW,mBAAmB,QAAQ;AAClC,YAAM,yBAAyB,KAAK,MAAM,qBAAqB;AAG/D,UAAI,WAAW,sBAAsB,GAAG;AACpC,eAAO;AAAA,UACH;AAAA,UACA,UAAU,UAAU,UAAU;AAAA,QAClC;AAAA,MACJ;AAAA,IACJ;AAAA,EAEJ,SAAS,OAAY;AAEjB,QAAI,EAAE,iBAAiB,gBAAgB;AACnC,YAAM;AAAA,IACV;AAAA,EACJ;AAEA,QAAM,IAAI,MAAM,8DAA8D,GAAa,iDAAiD;AAChJ","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"]}
@@ -1,62 +0,0 @@
1
- import { findLockFile, findLockFileSync } from './chunk-IIYQBLPC.js';
2
- import { existsSync } from 'node:fs';
3
- import { findUp, findUpSync, readJsonSync } from '@visulima/fs';
4
- import { dirname, join } from 'pathe';
5
-
6
- var packageJsonMatcher = (directory) => {
7
- if (existsSync(join(directory, "package.json"))) {
8
- const packageJson = readJsonSync(join(directory, "package.json"));
9
- if (packageJson.name && packageJson.private !== true) {
10
- return "package.json";
11
- }
12
- }
13
- return void 0;
14
- };
15
- var findPackageRoot = async (cwd) => {
16
- try {
17
- const lockFile = await findLockFile(cwd);
18
- return dirname(lockFile);
19
- } catch {
20
- }
21
- const gitConfig = await findUp(".git/config", {
22
- ...cwd && { cwd },
23
- type: "file"
24
- });
25
- if (gitConfig) {
26
- return dirname(dirname(gitConfig));
27
- }
28
- const filePath = await findUp(packageJsonMatcher, {
29
- ...cwd && { cwd },
30
- type: "file"
31
- });
32
- if (filePath) {
33
- return dirname(filePath);
34
- }
35
- throw new Error("Could not find root directory");
36
- };
37
- var findPackageRootSync = (cwd) => {
38
- try {
39
- const lockFile = findLockFileSync(cwd);
40
- return dirname(lockFile);
41
- } catch {
42
- }
43
- const gitConfig = findUpSync(".git/config", {
44
- ...cwd && { cwd },
45
- type: "file"
46
- });
47
- if (gitConfig) {
48
- return dirname(dirname(gitConfig));
49
- }
50
- const filePath = findUpSync(packageJsonMatcher, {
51
- ...cwd && { cwd },
52
- type: "file"
53
- });
54
- if (filePath) {
55
- return dirname(filePath);
56
- }
57
- throw new Error("Could not find root directory");
58
- };
59
-
60
- export { findPackageRoot, findPackageRootSync };
61
- //# sourceMappingURL=out.js.map
62
- //# sourceMappingURL=chunk-EYMR7Z2I.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package.ts"],"names":[],"mappings":";;;;;;AAAA,SAAS,kBAAkB;AAE3B,SAAS,QAAQ,YAAY,oBAAoB;AACjD,SAAS,SAAS,YAAY;AAK9B,IAAM,qBAAqB,CAAC,cAAsB;AAE9C,MAAI,WAAW,KAAK,WAAW,cAAc,CAAC,GAAG;AAC7C,UAAM,cAAc,aAA0B,KAAK,WAAW,cAAc,CAAC;AAE7E,QAAI,YAAY,QAAQ,YAAY,YAAY,MAAM;AAClD,aAAO;AAAA,IACX;AAAA,EACJ;AAEA,SAAO;AACX;AAaO,IAAM,kBAAkB,OAAO,QAAwC;AAC1E,MAAI;AACA,UAAM,WAAW,MAAM,aAAa,GAAG;AAEvC,WAAO,QAAQ,QAAQ;AAAA,EAC3B,QAAQ;AAAA,EAER;AAEA,QAAM,YAAY,MAAM,OAAO,eAAe;AAAA,IAC1C,GAAI,OAAO,EAAE,IAAI;AAAA,IACjB,MAAM;AAAA,EACV,CAAC;AAED,MAAI,WAAW;AACX,WAAO,QAAQ,QAAQ,SAAS,CAAC;AAAA,EACrC;AAEA,QAAM,WAAW,MAAM,OAAO,oBAAoB;AAAA,IAC9C,GAAI,OAAO,EAAE,IAAI;AAAA,IACjB,MAAM;AAAA,EACV,CAAC;AAED,MAAI,UAAU;AACV,WAAO,QAAQ,QAAQ;AAAA,EAC3B;AAEA,QAAM,IAAI,MAAM,+BAA+B;AACnD;AAEO,IAAM,sBAAsB,CAAC,QAA+B;AAC/D,MAAI;AACA,UAAM,WAAW,iBAAiB,GAAG;AAErC,WAAO,QAAQ,QAAQ;AAAA,EAC3B,QAAQ;AAAA,EAER;AAEA,QAAM,YAAY,WAAW,eAAe;AAAA,IACxC,GAAI,OAAO,EAAE,IAAI;AAAA,IACjB,MAAM;AAAA,EACV,CAAC;AAED,MAAI,WAAW;AACX,WAAO,QAAQ,QAAQ,SAAS,CAAC;AAAA,EACrC;AAEA,QAAM,WAAW,WAAW,oBAAoB;AAAA,IAC5C,GAAI,OAAO,EAAE,IAAI;AAAA,IACjB,MAAM;AAAA,EACV,CAAC;AAED,MAAI,UAAU;AACV,WAAO,QAAQ,QAAQ;AAAA,EAC3B;AAEA,QAAM,IAAI,MAAM,+BAA+B;AACnD","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"]}
@@ -1,88 +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 normalizeData = require('normalize-package-data');
8
- var pathe = require('pathe');
9
-
10
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
-
12
- var normalizeData__default = /*#__PURE__*/_interopDefault(normalizeData);
13
-
14
- // src/package-json.ts
15
- var PackageJsonFileCache = /* @__PURE__ */ new Map();
16
- var findPackageJson = async (cwd, options = {}) => {
17
- const filePath = await fs.findUp("package.json", {
18
- ...cwd && { cwd },
19
- type: "file"
20
- });
21
- if (!filePath) {
22
- throw new error.NotFoundError("No such file or directory, for package.json found.");
23
- }
24
- const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : PackageJsonFileCache;
25
- if (options.cache && cache.has(filePath)) {
26
- return cache.get(filePath);
27
- }
28
- const packageJson = await fs.readJson(filePath);
29
- normalizeData__default.default(packageJson);
30
- const output = {
31
- packageJson,
32
- path: filePath
33
- };
34
- cache.set(filePath, output);
35
- return output;
36
- };
37
- var findPackageJsonSync = (cwd, options = {}) => {
38
- const filePath = fs.findUpSync("package.json", {
39
- ...cwd && { cwd },
40
- type: "file"
41
- });
42
- if (!filePath) {
43
- throw new error.NotFoundError("No such file or directory, for package.json found.");
44
- }
45
- const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : PackageJsonFileCache;
46
- if (options.cache && cache.has(filePath)) {
47
- return cache.get(filePath);
48
- }
49
- const packageJson = fs.readJsonSync(filePath);
50
- normalizeData__default.default(packageJson);
51
- const output = {
52
- packageJson,
53
- path: filePath
54
- };
55
- cache.set(filePath, output);
56
- return output;
57
- };
58
- var writePackageJson = async (data, options = {}) => {
59
- const { cwd, ...writeOptions } = options;
60
- const directory = utils.toPath(options.cwd ?? process.cwd());
61
- await fs.writeJson(pathe.join(directory, "package.json"), data, writeOptions);
62
- };
63
- var writePackageJsonSync = (data, options = {}) => {
64
- const { cwd, ...writeOptions } = options;
65
- const directory = utils.toPath(options.cwd ?? process.cwd());
66
- fs.writeJsonSync(pathe.join(directory, "package.json"), data, writeOptions);
67
- };
68
- var parsePackageJson = (packageFile) => {
69
- const isObject = packageFile !== null && typeof packageFile === "object" && !Array.isArray(packageFile);
70
- const isString = typeof packageFile === "string";
71
- if (!isObject && !isString) {
72
- throw new TypeError("`packageFile` should be either an `object` or a `string`.");
73
- }
74
- const json = isObject ? structuredClone(packageFile) : (
75
- // eslint-disable-next-line security/detect-non-literal-fs-filename
76
- fs$1.existsSync(packageFile) ? fs.readJsonSync(packageFile) : utils.parseJson(packageFile)
77
- );
78
- normalizeData__default.default(json);
79
- return json;
80
- };
81
-
82
- exports.findPackageJson = findPackageJson;
83
- exports.findPackageJsonSync = findPackageJsonSync;
84
- exports.parsePackageJson = parsePackageJson;
85
- exports.writePackageJson = writePackageJson;
86
- exports.writePackageJsonSync = writePackageJsonSync;
87
- //# sourceMappingURL=out.js.map
88
- //# sourceMappingURL=chunk-G3SI24AJ.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-json.ts"],"names":[],"mappings":";AAAA,SAAS,kBAAkB;AAG3B,SAAS,QAAQ,YAAY,UAAU,cAAc,WAAW,qBAAqB;AACrF,SAAS,qBAAqB;AAC9B,SAAS,WAAW,cAAc;AAElC,OAAO,mBAAmB;AAC1B,SAAS,YAAY;AASrB,IAAM,uBAAuB,oBAAI,IAAkC;AAe5D,IAAM,kB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QAAQ,IAAI,CAAC;AAErD,QAAM,UAAU,KAAK,WAAW,cAAc,GAAG,MAAM,YAAY;AACvE;AAEO,IAAM,uBAAuB,CAAkB,MAAS,UAAqD,CAAC,MAAY;AAC7H,QAAM,EAAE,KAAK,GAAG,aAAa,IAAI;AACjC,QAAM,YAAY,OAAO,QAAQ,OAAO,QAAQ,IAAI,CAAC;AAErD,gBAAc,KAAK,WAAW,cAAc,GAAG,MAAM,YAAY;AACrE;AAEO,IAAM,mBAAmB,CAAC,gBAA4D;AAEzF,QAAM,WAAW,gBAAgB,QAAQ,OAAO,gBAAgB,YAAY,CAAC,MAAM,QAAQ,WAAW;AACtG,QAAM,WAAW,OAAO,gBAAgB;AAExC,MAAI,CAAC,YAAY,CAAC,UAAU;AACxB,UAAM,IAAI,UAAU,2DAA2D;AAAA,EACnF;AAEA,QAAM,OAAO,WACP,gBAAgB,WAAW;AAAA;AAAA,IAE3B,WAAW,WAAqB,IAC9B,aAAa,WAAqB,IAClC,UAAU,WAAqB;AAAA;AAEvC,gBAAc,IAAa;AAE3B,SAAO;AACX","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"]}
@@ -1,119 +0,0 @@
1
- import { parsePackageJson } from './chunk-UZ2FN6C5.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 lockFileNames = ["yarn.lock", "package-lock.json", "pnpm-lock.yaml", "npm-shrinkwrap.json", "bun.lockb"];
9
- var packageMangerFindUpMatcher = (directory) => {
10
- let lockFile;
11
- lockFileNames.forEach((lockFileName) => {
12
- if (!lockFile && existsSync(join(directory, lockFileName))) {
13
- lockFile = join(directory, lockFileName);
14
- }
15
- });
16
- if (lockFile) {
17
- return lockFile;
18
- }
19
- const packageJsonFilePath = join(directory, "package.json");
20
- if (existsSync(packageJsonFilePath)) {
21
- const packageJson = parsePackageJson(readFileSync(packageJsonFilePath, "utf8"));
22
- if (packageJson.packageManager !== void 0) {
23
- return packageJsonFilePath;
24
- }
25
- }
26
- return void 0;
27
- };
28
- var findPackageManagerOnFile = (foundFile) => {
29
- if (!foundFile) {
30
- throw new NotFoundError("Could not find a package manager");
31
- }
32
- if (foundFile.endsWith("package.json")) {
33
- const packageJson = parsePackageJson(foundFile);
34
- if (packageJson.packageManager) {
35
- const packageManagerNames = ["npm", "yarn", "pnpm", "bun"];
36
- const foundPackageManager = packageManagerNames.find((prefix) => packageJson.packageManager.startsWith(prefix));
37
- if (foundPackageManager) {
38
- return {
39
- packageManager: foundPackageManager,
40
- path: dirname(foundFile)
41
- };
42
- }
43
- }
44
- }
45
- if (foundFile.endsWith("yarn.lock")) {
46
- return {
47
- packageManager: "yarn",
48
- path: dirname(foundFile)
49
- };
50
- }
51
- if (foundFile.endsWith("package-lock.json") || foundFile.endsWith("npm-shrinkwrap.json")) {
52
- return {
53
- packageManager: "npm",
54
- path: dirname(foundFile)
55
- };
56
- }
57
- if (foundFile.endsWith("pnpm-lock.yaml")) {
58
- return {
59
- packageManager: "pnpm",
60
- path: dirname(foundFile)
61
- };
62
- }
63
- if (foundFile.endsWith("bun.lockb")) {
64
- return {
65
- packageManager: "bun",
66
- path: dirname(foundFile)
67
- };
68
- }
69
- throw new NotFoundError("Could not find a package manager");
70
- };
71
- var findLockFile = async (cwd) => {
72
- const filePath = await findUp(lockFileNames, {
73
- type: "file",
74
- ...cwd && { cwd }
75
- });
76
- if (!filePath) {
77
- throw new Error("Could not find lock file");
78
- }
79
- return filePath;
80
- };
81
- var findLockFileSync = (cwd) => {
82
- const filePath = findUpSync(lockFileNames, {
83
- type: "file",
84
- ...cwd && { cwd }
85
- });
86
- if (!filePath) {
87
- throw new Error("Could not find lock file");
88
- }
89
- return filePath;
90
- };
91
- var findPackageManager = async (cwd) => {
92
- const foundFile = await findUp(packageMangerFindUpMatcher, {
93
- ...cwd && { cwd }
94
- });
95
- return findPackageManagerOnFile(foundFile);
96
- };
97
- var findPackageManagerSync = (cwd) => {
98
- const foundFile = findUpSync(packageMangerFindUpMatcher, {
99
- ...cwd && { cwd }
100
- });
101
- return findPackageManagerOnFile(foundFile);
102
- };
103
- var getPackageManagerVersion = (name) => execSync(`${name} --version`).toString("utf8").trim();
104
- var identifyInitiatingPackageManager = async () => {
105
- if (!process.env.npm_config_user_agent) {
106
- return void 0;
107
- }
108
- const pmSpec = process.env.npm_config_user_agent.split(" ")[0];
109
- const separatorPos = pmSpec.lastIndexOf("/");
110
- const name = pmSpec.slice(0, Math.max(0, separatorPos));
111
- return {
112
- name: name === "npminstall" ? "cnpm" : name,
113
- version: pmSpec.slice(Math.max(0, separatorPos + 1))
114
- };
115
- };
116
-
117
- export { findLockFile, findLockFileSync, findPackageManager, findPackageManagerSync, getPackageManagerVersion, identifyInitiatingPackageManager };
118
- //# sourceMappingURL=out.js.map
119
- //# sourceMappingURL=chunk-IIYQBLPC.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-manager.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY,oBAAoB;AAEzC,SAAS,QAAQ,kBAAkB;AACnC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAI9B,IAAM,gBAAgB,CAAC,aAAa,qBAAqB,kBAAkB,uBAAuB,WAAW;AAE7G,IAAM,6BAA6B,CAAC,cAAsB;AACtD,MAAI;AAEJ,gBAAc,QAAQ,CAAC,iBAAiB;AAEpC,QAAI,CAAC,YAAY,WAAW,KAAK,WAAW,YAAY,CAAC,GAAG;AACxD,iBAAW,KAAK,WAAW,YAAY;AAAA,IAC3C;AAAA,EACJ,CAAC;AAED,MAAI,UAAU;AACV,WAAO;AAAA,EACX;AAEA,QAAM,sBAAsB,KAAK,WAAW,cAAc;AAE1D,MAAI,WAAW,mBAAmB,GAAG;AAEjC,UAAM,cAAc,iBAAiB,aAAa,qBAAqB,MAAM,CAAC;AAE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AI;AAAA,EACrB,CAAC;AAED,MAAI,CAAC,UAAU;AACX,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC9C;AAEA,SAAO;AACX;AAEO,IAAM,mBAAmB,CAAC,QAA+B;AAC5D,QAAM,WAAW,WAAW,eAAe;AAAA,IACvC,MAAM;AAAA,IACN,GAAI,OAAO,EAAE,IAAI;AAAA,EACrB,CAAC;AAED,MAAI,CAAC,UAAU;AACX,UAAM,IAAI,MAAM,0BAA0B;AAAA,EAC9C;AAEA,SAAO;AACX;AAoBO,IAAM,qBAAqB,OAAO,QAAsD;AAC3F,QAAM,YAAY,MAAM,OAAO,4BAA4B;AAAA,IACvD,GAAI,OAAO,EAAE,IAAI;AAAA,EACrB,CAAC;AAED,SAAO,yBAAyB,SAAS;AAC7C;AAcO,IAAM,yBAAyB,CAAC,QAA6C;AAChF,QAAM,YAAY,WAAW,4BAA4B;AAAA,IACrD,GAAI,OAAO,EAAE,IAAI;AAAA,EACrB,CAAC;AAED,SAAO,yBAAyB,SAAS;AAC7C;AAQO,IAAM,2BAA2B,CAAC,SAAyB,SAAS,GAAG,IAAI,YAAY,EAAE,SAAS,MAAM,EAAE,KAAK;AAW/G,IAAM,mCAAmC,YAM3C;AACD,MAAI,CAAC,QAAQ,IAAI,uBAAuB;AACpC,WAAO;AAAA,EACX;AAEA,QAAM,SAAS,QAAQ,IAAI,sBAAsB,MAAM,GAAG,EAAE,CAAC;AAC7D,QAAM,eAAe,OAAO,YAAY,GAAG;AAC3C,QAAM,OAAO,OAAO,MAAM,GAAG,KAAK,IAAI,GAAG,YAAY,CAAC;AAEtD,SAAO;AAAA,IACH,MAAM,SAAS,eAAe,SAAU;AAAA,IACxC,SAAS,OAAO,MAAM,KAAK,IAAI,GAAG,eAAe,CAAC,CAAC;AAAA,EACvD;AACJ","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\nconst packageMangerFindUpMatcher = (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\nconst findPackageManagerOnFile = (foundFile: string | undefined): PackageManagerResult => {\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 NotFoundError(\"Could not find a package manager\");\n};\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 */\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\n};\n\n/**\n * An 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\nexport const findPackageManagerSync = (cwd?: URL | string): PackageManagerResult => {\n const foundFile = findUpSync(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\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,126 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkG3SI24AJ_cjs = require('./chunk-G3SI24AJ.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 lockFileNames = ["yarn.lock", "package-lock.json", "pnpm-lock.yaml", "npm-shrinkwrap.json", "bun.lockb"];
11
- var packageMangerFindUpMatcher = (directory) => {
12
- let lockFile;
13
- lockFileNames.forEach((lockFileName) => {
14
- if (!lockFile && fs$1.existsSync(pathe.join(directory, lockFileName))) {
15
- lockFile = pathe.join(directory, lockFileName);
16
- }
17
- });
18
- if (lockFile) {
19
- return lockFile;
20
- }
21
- const packageJsonFilePath = pathe.join(directory, "package.json");
22
- if (fs$1.existsSync(packageJsonFilePath)) {
23
- const packageJson = chunkG3SI24AJ_cjs.parsePackageJson(fs$1.readFileSync(packageJsonFilePath, "utf8"));
24
- if (packageJson.packageManager !== void 0) {
25
- return packageJsonFilePath;
26
- }
27
- }
28
- return void 0;
29
- };
30
- var findPackageManagerOnFile = (foundFile) => {
31
- if (!foundFile) {
32
- throw new error.NotFoundError("Could not find a package manager");
33
- }
34
- if (foundFile.endsWith("package.json")) {
35
- const packageJson = chunkG3SI24AJ_cjs.parsePackageJson(foundFile);
36
- if (packageJson.packageManager) {
37
- const packageManagerNames = ["npm", "yarn", "pnpm", "bun"];
38
- const foundPackageManager = packageManagerNames.find((prefix) => packageJson.packageManager.startsWith(prefix));
39
- if (foundPackageManager) {
40
- return {
41
- packageManager: foundPackageManager,
42
- path: pathe.dirname(foundFile)
43
- };
44
- }
45
- }
46
- }
47
- if (foundFile.endsWith("yarn.lock")) {
48
- return {
49
- packageManager: "yarn",
50
- path: pathe.dirname(foundFile)
51
- };
52
- }
53
- if (foundFile.endsWith("package-lock.json") || foundFile.endsWith("npm-shrinkwrap.json")) {
54
- return {
55
- packageManager: "npm",
56
- path: pathe.dirname(foundFile)
57
- };
58
- }
59
- if (foundFile.endsWith("pnpm-lock.yaml")) {
60
- return {
61
- packageManager: "pnpm",
62
- path: pathe.dirname(foundFile)
63
- };
64
- }
65
- if (foundFile.endsWith("bun.lockb")) {
66
- return {
67
- packageManager: "bun",
68
- path: pathe.dirname(foundFile)
69
- };
70
- }
71
- throw new error.NotFoundError("Could not find a package manager");
72
- };
73
- var findLockFile = async (cwd) => {
74
- const filePath = await fs.findUp(lockFileNames, {
75
- type: "file",
76
- ...cwd && { cwd }
77
- });
78
- if (!filePath) {
79
- throw new Error("Could not find lock file");
80
- }
81
- return filePath;
82
- };
83
- var findLockFileSync = (cwd) => {
84
- const filePath = fs.findUpSync(lockFileNames, {
85
- type: "file",
86
- ...cwd && { cwd }
87
- });
88
- if (!filePath) {
89
- throw new Error("Could not find lock file");
90
- }
91
- return filePath;
92
- };
93
- var findPackageManager = async (cwd) => {
94
- const foundFile = await fs.findUp(packageMangerFindUpMatcher, {
95
- ...cwd && { cwd }
96
- });
97
- return findPackageManagerOnFile(foundFile);
98
- };
99
- var findPackageManagerSync = (cwd) => {
100
- const foundFile = fs.findUpSync(packageMangerFindUpMatcher, {
101
- ...cwd && { cwd }
102
- });
103
- return findPackageManagerOnFile(foundFile);
104
- };
105
- var getPackageManagerVersion = (name) => child_process.execSync(`${name} --version`).toString("utf8").trim();
106
- var identifyInitiatingPackageManager = async () => {
107
- if (!process.env.npm_config_user_agent) {
108
- return void 0;
109
- }
110
- const pmSpec = process.env.npm_config_user_agent.split(" ")[0];
111
- const separatorPos = pmSpec.lastIndexOf("/");
112
- const name = pmSpec.slice(0, Math.max(0, separatorPos));
113
- return {
114
- name: name === "npminstall" ? "cnpm" : name,
115
- version: pmSpec.slice(Math.max(0, separatorPos + 1))
116
- };
117
- };
118
-
119
- exports.findLockFile = findLockFile;
120
- exports.findLockFileSync = findLockFileSync;
121
- exports.findPackageManager = findPackageManager;
122
- exports.findPackageManagerSync = findPackageManagerSync;
123
- exports.getPackageManagerVersion = getPackageManagerVersion;
124
- exports.identifyInitiatingPackageManager = identifyInitiatingPackageManager;
125
- //# sourceMappingURL=out.js.map
126
- //# sourceMappingURL=chunk-IK5YSYLX.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/package-manager.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,gBAAgB;AACzB,SAAS,YAAY,oBAAoB;AAEzC,SAAS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AW/G,IAAM,mCAAmC,YAM3C;AACD,MAAI,CAAC,QAAQ,IAAI,uBAAuB;AACpC,WAAO;AAAA,EACX;AAEA,QAAM,SAAS,QAAQ,IAAI,sBAAsB,MAAM,GAAG,EAAE,CAAC;AAC7D,QAAM,eAAe,OAAO,YAAY,GAAG;AAC3C,QAAM,OAAO,OAAO,MAAM,GAAG,KAAK,IAAI,GAAG,YAAY,CAAC;AAEtD,SAAO;AAAA,IACH,MAAM,SAAS,eAAe,SAAU;AAAA,IACxC,SAAS,OAAO,MAAM,KAAK,IAAI,GAAG,eAAe,CAAC,CAAC;AAAA,EACvD;AACJ","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\nconst packageMangerFindUpMatcher = (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\nconst findPackageManagerOnFile = (foundFile: string | undefined): PackageManagerResult => {\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 NotFoundError(\"Could not find a package manager\");\n};\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 */\nexport const findPackageManager = async (cwd?: URL | string): Promise<PackageManagerResult> => {\n const foundFile = await findUp(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\n};\n\n/**\n * An 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\nexport const findPackageManagerSync = (cwd?: URL | string): PackageManagerResult => {\n const foundFile = findUpSync(packageMangerFindUpMatcher, {\n ...(cwd && { cwd }),\n });\n\n return findPackageManagerOnFile(foundFile);\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"]}