@lwrjs/shared-utils 0.8.0-alpha.14 → 0.8.0-alpha.16

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.
package/build/cjs/fs.cjs CHANGED
@@ -43,6 +43,7 @@ var import_object = __toModule(require("./object.cjs"));
43
43
  var import_chokidar = __toModule(require("chokidar"));
44
44
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
45
45
  var import_mime_types = __toModule(require("mime-types"));
46
+ var import_logger = __toModule(require("./logger.cjs"));
46
47
  function hashContent(source) {
47
48
  return import_crypto.default.createHash("md5").update(source).digest("hex");
48
49
  }
@@ -77,7 +78,7 @@ function setupWatcher(onModuleChange) {
77
78
  const fileWatcher = createFileWatcher();
78
79
  fileWatcher.on("change", (0, import_object.debounce)((file) => onModuleChange(file), 500));
79
80
  fileWatcher.on("unlink", (0, import_object.debounce)((file) => onModuleChange(file), 500));
80
- fileWatcher.on("add", (file) => console.log("Watching: ", file));
81
+ fileWatcher.on("add", (file) => import_logger.logger.info(`Watching: ${file}`));
81
82
  return fileWatcher;
82
83
  }
83
84
  function canResolveView(source, type) {
@@ -38,8 +38,10 @@ var DEBUG = "debug";
38
38
  var INFO = "info";
39
39
  var WARN = "warn";
40
40
  var ERROR = "error";
41
+ var options = {};
42
+ var DUPES = new Set();
41
43
  var currentLevel = process.env.LOG_LEVEL || INFO;
42
- var log = (level, message, additionalInfo) => {
44
+ function log(level, message, additionalInfo) {
43
45
  const LOG_LEVEL = process.env.LOG_LEVEL || INFO;
44
46
  if (currentLevel !== LOG_LEVEL) {
45
47
  currentLevel = LOG_LEVEL;
@@ -63,21 +65,31 @@ var log = (level, message, additionalInfo) => {
63
65
  shouldLog = true;
64
66
  break;
65
67
  }
68
+ if (shouldLog && options.dedupe && options.dedupe.has(level)) {
69
+ const key = `[${level}] : ${message}`;
70
+ if (DUPES.has(key)) {
71
+ shouldLog = false;
72
+ } else {
73
+ DUPES.add(key);
74
+ }
75
+ }
66
76
  if (shouldLog) {
67
77
  let logMethod;
68
78
  if (level == ERROR) {
69
79
  logMethod = console.error;
80
+ } else if (level == WARN) {
81
+ logMethod = console.warn;
70
82
  } else {
71
83
  logMethod = console.log;
72
84
  }
73
85
  if (additionalInfo) {
74
- logMethod(`[${level}] : ${message}
86
+ logMethod(`[${level}] ${message}
75
87
  Additional Info: ${JSON.stringify(additionalInfo)}`);
76
88
  } else {
77
- logMethod(`[${level}] : ${message}`);
89
+ logMethod(`[${level}] ${message}`);
78
90
  }
79
91
  }
80
- };
92
+ }
81
93
  var stringifyError = (error) => {
82
94
  if (error instanceof import_diagnostics.DiagnosticsError) {
83
95
  return JSON.stringify({
@@ -104,5 +116,9 @@ var logger = {
104
116
  info: (message, additionalInfo) => log(INFO, message, additionalInfo),
105
117
  warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
106
118
  error: (error, additionalInfo) => log(ERROR, stringifyError(error), additionalInfo),
107
- log
119
+ log,
120
+ setOptions: (opts) => {
121
+ options = opts;
122
+ },
123
+ currentLevel
108
124
  };
package/build/es/fs.js CHANGED
@@ -6,6 +6,7 @@ import { debounce } from './object.js';
6
6
  import chokidar from 'chokidar';
7
7
  import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
8
8
  import { lookup } from 'mime-types';
9
+ import { logger } from './logger.js';
9
10
  /**
10
11
  * Create a hash string for a source
11
12
  * @param source
@@ -67,7 +68,7 @@ export function setupWatcher(onModuleChange) {
67
68
  const fileWatcher = createFileWatcher();
68
69
  fileWatcher.on('change', debounce((file) => onModuleChange(file), 500));
69
70
  fileWatcher.on('unlink', debounce((file) => onModuleChange(file), 500));
70
- fileWatcher.on('add', (file) => console.log('Watching: ', file));
71
+ fileWatcher.on('add', (file) => logger.info(`Watching: ${file}`));
71
72
  return fileWatcher;
72
73
  }
73
74
  /**
@@ -4,6 +4,10 @@ export declare const DEBUG: LEVEL;
4
4
  export declare const INFO: LEVEL;
5
5
  export declare const WARN: LEVEL;
6
6
  export declare const ERROR: LEVEL;
7
+ declare type LoggerOptions = {
8
+ dedupe?: Set<string>;
9
+ };
10
+ declare function log(level: string, message: string, additionalInfo?: any): void;
7
11
  export declare const stringifyError: (error: any) => string;
8
12
  export declare const logger: {
9
13
  verbose: (message: string, additionalInfo?: any) => void;
@@ -11,7 +15,9 @@ export declare const logger: {
11
15
  info: (message: string, additionalInfo?: any) => void;
12
16
  warn: (message: string, additionalInfo?: any) => void;
13
17
  error: (error: any, additionalInfo?: any) => void;
14
- log: (level: string, message: string, additionalInfo?: any) => void;
18
+ log: typeof log;
19
+ setOptions: (opts: LoggerOptions) => void;
20
+ currentLevel: string;
15
21
  };
16
22
  export {};
17
23
  //# sourceMappingURL=logger.d.ts.map
@@ -4,8 +4,10 @@ export const DEBUG = 'debug';
4
4
  export const INFO = 'info';
5
5
  export const WARN = 'warn';
6
6
  export const ERROR = 'error';
7
+ let options = {};
8
+ const DUPES = new Set();
7
9
  let currentLevel = process.env.LOG_LEVEL || INFO;
8
- const log = (level, message, additionalInfo) => {
10
+ function log(level, message, additionalInfo) {
9
11
  const LOG_LEVEL = process.env.LOG_LEVEL || INFO;
10
12
  if (currentLevel !== LOG_LEVEL) {
11
13
  currentLevel = LOG_LEVEL;
@@ -29,22 +31,36 @@ const log = (level, message, additionalInfo) => {
29
31
  shouldLog = true;
30
32
  break;
31
33
  }
34
+ // Check if we should suppress dupes and we have already logged this message
35
+ if (shouldLog && options.dedupe && options.dedupe.has(level)) {
36
+ const key = `[${level}] : ${message}`;
37
+ if (DUPES.has(key)) {
38
+ shouldLog = false;
39
+ }
40
+ else {
41
+ // add key to de-duplicate cache
42
+ DUPES.add(key);
43
+ }
44
+ }
32
45
  if (shouldLog) {
33
46
  let logMethod;
34
47
  if (level == ERROR) {
35
48
  logMethod = console.error;
36
49
  }
50
+ else if (level == WARN) {
51
+ logMethod = console.warn;
52
+ }
37
53
  else {
38
54
  logMethod = console.log;
39
55
  }
40
56
  if (additionalInfo) {
41
- logMethod(`[${level}] : ${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}`);
57
+ logMethod(`[${level}] ${message} \nAdditional Info: ${JSON.stringify(additionalInfo)}`);
42
58
  }
43
59
  else {
44
- logMethod(`[${level}] : ${message}`);
60
+ logMethod(`[${level}] ${message}`);
45
61
  }
46
62
  }
47
- };
63
+ }
48
64
  export const stringifyError = (error) => {
49
65
  if (error instanceof DiagnosticsError) {
50
66
  return JSON.stringify({
@@ -74,5 +90,9 @@ export const logger = {
74
90
  warn: (message, additionalInfo) => log(WARN, message, additionalInfo),
75
91
  error: (error, additionalInfo) => log(ERROR, stringifyError(error), additionalInfo),
76
92
  log,
93
+ setOptions: (opts) => {
94
+ options = opts;
95
+ },
96
+ currentLevel,
77
97
  };
78
98
  //# sourceMappingURL=logger.js.map
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.8.0-alpha.14",
7
+ "version": "0.8.0-alpha.16",
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.14",
49
- "@lwrjs/types": "0.8.0-alpha.14",
48
+ "@lwrjs/diagnostics": "0.8.0-alpha.16",
49
+ "@lwrjs/types": "0.8.0-alpha.16",
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": "6d332d4e1364efe9b6ad0b022143cc2e7d04e2e0"
56
+ "gitHead": "9a8ed984498d72ee92735d161ac94cc14da4090e"
57
57
  }