@release-change/get-packages 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/browse-directories.d.ts +7 -0
  4. package/dist/browse-directories.d.ts.map +1 -0
  5. package/dist/browse-directories.js +20 -0
  6. package/dist/browse-directories.js.map +1 -0
  7. package/dist/get-npm-glob-patterns.d.ts +9 -0
  8. package/dist/get-npm-glob-patterns.d.ts.map +1 -0
  9. package/dist/get-npm-glob-patterns.js +18 -0
  10. package/dist/get-npm-glob-patterns.js.map +1 -0
  11. package/dist/get-package-dependencies.d.ts +7 -0
  12. package/dist/get-package-dependencies.d.ts.map +1 -0
  13. package/dist/get-package-dependencies.js +15 -0
  14. package/dist/get-package-dependencies.js.map +1 -0
  15. package/dist/get-package-manager.d.ts +9 -0
  16. package/dist/get-package-manager.d.ts.map +1 -0
  17. package/dist/get-package-manager.js +26 -0
  18. package/dist/get-package-manager.js.map +1 -0
  19. package/dist/get-package-name.d.ts +7 -0
  20. package/dist/get-package-name.d.ts.map +1 -0
  21. package/dist/get-package-name.js +32 -0
  22. package/dist/get-package-name.js.map +1 -0
  23. package/dist/get-package-version.d.ts +7 -0
  24. package/dist/get-package-version.d.ts.map +1 -0
  25. package/dist/get-package-version.js +23 -0
  26. package/dist/get-package-version.js.map +1 -0
  27. package/dist/get-packages-from-glob-patterns.d.ts +10 -0
  28. package/dist/get-packages-from-glob-patterns.d.ts.map +1 -0
  29. package/dist/get-packages-from-glob-patterns.js +34 -0
  30. package/dist/get-packages-from-glob-patterns.js.map +1 -0
  31. package/dist/get-packages.d.ts +8 -0
  32. package/dist/get-packages.d.ts.map +1 -0
  33. package/dist/get-packages.js +71 -0
  34. package/dist/get-packages.js.map +1 -0
  35. package/dist/get-packages.types.d.ts +6 -0
  36. package/dist/get-packages.types.d.ts.map +1 -0
  37. package/dist/get-packages.types.js +2 -0
  38. package/dist/get-packages.types.js.map +1 -0
  39. package/dist/get-pnpm-glob-patterns.d.ts +8 -0
  40. package/dist/get-pnpm-glob-patterns.d.ts.map +1 -0
  41. package/dist/get-pnpm-glob-patterns.js +36 -0
  42. package/dist/get-pnpm-glob-patterns.js.map +1 -0
  43. package/dist/get-root-package-manifest.d.ts +8 -0
  44. package/dist/get-root-package-manifest.d.ts.map +1 -0
  45. package/dist/get-root-package-manifest.js +19 -0
  46. package/dist/get-root-package-manifest.js.map +1 -0
  47. package/dist/get-root-pnpm-workspace-manifest.d.ts +7 -0
  48. package/dist/get-root-pnpm-workspace-manifest.d.ts.map +1 -0
  49. package/dist/get-root-pnpm-workspace-manifest.js +10 -0
  50. package/dist/get-root-pnpm-workspace-manifest.js.map +1 -0
  51. package/dist/index.d.ts +12 -0
  52. package/dist/index.d.ts.map +1 -0
  53. package/dist/index.js +11 -0
  54. package/dist/index.js.map +1 -0
  55. package/dist/is-monorepo.d.ts +8 -0
  56. package/dist/is-monorepo.d.ts.map +1 -0
  57. package/dist/is-monorepo.js +19 -0
  58. package/dist/is-monorepo.js.map +1 -0
  59. package/dist/pattern-to-regex.d.ts +7 -0
  60. package/dist/pattern-to-regex.d.ts.map +1 -0
  61. package/dist/pattern-to-regex.js +10 -0
  62. package/dist/pattern-to-regex.js.map +1 -0
  63. package/package.json +38 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present Victor Brito
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @release-change/get-packages
2
+
3
+ Functions used internally in release-change to get the packages from a monorepo
4
+
5
+ ![License: MIT](https://img.shields.io/github/license/release-change/release-change)
6
+ [![ESM-only package](https://img.shields.io/badge/package-ESM--only-ffe536)](https://nodejs.org/api/esm.html)
7
+ [![Conventional Commits 1.0.0](https://img.shields.io/badge/Conventional%20Commits-1.0.0-%23FE5196?logo=conventionalcommits&logoColor=white)](https://conventionalcommits.org)
8
+ [![Formatted with Biome](https://img.shields.io/badge/Formatted_with-Biome-60a5fa?style=flat&logo=biome)](https://biomejs.dev/)
9
+ ![NPM latest version](https://img.shields.io/npm/v/%40release-change%2Fget-packages/latest)
10
+ ![Node support](https://img.shields.io/node/v/%40release-change%2Fget-packages)
11
+ ![Build status](https://img.shields.io/github/actions/workflow/status/release-change/release-change/run-tests.yml)
12
+
13
+ ## Copyright & licence
14
+
15
+ © 2025-present Victor Brito — Released under the [MIT licence](./LICENSE).
@@ -0,0 +1,7 @@
1
+ /**
2
+ *Browses the directories recursively from the given directory.
3
+ * @param directory - The directory from which to start the browsing.
4
+ * @return An array of all the directories found recursively.
5
+ */
6
+ export declare const browseDirectories: (directory: string) => Promise<string[]>;
7
+ //# sourceMappingURL=browse-directories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browse-directories.d.ts","sourceRoot":"","sources":["../src/browse-directories.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,WAAW,MAAM,KAAG,OAAO,CAAC,MAAM,EAAE,CAW3E,CAAC"}
@@ -0,0 +1,20 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ /**
4
+ *Browses the directories recursively from the given directory.
5
+ * @param directory - The directory from which to start the browsing.
6
+ * @return An array of all the directories found recursively.
7
+ */
8
+ export const browseDirectories = async (directory) => {
9
+ const entries = (await fs.readdir(directory, { withFileTypes: true })).map(async (entry) => {
10
+ const pathToEntry = path.join(directory, entry.name);
11
+ if (entry.isDirectory()) {
12
+ const subDirectories = await browseDirectories(pathToEntry);
13
+ return [pathToEntry, ...subDirectories];
14
+ }
15
+ return [];
16
+ });
17
+ const directories = await Promise.all(entries);
18
+ return directories.flat();
19
+ };
20
+ //# sourceMappingURL=browse-directories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browse-directories.js","sourceRoot":"","sources":["../src/browse-directories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,KAAK,EAAE,SAAiB,EAAqB,EAAE;IAC9E,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAC,KAAK,EAAC,EAAE;QACvF,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;YACxB,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,CAAC;YAC5D,OAAO,CAAC,WAAW,EAAE,GAAG,cAAc,CAAC,CAAC;QAC1C,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC,CAAC;IACH,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,WAAW,CAAC,IAAI,EAAE,CAAC;AAC5B,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { PackageManifest } from "@release-change/config";
2
+ import type { GlobPatterns } from "./get-packages.types.js";
3
+ /**
4
+ * Gets glob patterns from the root `package.json` file.
5
+ * @param content - The content of root `package.json` as JSON.
6
+ * @return An object containing arrays of unique including and excluding glob patterns if there is a `workspaces` property, `null` otherwise.
7
+ */
8
+ export declare const getNpmGlobPatterns: (content: PackageManifest) => GlobPatterns | null;
9
+ //# sourceMappingURL=get-npm-glob-patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-npm-glob-patterns.d.ts","sourceRoot":"","sources":["../src/get-npm-glob-patterns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,SAAS,eAAe,KAAG,YAAY,GAAG,IAW5E,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Gets glob patterns from the root `package.json` file.
3
+ * @param content - The content of root `package.json` as JSON.
4
+ * @return An object containing arrays of unique including and excluding glob patterns if there is a `workspaces` property, `null` otherwise.
5
+ */
6
+ export const getNpmGlobPatterns = (content) => {
7
+ const patterns = {
8
+ include: [],
9
+ exclude: ["**/node_modules/**"]
10
+ };
11
+ const { workspaces } = content;
12
+ if (workspaces) {
13
+ patterns.include.push(...new Set([...workspaces]));
14
+ return patterns;
15
+ }
16
+ return null;
17
+ };
18
+ //# sourceMappingURL=get-npm-glob-patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-npm-glob-patterns.js","sourceRoot":"","sources":["../src/get-npm-glob-patterns.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,OAAwB,EAAuB,EAAE;IAClF,MAAM,QAAQ,GAAiB;QAC7B,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,CAAC,oBAAoB,CAAC;KAChC,CAAC;IACF,MAAM,EAAE,UAAU,EAAE,GAAG,OAAO,CAAC;IAC/B,IAAI,UAAU,EAAE,CAAC;QACf,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC;QACnD,OAAO,QAAQ,CAAC;IAClB,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the package dependencies from the `package.json` file.
3
+ * @param path - The path to the `package.json` file.
4
+ * @return An array of the dependency names extracted from the `dependencies` and `devDependencies` properties if the file exists, `null` otherwise.
5
+ */
6
+ export declare const getPackageDependencies: (path: string) => string[] | null;
7
+ //# sourceMappingURL=get-package-dependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-dependencies.d.ts","sourceRoot":"","sources":["../src/get-package-dependencies.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,MAAM,KAAG,MAAM,EAAE,GAAG,IAOhE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import fs from "node:fs";
2
+ /**
3
+ * Gets the package dependencies from the `package.json` file.
4
+ * @param path - The path to the `package.json` file.
5
+ * @return An array of the dependency names extracted from the `dependencies` and `devDependencies` properties if the file exists, `null` otherwise.
6
+ */
7
+ export const getPackageDependencies = (path) => {
8
+ if (fs.existsSync(path)) {
9
+ const fileContent = JSON.parse(fs.readFileSync(path, "utf8"));
10
+ const { dependencies, devDependencies } = fileContent;
11
+ return [...Object.keys(dependencies ?? {}), ...Object.keys(devDependencies ?? {})];
12
+ }
13
+ return null;
14
+ };
15
+ //# sourceMappingURL=get-package-dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-dependencies.js","sourceRoot":"","sources":["../src/get-package-dependencies.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAmB,EAAE;IACtE,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,WAAW,GAAoB,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC/E,MAAM,EAAE,YAAY,EAAE,eAAe,EAAE,GAAG,WAAW,CAAC;QACtD,OAAO,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,IAAI,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { PackageManager } from "./get-packages.types.js";
2
+ /**
3
+ * Gets the package manager used.
4
+ * @param cwd - The current working directory.
5
+ * @param env - The whole available environment variables.
6
+ * @return The package manager used if it is `npm` or `pnpm`, `null` otherwise.
7
+ */
8
+ export declare const getPackageManager: (cwd: string, env: NodeJS.ProcessEnv) => PackageManager;
9
+ //# sourceMappingURL=get-package-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-manager.d.ts","sourceRoot":"","sources":["../src/get-package-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAK9D;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,KAAK,MAAM,EAAE,KAAK,MAAM,CAAC,UAAU,KAAG,cAWvE,CAAC"}
@@ -0,0 +1,26 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ /**
4
+ * Gets the package manager used.
5
+ * @param cwd - The current working directory.
6
+ * @param env - The whole available environment variables.
7
+ * @return The package manager used if it is `npm` or `pnpm`, `null` otherwise.
8
+ */
9
+ export const getPackageManager = (cwd, env) => {
10
+ const { npm_config_user_agent: npmConfigUserAgent, PNPM_HOME } = env;
11
+ if (fs.existsSync(path.join(cwd, "pnpm-lock.yaml")))
12
+ return "pnpm";
13
+ if (fs.existsSync(path.join(cwd, "package-lock.json")))
14
+ return "npm";
15
+ if (PNPM_HOME)
16
+ return "pnpm";
17
+ if (npmConfigUserAgent) {
18
+ if (npmConfigUserAgent.includes("pnpm"))
19
+ return "pnpm";
20
+ if (npmConfigUserAgent.includes("npm"))
21
+ return "npm";
22
+ return null;
23
+ }
24
+ return null;
25
+ };
26
+ //# sourceMappingURL=get-package-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-manager.js","sourceRoot":"","sources":["../src/get-package-manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAE,GAAsB,EAAkB,EAAE;IACvF,MAAM,EAAE,qBAAqB,EAAE,kBAAkB,EAAE,SAAS,EAAE,GAAG,GAAG,CAAC;IACrE,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,gBAAgB,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC;IACnE,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACrE,IAAI,SAAS;QAAE,OAAO,MAAM,CAAC;IAC7B,IAAI,kBAAkB,EAAE,CAAC;QACvB,IAAI,kBAAkB,CAAC,QAAQ,CAAC,MAAM,CAAC;YAAE,OAAO,MAAM,CAAC;QACvD,IAAI,kBAAkB,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the package name from the `package.json` file.
3
+ * @param path - The path to the `package.json` file.
4
+ * @return The value of the `name` property if the file exists, `null` otherwise.
5
+ */
6
+ export declare const getPackageName: (path: string) => string | null;
7
+ //# sourceMappingURL=get-package-name.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-name.d.ts","sourceRoot":"","sources":["../src/get-package-name.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAsBtD,CAAC"}
@@ -0,0 +1,32 @@
1
+ import fs from "node:fs";
2
+ import { formatDetailedError } from "@release-change/shared";
3
+ /**
4
+ * Gets the package name from the `package.json` file.
5
+ * @param path - The path to the `package.json` file.
6
+ * @return The value of the `name` property if the file exists, `null` otherwise.
7
+ */
8
+ export const getPackageName = (path) => {
9
+ if (fs.existsSync(path)) {
10
+ const { name } = JSON.parse(fs.readFileSync(path, "utf8"));
11
+ if (name) {
12
+ if (typeof name === "string")
13
+ return name;
14
+ throw formatDetailedError({
15
+ title: `Failed to get the package name for ${path}`,
16
+ message: "`name` property must be a string.",
17
+ details: {
18
+ output: `path: ${path}`
19
+ }
20
+ });
21
+ }
22
+ throw formatDetailedError({
23
+ title: `Failed to get the package name for ${path}`,
24
+ message: "`name` property not found.",
25
+ details: {
26
+ output: `path: ${path}`
27
+ }
28
+ });
29
+ }
30
+ return null;
31
+ };
32
+ //# sourceMappingURL=get-package-name.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-name.js","sourceRoot":"","sources":["../src/get-package-name.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAiB,EAAE;IAC5D,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3D,IAAI,IAAI,EAAE,CAAC;YACT,IAAI,OAAO,IAAI,KAAK,QAAQ;gBAAE,OAAO,IAAI,CAAC;YAC1C,MAAM,mBAAmB,CAAC;gBACxB,KAAK,EAAE,sCAAsC,IAAI,EAAE;gBACnD,OAAO,EAAE,mCAAmC;gBAC5C,OAAO,EAAE;oBACP,MAAM,EAAE,SAAS,IAAI,EAAE;iBACxB;aACF,CAAC,CAAC;QACL,CAAC;QACD,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,sCAAsC,IAAI,EAAE;YACnD,OAAO,EAAE,4BAA4B;YACrC,OAAO,EAAE;gBACP,MAAM,EAAE,SAAS,IAAI,EAAE;aACxB;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the package version from the `package.json` file.
3
+ * @param path - The path to the `package.json` file.
4
+ * @return The value of the `version` property if the file exists, `null` otherwise.
5
+ */
6
+ export declare const getPackageVersion: (path: string) => string | null;
7
+ //# sourceMappingURL=get-package-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-version.d.ts","sourceRoot":"","sources":["../src/get-package-version.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAazD,CAAC"}
@@ -0,0 +1,23 @@
1
+ import fs from "node:fs";
2
+ import { formatDetailedError } from "@release-change/shared";
3
+ /**
4
+ * Gets the package version from the `package.json` file.
5
+ * @param path - The path to the `package.json` file.
6
+ * @return The value of the `version` property if the file exists, `null` otherwise.
7
+ */
8
+ export const getPackageVersion = (path) => {
9
+ if (fs.existsSync(path)) {
10
+ const { version } = JSON.parse(fs.readFileSync(path, "utf8"));
11
+ if (version)
12
+ return version;
13
+ throw formatDetailedError({
14
+ title: "Failed to get the package version",
15
+ message: `The \`version\` property was not found for ${path}.`,
16
+ details: {
17
+ output: `path: ${path}`
18
+ }
19
+ });
20
+ }
21
+ return null;
22
+ };
23
+ //# sourceMappingURL=get-package-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-package-version.js","sourceRoot":"","sources":["../src/get-package-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAiB,EAAE;IAC/D,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC9D,IAAI,OAAO;YAAE,OAAO,OAAO,CAAC;QAC5B,MAAM,mBAAmB,CAAC;YACxB,KAAK,EAAE,mCAAmC;YAC1C,OAAO,EAAE,8CAA8C,IAAI,GAAG;YAC9D,OAAO,EAAE;gBACP,MAAM,EAAE,SAAS,IAAI,EAAE;aACxB;SACF,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { Package } from "@release-change/shared/";
2
+ import type { GlobPatterns } from "./get-packages.types.js";
3
+ /**
4
+ * Gets the packages from the given glob patterns.
5
+ * @param globPatterns - The glob patterns to use.
6
+ * @param cwd - The current working directory.
7
+ * @return An array of package names and paths whose directory contains a `package.json` file with a `name` property.
8
+ */
9
+ export declare const getPackagesFromGlobPatterns: (globPatterns: GlobPatterns, cwd: string) => Promise<Package[]>;
10
+ //# sourceMappingURL=get-packages-from-glob-patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-packages-from-glob-patterns.d.ts","sourceRoot":"","sources":["../src/get-packages-from-glob-patterns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAS5D;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,cAAc,YAAY,EAC1B,KAAK,MAAM,KACV,OAAO,CAAC,OAAO,EAAE,CAsBnB,CAAC"}
@@ -0,0 +1,34 @@
1
+ import fs from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { browseDirectories } from "./browse-directories.js";
4
+ import { getPackageName } from "./get-package-name.js";
5
+ import { patternToRegex } from "./pattern-to-regex.js";
6
+ /**
7
+ * Gets the packages from the given glob patterns.
8
+ * @param globPatterns - The glob patterns to use.
9
+ * @param cwd - The current working directory.
10
+ * @return An array of package names and paths whose directory contains a `package.json` file with a `name` property.
11
+ */
12
+ export const getPackagesFromGlobPatterns = async (globPatterns, cwd) => {
13
+ const { include, exclude } = globPatterns;
14
+ const includeRegexps = include.map(patternToRegex);
15
+ const excludeRegexps = exclude.map(patternToRegex);
16
+ const directories = (await browseDirectories(cwd)).map(async (directory) => {
17
+ const isIncluded = includeRegexps.some(regex => regex.test(directory));
18
+ const isExcluded = excludeRegexps.some(regex => regex.test(directory));
19
+ if (isIncluded && !isExcluded) {
20
+ const filePath = path.join(directory, "package.json");
21
+ try {
22
+ await fs.access(filePath);
23
+ const packageName = getPackageName(filePath) ?? "";
24
+ return { name: packageName, pathname: path.relative(cwd, directory) };
25
+ }
26
+ catch {
27
+ return { name: "", pathname: "" };
28
+ }
29
+ }
30
+ return { name: "", pathname: "" };
31
+ });
32
+ return (await Promise.all(directories)).filter(directory => Boolean(directory.name) && Boolean(directory.pathname));
33
+ };
34
+ //# sourceMappingURL=get-packages-from-glob-patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-packages-from-glob-patterns.js","sourceRoot":"","sources":["../src/get-packages-from-glob-patterns.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAClC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC9C,YAA0B,EAC1B,GAAW,EACS,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC;IAC1C,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnD,MAAM,cAAc,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IACnD,MAAM,WAAW,GAAG,CAAC,MAAM,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,EAAC,SAAS,EAAC,EAAE;QACvE,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QACvE,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;QACvE,IAAI,UAAU,IAAI,CAAC,UAAU,EAAE,CAAC;YAC9B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YACtD,IAAI,CAAC;gBACH,MAAM,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC1B,MAAM,WAAW,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;gBACnD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,SAAS,CAAC,EAAE,CAAC;YACxE,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YACpC,CAAC;QACH,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACpC,CAAC,CAAC,CAAC;IACH,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAC5C,SAAS,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,SAAS,CAAC,QAAQ,CAAC,CACpE,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ContextBase, Package } from "@release-change/shared";
2
+ /**
3
+ * Gets the packages within the current working directory.
4
+ * @param context - The context where the CLI is running.
5
+ * @return An array of package names and paths to the packages found, including the root package.
6
+ */
7
+ export declare const getPackages: (context: ContextBase) => Promise<Package[]>;
8
+ //# sourceMappingURL=get-packages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-packages.d.ts","sourceRoot":"","sources":["../src/get-packages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAenE;;;;GAIG;AACH,eAAO,MAAM,WAAW,GAAU,SAAS,WAAW,KAAG,OAAO,CAAC,OAAO,EAAE,CAoDzE,CAAC"}
@@ -0,0 +1,71 @@
1
+ import path from "node:path";
2
+ import { inspect } from "node:util";
3
+ import { addErrorToContext, checkErrorType, setLogger } from "@release-change/logger";
4
+ import { formatDetailedError } from "@release-change/shared";
5
+ import { getNpmGlobPatterns } from "./get-npm-glob-patterns.js";
6
+ import { getPackageManager } from "./get-package-manager.js";
7
+ import { getPackagesFromGlobPatterns } from "./get-packages-from-glob-patterns.js";
8
+ import { getPnpmGlobPatterns } from "./get-pnpm-glob-patterns.js";
9
+ import { getRootPackageManifest } from "./get-root-package-manifest.js";
10
+ import { getRootPnpmWorkspaceManifest } from "./get-root-pnpm-workspace-manifest.js";
11
+ /**
12
+ * Gets the packages within the current working directory.
13
+ * @param context - The context where the CLI is running.
14
+ * @return An array of package names and paths to the packages found, including the root package.
15
+ */
16
+ export const getPackages = async (context) => {
17
+ const { cwd, env, config } = context;
18
+ const { debug } = config;
19
+ const logger = setLogger(debug);
20
+ logger.setScope("get-packages");
21
+ const packageManager = getPackageManager(cwd, env);
22
+ if (packageManager) {
23
+ const packages = [{ name: "", pathname: "." }];
24
+ if (debug) {
25
+ logger.setDebugScope("get-packages:get-packages");
26
+ logger.logDebug(`Package manager: ${packageManager}`);
27
+ }
28
+ if (packageManager === "pnpm") {
29
+ const content = getRootPnpmWorkspaceManifest(path.join(cwd, "pnpm-workspace.yaml"));
30
+ if (content) {
31
+ try {
32
+ const globPatterns = getPnpmGlobPatterns(content);
33
+ packages.push(...(await getPackagesFromGlobPatterns(globPatterns, cwd)));
34
+ if (debug) {
35
+ logger.logDebug(`Packages found (including root package): ${packages.length}`);
36
+ logger.logDebug(inspect(packages, { depth: Number.POSITIVE_INFINITY }));
37
+ }
38
+ }
39
+ catch (error) {
40
+ logger.logError(checkErrorType(error));
41
+ addErrorToContext(error, context);
42
+ process.exit(process.exitCode);
43
+ }
44
+ }
45
+ return packages;
46
+ }
47
+ try {
48
+ const rootPackageManifestContent = getRootPackageManifest(path.join(cwd, "package.json"));
49
+ const globPatterns = getNpmGlobPatterns(rootPackageManifestContent);
50
+ if (globPatterns) {
51
+ packages.push(...(await getPackagesFromGlobPatterns(globPatterns, cwd)));
52
+ }
53
+ if (debug) {
54
+ logger.logDebug(`Packages found (including root package): ${packages.length}`);
55
+ logger.logDebug(inspect(packages, { depth: Number.POSITIVE_INFINITY }));
56
+ }
57
+ return packages;
58
+ }
59
+ catch (error) {
60
+ logger.logError(checkErrorType(error));
61
+ addErrorToContext(error, context);
62
+ process.exit(process.exitCode);
63
+ }
64
+ }
65
+ throw formatDetailedError({
66
+ title: "Failed to get the package manager",
67
+ message: "The package manager must be either `npm` or `pnpm`.",
68
+ details: { output: String(packageManager) }
69
+ });
70
+ };
71
+ //# sourceMappingURL=get-packages.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-packages.js","sourceRoot":"","sources":["../src/get-packages.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,6 @@
1
+ export type PackageManager = "npm" | "pnpm" | null;
2
+ export type GlobPatterns = {
3
+ include: string[];
4
+ exclude: string[];
5
+ };
6
+ //# sourceMappingURL=get-packages.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-packages.types.d.ts","sourceRoot":"","sources":["../src/get-packages.types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,MAAM,GAAG,IAAI,CAAC;AACnD,MAAM,MAAM,YAAY,GAAG;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=get-packages.types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-packages.types.js","sourceRoot":"","sources":["../src/get-packages.types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ import type { GlobPatterns } from "./get-packages.types.js";
2
+ /**
3
+ * Gets glob patterns from the root `pnpm-workspace.yaml` file.
4
+ * @param content - The content of root `pnpm-workspace.yaml`.
5
+ * @return An object containing arrays of including and excluding glob patterns if there is a `packages` field.
6
+ */
7
+ export declare const getPnpmGlobPatterns: (content: string) => GlobPatterns;
8
+ //# sourceMappingURL=get-pnpm-glob-patterns.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-pnpm-glob-patterns.d.ts","sourceRoot":"","sources":["../src/get-pnpm-glob-patterns.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAI5D;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,GAAI,SAAS,MAAM,KAAG,YAyBrD,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { formatDetailedError } from "@release-change/shared";
2
+ /**
3
+ * Gets glob patterns from the root `pnpm-workspace.yaml` file.
4
+ * @param content - The content of root `pnpm-workspace.yaml`.
5
+ * @return An object containing arrays of including and excluding glob patterns if there is a `packages` field.
6
+ */
7
+ export const getPnpmGlobPatterns = (content) => {
8
+ const patterns = {
9
+ include: [],
10
+ exclude: ["**/node_modules/**"]
11
+ };
12
+ const matches = content
13
+ .replace(/^\s*#.+$/gm, "")
14
+ .matchAll(/^\s*-\s*(?<quote>['"])(?<pattern>[^']+)\k<quote>/gm);
15
+ for (const match of matches) {
16
+ if (match?.groups) {
17
+ const { pattern } = match.groups;
18
+ if (pattern) {
19
+ if (pattern.startsWith("!"))
20
+ patterns.exclude.push(pattern.replace(/^!/, ""));
21
+ else
22
+ patterns.include.push(pattern);
23
+ }
24
+ }
25
+ }
26
+ if (patterns.include.length)
27
+ return patterns;
28
+ throw formatDetailedError({
29
+ title: "Failed to get the glob patterns",
30
+ message: "The root `pnpm-workspace.yaml` file must have a `packages` field.",
31
+ details: {
32
+ output: "patterns.include.length: 0"
33
+ }
34
+ });
35
+ };
36
+ //# sourceMappingURL=get-pnpm-glob-patterns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-pnpm-glob-patterns.js","sourceRoot":"","sources":["../src/get-pnpm-glob-patterns.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAgB,EAAE;IACnE,MAAM,QAAQ,GAAiB;QAC7B,OAAO,EAAE,EAAE;QACX,OAAO,EAAE,CAAC,oBAAoB,CAAC;KAChC,CAAC;IACF,MAAM,OAAO,GAAG,OAAO;SACpB,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;SACzB,QAAQ,CAAC,oDAAoD,CAAC,CAAC;IAClE,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,KAAK,EAAE,MAAM,EAAE,CAAC;YAClB,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC,MAAM,CAAC;YACjC,IAAI,OAAO,EAAE,CAAC;gBACZ,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC;oBAAE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC;;oBACzE,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;IACH,CAAC;IACD,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM;QAAE,OAAO,QAAQ,CAAC;IAC7C,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,iCAAiC;QACxC,OAAO,EAAE,mEAAmE;QAC5E,OAAO,EAAE;YACP,MAAM,EAAE,4BAA4B;SACrC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { PackageManifest } from "@release-change/config";
2
+ /**
3
+ * Gets the content of the root package manifest (aka `package.json`).
4
+ * @param path - The path to the root package file.
5
+ * @return The content of the root `package.json` as JSON if the file is found.
6
+ */
7
+ export declare const getRootPackageManifest: (path: string) => PackageManifest;
8
+ //# sourceMappingURL=get-root-package-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-root-package-manifest.d.ts","sourceRoot":"","sources":["../src/get-root-package-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAM9D;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,MAAM,KAAG,eASrD,CAAC"}
@@ -0,0 +1,19 @@
1
+ import fs from "node:fs";
2
+ import { formatDetailedError } from "@release-change/shared";
3
+ /**
4
+ * Gets the content of the root package manifest (aka `package.json`).
5
+ * @param path - The path to the root package file.
6
+ * @return The content of the root `package.json` as JSON if the file is found.
7
+ */
8
+ export const getRootPackageManifest = (path) => {
9
+ if (fs.existsSync(path))
10
+ return JSON.parse(fs.readFileSync(path, "utf8"));
11
+ throw formatDetailedError({
12
+ title: "Failed to get the root package manifest (`package.json`)",
13
+ message: "File not found.",
14
+ details: {
15
+ output: `fs.existsSync(${path}): false`
16
+ }
17
+ });
18
+ };
19
+ //# sourceMappingURL=get-root-package-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-root-package-manifest.js","sourceRoot":"","sources":["../src/get-root-package-manifest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAmB,EAAE;IACtE,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1E,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,0DAA0D;QACjE,OAAO,EAAE,iBAAiB;QAC1B,OAAO,EAAE;YACP,MAAM,EAAE,iBAAiB,IAAI,UAAU;SACxC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Gets the content of the root workspace manifest (aka `pnpm-workspace.yaml`).
3
+ * @param path - The path to the root workspace file.
4
+ * @return The content of the root `pnpm-workspace.yaml` if the file is found, `null` otherwise.
5
+ */
6
+ export declare const getRootPnpmWorkspaceManifest: (path: string) => string | null;
7
+ //# sourceMappingURL=get-root-pnpm-workspace-manifest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-root-pnpm-workspace-manifest.d.ts","sourceRoot":"","sources":["../src/get-root-pnpm-workspace-manifest.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,4BAA4B,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAEpE,CAAC"}
@@ -0,0 +1,10 @@
1
+ import fs from "node:fs";
2
+ /**
3
+ * Gets the content of the root workspace manifest (aka `pnpm-workspace.yaml`).
4
+ * @param path - The path to the root workspace file.
5
+ * @return The content of the root `pnpm-workspace.yaml` if the file is found, `null` otherwise.
6
+ */
7
+ export const getRootPnpmWorkspaceManifest = (path) => {
8
+ return fs.existsSync(path) ? fs.readFileSync(path, "utf8") : null;
9
+ };
10
+ //# sourceMappingURL=get-root-pnpm-workspace-manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-root-pnpm-workspace-manifest.js","sourceRoot":"","sources":["../src/get-root-pnpm-workspace-manifest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB;;;;GAIG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,IAAY,EAAiB,EAAE;IAC1E,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACpE,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ export type { PackageManager } from "./get-packages.types.js";
2
+ export { getNpmGlobPatterns } from "./get-npm-glob-patterns.js";
3
+ export { getPackageDependencies } from "./get-package-dependencies.js";
4
+ export { getPackageManager } from "./get-package-manager.js";
5
+ export { getPackageName } from "./get-package-name.js";
6
+ export { getPackageVersion } from "./get-package-version.js";
7
+ export { getPackages } from "./get-packages.js";
8
+ export { getPnpmGlobPatterns } from "./get-pnpm-glob-patterns.js";
9
+ export { getRootPackageManifest } from "./get-root-package-manifest.js";
10
+ export { getRootPnpmWorkspaceManifest } from "./get-root-pnpm-workspace-manifest.js";
11
+ export { isMonorepo } from "./is-monorepo.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,11 @@
1
+ export { getNpmGlobPatterns } from "./get-npm-glob-patterns.js";
2
+ export { getPackageDependencies } from "./get-package-dependencies.js";
3
+ export { getPackageManager } from "./get-package-manager.js";
4
+ export { getPackageName } from "./get-package-name.js";
5
+ export { getPackageVersion } from "./get-package-version.js";
6
+ export { getPackages } from "./get-packages.js";
7
+ export { getPnpmGlobPatterns } from "./get-pnpm-glob-patterns.js";
8
+ export { getRootPackageManifest } from "./get-root-package-manifest.js";
9
+ export { getRootPnpmWorkspaceManifest } from "./get-root-pnpm-workspace-manifest.js";
10
+ export { isMonorepo } from "./is-monorepo.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,uCAAuC,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Package } from "@release-change/shared/";
2
+ /**
3
+ * Checks whether the current directory is a monorepo, based on the number of packages.
4
+ * @param packages - The list of packages.
5
+ * @return `true` if there are more than one package, `false` otherwise.
6
+ */
7
+ export declare const isMonorepo: (packages: Package[]) => boolean;
8
+ //# sourceMappingURL=is-monorepo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-monorepo.d.ts","sourceRoot":"","sources":["../src/is-monorepo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAIvD;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,UAAU,OAAO,EAAE,YAU7C,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { formatDetailedError } from "@release-change/shared";
2
+ /**
3
+ * Checks whether the current directory is a monorepo, based on the number of packages.
4
+ * @param packages - The list of packages.
5
+ * @return `true` if there are more than one package, `false` otherwise.
6
+ */
7
+ export const isMonorepo = (packages) => {
8
+ const { length } = packages;
9
+ if (length)
10
+ return length > 1;
11
+ throw formatDetailedError({
12
+ title: "Failed to check whether the current directory is a monorepo",
13
+ message: "There must be at least one package.",
14
+ details: {
15
+ output: "packages.length: 0"
16
+ }
17
+ });
18
+ };
19
+ //# sourceMappingURL=is-monorepo.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"is-monorepo.js","sourceRoot":"","sources":["../src/is-monorepo.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,QAAmB,EAAE,EAAE;IAChD,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAC5B,IAAI,MAAM;QAAE,OAAO,MAAM,GAAG,CAAC,CAAC;IAC9B,MAAM,mBAAmB,CAAC;QACxB,KAAK,EAAE,6DAA6D;QACpE,OAAO,EAAE,qCAAqC;QAC9C,OAAO,EAAE;YACP,MAAM,EAAE,oBAAoB;SAC7B;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Converts a pattern with globs to a regular expression.
3
+ * @param pattern - The pattern to convert.
4
+ * @return The regular expression corresponding to the pattern.
5
+ */
6
+ export declare const patternToRegex: (pattern: string) => RegExp;
7
+ //# sourceMappingURL=pattern-to-regex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern-to-regex.d.ts","sourceRoot":"","sources":["../src/pattern-to-regex.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,SAAS,MAAM,KAAG,MAGhD,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Converts a pattern with globs to a regular expression.
3
+ * @param pattern - The pattern to convert.
4
+ * @return The regular expression corresponding to the pattern.
5
+ */
6
+ export const patternToRegex = (pattern) => {
7
+ const regex = pattern.replace(/\*{2}/g, ".*").replace(/(?<!\.)\*/g, "[^/]*");
8
+ return new RegExp(regex);
9
+ };
10
+ //# sourceMappingURL=pattern-to-regex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pattern-to-regex.js","sourceRoot":"","sources":["../src/pattern-to-regex.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,OAAe,EAAU,EAAE;IACxD,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC7E,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@release-change/get-packages",
3
+ "version": "0.1.0",
4
+ "description": "Functions used internally in release-change to get the packages from a monorepo",
5
+ "keywords": [],
6
+ "homepage": "https://github.com/release-change/release-change",
7
+ "bugs": {
8
+ "url": "https://github.com/release-change/release-change/issues"
9
+ },
10
+ "author": "Victor Brito (https://victor-brito.dev)",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/release-change/release-change.git"
14
+ },
15
+ "type": "module",
16
+ "license": "MIT",
17
+ "files": [
18
+ "dist"
19
+ ],
20
+ "exports": {
21
+ "import": "./dist/index.js",
22
+ "types": "./dist/index.d.ts"
23
+ },
24
+ "engines": {
25
+ "node": "^20.18.3 || ^22.12.0 || ^24.0.0",
26
+ "npm": ">=10.8.2",
27
+ "pnpm": ">=10.28.0"
28
+ },
29
+ "dependencies": {
30
+ "@release-change/logger": "0.1.0",
31
+ "@release-change/shared": "0.1.0",
32
+ "@release-change/config": "0.1.0"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc",
36
+ "dev": "tsc --watch --preserveWatchOutput & vitest"
37
+ }
38
+ }