This repository was archived by the owner on Dec 4, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Expand file tree Collapse file tree 4 files changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,14 @@ import ComponentNotExistsException from './component-not-exists';
2
2
import ComponentNotExistsInException from './component-not-exists-in' ;
3
3
import NoConsumerFoundException from './no-consumer-found' ;
4
4
import MultipleScopesNoDefException from './multiple-scopes-no-def' ;
5
+ import PackageJsonNotFound from './package-json-not-found' ;
6
+ import PackageJsonAlreadyExists from './package-json-already-exists' ;
5
7
6
8
export {
7
9
ComponentNotExistsException ,
8
10
ComponentNotExistsInException ,
9
11
NoConsumerFoundException ,
10
12
MultipleScopesNoDefException ,
13
+ PackageJsonNotFound ,
14
+ PackageJsonAlreadyExists ,
11
15
} ;
Original file line number Diff line number Diff line change
1
+ export default class PackageJsonAlreadyExists extends Error {
2
+ constructor ( packageJsonPath ) {
3
+ super ( `The package.json in path "${ packageJsonPath } " already exists
4
+ ` ) ;
5
+ this . name = 'PackageJsonAlreadyExistsInException' ;
6
+ this . code = 'PJSONEX' ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ export default class PackageJsonNotFound extends Error {
2
+ constructor ( packageJsonPath ) {
3
+ super ( `The package.json in path "${ packageJsonPath } " has not found
4
+ ` ) ;
5
+ this . name = 'PackageJsonNotExistsInException' ;
6
+ this . code = 'ENOENT' ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -10,9 +10,10 @@ function composePath(componentRootFolder: string) {
10
10
}
11
11
12
12
function hasExisting ( componentRootFolder : string , throws ?: boolean = false ) : boolean {
13
- const exists = fs . pathExistsSync ( composePath ( componentRootFolder ) ) ;
13
+ const packageJsonPath = composePath ( componentRootFolder ) ;
14
+ const exists = fs . pathExistsSync ( packageJsonPath ) ;
14
15
if ( ! exists && throws ) {
15
- throw ( new PackageJsonNotFound ( ) ) ;
16
+ throw ( new PackageJsonNotFound ( packageJsonPath ) ) ;
16
17
}
17
18
return exists ;
18
19
}
@@ -68,7 +69,7 @@ export default class PackageJson {
68
69
69
70
async write ( { override = true } : { override ?: boolean } ) : Promise < boolean > {
70
71
if ( ! override && hasExisting ( this . componentRootFolder ) ) {
71
- return Promise . reject ( new PackageJsonAlreadyExists ( ) ) ;
72
+ return Promise . reject ( new PackageJsonAlreadyExists ( this . componentRootFolder ) ) ;
72
73
}
73
74
74
75
const plain = this . toPlainObject ( ) ;
You can’t perform that action at this time.
0 commit comments