@xh/hoist 75.0.0-SNAPSHOT.1753486175346 → 75.0.0-SNAPSHOT.1753490062755

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.
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import {PlainObject, Thunkable} from '@xh/hoist/core';
8
8
  import {Exception} from '@xh/hoist/core/exception/Exception';
9
+ import {LogSource, logWarn} from '@xh/hoist/utils/js/LogUtils';
9
10
  import {
10
11
  flatMap,
11
12
  forOwn,
@@ -168,6 +169,9 @@ export interface APIWarnOptions {
168
169
 
169
170
  /** An additional message. Can contain suggestions for alternatives. */
170
171
  msg?: string;
172
+
173
+ /** Source of message for labelling log message. */
174
+ source?: LogSource;
171
175
  }
172
176
 
173
177
  /**
@@ -176,8 +180,9 @@ export interface APIWarnOptions {
176
180
  export function apiRemoved(name: string, opts: APIWarnOptions = {}) {
177
181
  if ('test' in opts && isUndefined(opts.test)) return;
178
182
 
179
- const msg = opts.msg ? ` ${opts.msg}.` : '';
180
- throw Exception.create(`The use of '${name}' is no longer supported.${msg}`);
183
+ const src = opts.source ? `[${opts.source}] ` : '',
184
+ msg = opts.msg ? ` ${opts.msg}.` : '';
185
+ throw Exception.create(`${src}The use of '${name}' is no longer supported.${msg}`);
181
186
  }
182
187
 
183
188
  /**
@@ -193,7 +198,7 @@ export function apiDeprecated(name: string, opts: APIWarnOptions = {}) {
193
198
  msg = opts.msg ? ` ${opts.msg}.` : '',
194
199
  warn = `The use of '${name}' has been deprecated and will be removed in ${v}. ${msg}`;
195
200
  if (!_seenWarnings[warn]) {
196
- console.warn(warn);
201
+ logWarn(warn, opts.source);
197
202
  _seenWarnings[warn] = true;
198
203
  }
199
204
  }
@@ -72,6 +72,15 @@ export function logWarn(msgs: Some<unknown>, source?: LogSource) {
72
72
  return loggedDo(msgs, null, source, 'warn');
73
73
  }
74
74
 
75
+ /** Parse a LogSource in to a canonical string label. */
76
+ export function parseSource(source: LogSource): string {
77
+ if (!source) return null;
78
+ if (isString(source)) return source;
79
+ if (source['displayName']) return source['displayName'];
80
+ if (source.constructor) return source.constructor.name;
81
+ return null;
82
+ }
83
+
75
84
  //----------------------------------
76
85
  // Implementation
77
86
  //----------------------------------
@@ -117,14 +126,6 @@ function loggedDo<T>(messages: Some<unknown>, fn: () => T, source: LogSource, le
117
126
  return ret;
118
127
  }
119
128
 
120
- function parseSource(source: LogSource): string {
121
- if (!source) return null;
122
- if (isString(source)) return source;
123
- if (source['displayName']) return source['displayName'];
124
- if (source.constructor) return source.constructor.name;
125
- return null;
126
- }
127
-
128
129
  function writeLog(msgs: unknown[], src: string, level: LogLevel) {
129
130
  if (src) msgs = [`[${src}]`, ...msgs];
130
131