@containerbase/base 14.60.0 → 14.62.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.
package/README.md CHANGED
@@ -157,6 +157,7 @@ configure({ logger });
157
157
  ```
158
158
 
159
159
  `getLogger()` returns the configured logger, so a package building on `@containerbase/base` can log to the same one.
160
+ All installed copies of the package share the logger, also when they have different versions, so such a package logs to it even when it uses another copy.
160
161
  `isConfigured()` tells whether a logger was set, so that package can configure a fallback when nobody did:
161
162
 
162
163
  ```ts
package/dist/logger.d.ts CHANGED
@@ -21,7 +21,9 @@ export interface ConfigureOptions {
21
21
  }
22
22
  /**
23
23
  * Configures the package, eg. sets the logger its functions log to. Options
24
- * which are left out are reset to their defaults.
24
+ * which are left out are reset to their defaults. Every installed copy of the
25
+ * package shares the logger, so a package building on another version of this
26
+ * one logs to it too.
25
27
  *
26
28
  * @param options the options to set
27
29
  */
package/dist/logger.js CHANGED
@@ -8,26 +8,40 @@ const silentLogger = {
8
8
  warn: noop,
9
9
  error: noop,
10
10
  };
11
- let current = silentLogger;
12
- let configured = false;
11
+ /** The global key of the shared {@link LoggerState}. */
12
+ const registryKey = Symbol.for('containerbase.logger');
13
+ /**
14
+ * The shared logger state, created as a silent and unconfigured one by the
15
+ * first copy which needs it.
16
+ */
17
+ function state() {
18
+ const registry = globalThis;
19
+ return (registry[registryKey] ??= {
20
+ logger: silentLogger,
21
+ configured: false,
22
+ });
23
+ }
13
24
  /**
14
25
  * Configures the package, eg. sets the logger its functions log to. Options
15
- * which are left out are reset to their defaults.
26
+ * which are left out are reset to their defaults. Every installed copy of the
27
+ * package shares the logger, so a package building on another version of this
28
+ * one logs to it too.
16
29
  *
17
30
  * @param options the options to set
18
31
  */
19
32
  export function configure(options = {}) {
20
- current = options.logger ?? silentLogger;
21
- configured = options.logger !== undefined;
33
+ const current = state();
34
+ current.logger = options.logger ?? silentLogger;
35
+ current.configured = options.logger !== undefined;
22
36
  }
23
37
  /** The logger set by `configure`, a silent one by default. */
24
38
  export function getLogger() {
25
- return current;
39
+ return state().logger;
26
40
  }
27
41
  /**
28
42
  * Whether `configure` has set a logger, so a package building on this one can
29
43
  * configure a fallback logger itself when nobody else did.
30
44
  */
31
45
  export function isConfigured() {
32
- return configured;
46
+ return state().configured;
33
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@containerbase/base",
3
- "version": "14.60.0",
3
+ "version": "14.62.0",
4
4
  "description": "Metadata about the tools supported by containerbase",
5
5
  "keywords": [
6
6
  "containerbase",