Skip to content

Commit 3ca050c

Browse files
authored
feat: advanced commands (#71)
* fix: properly resolve parents for version commands * apply was actually a breaking change * update apply tests for new expected parameters * update covector snapshots * dep bumps now inherit dep change log * parents are resolved by the time we apply now * add tests for split out parent change function * rough in new fixture, add tests, update snaps * tweak fixtures * feat: complex commands * also return within version command * add dryRunCommand option * remove single quotes in fixture command * update snaps * remove terminal colors from commands * really make fixture tests stable
1 parent 54fd56e commit 3ca050c

File tree

16 files changed

+1629
-616
lines changed

16 files changed

+1629
-616
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"covector": minor
3+
---
4+
5+
Added new `dryRunCommand` to specify a different command to run instead in `--dry-run` mode instead of skipping the specified command.

.changes/config.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"pkgManagers": {
33
"javascript": {
4-
"build": "echo build run",
4+
"build": {
5+
"command": "echo build run",
6+
"dryRunCommand": true
7+
},
58
"version": true,
69
"getPublishedVersion": "npm view ${ pkg.pkg } version",
710
"publish": "npm publish --access public",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"covector": minor
3+
"@covector/assemble": minor
4+
"@covector/changelog": minor
5+
---
6+
7+
Allow complex commands specified as an object. This let's one specify a `dryRunCommand` that is executed in `--dry-run` mode instead (so no accidental publishes!) or to set `pipe` to `true` that the output is returned from the main covector function. The pipe likely won't be used directly, but can be consumed within the action to create a Github Release, etc.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"covector": patch
3+
"@covector/apply": minor
4+
"@covector/assemble": patch
5+
---
6+
7+
Version commands used to only run on changes, but ignore parents. Reconfigure that we resolve the parents and run commands on both direct changes and changes through a dependency.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"pkgManagers": {
3+
"javascript": {
4+
"version": true,
5+
"publish": { "command": "echo publish", "pipe": true },
6+
"build": { "command": "yarn build", "pipe": true },
7+
"test": [
8+
{ "command": "yarn build", "pipe": true },
9+
{ "command": "yarn test", "dryRunCommand": false },
10+
{ "command": "echo boop", "dryRunCommand": "echo deboop" }
11+
]
12+
}
13+
},
14+
"packages": {
15+
"package-one": {
16+
"path": "./packages/package-one",
17+
"manager": "javascript"
18+
},
19+
"package-two": {
20+
"path": "./packages/package-two",
21+
"manager": "javascript"
22+
}
23+
}
24+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "workspace",
3+
"description": "This is React. Trust.",
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"workspaces": [
7+
"packages/*"
8+
]
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "package-one",
3+
"version": "2.3.1",
4+
"license": "MIT",
5+
"scripts": {
6+
"build": "yarn info tauri@0.8.0 description",
7+
"test": "yarn info covector@0.1.0 license"
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "package-two",
3+
"version": "1.9.0",
4+
"license": "MIT",
5+
"scripts": {
6+
"build": "echo this command is not piped, it is run from scripts for pk2",
7+
"test": "echo this command is not piped, it is run from the test script"
8+
}
9+
}

packages/apply/__snapshots__/index.test.js.snap

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,87 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`list changes considering parents adds changes for dependency 1`] = `
4+
Object {
5+
"changes": Object {
6+
"changes": undefined,
7+
"releases": Object {
8+
"all": Object {
9+
"dependencies": undefined,
10+
"manager": "javascript",
11+
"parents": Array [
12+
"yarn-workspace-base-pkg-a",
13+
"yarn-workspace-base-pkg-b",
14+
],
15+
"path": undefined,
16+
"pkg": "all",
17+
"type": "minor",
18+
},
19+
"yarn-workspace-base-pkg-a": Object {
20+
"dependencies": undefined,
21+
"manager": "javascript",
22+
"parents": Array [],
23+
"path": undefined,
24+
"pkg": "all",
25+
"type": "minor",
26+
},
27+
"yarn-workspace-base-pkg-b": Object {
28+
"dependencies": undefined,
29+
"manager": "javascript",
30+
"parents": Array [
31+
"yarn-workspace-base-pkg-a",
32+
],
33+
"path": undefined,
34+
"pkg": "all",
35+
"type": "minor",
36+
},
37+
},
38+
},
39+
"consoleDir": Array [],
40+
"consoleLog": Array [],
41+
}
42+
`;
43+
44+
exports[`list changes considering parents bumps higher due to dependency bump 1`] = `
45+
Object {
46+
"changes": Object {
47+
"changes": undefined,
48+
"releases": Object {
49+
"all": Object {
50+
"dependencies": undefined,
51+
"manager": "javascript",
52+
"parents": Array [
53+
"yarn-workspace-base-pkg-a",
54+
"yarn-workspace-base-pkg-b",
55+
],
56+
"path": undefined,
57+
"pkg": "all",
58+
"type": "minor",
59+
},
60+
"yarn-workspace-base-pkg-a": Object {
61+
"dependencies": undefined,
62+
"manager": "javascript",
63+
"parents": Array [],
64+
"path": undefined,
65+
"pkg": "all",
66+
"type": "minor",
67+
},
68+
"yarn-workspace-base-pkg-b": Object {
69+
"dependencies": undefined,
70+
"manager": "javascript",
71+
"parents": Array [
72+
"yarn-workspace-base-pkg-a",
73+
],
74+
"path": undefined,
75+
"pkg": "all",
76+
"type": "minor",
77+
},
78+
},
79+
},
80+
"consoleDir": Array [],
81+
"consoleLog": Array [],
82+
}
83+
`;
84+
385
exports[`package file apply bump bumps multi js json 1`] = `
486
Object {
587
"consoleDir": Array [],

packages/apply/index.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,15 @@ const semver = require("semver");
44
const path = require("path");
55

66
module.exports.apply = function* ({
7-
changeList,
7+
commands,
88
config,
99
cwd = process.cwd(),
1010
bump = true,
1111
}) {
12-
const parents = resolveParents({ config });
13-
let changes = changeList.reduce((list, change) => {
14-
list[change.pkg] = change;
15-
list[change.pkg].parents = parents[change.pkg];
16-
return list;
12+
const changes = commands.reduce((finalChanges, command) => {
13+
finalChanges[command.pkg] = command;
14+
return finalChanges;
1715
}, {});
18-
19-
Object.keys(changes).forEach((main) => {
20-
if (changes[main].parents.length > 0) {
21-
changes[main].parents.forEach((pkg) => {
22-
if (!!changes[pkg]) {
23-
changes[pkg].type = compareBumps(
24-
changes[main].type,
25-
changes[pkg].type
26-
);
27-
} else {
28-
changes[pkg] = config.packages[pkg];
29-
changes[pkg].parents = [];
30-
changes[pkg].pkg = pkg;
31-
changes[pkg].type = changes[main].type;
32-
}
33-
});
34-
}
35-
});
36-
3716
let allPackages = yield readAll({ changes, config, cwd });
3817

3918
const bumps = bumpAll({ changes, allPackages });
@@ -105,6 +84,37 @@ const resolveParents = ({ config }) => {
10584
}, {});
10685
};
10786

87+
module.exports.changesConsideringParents = ({ assembledChanges, config }) => {
88+
const parents = resolveParents({ config });
89+
90+
let changes = Object.keys(assembledChanges.releases).reduce(
91+
(list, change) => {
92+
list[change] = assembledChanges.releases[change];
93+
list[change].parents = parents[change];
94+
return list;
95+
},
96+
{}
97+
);
98+
99+
Object.keys(changes).forEach((main) => {
100+
if (changes[main].parents.length > 0) {
101+
changes[main].parents.forEach((pkg) => {
102+
if (!!changes[pkg]) {
103+
changes[pkg].type = compareBumps(
104+
changes[main].type,
105+
changes[pkg].type
106+
);
107+
} else {
108+
changes[pkg] = { ...changes[main] };
109+
changes[pkg].parents = parents[pkg];
110+
}
111+
});
112+
}
113+
});
114+
115+
return { releases: changes, changes: assembledChanges.changes };
116+
};
117+
108118
const bumpAll = ({ changes, allPackages }) => {
109119
let packageFiles = { ...allPackages };
110120
for (let pkg of Object.keys(changes)) {

0 commit comments

Comments
 (0)