From 987971bd59c282e885679576262732e9afa297bb Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 2 Aug 2018 17:26:53 +0200 Subject: Fix bug where if there were multiple matches, it wouldn't always take the longest match --- packages/monorepo-scripts/src/utils/publish_utils.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'packages/monorepo-scripts') diff --git a/packages/monorepo-scripts/src/utils/publish_utils.ts b/packages/monorepo-scripts/src/utils/publish_utils.ts index 3cdd2c4fb..974fb4d0d 100644 --- a/packages/monorepo-scripts/src/utils/publish_utils.ts +++ b/packages/monorepo-scripts/src/utils/publish_utils.ts @@ -274,7 +274,7 @@ function findExportPathGivenTypedocName( packageName: string, typedocName: string, ): string { - const typeDocNameWithoutQuotes = _.replace(typedocName, '"', ''); + const typeDocNameWithoutQuotes = _.replace(typedocName, /"/g, ''); const sanitizedExportPathToExportPath: { [sanitizedName: string]: string } = {}; const exportPaths = _.keys(exportPathToExportedItems); const sanitizedExportPaths = _.map(exportPaths, exportPath => { @@ -292,7 +292,13 @@ function findExportPathGivenTypedocName( sanitizedExportPathToExportPath[exportPath] = exportPath; return exportPath; }); - const matchingSanitizedExportPathIfExists = _.find(sanitizedExportPaths, p => { + // We need to sort the exportPaths by length (longest first), so that the match finding will pick + // longer matches before shorter matches, since it might match both, but the longer match is more + // precisely what we are looking for. + const sanitizedExportPathsSortedByLength = sanitizedExportPaths.sort((a: string, b: string) => { + return b.length - a.length; + }); + const matchingSanitizedExportPathIfExists = _.find(sanitizedExportPathsSortedByLength, p => { return _.startsWith(typeDocNameWithoutQuotes, p); }); if (_.isUndefined(matchingSanitizedExportPathIfExists)) { -- cgit v1.2.3