@lwrjs/shared-utils 0.8.0-alpha.3 → 0.8.0-alpha.6

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.
@@ -24,13 +24,85 @@ var __toModule = (module2) => {
24
24
  // packages/@lwrjs/shared-utils/src/logger.ts
25
25
  __markAsModule(exports);
26
26
  __export(exports, {
27
- logger: () => logger
28
- });
29
- var import_winston = __toModule(require("winston"));
30
- var LOG_LEVEL = process.env.LOG_LEVEL || "info";
31
- console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
32
- var logger = import_winston.default.createLogger({
33
- level: LOG_LEVEL,
34
- format: import_winston.default.format.json(),
35
- transports: [new import_winston.default.transports.Console()]
27
+ DEBUG: () => DEBUG,
28
+ ERROR: () => ERROR,
29
+ INFO: () => INFO,
30
+ VERBOSE: () => VERBOSE,
31
+ WARN: () => WARN,
32
+ logger: () => logger,
33
+ stringifyError: () => stringifyError
36
34
  });
35
+ var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
36
+ var VERBOSE = "verbose";
37
+ var DEBUG = "debug";
38
+ var INFO = "info";
39
+ var WARN = "warn";
40
+ var ERROR = "error";
41
+ var currentLevel = process.env.LOG_LEVEL || INFO;
42
+ var log = (level, message, additionalInfo) => {
43
+ const LOG_LEVEL = process.env.LOG_LEVEL || INFO;
44
+ if (currentLevel !== LOG_LEVEL) {
45
+ currentLevel = LOG_LEVEL;
46
+ console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
47
+ }
48
+ let shouldLog = false;
49
+ switch (level) {
50
+ case VERBOSE:
51
+ shouldLog = LOG_LEVEL == VERBOSE;
52
+ break;
53
+ case DEBUG:
54
+ shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG;
55
+ break;
56
+ case INFO:
57
+ shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO;
58
+ break;
59
+ case WARN:
60
+ shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO || LOG_LEVEL == WARN;
61
+ break;
62
+ case ERROR:
63
+ shouldLog = true;
64
+ break;
65
+ }
66
+ if (shouldLog) {
67
+ let logMethod;
68
+ if (level == ERROR) {
69
+ logMethod = console.error;
70
+ } else {
71
+ logMethod = console.log;
72
+ }
73
+ if (additionalInfo) {
74
+ logMethod(`[${level}] : ${message}
75
+ Additional Info: ${JSON.stringify(additionalInfo)}`);
76
+ } else {
77
+ logMethod(`[${level}] : ${message}`);
78
+ }
79
+ }
80
+ };
81
+ var stringifyError = (error) => {
82
+ if (error instanceof import_diagnostics.DiagnosticsError) {
83
+ return JSON.stringify({
84
+ message: error.message,
85
+ diagnostics: error.diagnostics,
86
+ stack: error.stack
87
+ });
88
+ } else if (typeof error === "string" || error instanceof String) {
89
+ return error;
90
+ } else {
91
+ const propertyNames = Object.getOwnPropertyNames(error);
92
+ const retObj = {};
93
+ for (let property, i = 0, len = propertyNames.length; i < len; ++i) {
94
+ property = propertyNames[i];
95
+ const descriptor = Object.getOwnPropertyDescriptor(error, property);
96
+ retObj[property] = descriptor?.value;
97
+ }
98
+ return JSON.stringify(retObj);
99
+ }
100
+ };
101
+ var logger = {
102
+ verbose: (message, additionalInfo) => log(VERBOSE, message, additionalInfo),
103
+ debug: (message, additionalInfo) => log(DEBUG, message, additionalInfo),
104
+ info: (message, additionalInfo) => log(INFO, message, additionalInfo),
105
+ warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
106
+ error: (error, additionalInfo) => log(ERROR, stringifyError(error), additionalInfo),
107
+ log
108
+ };
@@ -73,6 +73,7 @@ async function transpileTs(tsAbsPath, {rootDir, cacheDir}) {
73
73
  bundle: true,
74
74
  logLevel: "error",
75
75
  entryPoints: [tsAbsPath],
76
+ sourcemap: true,
76
77
  outfile,
77
78
  plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)]
78
79
  });
@@ -1,3 +1,17 @@
1
- import winston from 'winston';
2
- export declare const logger: winston.Logger;
1
+ declare type LEVEL = 'verbose' | 'debug' | 'info' | 'warn' | 'error';
2
+ export declare const VERBOSE: LEVEL;
3
+ export declare const DEBUG: LEVEL;
4
+ export declare const INFO: LEVEL;
5
+ export declare const WARN: LEVEL;
6
+ export declare const ERROR: LEVEL;
7
+ export declare const stringifyError: (error: any) => string;
8
+ export declare const logger: {
9
+ verbose: (message: string, additionalInfo?: any) => void;
10
+ debug: (message: string, additionalInfo?: any) => void;
11
+ info: (message: string, additionalInfo?: any) => void;
12
+ warn: (message: string, additionalInfo?: any) => void;
13
+ error: (error: any, additionalInfo?: any) => void;
14
+ log: (level: string, message: string, additionalInfo?: any) => void;
15
+ };
16
+ export {};
3
17
  //# sourceMappingURL=logger.d.ts.map
@@ -1,9 +1,78 @@
1
- import winston from 'winston';
2
- const LOG_LEVEL = process.env.LOG_LEVEL || 'info';
3
- console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
4
- export const logger = winston.createLogger({
5
- level: LOG_LEVEL,
6
- format: winston.format.json(),
7
- transports: [new winston.transports.Console()],
8
- });
1
+ import { DiagnosticsError } from '@lwrjs/diagnostics';
2
+ export const VERBOSE = 'verbose';
3
+ export const DEBUG = 'debug';
4
+ export const INFO = 'info';
5
+ export const WARN = 'warn';
6
+ export const ERROR = 'error';
7
+ let currentLevel = process.env.LOG_LEVEL || INFO;
8
+ const log = (level, message, additionalInfo) => {
9
+ const LOG_LEVEL = process.env.LOG_LEVEL || INFO;
10
+ if (currentLevel !== LOG_LEVEL) {
11
+ currentLevel = LOG_LEVEL;
12
+ console.log(`LOG_LEVEL: ${LOG_LEVEL}`);
13
+ }
14
+ let shouldLog = false;
15
+ switch (level) {
16
+ case VERBOSE:
17
+ shouldLog = LOG_LEVEL == VERBOSE;
18
+ break;
19
+ case DEBUG:
20
+ shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG;
21
+ break;
22
+ case INFO:
23
+ shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO;
24
+ break;
25
+ case WARN:
26
+ shouldLog = LOG_LEVEL == VERBOSE || LOG_LEVEL == DEBUG || LOG_LEVEL == INFO || LOG_LEVEL == WARN;
27
+ break;
28
+ case ERROR:
29
+ shouldLog = true;
30
+ break;
31
+ }
32
+ if (shouldLog) {
33
+ let logMethod;
34
+ if (level == ERROR) {
35
+ logMethod = console.error;
36
+ }
37
+ else {
38
+ logMethod = console.log;
39
+ }
40
+ if (additionalInfo) {
41
+ logMethod(`[${level}] : ${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}`);
42
+ }
43
+ else {
44
+ logMethod(`[${level}] : ${message}`);
45
+ }
46
+ }
47
+ };
48
+ export const stringifyError = (error) => {
49
+ if (error instanceof DiagnosticsError) {
50
+ return JSON.stringify({
51
+ message: error.message,
52
+ diagnostics: error.diagnostics,
53
+ stack: error.stack,
54
+ });
55
+ }
56
+ else if (typeof error === 'string' || error instanceof String) {
57
+ return error;
58
+ }
59
+ else {
60
+ const propertyNames = Object.getOwnPropertyNames(error);
61
+ const retObj = {};
62
+ for (let property, i = 0, len = propertyNames.length; i < len; ++i) {
63
+ property = propertyNames[i];
64
+ const descriptor = Object.getOwnPropertyDescriptor(error, property);
65
+ retObj[property] = descriptor?.value;
66
+ }
67
+ return JSON.stringify(retObj);
68
+ }
69
+ };
70
+ export const logger = {
71
+ verbose: (message, additionalInfo) => log(VERBOSE, message, additionalInfo),
72
+ debug: (message, additionalInfo) => log(DEBUG, message, additionalInfo),
73
+ info: (message, additionalInfo) => log(INFO, message, additionalInfo),
74
+ warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
75
+ error: (error, additionalInfo) => log(ERROR, stringifyError(error), additionalInfo),
76
+ log,
77
+ };
9
78
  //# sourceMappingURL=logger.js.map
@@ -60,6 +60,7 @@ export async function transpileTs(tsAbsPath, { rootDir, cacheDir }) {
60
60
  bundle: true,
61
61
  logLevel: 'error',
62
62
  entryPoints: [tsAbsPath],
63
+ sourcemap: true,
63
64
  outfile,
64
65
  plugins: [ESBUILD_EXTENSION_PLUGIN(tsAbsPath, format)],
65
66
  });
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.3",
7
+ "version": "0.8.0-alpha.6",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -45,13 +45,13 @@
45
45
  "winston": "^3.7.2"
46
46
  },
47
47
  "devDependencies": {
48
- "@lwrjs/diagnostics": "0.8.0-alpha.3",
49
- "@lwrjs/types": "0.8.0-alpha.3",
48
+ "@lwrjs/diagnostics": "0.8.0-alpha.6",
49
+ "@lwrjs/types": "0.8.0-alpha.6",
50
50
  "@types/mime-types": "2.1.1",
51
51
  "@types/path-to-regexp": "^1.7.0"
52
52
  },
53
53
  "engines": {
54
54
  "node": ">=14.15.4 <19"
55
55
  },
56
- "gitHead": "bf22045bd29a832ff98f6bafa1120b5453960f8c"
56
+ "gitHead": "cf34943d7df7b570d1183836868462c10a6a136c"
57
57
  }