Skip to content

Commit

Permalink
Git doesn't believe in directories, which allows us to simplify thing…
Browse files Browse the repository at this point in the history
…s a bit
  • Loading branch information
NullVoxPopuli committed May 22, 2024
1 parent c534154 commit 09555ac
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
4 changes: 1 addition & 3 deletions src/changelog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ describe("Changelog", () => {

const TESTS = [
["", ""],
["/ember-fastboot", "ember-fastboot"],
["/ember-fastboot-2-fast-2-furious", "ember-fastboot-2-fast-2-furious"],
["/ember-fastboot/package.json", "ember-fastboot"],
["/ember-fastboot-2-fast-2-furious/package.json", "ember-fastboot-2-fast-2-furious"],
["/ember-fastboot-tokyo-drift", "ember-fastboot-tokyo-drift"],
["/ember-fastboot-tokyo-drift/package.json", "ember-fastboot-tokyo-drift"],
];

Expand Down
18 changes: 7 additions & 11 deletions src/changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,21 +91,17 @@ export default class Changelog {
// ember-fastboot-2-fast-2-furious
//
// in this case, we can't short circuit with length === 1, but we can do a longer match
const packageCandidates = this.config.packages.filter(p => absolutePath.startsWith(p.path));
const foundPackage = this.config.packages.find(p => {
let withSlash = p.path.endsWith("/") ? p.path : `${p.path}/`;

if (packageCandidates.length === 1) {
return packageCandidates[0].name;
}

let longestMatch = "";
return absolutePath.startsWith(withSlash);
});

for (let pkg of packageCandidates) {
if (pkg.name.length > longestMatch.length) {
longestMatch = pkg.name;
}
if (foundPackage) {
return foundPackage.name;
}

return longestMatch; // may be empty if 0 candidates exist
return "";
} else {
// if we did not find any packages then default to
const parts = path.split("/");
Expand Down

0 comments on commit 09555ac

Please sign in to comment.