-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(version): Add
--include-merged-tags
option (#1712)
- Loading branch information
Showing
21 changed files
with
256 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "1.0.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "independent" | ||
} |
4 changes: 4 additions & 0 deletions
4
commands/version/__tests__/__fixtures__/basic/packages/package-1/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"name": "package-1", | ||
"version": "1.0.0" | ||
} |
7 changes: 7 additions & 0 deletions
7
commands/version/__tests__/__fixtures__/basic/packages/package-2/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "package-2", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"package-1": "^1.0.0" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
commands/version/__tests__/__fixtures__/basic/packages/package-3/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "package-3", | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"package-2": "^1.0.0" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
commands/version/__tests__/__fixtures__/basic/packages/package-4/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "package-4", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"package-1": "^0.0.0" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
commands/version/__tests__/__fixtures__/basic/packages/package-5/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "package-5", | ||
"version": "1.0.0", | ||
"private": true, | ||
"dependencies": { | ||
"package-1": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
commands/version/__tests__/version-include-merged-tags.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"use strict"; | ||
|
||
// we're actually testing integration with git | ||
jest.unmock("@lerna/collect-updates"); | ||
|
||
const path = require("path"); | ||
const fs = require("fs"); | ||
|
||
// mocked modules | ||
const output = require("@lerna/output"); | ||
|
||
// helpers | ||
const initFixture = require("@lerna-test/init-fixture")(__dirname); | ||
const gitAdd = require("@lerna-test/git-add"); | ||
const gitCommit = require("@lerna-test/git-commit"); | ||
const gitTag = require("@lerna-test/git-tag"); | ||
const gitCheckout = require("@lerna-test/git-checkout"); | ||
const gitMerge = require("@lerna-test/git-merge"); | ||
|
||
// file under test | ||
const lernaVersion = require("@lerna-test/command-runner")(require("../command")); | ||
|
||
// remove quotes around top-level strings | ||
expect.addSnapshotSerializer({ | ||
test(val) { | ||
return typeof val === "string"; | ||
}, | ||
serialize(val, config, indentation, depth) { | ||
// top-level strings don't need quotes, but nested ones do (object properties, etc) | ||
return depth ? `"${val}"` : val; | ||
}, | ||
}); | ||
|
||
// normalize temp directory paths in snapshots | ||
expect.addSnapshotSerializer(require("@lerna-test/serialize-windows-paths")); | ||
expect.addSnapshotSerializer(require("@lerna-test/serialize-tempdir")); | ||
|
||
describe("version --include-merged-tags", () => { | ||
const setupGitChangesWithBranch = async (cwd, masterPaths, branchPaths) => { | ||
await gitTag(cwd, "v1.0.0"); | ||
await Promise.all(masterPaths.map(fp => fs.appendFileSync(path.join(cwd, fp), "1"))); | ||
await gitAdd(cwd, "-A"); | ||
await gitCommit(cwd, "Commit"); | ||
// Create release branch | ||
await gitCheckout(cwd, ["-b", "release/v1.0.1"]); | ||
// Switch into release branch | ||
await Promise.all(branchPaths.map(fp => fs.appendFileSync(path.join(cwd, fp), "1"))); | ||
await gitAdd(cwd, "-A"); | ||
await gitCommit(cwd, "Bump"); | ||
await gitTag(cwd, "v1.0.1"); | ||
await gitCheckout(cwd, ["master"]); | ||
await gitMerge(cwd, ["--no-ff", "release/v1.0.1"]); | ||
// Commit after merge | ||
await Promise.all(masterPaths.map(fp => fs.appendFileSync(path.join(cwd, fp), "1"))); | ||
await gitAdd(cwd, "-A"); | ||
await gitCommit(cwd, "Commit2"); | ||
}; | ||
|
||
describe("disabled", () => { | ||
it("should list changes to package-4", async () => { | ||
const testDir = await initFixture("basic"); | ||
|
||
await setupGitChangesWithBranch( | ||
testDir, | ||
["packages/package-2/random-file"], | ||
["packages/package-4/random-file"] | ||
); | ||
// Without --include-merged-tags we receive all changes since the last tag on master | ||
// in this case it's v1.0.0, this includes changes to package-4 which was released | ||
// in the release branch with v1.0.1 | ||
await lernaVersion(testDir)("--no-git-tag-version"); | ||
|
||
expect(output.logged()).toMatchInlineSnapshot(` | ||
Changes: | ||
- package-2: 1.0.0 => 1.0.1 | ||
- package-3: 1.0.0 => 1.0.1 | ||
- package-4: 1.0.0 => 1.0.1 | ||
`); | ||
}); | ||
}); | ||
|
||
describe("enabled", () => { | ||
it("should not list changes to package-4", async () => { | ||
const testDir = await initFixture("basic"); | ||
|
||
await setupGitChangesWithBranch( | ||
testDir, | ||
["packages/package-2/random-file"], | ||
["packages/package-4/random-file"] | ||
); | ||
// With --include-merged-tags we correctly detect that v1.0.1 was already tagged | ||
// and merged. We no longer want to receive package-4. | ||
await lernaVersion(testDir)("--no-git-tag-version", "--include-merged-tags"); | ||
|
||
expect(output.logged()).toMatchInlineSnapshot(` | ||
Changes: | ||
- package-2: 1.0.0 => 1.0.1 | ||
- package-3: 1.0.0 => 1.0.1 | ||
`); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
const execa = require("execa"); | ||
|
||
module.exports = gitCheckout; | ||
|
||
function gitCheckout(cwd, args) { | ||
return execa("git", ["checkout", ...args], { cwd }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@lerna-test/git-checkout", | ||
"version": "0.0.0-test-only", | ||
"description": "A local test helper", | ||
"main": "index.js", | ||
"private": true, | ||
"license": "MIT", | ||
"dependencies": { | ||
"execa": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"use strict"; | ||
|
||
const execa = require("execa"); | ||
|
||
module.exports = gitMerge; | ||
|
||
function gitMerge(cwd, args) { | ||
return execa("git", ["merge", ...args], { cwd }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@lerna-test/git-merge", | ||
"version": "0.0.0-test-only", | ||
"description": "A local test helper", | ||
"main": "index.js", | ||
"private": true, | ||
"license": "MIT", | ||
"dependencies": { | ||
"execa": "^1.0.0" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters