Skip to content

Commit 66ee593

Browse files
committed
Merge branch 'release/0.1.0' into develop
2 parents 8644656 + 89200f3 commit 66ee593

File tree

5 files changed

+56
-22
lines changed

5 files changed

+56
-22
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
All notable changes to this project will be documented in this file.
44

5-
## [unreleased]
5+
## [0.1.0] - 2024-09-03
66

77
### 🚀 Features
88

@@ -11,6 +11,11 @@ All notable changes to this project will be documented in this file.
1111
- *(logger)* Add base class with logger property
1212
- *(logger)* Add name and level property
1313
- *(logger)* Add log method for all levels
14+
- Add changelog with git-cliff
15+
16+
### 🐛 Bug Fixes
17+
18+
- [**breaking**] Remove base class since it was causing runtime error
1419

1520
### 🚜 Refactor
1621

@@ -19,6 +24,7 @@ All notable changes to this project will be documented in this file.
1924
### 📚 Documentation
2025

2126
- Use shields.io for badges
27+
- Add instructions on how to temporary type a property added by a decorator
2228

2329
### 🧪 Testing
2430

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,19 @@
44
![Codecov](https://img.shields.io/codecov/c/github/devsheva/simplelog)
55

66
A simple logger decorator amplify like
7+
8+
## Important
9+
10+
**Experimental decorators** are used for this package implementation and since experimental it has some bugs like unsafe typing.
11+
TypeScript compiler complains when it finds out a property used inside a class that calls a decorator cause it cannot infer it, so as a temporary workaround simply declare an interface
12+
13+
```ts
14+
interface Example {logger: any}
15+
16+
@Logger()
17+
class Example {
18+
hello() {
19+
this.logger.debug() // THIS IS VALID
20+
}
21+
}
22+
```

spec/base.spec.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

spec/logger.spec.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, expectTypeOf, it, vi } from 'vitest'
2-
import Base from '../src/base.js'
2+
33
import {
44
getLogLevel,
55
loggerDecorator,
@@ -9,19 +9,28 @@ import {
99

1010
describe('logger', () => {
1111
it('has a logger property', () => {
12-
class Test extends Base {}
12+
interface Test {
13+
logger: any
14+
}
15+
class Test {}
1316
loggerDecorator()(Test)
1417

1518
expect(Test.prototype).toHaveProperty('logger')
1619
})
1720

1821
it('overrides name if not provided', () => {
19-
class Test extends Base {}
22+
interface Test {
23+
logger: any
24+
}
25+
class Test {}
2026
loggerDecorator()(Test)
2127
})
2228

2329
it('sets name if provided', () => {
24-
class Test extends Base {}
30+
interface Test {
31+
logger: any
32+
}
33+
class Test {}
2534
loggerDecorator('test')(Test)
2635
const instance = new Test()
2736
expect(instance.logger).toHaveProperty('name', 'test')
@@ -30,14 +39,20 @@ describe('logger', () => {
3039
describe('options', () => {
3140
describe('level', () => {
3241
it('defaults to info', () => {
33-
class Test extends Base {}
42+
interface Test {
43+
logger: any
44+
}
45+
class Test {}
3446
loggerDecorator()(Test)
3547
const instance = new Test()
3648
expect(instance.logger).toHaveProperty('level', 'info')
3749
})
3850

3951
it('can be overridden', () => {
40-
class Test extends Base {}
52+
interface Test {
53+
logger: any
54+
}
55+
class Test {}
4156
loggerDecorator('', { level: 'debug' })(Test)
4257
const instance = new Test()
4358
expect(instance.logger).toHaveProperty('level', 'debug')
@@ -49,7 +64,10 @@ describe('logger', () => {
4964
it.each(['verbose', 'debug', 'info', 'warn', 'error'])(
5065
`has a %s method`,
5166
(level) => {
52-
class Test extends Base {}
67+
interface Test {
68+
logger: any
69+
}
70+
class Test {}
5371
loggerDecorator()(Test)
5472
const instance = new Test()
5573
expect(instance.logger).toHaveProperty(level)
@@ -58,7 +76,10 @@ describe('logger', () => {
5876
)
5977

6078
it('should log a message at the specified level', () => {
61-
class Test extends Base {
79+
interface Test {
80+
logger: any
81+
}
82+
class Test {
6283
hello() {
6384
this.logger.debug('hello')
6485
}
@@ -72,7 +93,10 @@ describe('logger', () => {
7293
})
7394

7495
it('should not log a message at a lower level', () => {
75-
class Test extends Base {
96+
interface Test {
97+
logger: any
98+
}
99+
class Test {
76100
hello() {
77101
this.logger.debug('hello')
78102
}

src/base.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)