Skip to content
This repository was archived by the owner on Apr 3, 2024. It is now read-only.

Commit e2f52b1

Browse files
chore: merge options.debug and options (#718)
If the `options` object given to the `start()` function has a debug property then, previously, the options used would be `options.debug`. Thus anything set in `options` itself, such as the `projectId` would not be used by the agent. This change suggests using the merger of `options` and `options.debug`.
1 parent dfa349e commit e2f52b1

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/index.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ export function start(
3939
options?: DebugAgentConfig | StackdriverConfig
4040
): Debuglet | IsReady {
4141
options = options || {};
42-
const agentConfig: DebugAgentConfig =
43-
(options as StackdriverConfig).debug || (options as DebugAgentConfig);
42+
const agentConfig: DebugAgentConfig = mergeConfigs(options);
4443

4544
// forceNewAgent_ is for testing purposes only.
4645
if (debuglet && !agentConfig.forceNewAgent_) {
@@ -53,3 +52,20 @@ export function start(
5352

5453
return agentConfig.testMode_ ? debuglet : debuglet.isReadyManager;
5554
}
55+
56+
/**
57+
* If the given `options` object has a `debug` property
58+
* of the same type, this function returns the union of the
59+
* properties in `options.debug` and `options` except that
60+
* the returned object no longer has a `debug` property.
61+
* If a field exists in both `options` and `options.debug`,
62+
* the value in `option.debug` takes precedence.
63+
*/
64+
function mergeConfigs<T>(options: T & {debug?: T}): T {
65+
if (!options.debug) {
66+
return options;
67+
}
68+
const result = Object.assign({}, options);
69+
delete result.debug;
70+
return Object.assign(result, options.debug);
71+
}

0 commit comments

Comments
 (0)