From 1041e4a169d9bbb21b715800eeadc3e29c67a374 Mon Sep 17 00:00:00 2001 From: Ian Clanton-Thuon Date: Wed, 21 Aug 2024 03:21:33 -0400 Subject: [PATCH] Fix a few issues with the typings generator plugin. --- .../fix-a-few-issues_2024-08-21-07-21.json | 10 ++++++ .../fix-a-few-issues_2024-08-21-07-21.json | 10 ++++++ .../config/subspaces/default/pnpm-lock.yaml | 3 -- .../package.json | 1 - .../src/LocalizationTypingsPlugin.ts | 2 +- .../src/TypingsGenerator.ts | 33 +++++++++++-------- 6 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 common/changes/@rushstack/heft-localization-typings-plugin/fix-a-few-issues_2024-08-21-07-21.json create mode 100644 common/changes/@rushstack/localization-utilities/fix-a-few-issues_2024-08-21-07-21.json diff --git a/common/changes/@rushstack/heft-localization-typings-plugin/fix-a-few-issues_2024-08-21-07-21.json b/common/changes/@rushstack/heft-localization-typings-plugin/fix-a-few-issues_2024-08-21-07-21.json new file mode 100644 index 00000000000..a93b21f6fe1 --- /dev/null +++ b/common/changes/@rushstack/heft-localization-typings-plugin/fix-a-few-issues_2024-08-21-07-21.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/heft-localization-typings-plugin", + "comment": "Fix an issue where the `stringNamesToIgnore` option was ignored.", + "type": "patch" + } + ], + "packageName": "@rushstack/heft-localization-typings-plugin" +} \ No newline at end of file diff --git a/common/changes/@rushstack/localization-utilities/fix-a-few-issues_2024-08-21-07-21.json b/common/changes/@rushstack/localization-utilities/fix-a-few-issues_2024-08-21-07-21.json new file mode 100644 index 00000000000..44e304d9d0b --- /dev/null +++ b/common/changes/@rushstack/localization-utilities/fix-a-few-issues_2024-08-21-07-21.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@rushstack/localization-utilities", + "comment": "Fix an issue where `inferDefaultExportInterfaceNameFromFilename` did not apply.", + "type": "patch" + } + ], + "packageName": "@rushstack/localization-utilities" +} \ No newline at end of file diff --git a/common/config/subspaces/default/pnpm-lock.yaml b/common/config/subspaces/default/pnpm-lock.yaml index 0c0dccf9ef1..28c5be93e60 100644 --- a/common/config/subspaces/default/pnpm-lock.yaml +++ b/common/config/subspaces/default/pnpm-lock.yaml @@ -2798,9 +2798,6 @@ importers: specifier: workspace:* version: link:../../libraries/localization-utilities devDependencies: - '@microsoft/api-extractor': - specifier: workspace:* - version: link:../../apps/api-extractor '@rushstack/heft': specifier: workspace:* version: link:../../apps/heft diff --git a/heft-plugins/heft-localization-typings-plugin/package.json b/heft-plugins/heft-localization-typings-plugin/package.json index 9134f3c65f1..8c8e846de1c 100644 --- a/heft-plugins/heft-localization-typings-plugin/package.json +++ b/heft-plugins/heft-localization-typings-plugin/package.json @@ -19,7 +19,6 @@ "@rushstack/heft": "^0.67.0" }, "devDependencies": { - "@microsoft/api-extractor": "workspace:*", "@rushstack/heft": "workspace:*", "local-node-rig": "workspace:*", "eslint": "~8.57.0" diff --git a/heft-plugins/heft-localization-typings-plugin/src/LocalizationTypingsPlugin.ts b/heft-plugins/heft-localization-typings-plugin/src/LocalizationTypingsPlugin.ts index 923b2d24c1e..b6e5e0e8161 100644 --- a/heft-plugins/heft-localization-typings-plugin/src/LocalizationTypingsPlugin.ts +++ b/heft-plugins/heft-localization-typings-plugin/src/LocalizationTypingsPlugin.ts @@ -71,7 +71,7 @@ export default class LocalizationTypingsPlugin implements IHeftTaskPlugin stringNamesToIgnoreSet.has(stringName) + ? (filePath: string, stringName: string) => stringNamesToIgnoreSet.has(stringName) : undefined, secondaryGeneratedTsFolders }); diff --git a/libraries/localization-utilities/src/TypingsGenerator.ts b/libraries/localization-utilities/src/TypingsGenerator.ts index 86fac8f0ec1..a680a0cb812 100644 --- a/libraries/localization-utilities/src/TypingsGenerator.ts +++ b/libraries/localization-utilities/src/TypingsGenerator.ts @@ -3,6 +3,7 @@ import { StringValuesTypingsGenerator, + type IStringValueTypings, type IExportAsDefaultOptions, type IStringValueTyping, type ITypingsGeneratorBaseOptions @@ -64,7 +65,11 @@ export class TypingsGenerator extends StringValuesTypingsGenerator { super({ ...options, fileExtensions: ['.resx', '.resx.json', '.loc.json', '.resjson'], - parseAndGenerateTypings: (content: string, filePath: string, relativeFilePath: string) => { + parseAndGenerateTypings: ( + content: string, + filePath: string, + relativeFilePath: string + ): IStringValueTypings => { const locFileData: ILocalizationFile = parseLocFile({ filePath, content, @@ -89,7 +94,6 @@ export class TypingsGenerator extends StringValuesTypingsGenerator { }); } - let exportAsDefaultInterfaceName: string | undefined; if (inferDefaultExportInterfaceNameFromFilename) { const lastSlashIndex: number = Math.max(filePath.lastIndexOf('/'), filePath.lastIndexOf('\\')); let extensionIndex: number = filePath.lastIndexOf('.'); @@ -100,20 +104,23 @@ export class TypingsGenerator extends StringValuesTypingsGenerator { const fileNameWithoutExtension: string = filePath.substring(lastSlashIndex + 1, extensionIndex); const normalizedFileName: string = fileNameWithoutExtension.replace(/[^a-zA-Z0-9$_]/g, ''); const firstCharUpperCased: string = normalizedFileName.charAt(0).toUpperCase(); - exportAsDefaultInterfaceName = `I${firstCharUpperCased}${normalizedFileName.slice(1)}`; + let interfaceName: string | undefined = `I${firstCharUpperCased}${normalizedFileName.slice(1)}`; - if ( - !exportAsDefaultInterfaceName.endsWith('strings') && - !exportAsDefaultInterfaceName.endsWith('Strings') - ) { - exportAsDefaultInterfaceName += 'Strings'; + if (!interfaceName.endsWith('strings') && !interfaceName.endsWith('Strings')) { + interfaceName += 'Strings'; } - } - return { - typings, - exportAsDefaultInterfaceName - }; + return { + typings, + exportAsDefault: { + interfaceName + } + }; + } else { + return { + typings + }; + } } }); }