From 31860438d4e49c5f41a83a44b78f5f4a4c7d795a Mon Sep 17 00:00:00 2001 From: Bart van den Ende Date: Tue, 1 Oct 2024 09:20:11 +0200 Subject: [PATCH 1/2] feat: Add support for new d.ts extension format when using TS moduleresolution 'bundler' or 'nodenext' --- apps/api-extractor/src/api/ExtractorConfig.ts | 7 +++-- .../src/api/test/ExtractorConfig.test.ts | 28 +++++++++++++++++++ ...rtvandenende-wm-4899_2024-10-01-07-19.json | 10 +++++++ 3 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 apps/api-extractor/src/api/test/ExtractorConfig.test.ts create mode 100644 common/changes/@rushstack/eslint-patch/bartvandenende-wm-4899_2024-10-01-07-19.json diff --git a/apps/api-extractor/src/api/ExtractorConfig.ts b/apps/api-extractor/src/api/ExtractorConfig.ts index 5f9a739c820..3bd42145232 100644 --- a/apps/api-extractor/src/api/ExtractorConfig.ts +++ b/apps/api-extractor/src/api/ExtractorConfig.ts @@ -257,8 +257,11 @@ export class ExtractorConfig { path.join(__dirname, '../schemas/api-extractor-defaults.json') ); - /** Match all three flavors for type declaration files (.d.ts, .d.mts, .d.cts) */ - private static readonly _declarationFileExtensionRegExp: RegExp = /\.d\.(c|m)?ts$/i; + /** + * Match all three flavors for type declaration files (.d.ts, .d.mts, .d.cts) + * including the new TS 5 bundle resolutions (.d.\{extension\}.ts, .d.\{extension\}.mts, .d.\{extension\}.cts) + **/ + private static readonly _declarationFileExtensionRegExp: RegExp = /\.d(\.[a-z]+)?\.(c|m)?ts$/i; /** {@inheritDoc IConfigFile.projectFolder} */ public readonly projectFolder: string; diff --git a/apps/api-extractor/src/api/test/ExtractorConfig.test.ts b/apps/api-extractor/src/api/test/ExtractorConfig.test.ts new file mode 100644 index 00000000000..fa821b5f890 --- /dev/null +++ b/apps/api-extractor/src/api/test/ExtractorConfig.test.ts @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import { ExtractorConfig } from '../ExtractorConfig'; + +describe('ExtractorConfig', () => { + describe('hasDtsFileExtension', () => { + it.each([ + ['test.ts', false], + ['test.cts', false], + ['test.mts', false], + ['test.d.ts', true], + ['test.d.mts', true], + ['test.d.cts', true], + ['test.css', false], + ['test.css.ts', false], + ['test.css.d.ts', true], + ['test.json', false], + ['test.json.ts', false], + ['test.d.css.ts', true], + ['test.json.d.ts', true], + ['test.d.json.ts', true] + ])('file "%s" has dts file extension equals "%s"', (file, expected) => { + const result = ExtractorConfig.hasDtsFileExtension(file); + expect(result).toEqual(expected); + }); + }); +}); diff --git a/common/changes/@rushstack/eslint-patch/bartvandenende-wm-4899_2024-10-01-07-19.json b/common/changes/@rushstack/eslint-patch/bartvandenende-wm-4899_2024-10-01-07-19.json new file mode 100644 index 00000000000..fdc04b30542 --- /dev/null +++ b/common/changes/@rushstack/eslint-patch/bartvandenende-wm-4899_2024-10-01-07-19.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/api-extractor", + "comment": "Add support for new d.ts extension format when using TS moduleresolution 'bundler' or 'nodenext'", + "type": "patch" + } + ], + "packageName": "@microsoft/api-extractor" +} \ No newline at end of file From b6c910eb4f323e34924a1c05f9eb2caee55353e7 Mon Sep 17 00:00:00 2001 From: Bart van den Ende Date: Tue, 1 Oct 2024 09:33:08 +0200 Subject: [PATCH 2/2] chore: improve ordering --- apps/api-extractor/src/api/test/ExtractorConfig.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/api-extractor/src/api/test/ExtractorConfig.test.ts b/apps/api-extractor/src/api/test/ExtractorConfig.test.ts index fa821b5f890..28b735289e4 100644 --- a/apps/api-extractor/src/api/test/ExtractorConfig.test.ts +++ b/apps/api-extractor/src/api/test/ExtractorConfig.test.ts @@ -15,9 +15,9 @@ describe('ExtractorConfig', () => { ['test.css', false], ['test.css.ts', false], ['test.css.d.ts', true], + ['test.d.css.ts', true], ['test.json', false], ['test.json.ts', false], - ['test.d.css.ts', true], ['test.json.d.ts', true], ['test.d.json.ts', true] ])('file "%s" has dts file extension equals "%s"', (file, expected) => {