yarn-version 8.7.1 → 9.0.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 (62) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +2 -152
  3. package/package.json +8 -33
  4. package/yarn-version.mjs +3 -0
  5. package/dist/index-node.mjs +0 -1276
  6. package/dist/index-node.mjs.map +0 -1
  7. package/rollup.config.mjs +0 -12
  8. package/src/__fixtures__/basic/package.json +0 -4
  9. package/src/__fixtures__/basic/yarn.lock +0 -12
  10. package/src/__fixtures__/monorepo/package.json +0 -7
  11. package/src/__fixtures__/monorepo/packages/package-1/package.json +0 -4
  12. package/src/__fixtures__/monorepo/packages/package-2/package.json +0 -7
  13. package/src/__fixtures__/monorepo/packages/package-3/package.json +0 -7
  14. package/src/__fixtures__/monorepo/packages/package-4/package.json +0 -7
  15. package/src/__fixtures__/monorepo/packages/package-5/package.json +0 -8
  16. package/src/__fixtures__/monorepo/yarn.lock +0 -0
  17. package/src/__fixtures__/monorepo-duplicate-names/package.json +0 -7
  18. package/src/__fixtures__/monorepo-duplicate-names/packages/pkg-a/package.json +0 -4
  19. package/src/__fixtures__/monorepo-duplicate-names/packages/pkg-b/package.json +0 -4
  20. package/src/__fixtures__/monorepo-invalid-package-json/package.json +0 -7
  21. package/src/__fixtures__/monorepo-invalid-package-json/packages/pkg-with-invalid-json/package.json +0 -5
  22. package/src/__fixtures__/monorepo-nested/package.json +0 -9
  23. package/src/__fixtures__/monorepo-nested/packages/deep-nested/package.json +0 -4
  24. package/src/__fixtures__/monorepo-nested/packages/nested-1/packages/package-nested.json +0 -4
  25. package/src/__fixtures__/monorepo-nested/packages/nested-1/packages/package.json +0 -4
  26. package/src/__fixtures__/monorepo-nested/packages/package-1/package.json +0 -4
  27. package/src/__fixtures__/monorepo-no-name/package.json +0 -7
  28. package/src/__fixtures__/monorepo-no-name/packages/no-name-package/package.json +0 -3
  29. package/src/__fixtures__/monorepo-object-form/package.json +0 -9
  30. package/src/__fixtures__/monorepo-object-form/packages/package-1/package.json +0 -4
  31. package/src/__fixtures__/monorepo-object-form/packages/package-2/package.json +0 -4
  32. package/src/__fixtures__/monorepo-object-form/packages/package-3/package.json +0 -4
  33. package/src/__fixtures__/monorepo-object-form/packages/package-4/package.json +0 -4
  34. package/src/__fixtures__/monorepo-object-form/packages/package-5/package.json +0 -4
  35. package/src/__fixtures__/no-version/package.json +0 -3
  36. package/src/__fixtures__/no-version/yarn.lock +0 -0
  37. package/src/__fixtures__/with-lifecycle/.yarn/install-state.gz +0 -0
  38. package/src/__fixtures__/with-lifecycle/package.json +0 -7
  39. package/src/__fixtures__/with-lifecycle/yarn.lock +0 -11
  40. package/src/commands/version.test.ts +0 -95
  41. package/src/commands/version.ts +0 -902
  42. package/src/index.ts +0 -13
  43. package/src/missing-types.d.ts +0 -10
  44. package/src/utils/UsageError.ts +0 -6
  45. package/src/utils/bumpTypeUtils.ts +0 -113
  46. package/src/utils/conventionalChangelogUtils.test.ts +0 -762
  47. package/src/utils/conventionalChangelogUtils.ts +0 -104
  48. package/src/utils/conventionalCommitConfigUtils.ts +0 -20
  49. package/src/utils/execCommand.ts +0 -189
  50. package/src/utils/generatorUtils.ts +0 -11
  51. package/src/utils/gitUtils.ts +0 -193
  52. package/src/utils/githubUtils.ts +0 -82
  53. package/src/utils/mapUtils.ts +0 -7
  54. package/src/utils/mapWorkspaces.test.ts +0 -89
  55. package/src/utils/packageDependenciesUtils.test.ts +0 -25
  56. package/src/utils/packageDependenciesUtils.ts +0 -80
  57. package/src/utils/packageUtils.test.ts +0 -32
  58. package/src/utils/packageUtils.ts +0 -127
  59. package/src/utils/updateChangelog.ts +0 -39
  60. package/src/utils/workspaceUtils.ts +0 -142
  61. package/tsconfig.json +0 -21
  62. package/vitest.config.js +0 -9
@@ -1,104 +0,0 @@
1
- import { writeChangelogString } from "conventional-changelog-writer";
2
- import { parseCommits as createConventionalCommitsParser } from "conventional-commits-parser";
3
- import type { Commit, ParserStreamOptions } from "conventional-commits-parser";
4
- import type { PackageJson } from "type-fest";
5
- import type { ConventionalChangelogConfig } from "./conventionalCommitConfigUtils.ts";
6
- import type { Workspace } from "./packageUtils.ts";
7
-
8
- export interface WhatBump {
9
- level: 0 | 1 | 2;
10
- reason: string;
11
- }
12
- export type WhatBumpResult = WhatBump | null | undefined;
13
- export interface BumperRecommendation extends WhatBump {
14
- releaseType: "major" | "minor" | "patch";
15
- commits: Commit[];
16
- }
17
- export interface EmptyBumperRecommendation {
18
- commits: Commit[];
19
- }
20
- export type BumperRecommendationResult =
21
- | BumperRecommendation
22
- | EmptyBumperRecommendation;
23
-
24
- export interface Preset {
25
- whatBump: (commits: Commit[]) => Promise<WhatBumpResult> | WhatBumpResult;
26
- tags?: unknown;
27
- commits?: unknown;
28
- parser?: ParserStreamOptions;
29
- }
30
-
31
- const versions: BumperRecommendation["releaseType"][] = [
32
- "major",
33
- "minor",
34
- "patch",
35
- ];
36
-
37
- export const recommendBump = async (
38
- commits: Parameters<ConventionalChangelogConfig["whatBump"]>[0],
39
- config: ConventionalChangelogConfig,
40
- ): Promise<Partial<BumperRecommendation>> => {
41
- const whatBump = config.whatBump;
42
- if (!whatBump) {
43
- throw new Error("whatBump method is missing in config");
44
- }
45
- const result = { ...(await whatBump(commits)) };
46
-
47
- return {
48
- ...result,
49
- releaseType: result.level != null ? versions[result.level] : undefined,
50
- };
51
- };
52
-
53
- export type Commits = Parameters<ConventionalChangelogConfig["whatBump"]>[0];
54
-
55
- export const generateChangelog = (
56
- workspace: Workspace,
57
- pkg: PackageJson,
58
- config: ConventionalChangelogConfig,
59
- previousTag: string | null,
60
- newTag: string | null,
61
- commits: Commits | undefined,
62
- date: string,
63
- // eslint-disable-next-line @typescript-eslint/max-params
64
- ): Promise<string> => {
65
- if (!newTag) {
66
- throw new Error(`Missing new tag for package "${pkg.name ?? ""}"`);
67
- }
68
-
69
- const originUrl =
70
- typeof pkg.repository === "string" ? pkg.repository : pkg.repository?.url;
71
- const match =
72
- originUrl &&
73
- typeof originUrl === "string" &&
74
- /^(?:git@|https?:\/\/)(?:([^./:]+(?:\.com)?)[/:])?([^/:]+)\/([^./:]+)(?:.git)?/.exec(
75
- originUrl,
76
- );
77
- const [, gitHost, gitAccount, repoName] = match || [
78
- undefined,
79
- undefined,
80
- undefined,
81
- undefined,
82
- ];
83
-
84
- return writeChangelogString(
85
- commits ?? [],
86
- {
87
- // @ts-expect-error - missing types
88
- previousTag,
89
- currentTag: newTag,
90
- linkCompare: previousTag != null,
91
- version: pkg.version,
92
- host: gitHost ? `https://${gitHost}` : undefined,
93
- owner: gitAccount,
94
- repository: repoName,
95
- date,
96
- },
97
- // @ts-expect-error - missing types
98
- config.writer,
99
- );
100
- };
101
-
102
- export const createCommitsParser = (config: ConventionalChangelogConfig) => {
103
- return createConventionalCommitsParser(config.parser);
104
- };
@@ -1,20 +0,0 @@
1
- // eslint-disable-next-line import/no-unresolved
2
- import { loadPreset } from "conventional-changelog-preset-loader";
3
- import { UsageError } from "./UsageError.ts";
4
- import type { Preset } from "./conventionalChangelogUtils.ts";
5
- import type { Workspace } from "./packageUtils.ts";
6
-
7
- export type ConventionalChangelogConfig = Preset;
8
-
9
- export const loadConventionalCommitConfig = async (
10
- rootWorkspace: Workspace,
11
- preset: string,
12
- ): Promise<ConventionalChangelogConfig> => {
13
- try {
14
- return await loadPreset<ConventionalChangelogConfig>(preset);
15
- } catch (error: any) {
16
- throw new UsageError(
17
- `Failed to require preset "${preset}": ${error.message as string}`,
18
- );
19
- }
20
- };
@@ -1,189 +0,0 @@
1
- import childProcess from "node:child_process";
2
- import type { Workspace } from "./packageUtils.ts";
3
-
4
- interface ExecResultIfFailed {
5
- code: number | null;
6
- signal: string | null;
7
- stdout: string;
8
- stderr: string;
9
- }
10
-
11
- interface ExecResultIfSuccess {
12
- code: null;
13
- signal: null;
14
- stdout: string;
15
- stderr: string;
16
- }
17
-
18
- type ExecResult<Strict extends boolean> = Strict extends true
19
- ? ExecResultIfSuccess
20
- : ExecResultIfFailed;
21
-
22
- async function execvp<const Strict extends boolean>(
23
- command: string,
24
- args: string[],
25
- {
26
- cwd = process.cwd(),
27
- env = process.env,
28
- encoding,
29
- strict,
30
- stdo = "pipe",
31
- }: {
32
- cwd?: string;
33
- env?: typeof process.env;
34
- encoding?: BufferEncoding;
35
- strict?: Strict;
36
- stdo?: "inherit" | "pipe";
37
- },
38
- ): Promise<ExecResult<Strict>> {
39
- const stdoutChunks: Uint8Array[] = [];
40
- const stderrChunks: Uint8Array[] = [];
41
- if (env.PWD !== undefined) {
42
- env = { ...env, PWD: cwd };
43
- }
44
- const subprocess = childProcess.spawn(command, args, {
45
- cwd,
46
- env,
47
- stdio: ["ignore", stdo, stdo],
48
- });
49
- subprocess.stdout?.on("data", (chunk) => {
50
- stdoutChunks.push(chunk);
51
- });
52
- subprocess.stderr?.on("data", (chunk) => {
53
- stderrChunks.push(chunk);
54
- });
55
- return new Promise((resolve, reject) => {
56
- subprocess.on("error", (err) => {
57
- reject(new Error(`Process ${command} failed to spawn`));
58
- });
59
- subprocess.on("close", (code, signal) => {
60
- const chunksToString = (chunks: Uint8Array[]): string =>
61
- stdo === "inherit"
62
- ? ""
63
- : Buffer.concat(chunks).toString(encoding ?? "utf8");
64
- const stdout = chunksToString(stdoutChunks);
65
- const stderr = chunksToString(stderrChunks);
66
- if (code === 0 || !strict) {
67
- resolve({
68
- code,
69
- signal,
70
- stdout,
71
- stderr,
72
- } as ExecResult<Strict>);
73
- } else {
74
- reject(
75
- new Error(
76
- `Process ${[command, ...args].join(" ")} exited ${code !== null ? `with code ${code}` : `with signal ${signal || ""}`}:\nstdout: ${stdout}\nstderr: ${stderr}`,
77
- ),
78
- );
79
- }
80
- });
81
- });
82
- }
83
-
84
- async function* spawnStreamStdout<const Strict extends boolean>(
85
- command: string,
86
- args: string[],
87
- {
88
- cwd = process.cwd(),
89
- env = process.env,
90
- encoding,
91
- strict,
92
- separator,
93
- }: {
94
- cwd?: string;
95
- env?: typeof process.env;
96
- encoding?: BufferEncoding;
97
- strict?: Strict;
98
- separator: string;
99
- },
100
- ): AsyncGenerator<string, ExecResult<Strict>, unknown> {
101
- const stderrChunks: Uint8Array[] = [];
102
- if (env.PWD !== undefined) {
103
- env = { ...env, PWD: cwd };
104
- }
105
- const subprocess = childProcess.spawn(command, args, {
106
- cwd,
107
- env,
108
- stdio: ["ignore", "pipe", "pipe"],
109
- });
110
-
111
- subprocess.stderr.on("data", (chunk) => {
112
- stderrChunks.push(chunk);
113
- });
114
-
115
- let chunk: Buffer;
116
- let payload: string[];
117
- let buffer = "";
118
-
119
- for await (chunk of subprocess.stdout) {
120
- buffer += chunk.toString();
121
-
122
- if (buffer.includes(separator)) {
123
- payload = buffer.split(separator);
124
- buffer = payload.pop() || "";
125
-
126
- yield* payload;
127
- }
128
- }
129
-
130
- if (buffer) {
131
- yield buffer;
132
- }
133
-
134
- return new Promise((resolve, reject) => {
135
- subprocess.on("error", (err) => {
136
- reject(new Error(`Process ${command} failed to spawn`));
137
- });
138
- subprocess.on("close", (code, signal) => {
139
- const chunksToString = (chunks: Uint8Array[]): string =>
140
- Buffer.concat(chunks).toString(encoding ?? "utf8");
141
- const stderr = chunksToString(stderrChunks);
142
- if (code === 0 || !strict) {
143
- resolve({
144
- code,
145
- signal,
146
- stderr,
147
- } as ExecResult<Strict>);
148
- } else {
149
- reject(
150
- new Error(
151
- `Process ${[command, ...args].join(" ")} exited ${code !== null ? `with code ${code}` : `with signal ${signal || ""}`}:\nstderr: ${stderr}`,
152
- ),
153
- );
154
- }
155
- });
156
- });
157
- }
158
-
159
- export const execCommand = (
160
- workspace: Workspace,
161
- commandAndArgs: string[] = [],
162
- stdo: "inherit" | "pipe" = "pipe",
163
- ): ReturnType<typeof execvp> => {
164
- const [command, ...args] = commandAndArgs;
165
- if (command === undefined) {
166
- throw new Error("Command is required");
167
- }
168
- return execvp(command, args, {
169
- cwd: workspace.cwd,
170
- strict: true,
171
- stdo,
172
- });
173
- };
174
-
175
- export const execCommandStreamStdout = (
176
- workspace: Workspace,
177
- commandAndArgs: string[] = [],
178
- separator = "\n",
179
- ): AsyncGenerator<string, ExecResult<true>, unknown> => {
180
- const [command, ...args] = commandAndArgs;
181
- if (command === undefined) {
182
- throw new Error("Command is required");
183
- }
184
- return spawnStreamStdout(command, args, {
185
- cwd: workspace.cwd,
186
- strict: true,
187
- separator,
188
- });
189
- };
@@ -1,11 +0,0 @@
1
- export async function asyncIterableToArray<T>(
2
- asyncIterable: AsyncIterable<T>,
3
- ): Promise<T[]> {
4
- const result: T[] = [];
5
-
6
- for await (const value of asyncIterable) {
7
- result.push(value);
8
- }
9
-
10
- return result;
11
- }
@@ -1,193 +0,0 @@
1
- import semver from "semver";
2
- import { UsageError } from "./UsageError.ts";
3
- import { execCommand, execCommandStreamStdout } from "./execCommand.ts";
4
- import type { Workspace } from "./packageUtils.ts";
5
-
6
- export const getGitCurrentBranch = async (
7
- workspace: Workspace,
8
- ): Promise<string> => {
9
- const { stdout } = await execCommand(workspace, [
10
- "git",
11
- "rev-parse",
12
- "--abbrev-ref",
13
- "HEAD",
14
- ]);
15
- const currentBranch = stdout.trim();
16
-
17
- if (currentBranch === "HEAD") {
18
- throw new UsageError("HEAD is detached. Please checkout a branch.");
19
- }
20
-
21
- return currentBranch;
22
- };
23
-
24
- export const createGitCommit = async (
25
- workspace: Workspace,
26
- commitMessage: string,
27
- ): Promise<void> => {
28
- await execCommand(workspace, ["git", "add", "-A"]);
29
-
30
- await execCommand(workspace, [
31
- "git",
32
- "commit",
33
- "--no-verify",
34
- "-m",
35
- commitMessage,
36
- ]);
37
- };
38
-
39
- export const createGitTag = async (
40
- workspace: Workspace,
41
- newTag: string,
42
- ): Promise<void> => {
43
- await execCommand(workspace, ["git", "tag", newTag, "-m", newTag]);
44
- };
45
-
46
- export const pushCommitsAndTags = async (
47
- workspace: Workspace,
48
- gitRemote: string,
49
- currentBranch: string,
50
- ): Promise<void> => {
51
- await execCommand(workspace, [
52
- "git",
53
- "push",
54
- "--follow-tags",
55
- "--no-verify",
56
- "--atomic",
57
- gitRemote,
58
- currentBranch,
59
- ]);
60
- };
61
-
62
- export const isBehindRemote = async (
63
- workspace: Workspace,
64
- gitRemote: string,
65
- currentBranch: string,
66
- ): Promise<boolean> => {
67
- await execCommand(workspace, ["git", "remote", "update", gitRemote]);
68
- const { stdout } = await execCommand(workspace, [
69
- "git",
70
- "rev-list",
71
- "--left-right",
72
- "--count",
73
- `${gitRemote}/${currentBranch}..${currentBranch}`,
74
- ]);
75
-
76
- const [behind] = stdout.split("\t").map((val) => parseInt(val, 10));
77
-
78
- return behind ? behind > 0 : false;
79
- };
80
-
81
- export const getDirtyFiles = async (workspace: Workspace): Promise<string> => {
82
- const { stdout: dirtyFiles } = await execCommand(workspace, [
83
- "git",
84
- "status",
85
- "--porcelain",
86
- ]);
87
- return dirtyFiles;
88
- };
89
-
90
- const toArray = <T>(input: T | T[]): T[] =>
91
- Array.isArray(input) ? input : [input];
92
-
93
- export interface GitTagVersion {
94
- tag: string;
95
- version: string;
96
- }
97
-
98
- export const getGitLatestTagVersion = async (
99
- workspace: Workspace,
100
- {
101
- prefix,
102
- skipUnstable,
103
- since,
104
- from = "",
105
- to = "HEAD",
106
- path,
107
- }: {
108
- prefix?: string;
109
- skipUnstable?: boolean;
110
- since?: Date | string;
111
- from?: string;
112
- to?: string;
113
- path?: string[] | string;
114
- } = {},
115
- ): Promise<GitTagVersion | null> => {
116
- // eslint-disable-next-line regexp/no-super-linear-backtracking
117
- const tagRegex = /tag:\s*(.+?)[,)]/gi;
118
- for await (const chunk of execCommandStreamStdout(workspace, [
119
- "git",
120
- "log",
121
- "--no-color",
122
- "--date-order",
123
- "--format=%d",
124
- ...(since
125
- ? [`--since=${since instanceof Date ? since.toISOString() : since}`]
126
- : []),
127
- [from, to].filter(Boolean).join(".."),
128
- ...(path ? ["--", ...toArray(path)] : []),
129
- ])) {
130
- const trimmed = chunk.trim();
131
- if (!trimmed) continue;
132
- const matches = trimmed.matchAll(tagRegex);
133
- for (const match of matches) {
134
- const tag = match[1];
135
- if (!tag) continue;
136
- if (prefix && !tag.startsWith(prefix)) {
137
- continue;
138
- }
139
- const version = prefix ? tag.slice(prefix.length) : tag;
140
- if (!semver.valid(version)) {
141
- continue;
142
- }
143
- if (skipUnstable && semver.prerelease(version)) {
144
- continue;
145
- }
146
- return { tag, version };
147
- }
148
- }
149
-
150
- return null;
151
- };
152
-
153
- const GIT_COMMIT_SEPARATOR =
154
- "------------------------ >8 ------------------------";
155
-
156
- export const getGitCommits = (
157
- workspace: Workspace,
158
- {
159
- path,
160
- from = "",
161
- to = "HEAD",
162
- format = "%B",
163
- reverse,
164
- merges,
165
- since,
166
- }: {
167
- format?: string;
168
- path?: string[] | string;
169
- from?: string;
170
- to?: string;
171
- reverse?: boolean;
172
- merges?: boolean;
173
- since?: Date | string;
174
- } = {},
175
- ) => {
176
- return execCommandStreamStdout(
177
- workspace,
178
- [
179
- "git",
180
- "log",
181
- `--format=${format}%n${GIT_COMMIT_SEPARATOR}`,
182
- ...(since
183
- ? [`--since=${since instanceof Date ? since.toISOString() : since}`]
184
- : []),
185
- ...(reverse ? ["--reverse"] : []),
186
- ...(merges ? ["--merges"] : []),
187
- ...(merges === false ? ["--no-merges"] : []),
188
- [from, to].filter(Boolean).join(".."),
189
- ...(path ? ["--", ...toArray(path)] : []),
190
- ],
191
- GIT_COMMIT_SEPARATOR,
192
- );
193
- };
@@ -1,82 +0,0 @@
1
- // eslint-disable-next-line import/no-unresolved -- esm-only package which is not supported by import plugin.
2
- import { Octokit } from "@octokit/rest";
3
- import { UsageError } from "./UsageError.ts";
4
- import type { Workspace } from "./packageUtils.ts";
5
-
6
- export async function createGitHubClient(): Promise<Octokit> {
7
- const { GH_TOKEN, GHE_API_URL, GHE_VERSION } = process.env;
8
-
9
- if (!GH_TOKEN) {
10
- throw new UsageError(
11
- '"GH_TOKEN" environment variable required when "createRelease" is set to "github"',
12
- );
13
- }
14
-
15
- if (GHE_VERSION) {
16
- Octokit.plugin(
17
- await import(`@octokit/plugin-enterprise-rest/ghe-${GHE_VERSION}`),
18
- );
19
- }
20
-
21
- const options = {
22
- auth: `token ${GH_TOKEN}`,
23
- };
24
-
25
- if (GHE_API_URL) {
26
- // TODO: refactor based on TS feedback
27
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
28
- // @ts-expect-error
29
- options.baseUrl = GHE_API_URL;
30
- }
31
-
32
- return new Octokit(options);
33
- }
34
-
35
- interface ParsedGithubUrl {
36
- username: string;
37
- reponame: string;
38
- }
39
-
40
- const githubRegex = /^https?:\/\/github.com\/([^#/]+)\/([^#/]+?)(?:\.git)?$/;
41
- export const parseGithubRepoUrl = (workspace: Workspace): ParsedGithubUrl => {
42
- const repository = workspace.pkg.repository;
43
-
44
- const url: string | undefined =
45
- typeof repository === "string" ? repository : repository?.url;
46
-
47
- if (!url) {
48
- throw new Error(
49
- "No repository URL found in manifest. Please add one and try again. https://docs.npmjs.com/cli/v9/configuring-npm/package-json#repository",
50
- );
51
- }
52
- const match = githubRegex.exec(url);
53
-
54
- if (!match) {
55
- throw new Error(`Invalid GitHub repository URL: "${url}"`);
56
- }
57
- const [, username, reponame] = match;
58
- if (!username || !reponame) {
59
- throw new Error(`Invalid GitHub repository URL: ${url}`);
60
- }
61
- return { username, reponame };
62
- };
63
-
64
- export const createGitRelease = async (
65
- githubClient: Octokit,
66
- parsedRepoUrl: ParsedGithubUrl,
67
- tag: string,
68
- body: string,
69
- prerelease: boolean,
70
- // eslint-disable-next-line @typescript-eslint/max-params
71
- ): Promise<void> => {
72
- await githubClient.repos.createRelease({
73
- owner: parsedRepoUrl.username,
74
- repo: parsedRepoUrl.reponame,
75
- // eslint-disable-next-line camelcase
76
- tag_name: tag,
77
- name: tag,
78
- body,
79
- draft: false,
80
- prerelease,
81
- });
82
- };
@@ -1,7 +0,0 @@
1
- export function getMapArrayItemForKey<K, V>(map: Map<K, V[]>, key: K): V[] {
2
- let value: V[] | undefined = map.get(key);
3
- if (value === undefined) {
4
- map.set(key, (value = [] as V[]));
5
- }
6
- return value;
7
- }
@@ -1,89 +0,0 @@
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
- });