diff --git a/src/changelog.spec.ts b/src/changelog.spec.ts index d7f7839..f62dc4a 100644 --- a/src/changelog.spec.ts +++ b/src/changelog.spec.ts @@ -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"], ]; diff --git a/src/changelog.ts b/src/changelog.ts index 3c78619..02c36ac 100644 --- a/src/changelog.ts +++ b/src/changelog.ts @@ -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("/");