Skip to content

Commit 0987482

Browse files
committed
fix: incorrect name in prod diagnostic
1 parent 341399c commit 0987482

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

‎docs/content/4.api/1.reference.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ interface DiagnosticCallParams {
6767

6868
### `defineProdDiagnostics(options?)`
6969

70-
Lean production counterpart to `defineDiagnostics`. Returns a `Proxy` that builds a minimal `Diagnostic` for any accessed code: the code becomes the `message` (`why`), `name` stays the default `Diagnostic`, and `docs` is derived from `docsBase`. It carries no catalog text, so it stays tiny in a bundle.
70+
Lean production counterpart to `defineDiagnostics`. Returns a `Proxy` that builds a minimal `Diagnostic` for any accessed code: the code becomes both the `message` (`why`) and the instance `name`, and `docs` is derived from `docsBase`. It carries no catalog text, so it stays tiny in a bundle.
7171

7272
```ts
7373
const diagnostics = defineProdDiagnostics({

‎src/prod-diagnostics.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ describe('defineProdDiagnostics', () => {
1010
expect(d).toBeInstanceOf(Diagnostic)
1111
})
1212

13-
it('uses the accessed code as `why` and keeps the default `name`', () => {
13+
it('uses the accessed code as `why` and as the instance `name`', () => {
1414
const errs = defineProdDiagnostics()
1515
const d = errs.NUXT_B2011()
16-
expect(d.name).toBe('Diagnostic')
16+
// parity with defineDiagnostics: the code becomes the instance name
17+
expect(d.name).toBe('NUXT_B2011')
1718
expect(d.message).toBe('NUXT_B2011')
1819
expect(d.why).toBe('NUXT_B2011')
1920
})

‎src/prod-diagnostics.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ export interface DefineProdDiagnosticsOptions<
3232
/**
3333
* Production counterpart to {@link defineDiagnostics}. Returns a `Proxy` that
3434
* builds a minimal {@link Diagnostic} for any accessed code: the code becomes
35-
* the `message` (`why`), `name` stays the default `'Diagnostic'`, and `docs` is
36-
* derived from `docsBase`. It carries no catalog text, so it stays tiny in a
37-
* bundle.
35+
* both the `message` (`why`) and the instance `name`, and `docs` is derived
36+
* from `docsBase`. It carries no catalog text, so it stays tiny in a bundle.
3837
*
3938
* The strip plugin (`@nostics/unplugin`) can rewrite a `defineDiagnostics()`
4039
* call into a `process.env.NODE_ENV === 'production'` ternary that selects this
@@ -72,6 +71,7 @@ export function defineProdDiagnostics<
7271
},
7372
handle,
7473
)
74+
diagnostic.name = code
7575
for (const reporter of reporters) reporter(diagnostic, reporterOptions)
7676
return diagnostic
7777
}

0 commit comments

Comments
 (0)