@forge/util 1.2.1-next.0 → 1.2.2-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,78 @@
1
+ # @atlassian/logger-interface
2
+
3
+ ## 1.3.21
4
+
5
+ ### Patch Changes
6
+
7
+ - c0069ef: Package is now compiled with Typescript 4.4
8
+
9
+ Useful links:
10
+
11
+ - https://github.com/Microsoft/TypeScript-wiki/blob/main/Breaking-Changes.md#more-compliant-indirect-calls-for-imported-functions
12
+ - http://perfectionkills.com/global-eval-what-are-the-options/
13
+
14
+ ## 1.3.20
15
+
16
+ ### Patch Changes
17
+
18
+ - fae10a6: Fixed an issue with compiled typings files after upgrading to TypeScript 4.3. The imports in the typings.d.ts files were compiled with paths relative to the monorepo root, rather than absolute package paths. This problem has now been fixed.
19
+
20
+ ## 1.3.19
21
+
22
+ ### Patch Changes
23
+
24
+ - fae196c: Added a feature to the monorepo so packages with non js entrypoints can be used
25
+
26
+ ## 1.3.18
27
+
28
+ ### Patch Changes
29
+
30
+ - fae1709: Fixed an issue during package building, so bumping all packages to ensure distribution assets are valid
31
+
32
+ ## 1.3.17
33
+
34
+ ### Patch Changes
35
+
36
+ - 97644a1: Set Typescript Compiler target to ES2018
37
+
38
+ ## 1.3.16
39
+
40
+ ### Patch Changes
41
+
42
+ - 85bb2aa: monorepo changes: rename packageJson.publishConfig to packageJson.config.publishOverrides
43
+
44
+ ## 1.3.15
45
+
46
+ ### Patch Changes
47
+
48
+ - 645304b: fix: ensure all monorepo packages do not use ranges in their dependencies (for changeset's automatic bumps)
49
+
50
+ ## 1.3.14
51
+
52
+ ### Patch Changes
53
+
54
+ - 4483856: re-add devDependencies back into package.json and update import order linting rules
55
+
56
+ ## 1.3.13
57
+
58
+ ### Patch Changes
59
+
60
+ - 6af309e: chore: update homepage field in package.json
61
+
62
+ ## 1.3.12
63
+
64
+ ### Patch Changes
65
+
66
+ - 37e36f9: fix: the main, types and typings fields in package.json were incorrect on publish
67
+
68
+ ## 1.3.11
69
+
70
+ ### Patch Changes
71
+
72
+ - b9aad92: fix: the previous patch version did not contain dist files
73
+
74
+ ## 1.3.10
75
+
76
+ ### Patch Changes
77
+
78
+ - c255e4f: Dev improvements: Updated how the package is tested and published
@@ -3,29 +3,27 @@
3
3
  Typescript interface that provides standard logging levels `debug`, `info`, `warn`, `error`, and `fatal`.
4
4
 
5
5
  ```typescript
6
-
7
6
  interface Logger {
8
- debug: LogMethod;
9
- info: LogMethod;
10
- warn: LogMethod;
11
- error: LogMethod;
12
- fatal: LogMethod;
7
+ debug: LogMethod;
8
+ info: LogMethod;
9
+ warn: LogMethod;
10
+ error: LogMethod;
11
+ fatal: LogMethod;
13
12
  }
14
13
 
15
14
  interface LogMethod {
16
- (...data: Array<any>): void;
15
+ (...data: Array<any>): void;
17
16
  }
18
17
  ```
19
18
 
20
- Arguments are untyped to provide freedom of choice for implementors.
19
+ Arguments are untyped to provide freedom of choice for implementors.
21
20
 
22
- An extension of `Logger` that contains a child method is provided for implementors that expose this method. Usually the `opts` object contains a set of fields that are added as fields to each logging entry done by the _child_ logger. It may also serve to set the minimum log level.
21
+ An extension of `Logger` that contains a child method is provided for implementors that expose this method. Usually the `opts` object contains a set of fields that are added as fields to each logging entry done by the _child_ logger. It may also serve to set the minimum log level.
23
22
 
24
23
  ```typescript
25
24
  interface HierarchicalLogger extends Logger {
26
- child(opts: any): HierarchicalLogger;
25
+ child(opts: any): HierarchicalLogger;
27
26
  }
28
27
  ```
29
28
 
30
29
  A default implementation named `NoLogger` is provided for testing purposes.
31
-
@@ -1,5 +1,5 @@
1
1
  export interface LogMethod {
2
- (...data: Array<any>): void;
2
+ (...data: any[]): void;
3
3
  }
4
4
  export interface Logger {
5
5
  debug: LogMethod;
@@ -12,12 +12,13 @@ export interface HierarchicalLogger extends Logger {
12
12
  child(opts: any): HierarchicalLogger;
13
13
  }
14
14
  export declare class NoLogger implements HierarchicalLogger {
15
- debug(..._data: Array<any>): void;
16
- info(..._data: Array<any>): void;
17
- warn(..._data: Array<any>): void;
18
- error(..._data: Array<any>): void;
19
- fatal(..._data: Array<any>): void;
20
- child(..._data: Array<any>): HierarchicalLogger;
15
+ debug(..._data: any[]): void;
16
+ info(..._data: any[]): void;
17
+ warn(..._data: any[]): void;
18
+ error(..._data: any[]): void;
19
+ fatal(..._data: any[]): void;
20
+ child(..._data: any[]): HierarchicalLogger;
21
21
  }
22
22
  export declare function isHierachicalLogger(obj: any): obj is HierarchicalLogger;
23
23
  export declare function isLogger(obj: any): obj is Logger;
24
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;CACxB;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,SAAS,CAAC;IACjB,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC;CAClB;AAED,MAAM,WAAW,kBAAmB,SAAQ,MAAM;IAChD,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG,kBAAkB,CAAC;CACtC;AAED,qBAAa,QAAS,YAAW,kBAAkB;IAE1C,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI;IAC5B,IAAI,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI;IAC3B,IAAI,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI;IAC3B,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI;IAC5B,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,IAAI;IAC5B,KAAK,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,GAAG,kBAAkB;CAIlD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,kBAAkB,CAEvE;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,MAAM,CAahD"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLogger = exports.isHierachicalLogger = exports.NoLogger = void 0;
4
+ class NoLogger {
5
+ /* eslint-disable @typescript-eslint/no-unused-vars */
6
+ debug(..._data) { }
7
+ info(..._data) { }
8
+ warn(..._data) { }
9
+ error(..._data) { }
10
+ fatal(..._data) { }
11
+ child(..._data) {
12
+ return this;
13
+ }
14
+ }
15
+ exports.NoLogger = NoLogger;
16
+ function isHierachicalLogger(obj) {
17
+ return 'child' in obj && typeof obj.child === 'function';
18
+ }
19
+ exports.isHierachicalLogger = isHierachicalLogger;
20
+ function isLogger(obj) {
21
+ return ('debug' in obj &&
22
+ typeof obj.debug === 'function' &&
23
+ 'info' in obj &&
24
+ typeof obj.info === 'function' &&
25
+ 'warn' in obj &&
26
+ typeof obj.warn === 'function' &&
27
+ 'error' in obj &&
28
+ typeof obj.error === 'function' &&
29
+ 'fatal' in obj &&
30
+ typeof obj.fatal === 'function');
31
+ }
32
+ exports.isLogger = isLogger;
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAgBA,MAAa,QAAQ;IACnB,sDAAsD;IAC/C,KAAK,CAAC,GAAG,KAAY,IAAS,CAAC;IAC/B,IAAI,CAAC,GAAG,KAAY,IAAS,CAAC;IAC9B,IAAI,CAAC,GAAG,KAAY,IAAS,CAAC;IAC9B,KAAK,CAAC,GAAG,KAAY,IAAS,CAAC;IAC/B,KAAK,CAAC,GAAG,KAAY,IAAS,CAAC;IAC/B,KAAK,CAAC,GAAG,KAAY;QAC1B,OAAO,IAAI,CAAC;IACd,CAAC;CAEF;AAXD,4BAWC;AAED,SAAgB,mBAAmB,CAAC,GAAQ;IAC1C,OAAO,OAAO,IAAI,GAAG,IAAI,OAAQ,GAA0B,CAAC,KAAK,KAAK,UAAU,CAAC;AACnF,CAAC;AAFD,kDAEC;AAED,SAAgB,QAAQ,CAAC,GAAQ;IAC/B,OAAO,CACL,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU;QAC/B,MAAM,IAAI,GAAG;QACb,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU;QAC9B,MAAM,IAAI,GAAG;QACb,OAAO,GAAG,CAAC,IAAI,KAAK,UAAU;QAC9B,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU;QAC/B,OAAO,IAAI,GAAG;QACd,OAAO,GAAG,CAAC,KAAK,KAAK,UAAU,CAChC,CAAC;AACJ,CAAC;AAbD,4BAaC"}
@@ -6,5 +6,6 @@ export declare class MockLogger implements HierarchicalLogger {
6
6
  error: LogMethod;
7
7
  fatal: LogMethod;
8
8
  child: () => HierarchicalLogger;
9
- _children: Array<MockLogger>;
9
+ private _children;
10
10
  }
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/mocks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGzD,qBAAa,UAAW,YAAW,kBAAkB;IAC5C,KAAK,EAAE,SAAS,CAAa;IAC7B,IAAI,EAAE,SAAS,CAAa;IAC5B,IAAI,EAAE,SAAS,CAAa;IAC5B,KAAK,EAAE,SAAS,CAAa;IAC7B,KAAK,EAAE,SAAS,CAAa;IAE7B,KAAK,EAAE,MAAM,kBAAkB,CAInC;IAGH,OAAO,CAAC,SAAS,CAAoB;CACtC"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MockLogger = void 0;
3
4
  // Export a mock so any users of this library that use jest can use it.
4
5
  class MockLogger {
5
6
  constructor() {
@@ -18,3 +19,4 @@ class MockLogger {
18
19
  }
19
20
  }
20
21
  exports.MockLogger = MockLogger;
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mocks/index.ts"],"names":[],"mappings":";;;AAEA,uEAAuE;AACvE,MAAa,UAAU;IAAvB;QACS,UAAK,GAAc,IAAI,CAAC,EAAE,EAAE,CAAC;QAC7B,SAAI,GAAc,IAAI,CAAC,EAAE,EAAE,CAAC;QAC5B,SAAI,GAAc,IAAI,CAAC,EAAE,EAAE,CAAC;QAC5B,UAAK,GAAc,IAAI,CAAC,EAAE,EAAE,CAAC;QAC7B,UAAK,GAAc,IAAI,CAAC,EAAE,EAAE,CAAC;QAE7B,UAAK,GAA6B,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE;YACpD,MAAM,WAAW,GAAG,IAAI,UAAU,EAAE,CAAC;YACrC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACjC,OAAO,WAAW,CAAC;QACrB,CAAC,CAAC,CAAC;QAEH,uDAAuD;QAC/C,cAAS,GAAiB,EAAE,CAAC;IACvC,CAAC;CAAA;AAfD,gCAeC"}
@@ -1,10 +1,6 @@
1
1
  {
2
2
  "name": "logger-interface",
3
- "version": "1.3.7",
4
- "repository": {
5
- "type": "git",
6
- "url": "https://bitbucket.org/atlassian/logger-interface/"
7
- },
3
+ "version": "1.3.21",
8
4
  "contributors": [
9
5
  {
10
6
  "name": "Callum Osmotherly",
@@ -15,48 +11,24 @@
15
11
  "email": "lleggieri@atlassian.com"
16
12
  }
17
13
  ],
18
- "main": "out/index.js",
19
- "scripts": {
20
- "build": "npm run lint-fix && npm run compile",
21
- "ci": "npm run lint && npm run compile && npm run test-specs",
22
- "compile": "rimraf ./out && tsc",
23
- "format": "tsfmt -r",
24
- "lint": "tslint -c tslint.json --project './tsconfig.json'",
25
- "lint-fix": "tslint -c tslint.json --project './tsconfig.json' --fix",
26
- "test": "npm run lint && jest -c jest.config.json --no-watchman",
27
- "precommit": "lint-staged",
28
- "prepare": "npm run build",
29
- "prepublishOnly": "npm test"
14
+ "main": "dist/index",
15
+ "license": "Proprietary",
16
+ "repository": {
17
+ "directory": "src/packages/logging/logger-interface",
18
+ "type": "git",
19
+ "url": "git@bitbucket.org:atlassian/incredible-monorepo.git"
30
20
  },
21
+ "homepage": "https://bitbucket.org/atlassian/incredible-monorepo/src/master/src/packages/logging/logger-interface",
31
22
  "files": [
32
- "src/**/*",
33
- "out/**/*",
34
- "docs/**/*",
35
- "README.md",
36
- "package.json"
23
+ "bin/",
24
+ "dist/",
25
+ "package.json",
26
+ "CHANGELOG.md",
27
+ "README.md"
37
28
  ],
38
- "lint-staged": {
39
- "*.ts": [
40
- "npm run lint-fix && npm run format",
41
- "git add"
42
- ]
43
- },
44
- "dependencies": {},
45
- "devDependencies": {
46
- "@types/jest": "^23.3.1",
47
- "@types/node": "^10.1.3",
48
- "husky": "^0.14.3",
49
- "jest": "^23.0.1",
50
- "lint-staged": "^7.1.2",
51
- "rimraf": "^2.6.2",
52
- "ts-jest": "^23.1.2",
53
- "ts-node": "^7.0.0",
54
- "ts-node-dev": "^1.0.0-pre.24",
55
- "tslint": "^5.10.0",
56
- "tslint-microsoft-contrib": "^5.0.3",
57
- "typescript": "^3.0.0",
58
- "typescript-formatter": "^7.2.0"
59
- },
60
- "types": "out/index.d.ts",
61
- "typings": "./out/index.d.ts"
29
+ "types": "dist/index.d.ts",
30
+ "typings": "dist/index.d.ts",
31
+ "config": {
32
+ "registry": "atlassian"
33
+ }
62
34
  }
package/scripts/build.sh CHANGED
@@ -1,54 +1,26 @@
1
1
  #! /bin/bash
2
2
 
3
- rm -rf ./tmp || true
4
- rm -rf ./packages || true
5
-
6
- function source-matches-destination () {
7
- if [ -d "$1" ] && [ -d "$2" ] && diff -r "$1" "$2"
8
- then
9
- true
10
- else
11
- false
12
- fi
13
- }
3
+ set -euo pipefail
14
4
 
15
- function add-package () {
16
- PACKAGE=$1
17
- DESTINATION=$(echo "$1" | rev | cut -d '@' -f 2 | cut -d '/' -f 1 | rev )
18
- MAX_COPY_RETRIES=3
19
-
20
- mkdir -p "./tmp/$DESTINATION"
21
- mkdir -p "./packages/$DESTINATION"
22
-
23
- cd "./tmp/$DESTINATION" &&
24
- npm pack $PACKAGE &&
25
- tar -xvf *.tgz &&
26
-
27
- retries=0
28
- cp -R "./package/." "../../packages/$DESTINATION"
29
- until source-matches-destination "./package/." "../../packages/$DESTINATION" || [ $retries -gt $MAX_COPY_RETRIES ]
30
- do
31
- echo "Copying $PACKAGE from $(pwd)/package to $(pwd)/../../packages/$DESTINATION failed"
32
- echo "Retrying copy (attempt $retries of $MAX_COPY_RETRIES)"
33
- cp -R "./package/." "../../packages/$DESTINATION"
34
- (( retries++ ))
35
- done
36
- cd ../../
37
-
38
- if [ $retries -gt $MAX_COPY_RETRIES ];
39
- then
40
- echo "Copying $PACKAGE failed!"
41
- return 1
42
- fi
43
- }
5
+ ROOT=$(cd "$(dirname "$0")/.."; pwd)
6
+ DEST="$ROOT/packages"
44
7
 
45
- add-package @atlassian/logger-interface@1.3.7
46
- add-package @atlassian/cs-ari@1.10.0
47
- add-package @atlassiansox/analytics-node-client@2.1.2
48
- add-package @atlassian/metrics-interface@1.3.3
8
+ rm -rf "$DEST"
9
+ mkdir "$DEST"
49
10
 
50
- find ./packages
11
+ add-package () {
12
+ PACKAGE="$1"
51
13
 
52
- node ./scripts/replace-packages.js
14
+ # Remove '@org/' part (e.g. '@atlassian/') in package name
15
+ # See https://www.gnu.org/software/bash/manual/bash.html#Shell-Parameter-Expansion
16
+ TARGET="${PACKAGE/#@*\//}"
53
17
 
54
- rm -rf ./tmp
18
+ cp -R "$ROOT/../../node_modules/$1" "$DEST/$TARGET"
19
+ }
20
+
21
+ add-package @atlassian/logger-interface
22
+ add-package @atlassian/cs-ari
23
+ add-package @atlassiansox/analytics-node-client
24
+ add-package @atlassian/metrics-interface
25
+
26
+ node ./scripts/replace-packages.js
package/scripts/pack.sh CHANGED
@@ -1,7 +1,7 @@
1
- echo $( \
2
- cd ./packages/analytics-node-client && \
3
- yarn install --production \
4
- );
5
- webpack;
6
- rm -rf ./packages/analytics-node-client/src/*;
7
- mv ./tmp/index.js ./packages/analytics-node-client/src;
1
+ #!/bin/bash
2
+
3
+ webpack
4
+ rm -rf ./packages/analytics-node-client/src
5
+ mkdir ./packages/analytics-node-client/src
6
+ mv ./tmp/index.js ./packages/analytics-node-client/src
7
+ rm -r ./tmp
package/webpack.config.js CHANGED
@@ -3,7 +3,7 @@ const path = require('path');
3
3
 
4
4
  module.exports = {
5
5
  mode: 'production',
6
- entry: './packages/analytics-node-client/src',
6
+ entry: '../../node_modules/@atlassiansox/analytics-node-client/src',
7
7
  output: {
8
8
  path: path.resolve(__dirname, 'tmp'),
9
9
  filename: 'index.js',
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const index_1 = require("../index");
4
- describe('isHierachicalLogger', () => {
5
- it('returns true for NoLogger', () => {
6
- expect(index_1.isHierachicalLogger(new index_1.NoLogger())).toBe(true);
7
- });
8
- it('returns false for loggers that do not have child method', () => {
9
- expect(index_1.isHierachicalLogger({})).toBe(false);
10
- expect(index_1.isHierachicalLogger({ child: {} })).toBe(false);
11
- });
12
- });
13
- describe('NoLogger', () => {
14
- it('debug does nothing', () => {
15
- new index_1.NoLogger().debug('value');
16
- });
17
- it('info does nothing', () => {
18
- new index_1.NoLogger().info('value');
19
- });
20
- it('warn does nothing', () => {
21
- new index_1.NoLogger().warn('value');
22
- });
23
- it('error does nothing', () => {
24
- new index_1.NoLogger().error('value');
25
- });
26
- it('fatal does nothing', () => {
27
- new index_1.NoLogger().fatal('value');
28
- });
29
- it('child does nothing', () => {
30
- new index_1.NoLogger().child('opts');
31
- });
32
- });
33
- describe('isLogger', () => {
34
- it('returns true for NoLogger', () => {
35
- expect(index_1.isLogger(new index_1.NoLogger())).toBe(true);
36
- });
37
- it('returns false for loggers that do not have logging methods', () => {
38
- expect(index_1.isLogger({ other: {} })).toBe(false);
39
- });
40
- });
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class NoLogger {
4
- debug(..._data) { }
5
- info(..._data) { }
6
- warn(..._data) { }
7
- error(..._data) { }
8
- fatal(..._data) { }
9
- child(..._data) {
10
- return this;
11
- }
12
- }
13
- exports.NoLogger = NoLogger;
14
- function isHierachicalLogger(obj) {
15
- return 'child' in obj &&
16
- (typeof obj.child === 'function');
17
- }
18
- exports.isHierachicalLogger = isHierachicalLogger;
19
- function isLogger(obj) {
20
- return 'debug' in obj && typeof obj.debug === 'function' &&
21
- 'info' in obj && typeof obj.info === 'function' &&
22
- 'warn' in obj && typeof obj.warn === 'function' &&
23
- 'error' in obj && typeof obj.error === 'function' &&
24
- 'fatal' in obj && typeof obj.fatal === 'function';
25
- }
26
- exports.isLogger = isLogger;
@@ -1,43 +0,0 @@
1
- import {NoLogger, isHierachicalLogger, isLogger} from '../index';
2
-
3
- describe('isHierachicalLogger', () => {
4
- it('returns true for NoLogger', () => {
5
- expect(isHierachicalLogger(new NoLogger())).toBe(true);
6
- });
7
-
8
- it('returns false for loggers that do not have child method', () => {
9
- expect(isHierachicalLogger({} as any)).toBe(false);
10
- expect(isHierachicalLogger({ child: {}} as any)).toBe(false);
11
- });
12
- });
13
-
14
- describe('NoLogger', () => {
15
- it('debug does nothing', () => {
16
- new NoLogger().debug('value');
17
- });
18
- it('info does nothing', () => {
19
- new NoLogger().info('value');
20
- });
21
- it('warn does nothing', () => {
22
- new NoLogger().warn('value');
23
- });
24
- it('error does nothing', () => {
25
- new NoLogger().error('value');
26
- });
27
- it('fatal does nothing', () => {
28
- new NoLogger().fatal('value');
29
- });
30
- it('child does nothing', () => {
31
- new NoLogger().child('opts');
32
- });
33
- });
34
-
35
- describe('isLogger', () => {
36
- it('returns true for NoLogger', () => {
37
- expect(isLogger(new NoLogger())).toBe(true);
38
- });
39
-
40
- it('returns false for loggers that do not have logging methods', () => {
41
- expect(isLogger({other: {}} as any)).toBe(false);
42
- });
43
- });
@@ -1,39 +0,0 @@
1
- export interface LogMethod {
2
- (...data: Array<any>): void;
3
- }
4
-
5
- export interface Logger {
6
- debug: LogMethod;
7
- info: LogMethod;
8
- warn: LogMethod;
9
- error: LogMethod;
10
- fatal: LogMethod;
11
- }
12
-
13
- export interface HierarchicalLogger extends Logger {
14
- child(opts: any): HierarchicalLogger;
15
- }
16
-
17
- export class NoLogger implements HierarchicalLogger {
18
- debug(..._data: Array<any>): void {}
19
- info(..._data: Array<any>): void {}
20
- warn(..._data: Array<any>): void {}
21
- error(..._data: Array<any>): void {}
22
- fatal(..._data: Array<any>): void {}
23
- child(..._data: Array<any>): HierarchicalLogger {
24
- return this;
25
- }
26
- }
27
-
28
- export function isHierachicalLogger(obj: any): obj is HierarchicalLogger {
29
- return 'child' in obj &&
30
- (typeof (obj as HierarchicalLogger).child === 'function');
31
- }
32
-
33
- export function isLogger(obj: any): obj is Logger {
34
- return 'debug' in obj && typeof obj.debug === 'function' &&
35
- 'info' in obj && typeof obj.info === 'function' &&
36
- 'warn' in obj && typeof obj.warn === 'function' &&
37
- 'error' in obj && typeof obj.error === 'function' &&
38
- 'fatal' in obj && typeof obj.fatal === 'function';
39
- }
@@ -1,19 +0,0 @@
1
- import { HierarchicalLogger, LogMethod } from '../index';
2
-
3
- // Export a mock so any users of this library that use jest can use it.
4
- export class MockLogger implements HierarchicalLogger {
5
- debug: LogMethod = jest.fn();
6
- info: LogMethod = jest.fn();
7
- warn: LogMethod = jest.fn();
8
- error: LogMethod = jest.fn();
9
- fatal: LogMethod = jest.fn();
10
-
11
- child: () => HierarchicalLogger = jest.fn(() => {
12
- const childLogger = new MockLogger();
13
- this._children.push(childLogger);
14
- return childLogger;
15
- });
16
-
17
- // A property to check children created by this logger.
18
- _children: Array<MockLogger> = [];
19
- }