@@ -20,9 +20,11 @@ export class PackageNameResolver {
2020 PackageNameResolver . GradleBuildName ,
2121 ] ;
2222 private applicationName : string ;
23+ private fileSystem : FileSystem ;
2324
24- constructor ( applicationName : string ) {
25+ constructor ( applicationName : string , fileSystem ?: FileSystem ) {
2526 this . applicationName = applicationName ;
27+ this . fileSystem = fileSystem || new FileSystem ( ) ;
2628 }
2729
2830 /**
@@ -47,36 +49,27 @@ export class PackageNameResolver {
4749 }
4850
4951 private async readApplicationId ( gradlePath : string ) : Promise < string | null > {
50- if ( gradlePath ) {
51- const fs = new FileSystem ( ) ;
52- if ( await fs . exists ( gradlePath ) ) {
53- const content = await fs . readFile ( gradlePath ) ;
54- const match = content . toString ( ) . match ( PackageNameResolver . ApplicationIdRegexp ) ;
55- return match ? match [ 2 ] : null ;
56- }
52+ if ( ! ( await this . fileSystem . exists ( gradlePath ) ) ) {
53+ return null ;
5754 }
58- return null ;
55+
56+ const content = await this . fileSystem . readFile ( gradlePath ) ;
57+ const match = content . toString ( ) . match ( PackageNameResolver . ApplicationIdRegexp ) ;
58+ return match ? match [ 2 ] : null ;
5959 }
6060
6161 /**
6262 * Given a manifest file path, it parses the file and returns the package name.
6363 * If the package name cannot be parsed, the default packge name is returned.
6464 */
6565 private async readPackageName ( manifestPath : string ) : Promise < string > {
66- if ( manifestPath ) {
67- const fs = new FileSystem ( ) ;
68- const exists = await fs . exists ( manifestPath ) ;
69- if ( exists ) {
70- const manifestContent = await fs . readFile ( manifestPath ) ;
71- let packageName = this . parsePackageName ( manifestContent . toString ( ) ) ;
72- if ( ! packageName ) {
73- packageName = this . getDefaultPackageName ( this . applicationName ) ;
74- }
75- return packageName ;
76- }
66+ if ( ! ( await this . fileSystem . exists ( manifestPath ) ) ) {
7767 return this . getDefaultPackageName ( this . applicationName ) ;
7868 }
79- return this . getDefaultPackageName ( this . applicationName ) ;
69+
70+ const manifestContent = await this . fileSystem . readFile ( manifestPath ) ;
71+ const packageName = this . parsePackageName ( manifestContent . toString ( ) ) ;
72+ return packageName || this . getDefaultPackageName ( this . applicationName ) ;
8073 }
8174
8275 /**
0 commit comments