Skip to content

Commit

Permalink
fix(command): more detailed error message when version cannot be found
Browse files Browse the repository at this point in the history
 - added separate error message if version cannot be found
 - distinguish btw. no lerna.json not availble and invalid lerna.json
  • Loading branch information
amorscher committed Nov 11, 2022
1 parent 050bad8 commit 5545d79
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
17 changes: 17 additions & 0 deletions core/command/__tests__/command.test.js
Expand Up @@ -388,6 +388,23 @@ describe("core-command", () => {
);
});

it("throws ENOVERSION when no version property exists in lerna.json", async () => {
const cwd = await initFixture("basic");

const lernaConfigPath = path.join(cwd, "lerna.json");
const lernaConfig = await fs.readJson(lernaConfigPath);
delete lernaConfig.version;
await fs.writeJson(lernaConfigPath, {
...lernaConfig,
});

await expect(testFactory({ cwd })).rejects.toThrow(
expect.objectContaining({
prefix: "ENOVERSION",
})
);
});

it("throws ENOWORKSPACES when npm client is pnpm and useWorkspaces is not true", async () => {
const cwd = await initFixture("pnpm");

Expand Down
6 changes: 5 additions & 1 deletion core/command/index.js
Expand Up @@ -240,10 +240,14 @@ class Command {
throw new ValidationError("ENOPKG", "`package.json` does not exist, have you run `lerna init`?");
}

if (!this.project.version) {
if (this.project.configNotFound) {
throw new ValidationError("ENOLERNA", "`lerna.json` does not exist, have you run `lerna init`?");
}

if (!this.project.version) {
throw new ValidationError("ENOVERSION", "Required property version does not exist in `lerna.json`");
}

if (this.options.independent && !this.project.isIndependent()) {
throw new ValidationError(
"EVERSIONMODE",
Expand Down
1 change: 1 addition & 0 deletions core/project/index.js
Expand Up @@ -62,6 +62,7 @@ class Project {
transform(obj) {
// cosmiconfig returns null when nothing is found
if (!obj) {
this.configNotFound = true;
return {
// No need to distinguish between missing and empty,
// saves a lot of noisy guards elsewhere
Expand Down

0 comments on commit 5545d79

Please sign in to comment.