-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: nested packages detection #294
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ const execa = require("execa"); | |
const hostedGitInfo = require("hosted-git-info"); | ||
|
||
import ConfigurationError from "./configuration-error"; | ||
import { getRootPath } from "./git"; | ||
|
||
export interface Configuration { | ||
repo: string; | ||
|
@@ -20,9 +21,7 @@ export interface ConfigLoaderOptions { | |
} | ||
|
||
export function load(options: ConfigLoaderOptions = {}): Configuration { | ||
let cwd = process.cwd(); | ||
let rootPath = execa.sync("git", ["rev-parse", "--show-toplevel"], { cwd }).stdout; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not really related to this PR, but I figured the git command belongs to the |
||
|
||
let rootPath = getRootPath(); | ||
return fromPath(rootPath, options); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`createMarkdown multiple tags outputs correct changelog 1`] = `""`; | ||
|
||
exports[`createMarkdown single project outputs correct changelog 1`] = `""`; | ||
|
||
exports[`createMarkdown single tags outputs correct changelog 1`] = `""`; | ||
|
||
exports[`multiple tags outputs correct changelog 1`] = `""`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ exports[`createMarkdown multiple tags outputs correct changelog 1`] = ` | |
## [email protected] (1977-05-25) | ||
|
||
#### :rocket: New Feature | ||
* \`a-new-hope\` | ||
* \`@star-wars/a-new-hope\` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mock data contains scoped package names, hence these changes. |
||
* [#1](https://github.com/lerna/lerna-changelog/pull/1) feat: May the force be with you ([@luke](https://github.com/luke)) | ||
|
||
#### Committers: 1 | ||
|
@@ -15,7 +15,7 @@ exports[`createMarkdown multiple tags outputs correct changelog 1`] = ` | |
## [email protected] (1977-05-25) | ||
|
||
#### :rocket: New Feature | ||
* \`a-new-hope\` | ||
* \`@star-wars/a-new-hope\` | ||
* [#1](https://github.com/lerna/lerna-changelog/pull/1) feat: May the force be with you ([@luke](https://github.com/luke)) | ||
|
||
#### Committers: 1 | ||
|
@@ -25,7 +25,7 @@ exports[`createMarkdown multiple tags outputs correct changelog 1`] = ` | |
## [email protected] (1977-05-25) | ||
|
||
#### :rocket: New Feature | ||
* \`a-new-hope\` | ||
* \`@star-wars/a-new-hope\` | ||
* [#1](https://github.com/lerna/lerna-changelog/pull/1) feat: May the force be with you ([@luke](https://github.com/luke)) | ||
|
||
#### Committers: 1 | ||
|
@@ -93,11 +93,11 @@ exports[`createMarkdown single tags outputs correct changelog 1`] = ` | |
## Unreleased (2099-01-01) | ||
|
||
#### :rocket: New Feature | ||
* \`the-force-awakens\`, \`rogue-one\` | ||
* \`@star-wars/the-force-awakens\`, \`@star-wars/rogue-one\` | ||
* [#7](https://github.com/lerna/lerna-changelog/pull/7) feat: that is not how the Force works! ([@han-solo](https://github.com/han-solo)) | ||
|
||
#### :nail_care: Enhancement | ||
* \`the-force-awakens\`, \`rogue-one\` | ||
* \`@star-wars/the-force-awakens\`, \`@star-wars/rogue-one\` | ||
* [#7](https://github.com/lerna/lerna-changelog/pull/7) feat: that is not how the Force works! ([@han-solo](https://github.com/han-solo)) | ||
|
||
#### Committers: 1 | ||
|
@@ -107,19 +107,19 @@ exports[`createMarkdown single tags outputs correct changelog 1`] = ` | |
## v6.0.0 (1983-05-25) | ||
|
||
#### :rocket: New Feature | ||
* \`return-of-the-jedi\` | ||
* \`@star-wars/return-of-the-jedi\` | ||
* [#5](https://github.com/lerna/lerna-changelog/pull/5) feat: I am your father ([@vader](https://github.com/vader)) | ||
|
||
#### :bug: Bug Fix | ||
* \`return-of-the-jedi\` | ||
* \`@star-wars/return-of-the-jedi\` | ||
* [#4](https://github.com/lerna/lerna-changelog/pull/4) fix: RRRAARRWHHGWWR ([@chewbacca](https://github.com/chewbacca)) | ||
|
||
#### :nail_care: Enhancement | ||
* \`return-of-the-jedi\` | ||
* \`@star-wars/return-of-the-jedi\` | ||
* [#6](https://github.com/lerna/lerna-changelog/pull/6) refactor: he is my brother ([@princess-leia](https://github.com/princess-leia)) | ||
|
||
#### :house: Maintenance | ||
* \`return-of-the-jedi\` | ||
* \`@star-wars/return-of-the-jedi\` | ||
* [#4](https://github.com/lerna/lerna-changelog/pull/4) fix: RRRAARRWHHGWWR ([@chewbacca](https://github.com/chewbacca)) | ||
|
||
#### Committers: 3 | ||
|
@@ -131,11 +131,11 @@ exports[`createMarkdown single tags outputs correct changelog 1`] = ` | |
## v5.0.0 (1980-05-17) | ||
|
||
#### :boom: Breaking Change | ||
* \`empire-strikes-back\` | ||
* \`@star-wars/empire-strikes-back\` | ||
* [#2](https://github.com/lerna/lerna-changelog/pull/2) chore: Terminate her... immediately! ([@gtarkin](https://github.com/gtarkin)) | ||
|
||
#### :bug: Bug Fix | ||
* \`empire-strikes-back\` | ||
* \`@star-wars/empire-strikes-back\` | ||
* [#3](https://github.com/lerna/lerna-changelog/pull/3) fix: Get me the rebels base! ([@vader](https://github.com/vader)) | ||
|
||
#### Committers: 2 | ||
|
@@ -146,7 +146,7 @@ exports[`createMarkdown single tags outputs correct changelog 1`] = ` | |
## v4.0.0 (1977-05-25) | ||
|
||
#### :rocket: New Feature | ||
* \`a-new-hope\` | ||
* \`@star-wars/a-new-hope\` | ||
* [#1](https://github.com/lerna/lerna-changelog/pull/1) feat: May the force be with you ([@luke](https://github.com/luke)) | ||
|
||
#### Committers: 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ jest.mock("../../src/changelog"); | |
jest.mock("../../src/github-api"); | ||
jest.mock("../git"); | ||
jest.mock("../fetch"); | ||
jest.mock("../packages"); | ||
|
||
const listOfCommits: CommitListItem[] = []; | ||
|
||
|
@@ -15,18 +16,21 @@ const listOfTags = ["v6.0.0", "v5.0.0", "v4.0.0", "v3.0.0", "v2.0.0", "v1.0.0", | |
const listOfPackagesForEachCommit: { [id: string]: string[] } = { | ||
a0000001: ["packages/random/foo.js"], | ||
a0000002: ["packages/random/package.json"], | ||
a0000003: ["packages/a-new-hope/rebels.js"], | ||
a0000004: ["packages/a-new-hope/package.json"], | ||
a0000005: ["packages/empire-strikes-back/death-star.js"], | ||
a0000006: ["packages/empire-strikes-back/death-star.js"], | ||
a0000007: ["packages/empire-strikes-back/hoth.js"], | ||
a0000008: ["packages/empire-strikes-back/hoth.js"], | ||
a0000009: ["packages/empire-strikes-back/package.json"], | ||
a0000010: ["packages/return-of-the-jedi/jabba-the-hutt.js"], | ||
a0000011: ["packages/return-of-the-jedi/vader-luke.js"], | ||
a0000012: ["packages/return-of-the-jedi/leia.js"], | ||
a0000013: ["packages/return-of-the-jedi/package.json"], | ||
a0000014: ["packages/the-force-awakens/mission.js", "packages/rogue-one/mission.js"], | ||
a0000003: ["packages/star-wars/a-new-hope/rebels.js"], | ||
a0000004: ["packages/star-wars/a-new-hope/package.json"], | ||
a0000005: ["packages/star-wars/empire-strikes-back/death-star.js"], | ||
a0000006: ["packages/star-wars/empire-strikes-back/death-star.js"], | ||
a0000007: ["packages/star-wars/empire-strikes-back/hoth.js"], | ||
a0000008: ["packages/star-wars/empire-strikes-back/hoth.js"], | ||
a0000009: ["packages/star-wars/empire-strikes-back/package.json"], | ||
a0000010: ["packages/star-wars/return-of-the-jedi/jabba-the-hutt.js"], | ||
a0000011: ["packages/star-wars/return-of-the-jedi/vader-luke.js"], | ||
a0000012: ["packages/star-wars/return-of-the-jedi/leia.js"], | ||
a0000013: ["packages/star-wars/return-of-the-jedi/package.json"], | ||
a0000014: [ | ||
"packages/star-wars/the-force-awakens/mission.js", | ||
"packages/star-wars/origin-stories/rogue-one/mission.js", | ||
], | ||
Comment on lines
+19
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to ensure that the "nested" package locations work. |
||
a0000015: ["packages/untitled/script.md"], | ||
}; | ||
|
||
|
@@ -106,45 +110,75 @@ const issuesCache = { | |
}, | ||
}, | ||
}; | ||
|
||
describe("multiple tags", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved inside the |
||
it("outputs correct changelog", async () => { | ||
require("../git").changedPaths.mockImplementation((sha: string) => listOfPackagesForEachCommit[sha]); | ||
require("../git").lastTag.mockImplementation(() => "v8.0.0"); | ||
require("../git").listCommits.mockImplementation(() => listOfCommits); | ||
require("../git").listTagNames.mockImplementation(() => [ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
]); | ||
|
||
require("../fetch").__setMockResponses({ | ||
...usersCache, | ||
...issuesCache, | ||
}); | ||
|
||
const MockedChangelog = require("../changelog").default; | ||
const changelog = new MockedChangelog(); | ||
|
||
const markdown = await changelog.createMarkdown(); | ||
|
||
expect(markdown).toMatchSnapshot(); | ||
}); | ||
}); | ||
const listOfWorkspacePackages = [ | ||
{ | ||
name: "random", | ||
location: "/path/to/project/packages/random", | ||
}, | ||
{ | ||
name: "@star-wars/a-new-hope", | ||
location: "/path/to/project/packages/star-wars/a-new-hope", | ||
}, | ||
{ | ||
name: "@star-wars/empire-strikes-back", | ||
location: "/path/to/project/packages/star-wars/empire-strikes-back", | ||
}, | ||
{ | ||
name: "@star-wars/return-of-the-jedi", | ||
location: "/path/to/project/packages/star-wars/return-of-the-jedi", | ||
}, | ||
{ | ||
name: "@star-wars/the-force-awakens", | ||
location: "/path/to/project/packages/star-wars/the-force-awakens", | ||
}, | ||
{ | ||
name: "@star-wars/rogue-one", | ||
location: "/path/to/project/packages/star-wars/origin-stories/rogue-one", | ||
}, | ||
{ | ||
name: "@star-wars/solo", | ||
location: "/path/to/project/packages/star-wars/origin-stories/solo", | ||
}, | ||
]; | ||
|
||
describe("createMarkdown", () => { | ||
beforeEach(() => { | ||
require("../fetch").__resetMockResponses(); | ||
require("../packages").getPackages.mockImplementation(() => listOfWorkspacePackages); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe("multiple tags", () => { | ||
it("outputs correct changelog", async () => { | ||
require("../git").changedPaths.mockImplementation((sha: string) => listOfPackagesForEachCommit[sha]); | ||
require("../git").lastTag.mockImplementation(() => "v8.0.0"); | ||
require("../git").listCommits.mockImplementation(() => listOfCommits); | ||
require("../git").listTagNames.mockImplementation(() => [ | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
"[email protected]", | ||
]); | ||
|
||
require("../fetch").__setMockResponses({ | ||
...usersCache, | ||
...issuesCache, | ||
}); | ||
|
||
const MockedChangelog = require("../changelog").default; | ||
const changelog = new MockedChangelog(); | ||
|
||
const markdown = await changelog.createMarkdown(); | ||
|
||
expect(markdown).toMatchSnapshot(); | ||
}); | ||
}); | ||
describe("single tags", () => { | ||
it("outputs correct changelog", async () => { | ||
require("../git").changedPaths.mockImplementation((sha: string) => listOfPackagesForEachCommit[sha]); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new logic to get the package name.