From c1089cf5e538e04cbd8fa2c866ce2a39609eb4a9 Mon Sep 17 00:00:00 2001 From: Zhongpin Wang Date: Thu, 24 Jul 2025 13:32:04 +0200 Subject: [PATCH 1/3] fix: ignore as aliases in barrel files --- .github/actions/check-public-api/index.js | 6 ++++-- build-packages/check-public-api/check-public-api.spec.ts | 8 +++++--- build-packages/check-public-api/index.ts | 6 ++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/.github/actions/check-public-api/index.js b/.github/actions/check-public-api/index.js index 7be7b6454b..cfb9ab8022 100644 --- a/.github/actions/check-public-api/index.js +++ b/.github/actions/check-public-api/index.js @@ -209,13 +209,15 @@ function parseExportedObjectsInFile(fileContent) { /** * Parse a barrel file for the exported objects. * It selects all string in \{\} e.g. export \{a,b,c\} from './xyz' will result in [a,b,c]. - * /\/\*[\s\S]*?\*\/|\/\/.*|[\s]+/g - Matches single-line comments or multi-line comments or whitespaces. + * Aliases defined with 'as' keyword are removed. * @param fileContent - Content of the index file to be parsed. * @param regex - Regular expression used for matching exports. * @returns List of objects exported by the given index file. */ function parseBarrelFile(fileContent, regex) { - const normalized = fileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+/g, ''); + // Remove block comments, single-line comments, 'as' keyword and aliases, and whitespace characters + const normalized = fileContent + .replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+as[\s]+[a-zA-Z_$][0-9a-zA-Z_$]*|[\s]+/g, ''); const groups = captureGroupsFromGlobalRegex(regex, normalized); return (0, util_1.flatten)(groups.map(group => group.split(','))); } diff --git a/build-packages/check-public-api/check-public-api.spec.ts b/build-packages/check-public-api/check-public-api.spec.ts index 5390d13c14..fd496f4983 100644 --- a/build-packages/check-public-api/check-public-api.spec.ts +++ b/build-packages/check-public-api/check-public-api.spec.ts @@ -235,9 +235,11 @@ export declare type MyType = {value:string} const dummyIndexFile = `export { o1 } from './bla'; - export { o2, o3 } from './bla'; - export { o4, - + export { o2, o3 as o3$Some_thing } from './bla'; // :-) This is a comment + export { o4 as o4Something, + /**** + * * This is a block comment **??? * + * **/ o5,o6, o7} from './bla'; `; diff --git a/build-packages/check-public-api/index.ts b/build-packages/check-public-api/index.ts index 820a5e8f60..569579c2b1 100644 --- a/build-packages/check-public-api/index.ts +++ b/build-packages/check-public-api/index.ts @@ -268,13 +268,15 @@ export function parseExportedObjectsInFile( /** * Parse a barrel file for the exported objects. * It selects all string in \{\} e.g. export \{a,b,c\} from './xyz' will result in [a,b,c]. - * /\/\*[\s\S]*?\*\/|\/\/.*|[\s]+/g - Matches single-line comments or multi-line comments or whitespaces. + * Aliases defined with 'as' keyword are removed. * @param fileContent - Content of the index file to be parsed. * @param regex - Regular expression used for matching exports. * @returns List of objects exported by the given index file. */ export function parseBarrelFile(fileContent: string, regex: RegExp): string[] { - const normalized = fileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+/g, ''); + // Remove block comments, single-line comments, 'as' keyword and aliases, and whitespace characters + const normalized = fileContent + .replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+as[\s]+[a-zA-Z_$][0-9a-zA-Z_$]*|[\s]+/g, ''); const groups = captureGroupsFromGlobalRegex(regex, normalized); return flatten(groups.map(group => group.split(','))); From a590d7ae7d33b1e07d4b41b5dbd57c8eaa85bb15 Mon Sep 17 00:00:00 2001 From: cloud-sdk-js Date: Thu, 24 Jul 2025 11:38:00 +0000 Subject: [PATCH 2/3] Changes from lint:fix --- build-packages/check-public-api/index.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build-packages/check-public-api/index.ts b/build-packages/check-public-api/index.ts index 569579c2b1..09a86dfdf6 100644 --- a/build-packages/check-public-api/index.ts +++ b/build-packages/check-public-api/index.ts @@ -275,8 +275,10 @@ export function parseExportedObjectsInFile( */ export function parseBarrelFile(fileContent: string, regex: RegExp): string[] { // Remove block comments, single-line comments, 'as' keyword and aliases, and whitespace characters - const normalized = fileContent - .replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+as[\s]+[a-zA-Z_$][0-9a-zA-Z_$]*|[\s]+/g, ''); + const normalized = fileContent.replace( + /\/\*[\s\S]*?\*\/|\/\/.*|[\s]+as[\s]+[a-zA-Z_$][0-9a-zA-Z_$]*|[\s]+/g, + '' + ); const groups = captureGroupsFromGlobalRegex(regex, normalized); return flatten(groups.map(group => group.split(','))); From ace83c013085d73c7d98f22e1ccbda0d8903bdf6 Mon Sep 17 00:00:00 2001 From: cloud-sdk-js Date: Thu, 24 Jul 2025 11:40:12 +0000 Subject: [PATCH 3/3] Changes from lint:fix --- .github/actions/check-public-api/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/actions/check-public-api/index.js b/.github/actions/check-public-api/index.js index cfb9ab8022..17c4b22ab7 100644 --- a/.github/actions/check-public-api/index.js +++ b/.github/actions/check-public-api/index.js @@ -216,8 +216,7 @@ function parseExportedObjectsInFile(fileContent) { */ function parseBarrelFile(fileContent, regex) { // Remove block comments, single-line comments, 'as' keyword and aliases, and whitespace characters - const normalized = fileContent - .replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+as[\s]+[a-zA-Z_$][0-9a-zA-Z_$]*|[\s]+/g, ''); + const normalized = fileContent.replace(/\/\*[\s\S]*?\*\/|\/\/.*|[\s]+as[\s]+[a-zA-Z_$][0-9a-zA-Z_$]*|[\s]+/g, ''); const groups = captureGroupsFromGlobalRegex(regex, normalized); return (0, util_1.flatten)(groups.map(group => group.split(','))); }