Skip to content
This repository was archived by the owner on Dec 4, 2022. It is now read-only.

Commit e92f36e

Browse files
committed
Create missing exception classes
1 parent 12999b0 commit e92f36e

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/exceptions/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@ import ComponentNotExistsException from './component-not-exists';
22
import ComponentNotExistsInException from './component-not-exists-in';
33
import NoConsumerFoundException from './no-consumer-found';
44
import MultipleScopesNoDefException from './multiple-scopes-no-def';
5+
import PackageJsonNotFound from './package-json-not-found';
6+
import PackageJsonAlreadyExists from './package-json-already-exists';
57

68
export {
79
ComponentNotExistsException,
810
ComponentNotExistsInException,
911
NoConsumerFoundException,
1012
MultipleScopesNoDefException,
13+
PackageJsonNotFound,
14+
PackageJsonAlreadyExists,
1115
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
}

src/package-json/package-json.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ function composePath(componentRootFolder: string) {
1010
}
1111

1212
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);
1415
if (!exists && throws) {
15-
throw (new PackageJsonNotFound());
16+
throw (new PackageJsonNotFound(packageJsonPath));
1617
}
1718
return exists;
1819
}
@@ -68,7 +69,7 @@ export default class PackageJson {
6869

6970
async write({ override = true }: { override?: boolean }): Promise<boolean> {
7071
if (!override && hasExisting(this.componentRootFolder)) {
71-
return Promise.reject(new PackageJsonAlreadyExists());
72+
return Promise.reject(new PackageJsonAlreadyExists(this.componentRootFolder));
7273
}
7374

7475
const plain = this.toPlainObject();

0 commit comments

Comments
 (0)