Skip to content

Commit

Permalink
fix(add): Validate local package version (#1804)
Browse files Browse the repository at this point in the history
Fixes #1799
  • Loading branch information
tanhauhau authored and evocateur committed Dec 6, 2018
1 parent e8c9535 commit ed6e2db
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
@@ -0,0 +1,3 @@
{
"version": "1.0.0"
}
@@ -0,0 +1,8 @@
{
"name": "unspecified-version",
"version": "monorepo",
"private": true,
"dependencies": {
"bar": "^2.0.0"
}
}
@@ -0,0 +1,3 @@
{
"name": "@test/package-1"
}
@@ -0,0 +1,4 @@
{
"name": "@test/package-2",
"version": "2.0.0"
}
12 changes: 12 additions & 0 deletions commands/add/__tests__/add-command.test.js
Expand Up @@ -49,6 +49,18 @@ describe("AddCommand", () => {
}
});

it("should throw for adding local package without specified version", async () => {
expect.assertions(1);

const testDir = await initFixture("unspecified-version");

try {
await lernaAdd(testDir)("@test/package-1");
} catch (err) {
expect(err.message).toMatch(/Requested package has no version:/);
}
});

it("should reference remote dependencies", async () => {
const testDir = await initFixture("basic");

Expand Down
8 changes: 8 additions & 0 deletions commands/add/index.js
Expand Up @@ -50,6 +50,14 @@ class AddCommand extends Command {

chain = chain.then(() => this.getPackageVersion());
chain = chain.then(version => {
if (version == null) {
throw new ValidationError(
"ENOTSATISFIED",
dedent`
Requested package has no version: ${this.spec.name}
`
);
}
this.spec.version = version;
});

Expand Down

0 comments on commit ed6e2db

Please sign in to comment.