yarn-version 8.6.1 → 8.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/index-node.mjs +257 -230
  3. package/dist/index-node.mjs.map +1 -1
  4. package/package.json +7 -12
  5. package/src/__fixtures__/monorepo-duplicate-names/package.json +7 -0
  6. package/src/__fixtures__/monorepo-duplicate-names/packages/pkg-a/package.json +4 -0
  7. package/src/__fixtures__/monorepo-duplicate-names/packages/pkg-b/package.json +4 -0
  8. package/src/__fixtures__/monorepo-invalid-package-json/package.json +7 -0
  9. package/src/__fixtures__/monorepo-invalid-package-json/packages/pkg-with-invalid-json/package.json +5 -0
  10. package/src/__fixtures__/monorepo-nested/package.json +9 -0
  11. package/src/__fixtures__/monorepo-nested/packages/deep-nested/package.json +4 -0
  12. package/src/__fixtures__/monorepo-nested/packages/nested-1/packages/package-nested.json +4 -0
  13. package/src/__fixtures__/monorepo-nested/packages/nested-1/packages/package.json +4 -0
  14. package/src/__fixtures__/monorepo-nested/packages/package-1/package.json +4 -0
  15. package/src/__fixtures__/monorepo-no-name/package.json +7 -0
  16. package/src/__fixtures__/monorepo-no-name/packages/no-name-package/package.json +3 -0
  17. package/src/__fixtures__/monorepo-object-form/package.json +9 -0
  18. package/src/__fixtures__/monorepo-object-form/packages/package-1/package.json +4 -0
  19. package/src/__fixtures__/monorepo-object-form/packages/package-2/package.json +4 -0
  20. package/src/__fixtures__/monorepo-object-form/packages/package-3/package.json +4 -0
  21. package/src/__fixtures__/monorepo-object-form/packages/package-4/package.json +4 -0
  22. package/src/__fixtures__/monorepo-object-form/packages/package-5/package.json +4 -0
  23. package/src/commands/version.test.ts +14 -8
  24. package/src/commands/version.ts +269 -273
  25. package/src/missing-types.d.ts +0 -1
  26. package/src/utils/conventionalChangelogUtils.test.ts +1 -0
  27. package/src/utils/mapWorkspaces.test.ts +89 -0
  28. package/src/utils/packageDependenciesUtils.test.ts +1 -0
  29. package/src/utils/packageUtils.test.ts +32 -0
  30. package/src/utils/packageUtils.ts +52 -22
  31. package/tsconfig.json +1 -3
@@ -0,0 +1,89 @@
1
+ import path from "node:path";
2
+ import { describe, expect, it } from "vitest";
3
+ import { createProjectWorkspace, createWorkspace } from "./packageUtils.ts";
4
+
5
+ const toAbs = (p: string) => path.resolve(p);
6
+
7
+ const fixturesRoot = path.resolve(
8
+ new URL("../__fixtures__", import.meta.url).pathname,
9
+ );
10
+
11
+ describe("mapWorkspaces - baseline checks", () => {
12
+ it("should map packages for array workspaces (monorepo)", async () => {
13
+ const root = path.join(fixturesRoot, "monorepo");
14
+
15
+ const rootWorkspace = await createWorkspace(root);
16
+ const project = await createProjectWorkspace(rootWorkspace);
17
+ const keys = [...project.children.keys()].toSorted();
18
+
19
+ expect(keys.length).toBe(5);
20
+ expect(keys).toContain("package-1");
21
+ expect(keys).toContain("package-2");
22
+ expect(project.children.get("package-1")!.cwd).toBe(
23
+ toAbs(path.join(root, "packages/package-1")),
24
+ );
25
+ });
26
+
27
+ it("should map packages for object workspaces (monorepo-object-form)", async () => {
28
+ const root = path.join(fixturesRoot, "monorepo-object-form");
29
+ const rootWorkspace = await createWorkspace(root);
30
+ const project = await createProjectWorkspace(rootWorkspace);
31
+ const keys = [...project.children.keys()].toSorted();
32
+ expect(keys.length).toBe(5);
33
+ });
34
+
35
+ it("should map nested patterns and double star patterns", async () => {
36
+ const root = path.join(fixturesRoot, "monorepo-nested");
37
+ const rootWorkspace = await createWorkspace(root);
38
+ const project = await createProjectWorkspace(rootWorkspace);
39
+ const keys = [...project.children.keys()];
40
+ expect(keys).toContain("nested-package-1");
41
+ expect(keys).toContain("nested-package-2");
42
+ expect(keys).toContain("deep-nested-package");
43
+ });
44
+
45
+ it("should fallback to folder name when package.json has no name", async () => {
46
+ const root = path.join(fixturesRoot, "monorepo-no-name");
47
+ const rootWorkspace = await createWorkspace(root);
48
+ const project = await createProjectWorkspace(rootWorkspace);
49
+ const keys = [...project.children.keys()];
50
+ expect(keys).toContain("no-name-package");
51
+ });
52
+
53
+ it("should throw when duplicate workspace names exist (baseline behavior)", async () => {
54
+ const root = path.join(fixturesRoot, "monorepo-duplicate-names");
55
+ const rootWorkspace = await createWorkspace(root);
56
+ let thrown = false;
57
+ try {
58
+ await createProjectWorkspace(rootWorkspace);
59
+ } catch {
60
+ thrown = true;
61
+ }
62
+ expect(thrown).toBe(true);
63
+ });
64
+
65
+ it("should expose an error or skip invalid package.json (baseline behavior)", async () => {
66
+ const root = path.join(fixturesRoot, "monorepo-invalid-package-json");
67
+ const rootWorkspace = await createWorkspace(root);
68
+ // Ensure it throws or skips: we'll try to call createProjectWorkspace and assert throw
69
+ let thrown = false;
70
+ try {
71
+ await createProjectWorkspace(rootWorkspace);
72
+ } catch {
73
+ thrown = true;
74
+ }
75
+ // Accept either behavior as baseline: ensure we detect if it currently throws.
76
+ // We assert that at least it doesn't silently include the invalid package by name
77
+ // so if it didn't throw, ensure the invalid package isn't listed
78
+ if (!thrown) {
79
+ const project = await createProjectWorkspace(rootWorkspace);
80
+ const keys = [...project.children.keys()];
81
+ expect(keys).not.toContain("invalid-json-package");
82
+ }
83
+ });
84
+
85
+ it("should have node:fs/promises glob available (engine requirement)", async () => {
86
+ const fsp = await import("node:fs/promises");
87
+ expect(typeof (fsp as any).glob).toBe("function");
88
+ });
89
+ });
@@ -1,3 +1,4 @@
1
+ import { describe, expect, it } from "vitest";
1
2
  import { PackageDependencyDescriptorUtils } from "./packageDependenciesUtils.ts";
2
3
 
3
4
  describe("PackageDependencyDescriptorUtils.parse", () => {
@@ -0,0 +1,32 @@
1
+ import path from "node:path";
2
+ import { describe, expect, it } from "vitest";
3
+ import {
4
+ createProjectWorkspace,
5
+ createWorkspace,
6
+ findRootWorkspace,
7
+ } from "./packageUtils.ts";
8
+
9
+ const fixturesRoot = path.resolve(
10
+ new URL("../__fixtures__", import.meta.url).pathname,
11
+ );
12
+
13
+ describe("packageUtils integration", () => {
14
+ it("findRootWorkspace finds root from subpackage path", async () => {
15
+ const subPath = path.join(fixturesRoot, "monorepo/packages/package-1");
16
+ const root = await findRootWorkspace(subPath);
17
+ expect(root).toBeTruthy();
18
+ expect(root!.pkg.name).toBe("monorepo");
19
+ });
20
+
21
+ it("createProjectWorkspace returns children and correct relativeCwd", async () => {
22
+ const rootPath = path.join(fixturesRoot, "monorepo");
23
+ const rootWorkspace = await createWorkspace(rootPath);
24
+ const project = await createProjectWorkspace(rootWorkspace);
25
+ const children = [...project.children.values()];
26
+ expect(children.length).toBe(5);
27
+ // Check a sample relativeCwd
28
+ const pkg1 = project.children.get("package-1");
29
+ expect(pkg1).toBeTruthy();
30
+ expect(pkg1!.relativeCwd).toBe("packages/package-1");
31
+ });
32
+ });
@@ -1,8 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-use-before-define */
2
- import fs from "node:fs/promises";
2
+ // eslint-disable-next-line n/no-unsupported-features/node-builtins
3
+ import fs, { glob } from "node:fs/promises";
3
4
  import path from "node:path";
4
- import mapWorkspaces from "@npmcli/map-workspaces";
5
- import prettyPkg from "@pob/pretty-pkg";
6
5
  import type { PackageJson } from "type-fest";
7
6
 
8
7
  export interface Workspace {
@@ -16,26 +15,60 @@ export interface ProjectWorkspace {
16
15
  readonly children: Map<string, Workspace>;
17
16
  }
18
17
 
18
+ async function mapWorkspacesFromPkg({
19
+ cwd,
20
+ pkg,
21
+ }: {
22
+ cwd: string;
23
+ pkg: PackageJson;
24
+ }): Promise<Map<string, Workspace>> {
25
+ const workspacesPatterns: string[] = Array.isArray(pkg.workspaces)
26
+ ? pkg.workspaces
27
+ : pkg.workspaces?.packages || [];
28
+
29
+ const map = new Map<string, Workspace>();
30
+
31
+ for (const pattern of workspacesPatterns) {
32
+ const normalized = pattern.endsWith("package.json")
33
+ ? pattern
34
+ : `${pattern.replace(/\/*$/, "")}/package.json`;
35
+
36
+ const files = glob(normalized, { cwd });
37
+ for await (const file of files) {
38
+ const packageDir = path.join(cwd, path.dirname(file));
39
+ const packageJson: PackageJson = await readPkg(packageDir);
40
+ const workspaceName = packageJson.name || path.basename(packageDir);
41
+ if (map.has(workspaceName)) {
42
+ const existingWorkspace = map.get(workspaceName);
43
+ if (existingWorkspace && existingWorkspace.cwd !== packageDir) {
44
+ throw new Error(
45
+ `must not have multiple workspaces with the same name\npackage '${workspaceName}' has conflicts in the following paths:\n ${existingWorkspace.cwd}\n ${packageDir}`,
46
+ );
47
+ }
48
+ // if it's the same package dir, ignore duplicate match
49
+ if (existingWorkspace && existingWorkspace.cwd === packageDir) continue;
50
+ }
51
+ map.set(workspaceName, { cwd: packageDir, pkg: packageJson });
52
+ }
53
+ }
54
+ return map;
55
+ }
56
+
19
57
  export const createProjectWorkspace = async (
20
58
  root: Workspace,
21
59
  ): Promise<ProjectWorkspace> => {
22
- const map: Map<string, string> = root.pkg.workspaces
23
- ? await mapWorkspaces({ cwd: root.cwd, pkg: root.pkg })
60
+ const map: Map<string, Workspace> = root.pkg.workspaces
61
+ ? await mapWorkspacesFromPkg({ cwd: root.cwd, pkg: root.pkg })
24
62
  : new Map();
25
63
 
26
64
  const children = new Map<string, Workspace>(
27
- await Promise.all(
28
- [...map.entries()].map(
29
- async ([packageName, packagePath]) =>
30
- [
31
- packageName,
32
- {
33
- ...(await createWorkspace(packagePath)),
34
- relativeCwd: path.relative(root.cwd, packagePath),
35
- } satisfies Workspace,
36
- ] as const,
37
- ),
38
- ),
65
+ [...map.entries()].map(([packageName, workspace]) => {
66
+ const w: Workspace = {
67
+ ...workspace,
68
+ relativeCwd: path.relative(root.cwd, workspace.cwd),
69
+ };
70
+ return [packageName, w] as const;
71
+ }),
39
72
  );
40
73
  return { root, children };
41
74
  };
@@ -71,11 +104,8 @@ export const createWorkspace = async (path: string): Promise<Workspace> => {
71
104
  return { cwd: path, pkg };
72
105
  };
73
106
 
74
- export async function writePkg(
75
- workspace: Workspace,
76
- prettierOptions = undefined,
77
- ): Promise<void> {
78
- const string = await prettyPkg(workspace.pkg, prettierOptions);
107
+ export async function writePkg(workspace: Workspace): Promise<void> {
108
+ const string = `${JSON.stringify(workspace.pkg, null, 2)}\n`;
79
109
  await fs.writeFile(getPackageJsonPath(workspace.cwd), string, "utf8");
80
110
  }
81
111
 
package/tsconfig.json CHANGED
@@ -15,9 +15,7 @@
15
15
 
16
16
  "paths": {
17
17
  "@pob/rollup-esbuild": ["../../@pob/rollup-esbuild/lib"],
18
- "@pob/rollup-esbuild/*": ["../../@pob/rollup-esbuild/lib/*"],
19
- "@pob/pretty-pkg": ["../../@pob/pretty-pkg/lib"],
20
- "@pob/pretty-pkg/*": ["../../@pob/pretty-pkg/lib/*"]
18
+ "@pob/rollup-esbuild/*": ["../../@pob/rollup-esbuild/lib/*"]
21
19
  }
22
20
  }
23
21
  }