@teambit/logger 0.0.932 → 0.0.933

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.
@@ -1,2 +1,2 @@
1
- import React from 'react';
2
- export declare const Logo: () => React.JSX.Element;
1
+ /// <reference types="react" />
2
+ export declare const Logo: () => JSX.Element;
@@ -1,7 +1,7 @@
1
1
  import { Logger } from './logger';
2
2
  export declare class LoggerMain {
3
3
  static runtime: import("@teambit/harmony").RuntimeDefinition;
4
- static dependencies: never[];
4
+ static dependencies: any[];
5
5
  createLogger(extensionName: string): Logger;
6
6
  static provider(): Promise<LoggerMain>;
7
7
  }
@@ -1,5 +1,5 @@
1
1
  import type { Logger } from './logger';
2
- export declare type ConsoleOnStart = 'normal' | 'title';
2
+ export type ConsoleOnStart = 'normal' | 'title';
3
3
  /**
4
4
  * use it for a long running process. upon creation it logs the `processDescription`.
5
5
  * if the process involves iteration over a list of items, such as running tag on a list of
@@ -16,7 +16,7 @@ export declare class LongProcessLogger {
16
16
  private totalItems?;
17
17
  private currentItem;
18
18
  private startTime;
19
- constructor(logPublisher: Logger, extensionName: string, processDescription: string, totalItems?: number | undefined, shouldConsole?: ConsoleOnStart);
19
+ constructor(logPublisher: Logger, extensionName: string, processDescription: string, totalItems?: number, shouldConsole?: ConsoleOnStart);
20
20
  logProgress(itemName?: string, showProcessDescription?: boolean): void;
21
21
  end(shouldConsole?: 'success' | 'error'): void;
22
22
  getProgress(): string;
@@ -1,5 +1,5 @@
1
- import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_logger@0.0.932/dist/logger.composition.js';
2
- import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_logger@0.0.932/dist/logger.docs.mdx';
1
+ import * as compositions_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_logger@0.0.933/dist/logger.composition.js';
2
+ import * as overview_0 from '/home/circleci/Library/Caches/Bit/capsules/8891be5ad3d35bfc38b9cd90c0e05b598a5a55af/teambit.harmony_logger@0.0.933/dist/logger.docs.mdx';
3
3
 
4
4
  export const compositions = [compositions_0];
5
5
  export const overview = [overview_0];
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { Logger } from './logger';
2
+ export type { LoggerMain } from './logger.main.runtime';
3
+ export { LoggerAspect } from './logger.aspect';
4
+ export { LongProcessLogger } from './long-process-logger';
@@ -0,0 +1,7 @@
1
+ import { Aspect } from '@teambit/harmony';
2
+
3
+ export const LoggerAspect = Aspect.create({
4
+ id: 'teambit.harmony/logger',
5
+ dependencies: [],
6
+ defaultConfig: {},
7
+ });
@@ -0,0 +1,19 @@
1
+ import { MainRuntime } from '@teambit/cli';
2
+
3
+ import { Logger } from './logger';
4
+ import { LoggerAspect } from './logger.aspect';
5
+
6
+ export class LoggerMain {
7
+ static runtime = MainRuntime;
8
+ static dependencies = [];
9
+
10
+ createLogger(extensionName: string): Logger {
11
+ return new Logger(extensionName);
12
+ }
13
+
14
+ static async provider() {
15
+ return new LoggerMain();
16
+ }
17
+ }
18
+
19
+ LoggerAspect.addRuntime(LoggerMain);
package/logger.ts ADDED
@@ -0,0 +1,154 @@
1
+ import loader from '@teambit/legacy/dist/cli/loader';
2
+ import logger, { IBitLogger } from '@teambit/legacy/dist/logger/logger';
3
+ import chalk from 'chalk';
4
+
5
+ import { ConsoleOnStart, LongProcessLogger } from './long-process-logger';
6
+
7
+ export class Logger implements IBitLogger {
8
+ constructor(private extensionName: string) {}
9
+
10
+ trace(message: string, ...meta: any[]) {
11
+ logger.trace(this.colorMessage(message), ...meta);
12
+ }
13
+ debug(message: string, ...meta: any[]) {
14
+ logger.debug(this.colorMessage(message), ...meta);
15
+ }
16
+ info(message: string, ...meta: any[]) {
17
+ logger.info(this.colorMessage(message), ...meta);
18
+ }
19
+ warn(message: string, ...meta: any[]) {
20
+ logger.warn(this.colorMessage(message), ...meta);
21
+ }
22
+ error(message: string, ...meta: any[]) {
23
+ logger.error(this.colorMessage(message), ...meta);
24
+ }
25
+ fatal(message: string, ...meta: any[]) {
26
+ logger.fatal(this.colorMessage(message), ...meta);
27
+ }
28
+
29
+ get isLoaderStarted() {
30
+ return loader.isStarted;
31
+ }
32
+ /**
33
+ * use it for a long running process. upon creation it logs the `processDescription`.
34
+ * if the process involves iteration over a list of items, such as running tag on a list of
35
+ * components, then pass the `totalItems` as the total of the total components in the list.
36
+ * later, during the iteration, call `LongProcessLogger.logProgress(componentName)`.
37
+ * once done, call `LongProcessLogger.end()`
38
+ * the status-line will show all messages in the terminal.
39
+ */
40
+ createLongProcessLogger(
41
+ processDescription: string,
42
+ totalItems?: number,
43
+ shouldConsole?: ConsoleOnStart
44
+ ): LongProcessLogger {
45
+ return new LongProcessLogger(this, this.extensionName, processDescription, totalItems, shouldConsole);
46
+ }
47
+ /**
48
+ * single status-line on the bottom of the screen.
49
+ * the text is replaced every time this method is called.
50
+ */
51
+ setStatusLine(text: string, shouldPrintOnCI = false) {
52
+ if (process.env.CI && !shouldPrintOnCI) return;
53
+ loader.setTextAndRestart(text);
54
+ }
55
+ /**
56
+ * remove the text from the last line on the screen.
57
+ */
58
+ clearStatusLine() {
59
+ loader.stop();
60
+ }
61
+ /**
62
+ * print to the screen. if message is empty, print the last logged message.
63
+ */
64
+ console(message?: string, ...meta: any[]) {
65
+ if (message) this.info(message, meta);
66
+ if (!loader.isStarted && logger.shouldWriteToConsole) {
67
+ // eslint-disable-next-line no-console
68
+ console.log(message, ...meta);
69
+ } else {
70
+ loader.stopAndPersist({ text: message });
71
+ }
72
+ }
73
+
74
+ /**
75
+ * @deprecated
76
+ * try using consoleWarning. if not possible, rename this method to a clearer one
77
+ */
78
+ consoleWarn(message?: string, ...meta: any[]) {
79
+ if (message) this.warn(message, ...meta);
80
+ if (!loader.isStarted && logger.shouldWriteToConsole) {
81
+ // eslint-disable-next-line no-console
82
+ console.warn(message, ...meta);
83
+ } else {
84
+ loader.stopAndPersist({ text: message });
85
+ }
86
+ }
87
+
88
+ /**
89
+ * @deprecated
90
+ * try using consoleFailure. if not possible, rename this method to a clearer one
91
+ */
92
+ consoleError(message?: string, ...meta: any[]) {
93
+ if (message) this.error(message, ...meta);
94
+ if (!loader.isStarted && logger.shouldWriteToConsole) {
95
+ // eslint-disable-next-line no-console
96
+ console.error(message, ...meta);
97
+ } else {
98
+ loader.stopAndPersist({ text: message });
99
+ }
100
+ }
101
+
102
+ /**
103
+ * print to the screen as a title, with bold text.
104
+ */
105
+ consoleTitle(message: string) {
106
+ this.info(message);
107
+ loader.stopAndPersist({ text: chalk.bold(message) });
108
+ }
109
+ /**
110
+ * print to the screen with a green `✔` prefix. if message is empty, print the last logged message.
111
+ */
112
+ consoleSuccess(message?: string, startTime?: [number, number]) {
113
+ if (message) this.info(message);
114
+ loader.succeed(message, startTime);
115
+ }
116
+
117
+ /**
118
+ * turn off the logger.
119
+ */
120
+ off() {
121
+ return loader.off();
122
+ }
123
+
124
+ on() {
125
+ return loader.on();
126
+ }
127
+
128
+ profile(id: string, console?: boolean) {
129
+ logger.profile(id, console);
130
+ }
131
+
132
+ /**
133
+ * print to the screen with a red `✖` prefix. if message is empty, print the last logged message.
134
+ */
135
+ consoleFailure(message?: string) {
136
+ if (message) this.error(message);
137
+ loader.fail(message);
138
+ }
139
+ /**
140
+ * print to the screen with a red `⚠` prefix. if message is empty, print the last logged message.
141
+ */
142
+ consoleWarning(message?: string) {
143
+ if (message) {
144
+ this.warn(message);
145
+ message = chalk.yellow(message);
146
+ }
147
+ loader.warn(message);
148
+ }
149
+
150
+ private colorMessage(message: string) {
151
+ if (logger.isJsonFormat) return `${this.extensionName}, ${message}`;
152
+ return `${chalk.bold(this.extensionName)}, ${message}`;
153
+ }
154
+ }
@@ -0,0 +1,63 @@
1
+ import prettyTime from 'pretty-time';
2
+ import type { Logger } from './logger';
3
+
4
+ export type ConsoleOnStart = 'normal' | 'title';
5
+
6
+ /**
7
+ * use it for a long running process. upon creation it logs the `processDescription`.
8
+ * if the process involves iteration over a list of items, such as running tag on a list of
9
+ * components, then pass the `totalItems` as the total components in the list.
10
+ * later, during the iteration, call `logProgress(componentName)`.
11
+ * once done, call `end()`.
12
+ * the status-line will show all messages in the terminal.
13
+ * see README for more data.
14
+ */
15
+ export class LongProcessLogger {
16
+ private currentItem = 0;
17
+ private startTime = process.hrtime();
18
+ constructor(
19
+ private logPublisher: Logger,
20
+ private extensionName: string,
21
+ private processDescription: string,
22
+ private totalItems?: number,
23
+ shouldConsole?: ConsoleOnStart
24
+ ) {
25
+ this.start(shouldConsole);
26
+ }
27
+
28
+ logProgress(itemName = '', showProcessDescription = true) {
29
+ this.currentItem += 1;
30
+ const processDesc = showProcessDescription ? `${this.processDescription} ` : '';
31
+ const message = `${processDesc}${this.getProgress()} ${itemName}`;
32
+ this.logPublisher.debug(message);
33
+ this.logPublisher.setStatusLine(message, true);
34
+ }
35
+
36
+ end(shouldConsole?: 'success' | 'error') {
37
+ if (process.env.CI && !shouldConsole) shouldConsole = 'success';
38
+ const description = this.processDescription;
39
+ const duration = process.hrtime(this.startTime);
40
+ const completedOrFailedStr = !shouldConsole || shouldConsole === 'success' ? 'Succeeded' : 'Failed';
41
+ const message = `${description}. ${completedOrFailedStr} in ${prettyTime(duration)}`;
42
+ this.logPublisher.info(message);
43
+ if (shouldConsole) {
44
+ if (shouldConsole === 'success') this.logPublisher.consoleSuccess(message);
45
+ else this.logPublisher.consoleFailure(message);
46
+ } else this.logPublisher.setStatusLine(message);
47
+ }
48
+
49
+ getProgress() {
50
+ return `(${this.currentItem}/${this.totalItems})`;
51
+ }
52
+
53
+ private start(shouldConsole?: ConsoleOnStart) {
54
+ if (process.env.CI && !shouldConsole) shouldConsole = 'normal';
55
+ const totalItemsStr = this.totalItems ? `(total: ${this.totalItems})` : '';
56
+ const message = `${this.processDescription} ${totalItemsStr}`;
57
+ this.logPublisher.info(message);
58
+ if (shouldConsole) {
59
+ if (shouldConsole === 'title') this.logPublisher.consoleTitle(message);
60
+ else this.logPublisher.console(message);
61
+ } else this.logPublisher.setStatusLine(message);
62
+ }
63
+ }
package/package.json CHANGED
@@ -1,34 +1,30 @@
1
1
  {
2
2
  "name": "@teambit/logger",
3
- "version": "0.0.932",
3
+ "version": "0.0.933",
4
4
  "homepage": "https://bit.cloud/teambit/harmony/logger",
5
5
  "main": "dist/index.js",
6
6
  "componentId": {
7
7
  "scope": "teambit.harmony",
8
8
  "name": "logger",
9
- "version": "0.0.932"
9
+ "version": "0.0.933"
10
10
  },
11
11
  "dependencies": {
12
12
  "chalk": "2.4.2",
13
13
  "pretty-time": "1.1.0",
14
- "core-js": "^3.0.0",
15
- "@babel/runtime": "7.20.0",
16
14
  "@teambit/harmony": "0.4.6",
17
- "@teambit/cli": "0.0.839"
15
+ "@teambit/cli": "0.0.840"
18
16
  },
19
17
  "devDependencies": {
20
- "@types/react": "^17.0.8",
21
18
  "@types/mocha": "9.1.0",
22
- "@types/node": "12.20.4",
23
- "@types/react-dom": "^17.0.5",
24
- "@types/jest": "^26.0.0",
25
- "@types/testing-library__jest-dom": "5.9.5",
19
+ "@types/jest": "^29.2.2",
20
+ "@types/testing-library__jest-dom": "^5.9.5",
21
+ "@teambit/harmony.envs.core-aspect-env": "0.0.13",
26
22
  "@teambit/harmony.aspect-docs.logger": "0.0.165"
27
23
  },
28
24
  "peerDependencies": {
29
- "@teambit/legacy": "1.0.624",
30
- "react": "^16.8.0 || ^17.0.0",
31
- "react-dom": "^16.8.0 || ^17.0.0"
25
+ "react": "^17.0.0 || ^18.0.0",
26
+ "@types/react": "^18.2.12",
27
+ "@teambit/legacy": "1.0.624"
32
28
  },
33
29
  "license": "Apache-2.0",
34
30
  "optionalDependencies": {},
@@ -42,7 +38,7 @@
42
38
  },
43
39
  "private": false,
44
40
  "engines": {
45
- "node": ">=12.22.0"
41
+ "node": ">=16.0.0"
46
42
  },
47
43
  "repository": {
48
44
  "type": "git",
@@ -51,12 +47,9 @@
51
47
  "keywords": [
52
48
  "bit",
53
49
  "bit-aspect",
50
+ "bit-core-aspect",
54
51
  "components",
55
52
  "collaboration",
56
- "web",
57
- "react",
58
- "react-components",
59
- "angular",
60
- "angular-components"
53
+ "web"
61
54
  ]
62
55
  }
package/tsconfig.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "lib": [
4
- "es2019",
5
- "DOM",
6
- "ES6",
7
- "DOM.Iterable",
8
- "ScriptHost"
4
+ "esnext",
5
+ "dom",
6
+ "dom.Iterable"
9
7
  ],
10
- "target": "es2015",
11
- "module": "CommonJS",
12
- "jsx": "react",
13
- "allowJs": true,
14
- "composite": true,
8
+ "target": "es2020",
9
+ "module": "es2020",
10
+ "jsx": "react-jsx",
15
11
  "declaration": true,
16
12
  "sourceMap": true,
17
- "skipLibCheck": true,
18
13
  "experimentalDecorators": true,
19
- "outDir": "dist",
14
+ "skipLibCheck": true,
20
15
  "moduleResolution": "node",
21
16
  "esModuleInterop": true,
22
- "rootDir": ".",
23
17
  "resolveJsonModule": true,
24
- "emitDeclarationOnly": true,
25
- "emitDecoratorMetadata": true,
26
- "allowSyntheticDefaultImports": true,
27
- "strictPropertyInitialization": false,
28
- "strict": true,
29
- "noImplicitAny": false,
30
- "preserveConstEnums": true
18
+ "allowJs": true,
19
+ "outDir": "dist",
20
+ "emitDeclarationOnly": true
31
21
  },
32
22
  "exclude": [
23
+ "artifacts",
24
+ "public",
33
25
  "dist",
26
+ "node_modules",
27
+ "package.json",
34
28
  "esm.mjs",
35
- "package.json"
29
+ "**/*.cjs",
30
+ "./dist"
36
31
  ],
37
32
  "include": [
38
33
  "**/*",
package/types/asset.d.ts CHANGED
@@ -5,12 +5,12 @@ declare module '*.png' {
5
5
  declare module '*.svg' {
6
6
  import type { FunctionComponent, SVGProps } from 'react';
7
7
 
8
- export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
8
+ export const ReactComponent: FunctionComponent<
9
+ SVGProps<SVGSVGElement> & { title?: string }
10
+ >;
9
11
  const src: string;
10
12
  export default src;
11
13
  }
12
-
13
- // @TODO Gilad
14
14
  declare module '*.jpg' {
15
15
  const value: any;
16
16
  export = value;
@@ -27,3 +27,15 @@ declare module '*.bmp' {
27
27
  const value: any;
28
28
  export = value;
29
29
  }
30
+ declare module '*.otf' {
31
+ const value: any;
32
+ export = value;
33
+ }
34
+ declare module '*.woff' {
35
+ const value: any;
36
+ export = value;
37
+ }
38
+ declare module '*.woff2' {
39
+ const value: any;
40
+ export = value;
41
+ }