Skip to content

Commit 795ac49

Browse files
committed
Honor liveDebugger.enable: false to match other plugins
The previous commit reduced enablement to `!!config[CONFIG_KEY]`, which meant `{ liveDebugger: { enable: false } }` silently kept the plugin enabled. Every other plugin in this repo (`apps`, `error-tracking`, `metrics`, `output`, `rum`) accepts an explicit `enable: false` — either directly (`apps`) or implicitly via spread ordering (the rest). Switch `validate.ts` to the explicit `apps`-style pattern: enable: pluginConfig.enable ?? !!config[CONFIG_KEY] so that: - omitted `liveDebugger` key -> disabled - `liveDebugger: {}` -> enabled - `liveDebugger: { enable: true }` -> enabled - `liveDebugger: { enable: false }` -> disabled Also add a runtime `typeof enable === 'boolean'` check alongside the existing boolean-option validations, and re-document `liveDebugger.enable` in the README to match the `apps` README wording. Test coverage: - Restore the "return an empty array when enable is false" test in `index.test.ts`. - Add `enable: false` / `enable: true` cases to `validateOptions` defaults tests and a new `invalid enable` describe block covering non-boolean inputs. Extend the `multiple errors` aggregate test to include `enable`.
1 parent d63bd7f commit 795ac49

4 files changed

Lines changed: 56 additions & 1 deletion

File tree

packages/plugins/live-debugger/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Automatically instrument JavaScript functions at build time to enable Live Debug
1212
- [Required peer dependencies](#required-peer-dependencies)
1313
- [Configuration](#configuration)
1414
- [How it works](#how-it-works)
15+
- [liveDebugger.enable](#livedebuggerenable)
1516
- [liveDebugger.include](#livedebuggerinclude)
1617
- [liveDebugger.exclude](#livedebuggerexclude)
1718
- [liveDebugger.honorSkipComments](#livedebuggerhonorskipcomments)
@@ -115,6 +116,12 @@ const double = (x) => {
115116
};
116117
```
117118

119+
### liveDebugger.enable
120+
121+
> default: `true` when a `liveDebugger` config block is present
122+
123+
Enable or disable the plugin without removing its configuration.
124+
118125
### liveDebugger.include
119126

120127
> default: `[/\.[jt]sx?$/]`

packages/plugins/live-debugger/src/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ describe('getLiveDebuggerPlugin', () => {
294294
});
295295

296296
describe('getPlugins', () => {
297+
it('should return an empty array when enable is false', () => {
298+
const arg = getGetPluginsArg({ liveDebugger: { enable: false } });
299+
300+
const plugins = getPlugins(arg);
301+
302+
expect(plugins).toEqual([]);
303+
expect(arg.context.inject).not.toHaveBeenCalled();
304+
});
305+
297306
it('should return an empty array when liveDebugger config is omitted', () => {
298307
const arg = getGetPluginsArg();
299308

packages/plugins/live-debugger/src/validate.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ describe('validateOptions', () => {
5050
namedOnly: false,
5151
} satisfies LiveDebuggerOptionsWithDefaults,
5252
},
53+
{
54+
description: 'honor enable: false even when the config key is present',
55+
input: makeConfig({ enable: false }),
56+
expected: expect.objectContaining({ enable: false }),
57+
},
58+
{
59+
description: 'honor enable: true (redundant but valid)',
60+
input: makeConfig({ enable: true }),
61+
expected: expect.objectContaining({ enable: true }),
62+
},
5363
];
5464

5565
test.each(cases)('should $description', ({ input, expected }) => {
@@ -210,6 +220,28 @@ describe('validateOptions', () => {
210220
});
211221
});
212222

223+
describe('invalid enable', () => {
224+
const cases = [
225+
{
226+
description: 'reject enable when a string',
227+
input: makeConfig({ enable: 'yes' }),
228+
},
229+
{
230+
description: 'reject enable when a number',
231+
input: makeConfig({ enable: 1 }),
232+
},
233+
];
234+
235+
test.each(cases)('should $description', ({ input }) => {
236+
expect(() => validateOptions(input, mockLogger)).toThrow(
237+
`Invalid configuration for ${PLUGIN_NAME}.`,
238+
);
239+
expect(mockLogger.error).toHaveBeenCalledWith(
240+
expect.stringMatching(/enable.*must be a boolean/),
241+
);
242+
});
243+
});
244+
213245
describe('invalid honorSkipComments', () => {
214246
const cases = [
215247
{
@@ -279,6 +311,7 @@ describe('validateOptions', () => {
279311
describe('multiple errors', () => {
280312
it('should aggregate all validation errors before throwing', () => {
281313
const input = makeConfig({
314+
enable: 'yes',
282315
include: 'bad',
283316
exclude: 'bad',
284317
honorSkipComments: 42,
@@ -291,6 +324,7 @@ describe('validateOptions', () => {
291324
);
292325

293326
const errorMessage = (mockLogger.error as jest.Mock).mock.calls[0][0] as string;
327+
expect(errorMessage).toMatch(/enable/);
294328
expect(errorMessage).toMatch(/include/);
295329
expect(errorMessage).toMatch(/exclude/);
296330
expect(errorMessage).toMatch(/honorSkipComments/);

packages/plugins/live-debugger/src/validate.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export const validateOptions = (config: Options, log: Logger): LiveDebuggerOptio
1515
const pluginConfig: LiveDebuggerOptions = config[CONFIG_KEY] || {};
1616
const errors: string[] = [];
1717

18+
// Validate enable option
19+
if (pluginConfig.enable !== undefined && typeof pluginConfig.enable !== 'boolean') {
20+
errors.push(`${red('enable')} must be a boolean`);
21+
}
22+
1823
// Validate include option
1924
if (pluginConfig.include !== undefined) {
2025
if (!Array.isArray(pluginConfig.include)) {
@@ -80,7 +85,7 @@ export const validateOptions = (config: Options, log: Logger): LiveDebuggerOptio
8085

8186
// Build the final configuration with defaults
8287
return {
83-
enable: !!config[CONFIG_KEY],
88+
enable: pluginConfig.enable ?? !!config[CONFIG_KEY],
8489
include: pluginConfig.include || [/\.[jt]sx?$/], // .js, .jsx, .ts, .tsx
8590
exclude: pluginConfig.exclude || [
8691
/\/node_modules\//,

0 commit comments

Comments
 (0)