11/* eslint-disable jsdoc/require-jsdoc */
22
3- import path , {
4- join ,
5- resolve ,
6- parse ,
7- basename ,
8- dirname ,
9- posix ,
10- sep
11- } from 'path' ;
3+ import { join , resolve , parse , basename , dirname , posix , sep } from 'path' ;
124import { promises , existsSync } from 'fs' ;
135import { glob } from 'glob' ;
146import { info , warning , error , getInput , setFailed } from '@actions/core' ;
@@ -20,15 +12,11 @@ import {
2012 readIncludeExcludeWithDefaults ,
2113 transpileDirectory
2214} from '@sap-cloud-sdk/generator-common/internal' ;
23- import type { CompilerOptions } from 'typescript' ;
2415import { getPackages } from '@manypkg/get-packages' ;
16+ import type { CompilerOptions } from 'typescript' ;
2517
2618const { readFile, lstat, readdir } = promises ;
2719
28- const localConfigPath = join (
29- process . cwd ( ) ,
30- 'build-packages/check-public-api/local-config.json'
31- ) ;
3220const pathToTsConfigRoot = join ( process . cwd ( ) , 'tsconfig.json' ) ;
3321const pathRootNodeModules = join ( process . cwd ( ) , 'node_modules' ) ;
3422export const regexExportedIndex = / e x p o r t (?: t y p e ) ? \{ ( [ \w , ] + ) \} f r o m ' \. / g;
@@ -48,14 +36,24 @@ function paths(pathToPackage: string): {
4836 pathCompiled : string ;
4937} {
5038 return {
51- pathToSource : join ( pathToPackage , 'src' ) ,
52- pathToPackageJson : join ( pathToPackage , 'package.json' ) ,
53- pathToTsConfig : join ( pathToPackage , 'tsconfig.json' ) ,
54- pathToNodeModules : join ( pathToPackage , 'node_modules' ) ,
39+ pathToSource : getPathWithPosixSeparator ( join ( pathToPackage , 'src' ) ) ,
40+ pathToPackageJson : getPathWithPosixSeparator (
41+ join ( pathToPackage , 'package.json' )
42+ ) ,
43+ pathToTsConfig : getPathWithPosixSeparator (
44+ join ( pathToPackage , 'tsconfig.json' )
45+ ) ,
46+ pathToNodeModules : getPathWithPosixSeparator (
47+ join ( pathToPackage , 'node_modules' )
48+ ) ,
5549 pathCompiled : 'dist'
5650 } ;
5751}
5852
53+ function getPathWithPosixSeparator ( filePath : string ) : string {
54+ return filePath . split ( sep ) . join ( posix . sep ) ;
55+ }
56+
5957function mockFileSystem ( pathToPackage : string ) {
6058 const { pathToSource, pathToTsConfig, pathToNodeModules, pathToPackageJson } =
6159 paths ( pathToPackage ) ;
@@ -105,15 +103,13 @@ function compareApisAndLog(
105103 allExportedTypes : ExportedObject [ ]
106104) : boolean {
107105 let setsAreEqual = true ;
108- const ignoredPaths = getListFromInput ( 'ignored_paths ') ;
106+ const ignoredPathPattern = getInput ( 'ignored_path_pattern ') ;
109107
110108 allExportedTypes . forEach ( exportedType => {
111- const normalizedPath = exportedType . path . split ( sep ) . join ( posix . sep ) ;
109+ const normalizedPath = getPathWithPosixSeparator ( exportedType . path ) ;
112110
113- const isPathMatched = ignoredPaths . length
114- ? ignoredPaths . some ( ignoredPath =>
115- normalizedPath . includes ( ignoredPath . split ( sep ) . join ( posix . sep ) )
116- )
111+ const isPathMatched = ignoredPathPattern
112+ ? new RegExp ( ignoredPathPattern ) . test ( normalizedPath )
117113 : false ;
118114 if (
119115 ! allExportedIndex . find ( nameInIndex => exportedType . name === nameInIndex )
@@ -169,7 +165,10 @@ export async function checkApiOfPackage(pathToPackage: string): Promise<void> {
169165 usePrettier : false
170166 }
171167 } ,
172- { exclude : includeExclude ?. exclude ! , include : [ '**/*.ts' ] }
168+ {
169+ exclude : includeExclude ? includeExclude . exclude : [ ] ,
170+ include : [ '**/*.ts' ]
171+ }
173172 ) ;
174173
175174 const forceInternalExports = getInput ( 'force_internal_exports' ) === 'true' ;
@@ -309,16 +308,16 @@ export async function parseIndexFile(
309308 ...parseExportedObjectsInFile ( fileContent ) . map ( obj => obj . name )
310309 ] ;
311310 const starFiles = captureGroupsFromGlobalRegex (
312- / e x p o r t \* f r o m ' ( [ \w \ /. - ] + ) ' / g,
311+ / e x p o r t \* f r o m ' ( [ \w / . - ] + ) ' / g,
313312 fileContent
314313 ) ;
315314 const starFileExports = await Promise . all (
316315 starFiles . map ( async relativeFilePath => {
317- const filePath = relativeFilePath . endsWith ( '.js' )
316+ const absolutePath = relativeFilePath . endsWith ( '.js' )
318317 ? resolve ( cwd , `${ relativeFilePath . slice ( 0 , - 3 ) } .ts` )
319318 : resolve ( cwd , `${ relativeFilePath } .ts` ) ;
320319
321- return parseIndexFile ( filePath , forceInternalExports ) ;
320+ return parseIndexFile ( absolutePath , forceInternalExports ) ;
322321 } )
323322 ) ;
324323 return [ ...localExports , ...starFileExports . flat ( ) ] ;
@@ -410,8 +409,8 @@ async function runCheckApi() {
410409 for ( const pkg of packagesToCheck ) {
411410 try {
412411 await checkApiOfPackage ( pkg . dir ) ;
413- } catch ( error ) {
414- setFailed ( `API check failed for ${ pkg . relativeDir } : ${ error } ` ) ;
412+ } catch ( e ) {
413+ setFailed ( `API check failed for ${ pkg . relativeDir } : ${ e } ` ) ;
415414 process . exit ( 1 ) ;
416415 }
417416 }
0 commit comments