Skip to content

Commit 9d47974

Browse files
authored
fix: gather-versions doesn't work for >= 2 dependencies (#833)
* fix: gather-versions doesn't work for 0 or 1 dependencies When I simplified the command-line that `gather-versions` takes, I forgot to take out the condition that requires a minimum number of arguments. The result is that `gather-versions` won't do anything thing for packages that have 0 or 1 workspace dependency; plus, the script didn't actually exit with an error code when that happened, so it was hard to detect. Fix that in this PR, and also add a test that runs the `gather-versions` task properly from a projen monorepo config using `TaskRuntime`. * fix: gather-versions doesn't work for >= 2 dependencies During refactoring I accidentally removed a `.join(' ')` so an array stringifies fine but stringifies to the wrong string. Instead of: ``` a b c ``` it stringifies to ``` a,b,c ``` Which is not a command-line argument per package, but once command-line argument with all packages in there.
1 parent 03282d7 commit 9d47974

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/yarn/gather-versions.task.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class GatherVersions implements TaskOptions, TaskStep {
3434
public get exec(): string {
3535
// We must resolve paths at runtime to avoid writing '/home/$USER/...' into the `tasks.json` file
3636
const main = `require(require.resolve('${currentPackageName()}/lib/yarn/gather-versions.exec.js')).cliMain()`;
37-
return `node -e "${main}" ${Object.entries(this.repoDependencies).map(([d, r]) => `${d}=${r}`)}`;
37+
return `node -e "${main}" ${Object.entries(this.repoDependencies).map(([d, r]) => `${d}=${r}`).join(' ')}`;
3838
}
3939

4040
public toJSON() {

test/gather-versions.test.ts

+15-11
Original file line numberDiff line numberDiff line change
@@ -64,25 +64,27 @@ const NO_DEVDEPS: Partial<TypeScriptWorkspaceOptions> = {
6464
prettier: false,
6565
};
6666

67-
test('make sure a run of gather-versions writes the right version to package.json', async () => {
67+
test.each([0, 1, 2])('make sure gather-versions works for %p dependencies', async (N) => {
6868
// GIVEN
6969
const parent = new yarn.CdkLabsMonorepo({
7070
name: 'monorepo',
7171
defaultReleaseBranch: 'main',
7272
release: true,
7373
});
74-
75-
const dep = new yarn.TypeScriptWorkspace({
76-
parent,
77-
name: '@cdklabs/one',
78-
...NO_DEVDEPS,
79-
});
74+
let deps: yarn.TypeScriptWorkspace[] = [];
75+
for (let i = 0; i < N; i++) {
76+
deps.push(new yarn.TypeScriptWorkspace({
77+
parent,
78+
name: `@cdklabs/dep${i}`,
79+
...NO_DEVDEPS,
80+
}));
81+
}
8082

8183
// WHEN
8284
const pack = new yarn.TypeScriptWorkspace({
8385
parent,
8486
name: '@cdklabs/two',
85-
deps: [dep.customizeReference({ versionType: 'exact' })],
87+
deps: deps.map(dep => dep.customizeReference({ versionType: 'exact' })),
8688
...NO_DEVDEPS,
8789
});
8890

@@ -93,9 +95,11 @@ test('make sure a run of gather-versions writes the right version to package.jso
9395
new TaskRuntime(pack.outdir).runTask('gather-versions');
9496

9597
const packageJson = JSON.parse(await fs.readFile(path.join(pack.outdir, 'package.json'), 'utf-8'));
96-
expect(Object.entries(packageJson.dependencies)).toContainEqual([
97-
'@cdklabs/one', '0.0.0',
98-
]);
98+
for (let i = 0; i < N; i++) {
99+
expect(Object.entries(packageJson.dependencies)).toContainEqual([
100+
`@cdklabs/dep${i}`, '0.0.0',
101+
]);
102+
}
99103
}, 60_000); // Needs to install real packages
100104

101105
/**

0 commit comments

Comments
 (0)