yarn-version 1.0.0-pre → 1.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.
- package/CHANGELOG.md +118 -0
- package/README.md +161 -0
- package/build/index-node18.mjs +152 -114
- package/build/index-node18.mjs.map +1 -1
- package/package.json +10 -9
- package/src/__fixtures__/basic/package.json +4 -0
- package/src/__fixtures__/basic/yarn.lock +12 -0
- package/src/__fixtures__/monorepo/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-1/package.json +4 -0
- package/src/__fixtures__/monorepo/packages/package-2/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-3/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-4/package.json +7 -0
- package/src/__fixtures__/monorepo/packages/package-5/package.json +8 -0
- package/src/__fixtures__/monorepo/yarn.lock +0 -0
- package/src/__fixtures__/no-version/package.json +3 -0
- package/src/__fixtures__/no-version/yarn.lock +0 -0
- package/src/__fixtures__/with-lifecycle/.yarn/install-state.gz +0 -0
- package/src/__fixtures__/with-lifecycle/package.json +7 -0
- package/src/__fixtures__/with-lifecycle/yarn.lock +11 -0
- package/src/commands/version.test.ts +63 -61
- package/src/commands/version.ts +691 -655
- package/src/utils/UsageError.ts +6 -1
- package/src/utils/conventionalChangelogUtils.ts +4 -0
- package/src/utils/packageDependenciesUtils.test.ts +18 -7
- package/src/utils/packageDependenciesUtils.ts +9 -2
- package/src/utils/updateChangelog.ts +0 -0
- package/src/utils/workspaceUtils.ts +0 -0
|
@@ -1,86 +1,88 @@
|
|
|
1
1
|
import { URL, fileURLToPath } from "node:url";
|
|
2
|
-
import
|
|
2
|
+
import { Level } from "nightingale";
|
|
3
|
+
import { StringHandler } from "nightingale-string";
|
|
4
|
+
import type { VersionCommandOptions } from "./version";
|
|
5
|
+
import { Defaults, versionCommandAction } from "./version";
|
|
3
6
|
|
|
4
7
|
interface ExecuteCommandResult {
|
|
5
8
|
exitCode: number;
|
|
6
9
|
stdout: string;
|
|
7
10
|
stderr: string;
|
|
8
11
|
}
|
|
12
|
+
const presetOption = {
|
|
13
|
+
// preset: fileURLToPath(
|
|
14
|
+
// new URL(
|
|
15
|
+
// "../../node_modules/conventional-changelog-conventionalcommits",
|
|
16
|
+
// import.meta.url,
|
|
17
|
+
// ),
|
|
18
|
+
// ),
|
|
19
|
+
};
|
|
9
20
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
options: {
|
|
13
|
-
cwd: URL;
|
|
14
|
-
},
|
|
15
|
-
): ExecuteCommandResult {
|
|
16
|
-
try {
|
|
17
|
-
versionCommand.parse(args, { cwd: options.cwd });
|
|
18
|
-
// const stdout = execFileSync("yarn", [command, ...args], {
|
|
19
|
-
// cwd: fileURLToPath(options.cwd),
|
|
20
|
-
// stdio: "pipe",
|
|
21
|
-
// });
|
|
22
|
-
// return { exitCode: 0, stdout: stdout.toString("utf8"), stderr: "" };
|
|
23
|
-
} catch (error: any) {
|
|
24
|
-
if (error.status == null) {
|
|
25
|
-
throw error;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
exitCode: error.status,
|
|
30
|
-
stdout: error.stdout?.toString("utf8"),
|
|
31
|
-
stderr: error.stderr?.toString("utf8"),
|
|
32
|
-
};
|
|
33
|
-
}
|
|
21
|
+
class NightingaleTestHandler extends StringHandler {
|
|
22
|
+
isHandling = () => true;
|
|
34
23
|
}
|
|
35
24
|
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"../../node_modules/conventional-changelog-conventionalcommits",
|
|
41
|
-
import.meta.url,
|
|
42
|
-
),
|
|
43
|
-
),
|
|
44
|
-
];
|
|
25
|
+
const executeAction = async (
|
|
26
|
+
options: Partial<VersionCommandOptions>,
|
|
27
|
+
): Promise<ExecuteCommandResult> => {
|
|
28
|
+
const nightingaleHandler = new NightingaleTestHandler(Level.ALL);
|
|
45
29
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"yarn-version",
|
|
50
|
-
[...presetOption, "--dry-run"],
|
|
30
|
+
try {
|
|
31
|
+
await versionCommandAction(
|
|
32
|
+
{ ...Defaults, ...options, cwdIsRoot: true },
|
|
51
33
|
{
|
|
52
|
-
|
|
34
|
+
nightingaleHandler,
|
|
53
35
|
},
|
|
54
36
|
);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
return {
|
|
39
|
+
exitCode: 1,
|
|
40
|
+
stdout: "",
|
|
41
|
+
stderr: (error as any).toString(),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
exitCode: 0,
|
|
46
|
+
stdout: nightingaleHandler.string,
|
|
47
|
+
stderr: "",
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
describe("version", () => {
|
|
52
|
+
it("should fail if package has no version", async () => {
|
|
53
|
+
const { exitCode, stdout, stderr } = await executeAction({
|
|
54
|
+
...presetOption,
|
|
55
|
+
dryRun: true,
|
|
56
|
+
cwd: fileURLToPath(
|
|
57
|
+
new URL("../__fixtures__/no-version", import.meta.url),
|
|
58
|
+
),
|
|
59
|
+
});
|
|
55
60
|
expect(exitCode).toBe(1);
|
|
56
|
-
expect(
|
|
61
|
+
expect(stderr).toContain(
|
|
57
62
|
'UsageError: package.json has no version in its manifest. For the first release, set to "1.0.0-pre" or "0.1.0-pre".',
|
|
58
63
|
); // replace with expected output
|
|
59
|
-
expect(
|
|
64
|
+
expect(stdout).toBeFalsy();
|
|
60
65
|
});
|
|
61
66
|
|
|
62
|
-
it("should fail if --prerelease is passed", () => {
|
|
63
|
-
const { exitCode, stdout, stderr } =
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
);
|
|
67
|
+
it("should fail if --prerelease is passed", async () => {
|
|
68
|
+
const { exitCode, stdout, stderr } = await executeAction({
|
|
69
|
+
...presetOption,
|
|
70
|
+
prerelease: "alpha",
|
|
71
|
+
dryRun: true,
|
|
72
|
+
cwd: fileURLToPath(new URL("../__fixtures__/basic", import.meta.url)),
|
|
73
|
+
});
|
|
70
74
|
expect(exitCode).toBe(1);
|
|
71
|
-
expect(
|
|
72
|
-
expect(
|
|
75
|
+
expect(stderr).toContain("prerelease is not supported yet."); // replace with expected output
|
|
76
|
+
expect(stdout).toBeFalsy();
|
|
73
77
|
});
|
|
74
78
|
|
|
75
|
-
it("should pass with dry-run and force", () => {
|
|
76
|
-
const { exitCode, stdout, stderr } =
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
console.log(stdout);
|
|
79
|
+
it("should pass with dry-run and force", async () => {
|
|
80
|
+
const { exitCode, stdout, stderr } = await executeAction({
|
|
81
|
+
...presetOption,
|
|
82
|
+
force: "minor",
|
|
83
|
+
dryRun: true,
|
|
84
|
+
cwd: fileURLToPath(new URL("../__fixtures__/basic", import.meta.url)),
|
|
85
|
+
});
|
|
84
86
|
expect(stderr).toBeFalsy();
|
|
85
87
|
expect(exitCode).toBe(0);
|
|
86
88
|
expect(stdout).toContain("basic: 1.0.0 -> 1.1.0"); // replace with expected output
|