Skip to content

Commit

Permalink
fix: show existed message if package version existed
Browse files Browse the repository at this point in the history
  • Loading branch information
favoyang committed Apr 10, 2020
1 parent 93a0b07 commit df6ec50
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/cmd-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,16 @@ const _add = async function(pkg) {
const oldVersion = manifest.dependencies[name];
manifest.dependencies[name] = version;
if (!oldVersion) {
// Log the added package
log.info(`added: ${name}@${version}`);
dirty = true;
} else if (oldVersion != version) {
// Log the modified package version
log.info(`modified: ${name} ${oldVersion} => ${version}`);
dirty = true;
} else {
// Log add package statement anyway
log.info(`added: ${name}@${version}`);
// Log the existed package
log.info(`existed: ${name}@${version}`);
}
if (!useUpstream) {
// add to scopedRegistries
Expand Down
37 changes: 37 additions & 0 deletions test/test-cmd-add.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ describe("cmd-add.js", function() {
const remotePkgInfoA = {
name: "com.base.package-a",
versions: {
"0.1.0": {
name: "com.base.package-a",
version: "0.1.0",
dependencies: {}
},
"1.0.0": {
name: "com.base.package-a",
version: "1.0.0",
Expand Down Expand Up @@ -235,6 +240,38 @@ describe("cmd-add.js", function() {
.includes("manifest updated")
.should.be.ok();
});
it("add pkg@0.1.0 then pkg@1.0.0", async function() {
const retCode1 = await add("com.base.package-a@0.1.0", options);
retCode1.should.equal(0);
const retCode2 = await add("com.base.package-a@1.0.0", options);
retCode2.should.equal(0);
const manifest = await loadManifest();
manifest.should.be.deepEqual(expectedManifestA);
stdout
.captured()
.includes("modified: ")
.should.be.ok();
stdout
.captured()
.includes("manifest updated")
.should.be.ok();
});
it("add exited pkg version", async function() {
const retCode1 = await add("com.base.package-a@1.0.0", options);
retCode1.should.equal(0);
const retCode2 = await add("com.base.package-a@1.0.0", options);
retCode2.should.equal(0);
const manifest = await loadManifest();
manifest.should.be.deepEqual(expectedManifestA);
stdout
.captured()
.includes("existed: ")
.should.be.ok();
stdout
.captured()
.includes("manifest updated")
.should.be.ok();
});
it("add pkg@not-exist-version", async function() {
const retCode = await add("com.base.package-a@2.0.0", options);
retCode.should.equal(1);
Expand Down

0 comments on commit df6ec50

Please sign in to comment.