Fix safeEntityName
createOrMergeEntity was replacing capital letters with -. For example "@internal/pluginApi" would result in "internal-plugin-pi". Updated to correctly handle capital letters, prefixing them with - unless they are the first character. For example "@internal/pluginApi" would result in "internal-plugin-api". Signed-off-by: Brian Hudson <brian.r.hudson@gmail.com> m>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/repo-tools': patch
|
||||
---
|
||||
|
||||
Resolved an issue with generate-catalog-info where it was replacing upper case characters with -.
|
||||
@@ -165,8 +165,17 @@ async function fixCatalogInfoYaml(options: FixOptions) {
|
||||
relativePath('.', yamlPath),
|
||||
);
|
||||
const safeName = packageJson.name
|
||||
.replace(/[^a-z0-9_\-\.]+/g, '-')
|
||||
.replace(/^[^a-z0-9]|[^a-z0-9]$/g, '');
|
||||
.replace(/^[^\w\s]|[^a-z0-9]$/g, '')
|
||||
.replace(/[^A-Za-z0-9_\-.]+/g, '-')
|
||||
.replace(/([A-Z])/g, (_, letter, index, original) => {
|
||||
if (index !== 0) {
|
||||
const previousChar = original[index - 1];
|
||||
if (previousChar !== '-') {
|
||||
return `-${letter.toLowerCase()}`;
|
||||
}
|
||||
}
|
||||
return letter.toLowerCase();
|
||||
});
|
||||
let yamlJson: BackstagePackageEntity;
|
||||
|
||||
try {
|
||||
@@ -241,8 +250,17 @@ function createOrMergeEntity(
|
||||
existingEntity: BackstagePackageEntity | Record<string, any> = {},
|
||||
): BackstagePackageEntity {
|
||||
const safeEntityName = packageJson.name
|
||||
.replace(/[^a-z0-9_\-\.]+/g, '-')
|
||||
.replace(/^[^a-z0-9]|[^a-z0-9]$/g, '');
|
||||
.replace(/^[^\w\s]|[^a-z0-9]$/g, '')
|
||||
.replace(/[^A-Za-z0-9_\-.]+/g, '-')
|
||||
.replace(/([A-Z])/g, (_, letter, index, original) => {
|
||||
if (index !== 0) {
|
||||
const previousChar = original[index - 1];
|
||||
if (previousChar !== '-') {
|
||||
return `-${letter.toLowerCase()}`;
|
||||
}
|
||||
}
|
||||
return letter.toLowerCase();
|
||||
});
|
||||
|
||||
return {
|
||||
...existingEntity,
|
||||
|
||||
Reference in New Issue
Block a user