Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/tidy-pandas-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@changesets/get-dependents-graph": patch
"@changesets/cli": patch
---

Report an actionable dependency graph error when a dependency name collides with a versionless workspace package instead of crashing while formatting its missing version.
37 changes: 37 additions & 0 deletions packages/get-dependents-graph/src/get-dependency-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,43 @@ describe("getting the dependency graph", function () {
}),
);

it(
"should report dependencies that collide with a versionless workspace package",
temporarilySilenceLogs(() => {
const rootPackage: Package = {
dir: path.resolve(),
packageJson: { name: "root", version: "1.0.0" },
};
const { valid } = getDependencyGraph(
{
tool: { type: "pnpm" },
rootDir: rootPackage.dir,
rootPackage,
packages: [
{
dir: "packages/stripe",
packageJson: {
name: "stripe",
private: true,
dependencies: {
stripe: "^18.0.0",
},
} as unknown as Package["packageJson"],
},
],
},
rootPackage,
);

expect(valid).toBe(false);
expect(
stripVTControlCharacters((console.error as any).mock.calls[0][0]),
).toBe(
"Package stripe depends on stripe@^18.0.0, but stripe is also the name of a workspace package without a version. Add a version to stripe or rename the workspace package.",
);
}),
);

it(
"should skip dependencies not specified using workspace protocol when bumpVersionsWithWorkspaceProtocolOnly is true",
temporarilySilenceLogs(() => {
Expand Down
27 changes: 18 additions & 9 deletions packages/get-dependents-graph/src/get-dependency-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,28 @@ export function getDependencyGraph(
dependencies.push(depName);
continue;
}

if (!getValidRange(depRange)) {
valid = false;
// TODO: replace with returning errors/warnings
console.error(
`Package ${c.blue(name)} must depend on the current version of ${c.blue(depName)}: ${c.green(expected)} vs ${c.red(rawDepRange)}`,
);
continue;
}
} else if (bumpVersionsWithWorkspaceProtocolOnly) {
continue;
}

if (typeof expected !== "string") {
valid = false;
// TODO: replace with returning errors/warnings
console.error(
`Package ${c.blue(name)} depends on ${c.blue(depName)}@${c.red(rawDepRange)}, but ${c.blue(depName)} is also the name of a workspace package without a version. Add a version to ${c.blue(depName)} or rename the workspace package.`,
);
continue;
}

if (usesWorkspaceRange && !getValidRange(depRange)) {
valid = false;
// TODO: replace with returning errors/warnings
console.error(
`Package ${c.blue(name)} must depend on the current version of ${c.blue(depName)}: ${c.green(expected)} vs ${c.red(rawDepRange)}`,
);
continue;
}

const range = getValidRange(depRange);

if ((range && !range.test(expected)) || isProtocolRange(depRange)) {
Expand Down