@visulima/package 1.8.1 → 1.8.3

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 (89) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE.md +17 -0
  3. package/dist/error.cjs +1 -14
  4. package/dist/error.d.mts +9 -0
  5. package/dist/error.mjs +1 -0
  6. package/dist/index.cjs +1 -156
  7. package/dist/index.d.cts +2 -3
  8. package/dist/index.d.mts +18 -0
  9. package/dist/index.d.ts +2 -3
  10. package/dist/index.mjs +1 -0
  11. package/dist/monorepo.cjs +1 -14
  12. package/dist/monorepo.d.mts +8 -0
  13. package/dist/monorepo.mjs +1 -0
  14. package/dist/package-json.cjs +1 -28
  15. package/dist/package-json.d.cts +3 -5
  16. package/dist/package-json.d.mts +22 -0
  17. package/dist/package-json.d.ts +3 -5
  18. package/dist/package-json.mjs +1 -0
  19. package/dist/package-manager.cjs +1 -33
  20. package/dist/package-manager.d.mts +16 -0
  21. package/dist/package-manager.mjs +1 -0
  22. package/dist/package.cjs +1 -18
  23. package/dist/package.d.mts +4 -0
  24. package/dist/package.mjs +1 -0
  25. package/dist/shared/package.DipMHw9r.cjs +1 -0
  26. package/dist/shared/package.DvbNGF15.mjs +1 -0
  27. package/dist/shared/package.SZmjOQBM.d.cts +2076 -0
  28. package/dist/shared/package.SZmjOQBM.d.mts +2076 -0
  29. package/dist/shared/package.SZmjOQBM.d.ts +2076 -0
  30. package/dist/shared/package.Xn4v2Y_g.cjs +1 -0
  31. package/dist/shared/package.zhGeUcxO.mjs +1 -0
  32. package/dist/tsconfig/index.cjs +1 -0
  33. package/dist/tsconfig/index.d.cts +34 -0
  34. package/dist/tsconfig/index.d.mts +34 -0
  35. package/dist/tsconfig/index.d.ts +34 -0
  36. package/dist/tsconfig/index.mjs +1 -0
  37. package/package.json +32 -40
  38. package/dist/chunk-5VO6NTKJ.js +0 -361
  39. package/dist/chunk-5VO6NTKJ.js.map +0 -1
  40. package/dist/chunk-7IOK6YPW.cjs +0 -52
  41. package/dist/chunk-7IOK6YPW.cjs.map +0 -1
  42. package/dist/chunk-CVVFWSMT.cjs +0 -65
  43. package/dist/chunk-CVVFWSMT.cjs.map +0 -1
  44. package/dist/chunk-E2PKJX3Q.js +0 -54
  45. package/dist/chunk-E2PKJX3Q.js.map +0 -1
  46. package/dist/chunk-EYMR7Z2I.js +0 -62
  47. package/dist/chunk-EYMR7Z2I.js.map +0 -1
  48. package/dist/chunk-G3SI24AJ.cjs +0 -88
  49. package/dist/chunk-G3SI24AJ.cjs.map +0 -1
  50. package/dist/chunk-IIYQBLPC.js +0 -119
  51. package/dist/chunk-IIYQBLPC.js.map +0 -1
  52. package/dist/chunk-IK5YSYLX.cjs +0 -126
  53. package/dist/chunk-IK5YSYLX.cjs.map +0 -1
  54. package/dist/chunk-UZ2FN6C5.js +0 -78
  55. package/dist/chunk-UZ2FN6C5.js.map +0 -1
  56. package/dist/chunk-WXFZK4G3.cjs +0 -374
  57. package/dist/chunk-WXFZK4G3.cjs.map +0 -1
  58. package/dist/chunk-YLCN7EVV.js +0 -50
  59. package/dist/chunk-YLCN7EVV.js.map +0 -1
  60. package/dist/chunk-YOQXHFU3.cjs +0 -56
  61. package/dist/chunk-YOQXHFU3.cjs.map +0 -1
  62. package/dist/error.cjs.map +0 -1
  63. package/dist/error.js +0 -5
  64. package/dist/error.js.map +0 -1
  65. package/dist/index.cjs.map +0 -1
  66. package/dist/index.js +0 -66
  67. package/dist/index.js.map +0 -1
  68. package/dist/monorepo.cjs.map +0 -1
  69. package/dist/monorepo.js +0 -5
  70. package/dist/monorepo.js.map +0 -1
  71. package/dist/package-json.cjs.map +0 -1
  72. package/dist/package-json.js +0 -3
  73. package/dist/package-json.js.map +0 -1
  74. package/dist/package-manager.cjs.map +0 -1
  75. package/dist/package-manager.js +0 -4
  76. package/dist/package-manager.js.map +0 -1
  77. package/dist/package.cjs.map +0 -1
  78. package/dist/package.js +0 -5
  79. package/dist/package.js.map +0 -1
  80. package/dist/tsconfig-G-HInwrt.d.ts +0 -30
  81. package/dist/tsconfig-d4zwQgCH.d.cts +0 -30
  82. package/dist/tsconfig.cjs +0 -36
  83. package/dist/tsconfig.cjs.map +0 -1
  84. package/dist/tsconfig.d.cts +0 -5
  85. package/dist/tsconfig.d.ts +0 -5
  86. package/dist/tsconfig.js +0 -3
  87. package/dist/tsconfig.js.map +0 -1
  88. package/dist/types-hoigZ9HA.d.cts +0 -9
  89. package/dist/types-hoigZ9HA.d.ts +0 -9
@@ -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":"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","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,78 +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 normalizeData from 'normalize-package-data';
6
- import { join } from 'pathe';
7
-
8
- // src/package-json.ts
9
- var PackageJsonFileCache = /* @__PURE__ */ new Map();
10
- var findPackageJson = async (cwd, options = {}) => {
11
- const filePath = await findUp("package.json", {
12
- ...cwd && { cwd },
13
- type: "file"
14
- });
15
- if (!filePath) {
16
- throw new NotFoundError("No such file or directory, for package.json found.");
17
- }
18
- const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : PackageJsonFileCache;
19
- if (options.cache && cache.has(filePath)) {
20
- return cache.get(filePath);
21
- }
22
- const packageJson = await readJson(filePath);
23
- normalizeData(packageJson);
24
- const output = {
25
- packageJson,
26
- path: filePath
27
- };
28
- cache.set(filePath, output);
29
- return output;
30
- };
31
- var findPackageJsonSync = (cwd, options = {}) => {
32
- const filePath = findUpSync("package.json", {
33
- ...cwd && { cwd },
34
- type: "file"
35
- });
36
- if (!filePath) {
37
- throw new NotFoundError("No such file or directory, for package.json found.");
38
- }
39
- const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : PackageJsonFileCache;
40
- if (options.cache && cache.has(filePath)) {
41
- return cache.get(filePath);
42
- }
43
- const packageJson = readJsonSync(filePath);
44
- normalizeData(packageJson);
45
- const output = {
46
- packageJson,
47
- path: filePath
48
- };
49
- cache.set(filePath, output);
50
- return output;
51
- };
52
- var writePackageJson = async (data, options = {}) => {
53
- const { cwd, ...writeOptions } = options;
54
- const directory = toPath(options.cwd ?? process.cwd());
55
- await writeJson(join(directory, "package.json"), data, writeOptions);
56
- };
57
- var writePackageJsonSync = (data, options = {}) => {
58
- const { cwd, ...writeOptions } = options;
59
- const directory = toPath(options.cwd ?? process.cwd());
60
- writeJsonSync(join(directory, "package.json"), data, writeOptions);
61
- };
62
- var parsePackageJson = (packageFile) => {
63
- const isObject = packageFile !== null && typeof packageFile === "object" && !Array.isArray(packageFile);
64
- const isString = typeof packageFile === "string";
65
- if (!isObject && !isString) {
66
- throw new TypeError("`packageFile` should be either an `object` or a `string`.");
67
- }
68
- const json = isObject ? structuredClone(packageFile) : (
69
- // eslint-disable-next-line security/detect-non-literal-fs-filename
70
- existsSync(packageFile) ? readJsonSync(packageFile) : parseJson(packageFile)
71
- );
72
- normalizeData(json);
73
- return json;
74
- };
75
-
76
- export { findPackageJson, findPackageJsonSync, parsePackageJson, writePackageJson, writePackageJsonSync };
77
- //# sourceMappingURL=out.js.map
78
- //# sourceMappingURL=chunk-UZ2FN6C5.js.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,kBAAkB,OAAO,KAAoB,UAAuB,CAAC,MAAqC;AACnH,QAAM,WAAW,MAAM,OAAO,gBAAgB;AAAA,IAC1C,GAAI,OAAO,EAAE,IAAI;AAAA,IACjB,MAAM;AAAA,EACV,CAAC;AAED,MAAI,CAAC,UAAU;AACX,UAAM,IAAI,cAAc,oDAAoD;AAAA,EAChF;AAEA,QAAM,QAAQ,QAAQ,SAAS,OAAO,QAAQ,UAAU,YAAY,QAAQ,QAAQ;AAEpF,MAAI,QAAQ,SAAS,MAAM,IAAI,QAAQ,GAAG;AACtC,WAAO,MAAM,IAAI,QAAQ;AAAA,EAC7B;AAEA,QAAM,cAAc,MAAM,SAAS,QAAQ;AAE3C,gBAAc,WAAoB;AAElC,QAAM,SAAS;AAAA,IACX;AAAA,IACA,MAAM;AAAA,EACV;AAEA,QAAM,IAAI,UAAU,MAAM;AAE1B,SAAO;AACX;AAEO,IAAM,sBAAsB,CAAC,KAAoB,UAAuB,CAAC,MAA4B;AACxG,QAAM,WAAW,WAAW,gBAAgB;AAAA,IACxC,GAAI,OAAO,EAAE,IAAI;AAAA,IACjB,MAAM;AAAA,EACV,CAAC;AAED,MAAI,CAAC,UAAU;AACX,UAAM,IAAI,cAAc,oDAAoD;AAAA,EAChF;AAEA,QAAM,QAAQ,QAAQ,SAAS,OAAO,QAAQ,UAAU,YAAY,QAAQ,QAAQ;AAEpF,MAAI,QAAQ,SAAS,MAAM,IAAI,QAAQ,GAAG;AACtC,WAAO,MAAM,IAAI,QAAQ;AAAA,EAC7B;AAEA,QAAM,cAAc,aAAa,QAAQ;AAEzC,gBAAc,WAAoB;AAElC,QAAM,SAAS;AAAA,IACX;AAAA,IACA,MAAM;AAAA,EACV;AAEA,QAAM,IAAI,UAAU,MAAM;AAE1B,SAAO;AACX;AAYO,IAAM,mBAAmB,OAAwB,MAAS,UAAqD,CAAC,MAAqB;AACxI,QAAM,EAAE,KAAK,GAAG,aAAa,IAAI;AACjC,QAAM,YAAY,OAAO,QAAQ,OAAO,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,374 +0,0 @@
1
- 'use strict';
2
-
3
- var fs = require('@visulima/fs');
4
- var error = require('@visulima/fs/error');
5
- var utils = require('@visulima/fs/utils');
6
- var pathe = require('pathe');
7
- var jsoncParser = require('jsonc-parser');
8
- var fs$1 = require('fs');
9
- var Module = require('module');
10
- var path = require('path');
11
- var resolvePkgMaps = require('resolve-pkg-maps');
12
-
13
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
14
-
15
- var Module__default = /*#__PURE__*/_interopDefault(Module);
16
-
17
- // src/tsconfig.ts
18
- var readJsonc = (jsonPath) => jsoncParser.parse(fs.readFileSync(jsonPath));
19
- var getPnpApi = () => {
20
- const { findPnpApi } = Module__default.default;
21
- return findPnpApi?.(process.cwd());
22
- };
23
- var resolveFromPackageJsonPath = (packageJsonPath, subpath, ignoreExports, cache) => {
24
- const cacheKey = `resolveFromPackageJsonPath:${packageJsonPath}:${subpath}:${ignoreExports}`;
25
- if (cache?.has(cacheKey)) {
26
- return cache.get(cacheKey);
27
- }
28
- const packageJson = readJsonc(packageJsonPath);
29
- if (!packageJson) {
30
- return void 0;
31
- }
32
- let resolvedPath = subpath || "tsconfig.json";
33
- if (!ignoreExports && packageJson.exports) {
34
- try {
35
- const [resolvedExport] = resolvePkgMaps.resolveExports(packageJson.exports, subpath, ["require", "types"]);
36
- resolvedPath = resolvedExport;
37
- } catch {
38
- return false;
39
- }
40
- } else if (!subpath && packageJson.tsconfig) {
41
- resolvedPath = packageJson.tsconfig;
42
- }
43
- resolvedPath = path.join(packageJsonPath, "..", resolvedPath);
44
- cache?.set(cacheKey, resolvedPath);
45
- return resolvedPath;
46
- };
47
- var PACKAGE_JSON = "package.json";
48
- var TS_CONFIG_JSON = "tsconfig.json";
49
- var resolveExtendsPath = (requestedPath, directoryPath, cache) => {
50
- let filePath = requestedPath;
51
- if (requestedPath === "..") {
52
- filePath = path.join(filePath, TS_CONFIG_JSON);
53
- }
54
- if (requestedPath.startsWith(".")) {
55
- filePath = path.resolve(directoryPath, filePath);
56
- }
57
- if (path.isAbsolute(filePath)) {
58
- if (fs$1.existsSync(filePath)) {
59
- if (fs$1.statSync(filePath).isFile()) {
60
- return filePath;
61
- }
62
- } else if (!filePath.endsWith(".json")) {
63
- const jsonPath = `${filePath}.json`;
64
- if (fs$1.existsSync(jsonPath)) {
65
- return jsonPath;
66
- }
67
- }
68
- return void 0;
69
- }
70
- const [orgOrName, ...remaining] = requestedPath.split("/");
71
- const packageName = orgOrName.startsWith("@") ? `${orgOrName}/${remaining.shift()}` : orgOrName;
72
- const subpath = remaining.join("/");
73
- const pnpApi = getPnpApi();
74
- if (pnpApi) {
75
- const { resolveRequest: resolveWithPnp } = pnpApi;
76
- try {
77
- if (packageName === requestedPath) {
78
- const packageJsonPath2 = resolveWithPnp(path.join(packageName, PACKAGE_JSON), directoryPath);
79
- if (packageJsonPath2) {
80
- const resolvedPath = resolveFromPackageJsonPath(packageJsonPath2, subpath, false, cache);
81
- if (resolvedPath && fs$1.existsSync(resolvedPath)) {
82
- return resolvedPath;
83
- }
84
- }
85
- } else {
86
- let resolved;
87
- try {
88
- resolved = resolveWithPnp(requestedPath, directoryPath, { extensions: [".json"] });
89
- } catch {
90
- resolved = resolveWithPnp(path.join(requestedPath, TS_CONFIG_JSON), directoryPath);
91
- }
92
- if (resolved) {
93
- return resolved;
94
- }
95
- }
96
- } catch {
97
- }
98
- }
99
- const packagePath = fs.findUpSync(
100
- (directory) => {
101
- const path$1 = path.join(directory, "node_modules", packageName);
102
- if (fs$1.existsSync(path$1)) {
103
- return path.join("node_modules", packageName);
104
- }
105
- return void 0;
106
- },
107
- {
108
- cwd: directoryPath,
109
- type: "directory"
110
- }
111
- );
112
- if (!packagePath || !fs$1.statSync(packagePath).isDirectory()) {
113
- return void 0;
114
- }
115
- const packageJsonPath = path.join(packagePath, PACKAGE_JSON);
116
- if (fs$1.existsSync(packageJsonPath)) {
117
- const resolvedPath = resolveFromPackageJsonPath(packageJsonPath, subpath, false, cache);
118
- if (resolvedPath === false) {
119
- return void 0;
120
- }
121
- if (resolvedPath && fs$1.existsSync(resolvedPath) && fs$1.statSync(resolvedPath).isFile()) {
122
- return resolvedPath;
123
- }
124
- }
125
- const fullPackagePath = path.join(packagePath, subpath);
126
- const jsonExtension = fullPackagePath.endsWith(".json");
127
- if (!jsonExtension) {
128
- const fullPackagePathWithJson = `${fullPackagePath}.json`;
129
- if (fs$1.existsSync(fullPackagePathWithJson)) {
130
- return fullPackagePathWithJson;
131
- }
132
- }
133
- if (!fs$1.existsSync(fullPackagePath)) {
134
- return void 0;
135
- }
136
- if (fs$1.statSync(fullPackagePath).isDirectory()) {
137
- const fullPackageJsonPath = path.join(fullPackagePath, PACKAGE_JSON);
138
- if (fs$1.existsSync(fullPackageJsonPath)) {
139
- const resolvedPath = resolveFromPackageJsonPath(fullPackageJsonPath, "", true, cache);
140
- if (resolvedPath && fs$1.existsSync(resolvedPath)) {
141
- return resolvedPath;
142
- }
143
- }
144
- const tsconfigPath = path.join(fullPackagePath, TS_CONFIG_JSON);
145
- if (fs$1.existsSync(tsconfigPath)) {
146
- return tsconfigPath;
147
- }
148
- } else if (jsonExtension) {
149
- return fullPackagePath;
150
- }
151
- return void 0;
152
- };
153
- var resolve_extends_path_default = resolveExtendsPath;
154
-
155
- // src/read-tsconfig.ts
156
- var readJsonc2 = (jsonPath) => jsoncParser.parse(fs.readFileSync(jsonPath));
157
- var normalizePath = (path) => pathe.toNamespacedPath(/^\.{1,2}(?:\/.*)?$/.test(path) ? path : `./${path}`);
158
- var resolveExtends = (extendsPath, fromDirectoryPath, circularExtendsTracker, options) => {
159
- const resolvedExtendsPath = resolve_extends_path_default(extendsPath, fromDirectoryPath);
160
- if (!resolvedExtendsPath) {
161
- throw new error.NotFoundError(`No such file or directory, for '${extendsPath}' found.`);
162
- }
163
- if (circularExtendsTracker.has(resolvedExtendsPath)) {
164
- throw new Error(`Circularity detected while resolving configuration: ${resolvedExtendsPath}`);
165
- }
166
- circularExtendsTracker.add(resolvedExtendsPath);
167
- const extendsDirectoryPath = pathe.dirname(resolvedExtendsPath);
168
- const extendsConfig = internalParseTsConfig(resolvedExtendsPath, options, circularExtendsTracker);
169
- delete extendsConfig.references;
170
- const { compilerOptions } = extendsConfig;
171
- if (compilerOptions) {
172
- const resolvePaths = ["baseUrl", "outDir"];
173
- for (const property of resolvePaths) {
174
- const unresolvedPath = compilerOptions[property];
175
- if (unresolvedPath) {
176
- compilerOptions[property] = pathe.relative(fromDirectoryPath, pathe.join(extendsDirectoryPath, unresolvedPath)).replaceAll("\\", "/") || "./";
177
- }
178
- }
179
- }
180
- if (extendsConfig.files) {
181
- extendsConfig.files = extendsConfig.files.map((file) => pathe.relative(fromDirectoryPath, pathe.join(extendsDirectoryPath, file)));
182
- }
183
- if (extendsConfig.include) {
184
- extendsConfig.include = extendsConfig.include.map((file) => pathe.relative(fromDirectoryPath, pathe.join(extendsDirectoryPath, file)));
185
- }
186
- if (extendsConfig.exclude) {
187
- extendsConfig.exclude = extendsConfig.exclude.map((file) => pathe.relative(fromDirectoryPath, pathe.join(extendsDirectoryPath, file)));
188
- }
189
- return extendsConfig;
190
- };
191
- var internalParseTsConfig = (tsconfigPath, options, circularExtendsTracker = /* @__PURE__ */ new Set()) => {
192
- let config;
193
- try {
194
- config = readJsonc2(tsconfigPath) || {};
195
- } catch {
196
- throw new Error(`Cannot resolve tsconfig at path: ${tsconfigPath}`);
197
- }
198
- if (typeof config !== "object") {
199
- throw new SyntaxError(`Failed to parse tsconfig at: ${tsconfigPath}`);
200
- }
201
- const directoryPath = pathe.dirname(tsconfigPath);
202
- if (config.compilerOptions) {
203
- const { compilerOptions } = config;
204
- if (compilerOptions.paths && !compilerOptions.baseUrl) {
205
- compilerOptions[implicitBaseUrlSymbol] = directoryPath;
206
- }
207
- }
208
- if (config.extends) {
209
- const extendsPathList = Array.isArray(config.extends) ? config.extends : [config.extends];
210
- delete config.extends;
211
- for (const extendsPath of extendsPathList.reverse()) {
212
- const extendsConfig = resolveExtends(extendsPath, directoryPath, new Set(circularExtendsTracker), options);
213
- const merged = {
214
- ...extendsConfig,
215
- ...config,
216
- compilerOptions: {
217
- ...extendsConfig.compilerOptions,
218
- ...config.compilerOptions
219
- }
220
- };
221
- if (extendsConfig.watchOptions) {
222
- merged.watchOptions = {
223
- ...extendsConfig.watchOptions,
224
- ...config.watchOptions
225
- };
226
- }
227
- config = merged;
228
- }
229
- }
230
- if (config.compilerOptions) {
231
- const { compilerOptions } = config;
232
- const normalizedPaths = ["baseUrl", "rootDir"];
233
- for (const property of normalizedPaths) {
234
- const unresolvedPath = compilerOptions[property];
235
- if (unresolvedPath) {
236
- const resolvedBaseUrl = pathe.resolve(directoryPath, unresolvedPath);
237
- const relativeBaseUrl = pathe.relative(directoryPath, resolvedBaseUrl);
238
- compilerOptions[property] = normalizePath(relativeBaseUrl);
239
- }
240
- }
241
- const { outDir } = compilerOptions;
242
- if (outDir) {
243
- if (!Array.isArray(config.exclude)) {
244
- config.exclude = [];
245
- }
246
- if (!config.exclude.includes(outDir)) {
247
- config.exclude.push(outDir);
248
- }
249
- compilerOptions.outDir = normalizePath(outDir);
250
- }
251
- if (options?.tscCompatible && compilerOptions.module === "node16") {
252
- compilerOptions.allowSyntheticDefaultImports = compilerOptions.allowSyntheticDefaultImports ?? true;
253
- compilerOptions.esModuleInterop = compilerOptions.esModuleInterop ?? true;
254
- compilerOptions.moduleDetection = compilerOptions.moduleDetection ?? "force";
255
- compilerOptions.moduleResolution = compilerOptions.moduleResolution ?? "node16";
256
- compilerOptions.target = compilerOptions.target ?? "es2022";
257
- compilerOptions.useDefineForClassFields = compilerOptions.useDefineForClassFields ?? true;
258
- }
259
- if (options?.tscCompatible && compilerOptions.strict) {
260
- compilerOptions.noImplicitAny = compilerOptions.noImplicitAny ?? true;
261
- compilerOptions.noImplicitThis = compilerOptions.noImplicitThis ?? true;
262
- compilerOptions.strictNullChecks = compilerOptions.strictNullChecks ?? true;
263
- compilerOptions.strictFunctionTypes = compilerOptions.strictFunctionTypes ?? true;
264
- compilerOptions.strictBindCallApply = compilerOptions.strictBindCallApply ?? true;
265
- compilerOptions.strictPropertyInitialization = compilerOptions.strictPropertyInitialization ?? true;
266
- compilerOptions.alwaysStrict = compilerOptions.alwaysStrict ?? true;
267
- compilerOptions.useUnknownInCatchVariables = compilerOptions.useUnknownInCatchVariables ?? true;
268
- }
269
- if (options?.tscCompatible && compilerOptions.isolatedModules) {
270
- compilerOptions.preserveConstEnums = compilerOptions.preserveConstEnums ?? true;
271
- }
272
- if (options?.tscCompatible && compilerOptions.esModuleInterop) {
273
- compilerOptions.allowSyntheticDefaultImports = compilerOptions.allowSyntheticDefaultImports ?? true;
274
- }
275
- if (options?.tscCompatible && compilerOptions.target === "esnext") {
276
- compilerOptions.useDefineForClassFields = compilerOptions.useDefineForClassFields ?? true;
277
- }
278
- } else {
279
- config.compilerOptions = {};
280
- }
281
- if (config.files) {
282
- config.files = config.files.map((element) => normalizePath(element));
283
- }
284
- if (config.include) {
285
- config.include = config.include.map((element) => pathe.normalize(element));
286
- }
287
- if (config.watchOptions) {
288
- const { watchOptions } = config;
289
- if (watchOptions.excludeDirectories) {
290
- watchOptions.excludeDirectories = watchOptions.excludeDirectories.map((excludePath) => pathe.resolve(directoryPath, excludePath));
291
- }
292
- }
293
- return config;
294
- };
295
- var implicitBaseUrlSymbol = Symbol("implicitBaseUrl");
296
- var readTsConfig = (tsconfigPath, options) => internalParseTsConfig(tsconfigPath, options);
297
-
298
- // src/tsconfig.ts
299
- var TsConfigFileCache = /* @__PURE__ */ new Map();
300
- var findTsConfig = async (cwd, options = {}) => {
301
- const configFileName = options.configFileName ?? "tsconfig.json";
302
- let filePath = await fs.findUp(configFileName, {
303
- ...cwd && { cwd },
304
- type: "file"
305
- });
306
- if (!filePath) {
307
- filePath = await fs.findUp("jsconfig.json", {
308
- ...cwd && { cwd },
309
- type: "file"
310
- });
311
- }
312
- if (!filePath) {
313
- throw new error.NotFoundError(`No such file or directory, for ${configFileName} or jsconfig.json found.`);
314
- }
315
- const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : TsConfigFileCache;
316
- if (options.cache && cache.has(filePath)) {
317
- return cache.get(filePath);
318
- }
319
- const output = {
320
- config: readTsConfig(filePath),
321
- path: filePath
322
- };
323
- if (options.cache) {
324
- cache.set(filePath, output);
325
- }
326
- return output;
327
- };
328
- var findTSConfig = findTsConfig;
329
- var findTsConfigSync = (cwd, options = {}) => {
330
- const configFileName = options.configFileName ?? "tsconfig.json";
331
- let filePath = fs.findUpSync(configFileName, {
332
- ...cwd && { cwd },
333
- type: "file"
334
- });
335
- if (!filePath) {
336
- filePath = fs.findUpSync("jsconfig.json", {
337
- ...cwd && { cwd },
338
- type: "file"
339
- });
340
- }
341
- if (!filePath) {
342
- throw new error.NotFoundError(`No such file or directory, for ${configFileName} or jsconfig.json found.`);
343
- }
344
- const cache = options.cache && typeof options.cache !== "boolean" ? options.cache : TsConfigFileCache;
345
- if (options.cache && cache.has(filePath)) {
346
- return cache.get(filePath);
347
- }
348
- const output = {
349
- config: readTsConfig(filePath),
350
- path: filePath
351
- };
352
- if (options.cache) {
353
- cache.set(filePath, output);
354
- }
355
- return output;
356
- };
357
- var findTSConfigSync = findTsConfigSync;
358
- var writeTsConfig = async (data, options = {}) => {
359
- const { cwd, ...writeOptions } = options;
360
- const directory = utils.toPath(options.cwd ?? process.cwd());
361
- await fs.writeJson(pathe.join(directory, "tsconfig.json"), data, writeOptions);
362
- };
363
- var writeTSConfig = writeTsConfig;
364
-
365
- exports.findTSConfig = findTSConfig;
366
- exports.findTSConfigSync = findTSConfigSync;
367
- exports.findTsConfig = findTsConfig;
368
- exports.findTsConfigSync = findTsConfigSync;
369
- exports.implicitBaseUrlSymbol = implicitBaseUrlSymbol;
370
- exports.readTsConfig = readTsConfig;
371
- exports.writeTSConfig = writeTSConfig;
372
- exports.writeTsConfig = writeTsConfig;
373
- //# sourceMappingURL=out.js.map
374
- //# sourceMappingURL=chunk-WXFZK4G3.cjs.map