Skip to content

Commit be4fe8d

Browse files
committed
refactor(deps): drop onlyBundle; resolve schema/diagnostics types via devframe peer
tsdown's default deps/devDeps split already expresses bundle intent (dependencies external, devDependencies bundled), so the onlyBundle whitelists in devframe/hub/json-render are removed. devframe re-exports the Standard Schema contract type from devframe/utils/simple-schema and adds a DevframeDiagnostics helper type to devframe/utils/nostics. @devframes/json-render now names both through the devframe peer instead of inlining nostics or depending on @standard-schema/spec: its public dts references devframe/utils/simple-schema and devframe/utils/nostics, and @standard-schema/spec is dropped from its package.json. Any integration can reuse both the same way.
1 parent b37efa4 commit be4fe8d

13 files changed

Lines changed: 71 additions & 161 deletions

File tree

‎packages/devframe/src/utils/nostics.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,26 @@ export function defineDiagnostics<
4141
docsBase?: string | ((code: keyof Codes) => string | undefined)
4242
codes: Codes
4343
reporters?: Reporters
44-
}): Diagnostics<Codes, readonly [typeof devframeReporter, ...Reporters]> {
44+
}): DevframeDiagnostics<Codes, Reporters> {
4545
return defineNosticsDiagnostics({
4646
...options,
4747
reporters: [devframeReporter, ...(options.reporters ?? [])],
48-
}) as Diagnostics<Codes, readonly [typeof devframeReporter, ...Reporters]>
48+
}) as DevframeDiagnostics<Codes, Reporters>
4949
}
5050

51+
/**
52+
* The `Diagnostics` object returned by devframe's {@link defineDiagnostics}
53+
* (devframe's ANSI console reporter is always prepended). Integrations that
54+
* export their own `defineDiagnostics(...)` result as public API annotate it
55+
* with this type, so the reference resolves through `devframe/utils/nostics`
56+
* rather than inlining `nostics`'s types or taking a direct `nostics`
57+
* dependency.
58+
*/
59+
export type DevframeDiagnostics<
60+
Codes extends Record<string, DiagnosticDefinition>,
61+
Reporters extends readonly AnyDiagnosticReporter[] = [],
62+
> = Diagnostics<Codes, readonly [typeof devframeReporter, ...Reporters]>
63+
5164
export {
5265
createConsoleReporter,
5366
defineProdDiagnostics,

‎packages/devframe/src/utils/simple-schema.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import type { StandardSchemaV1 } from '@standard-schema/spec'
22

3+
/**
4+
* Re-exported [Standard Schema](https://standardschema.dev/) contract types so
5+
* integrations can type `args`/`returns`/view schemas against Standard Schema
6+
* through the devframe peer, without taking their own `@standard-schema/spec`
7+
* dependency (devframe inlines the declarations into its own `.d.mts`).
8+
*/
9+
export type { StandardSchemaV1 } from '@standard-schema/spec'
10+
311
/**
412
* A tiny, zero-dependency [Standard Schema](https://standardschema.dev/)
513
* builder.

‎packages/devframe/tsdown.config.ts‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const deps = {
2626
'@jridgewell/trace-mapping',
2727
],
2828
/**
29-
* `whenexpr` is runtime-only bundled (see `onlyBundle` below); its
29+
* `whenexpr` is a devDependency, so its runtime is bundled in; its
3030
* declaration file mixes type-only and value named exports
3131
* (`export { type WhenExpression, evaluateWhen, ... }`) in a way that
3232
* trips up rolldown's dts bundler when it tries to inline the type
@@ -38,27 +38,6 @@ const deps = {
3838
dts: {
3939
neverBundle: ['whenexpr'],
4040
},
41-
onlyBundle: [
42-
'@standard-schema/spec',
43-
'acorn',
44-
'birpc',
45-
'get-port-please',
46-
'immer',
47-
'launch-editor',
48-
'mlly',
49-
'mrmime',
50-
'obug',
51-
'ohash',
52-
'p-limit',
53-
'perfect-debounce',
54-
'picocolors',
55-
'shell-quote',
56-
'structured-clone-es',
57-
'tinyexec',
58-
'ua-parser-modern',
59-
'whenexpr',
60-
'yocto-queue',
61-
],
6241
}
6342

6443
// The node build reaches `devframe/utils/shared-state` through the same

‎packages/hub/tsdown.config.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,5 @@ export default defineConfig({
2222
'postcss',
2323
'rolldown',
2424
],
25-
onlyBundle: [
26-
'@standard-schema/spec',
27-
'acorn',
28-
'get-port-please',
29-
],
3025
},
3126
})

‎packages/json-render/package.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
},
5151
"devDependencies": {
5252
"@devframes/hub": "workspace:*",
53-
"@standard-schema/spec": "catalog:deps",
5453
"@types/node": "catalog:types",
5554
"devframe": "workspace:*",
5655
"tsdown": "catalog:build"

‎packages/json-render/src/node/create-view.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { StandardSchemaV1 } from '@standard-schema/spec'
21
import type { DevframeNodeContext, DevframeScopedNodeContext } from 'devframe'
32
import type { SharedState, SharedStatePatch } from 'devframe/utils/shared-state'
3+
import type { StandardSchemaV1 } from 'devframe/utils/simple-schema'
44
import type { DevframeJsonRenderSpec, JsonRenderStatePatch, JsonRenderView } from '../types'
55
import type { JsonRenderIndex } from '../view-index'
66
import { createSharedState } from 'devframe/utils/shared-state'
Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,48 @@
1+
import type { DevframeDiagnostics } from 'devframe/utils/nostics'
12
import { defineDiagnostics } from 'devframe/utils/nostics'
23

4+
const codes = {
5+
DF0038: {
6+
why: (p: { id: string, key: string, issues: string }) =>
7+
`JSON-render view "${p.id}" received invalid props on element "${p.key}": ${p.issues}`,
8+
fix: 'Match the element props to the base catalog\'s prop schema for that component. See the component reference for the expected shape.',
9+
},
10+
DF0039: {
11+
why: (p: { id: string, scope: string }) =>
12+
`A JSON-render view with id "${p.id}" already exists in scope "${p.scope}".`,
13+
fix: 'Give each view a stable id unique within its scope, or dispose the previous view before recreating it.',
14+
},
15+
DF0040: {
16+
why: (p: { id: string }) =>
17+
`JSON-render view "${p.id}" was used after it was disposed.`,
18+
fix: 'Create a fresh view with `createJsonRenderView` instead of reusing a disposed handle.',
19+
},
20+
DF0041: {
21+
why: (p: { id: string, reason: string }) =>
22+
`JSON-render view "${p.id}" spec is not JSON-serializable: ${p.reason}`,
23+
fix: 'Specs and state travel as strict JSON, so remove functions, symbols, class instances, Map/Set, or circular references.',
24+
},
25+
DF0073: {
26+
why: (p: { id: string, issues: string }) =>
27+
`JSON-render view "${p.id}" does not match its configured schema: ${p.issues}`,
28+
fix: 'Match the authored spec to the Standard Schema passed to `createJsonRenderView`.',
29+
},
30+
DF0074: {
31+
why: (p: { id: string }) =>
32+
`JSON-render view "${p.id}" uses an asynchronous Standard Schema.`,
33+
fix: 'Use a synchronous Standard Schema so initial creation and updates remain synchronous.',
34+
},
35+
}
36+
337
/**
438
* `@devframes/json-render` protocol/runtime diagnostics share the `DF`
539
* prefix and use the next globally available core codes. Browser-only render
640
* failures keep `console.*` in the UI package.
41+
*
42+
* Annotated with {@link DevframeDiagnostics} so the public type resolves
43+
* through the `devframe/utils/nostics` peer rather than inlining `nostics`.
744
*/
8-
export const diagnostics = defineDiagnostics({
45+
export const diagnostics: DevframeDiagnostics<typeof codes> = defineDiagnostics({
946
docsBase: 'https://devfra.me/errors',
10-
codes: {
11-
DF0038: {
12-
why: (p: { id: string, key: string, issues: string }) =>
13-
`JSON-render view "${p.id}" received invalid props on element "${p.key}": ${p.issues}`,
14-
fix: 'Match the element props to the base catalog\'s prop schema for that component. See the component reference for the expected shape.',
15-
},
16-
DF0039: {
17-
why: (p: { id: string, scope: string }) =>
18-
`A JSON-render view with id "${p.id}" already exists in scope "${p.scope}".`,
19-
fix: 'Give each view a stable id unique within its scope, or dispose the previous view before recreating it.',
20-
},
21-
DF0040: {
22-
why: (p: { id: string }) =>
23-
`JSON-render view "${p.id}" was used after it was disposed.`,
24-
fix: 'Create a fresh view with `createJsonRenderView` instead of reusing a disposed handle.',
25-
},
26-
DF0041: {
27-
why: (p: { id: string, reason: string }) =>
28-
`JSON-render view "${p.id}" spec is not JSON-serializable: ${p.reason}`,
29-
fix: 'Specs and state travel as strict JSON, so remove functions, symbols, class instances, Map/Set, or circular references.',
30-
},
31-
DF0073: {
32-
why: (p: { id: string, issues: string }) =>
33-
`JSON-render view "${p.id}" does not match its configured schema: ${p.issues}`,
34-
fix: 'Match the authored spec to the Standard Schema passed to `createJsonRenderView`.',
35-
},
36-
DF0074: {
37-
why: (p: { id: string }) =>
38-
`JSON-render view "${p.id}" uses an asynchronous Standard Schema.`,
39-
fix: 'Use a synchronous Standard Schema so initial creation and updates remain synchronous.',
40-
},
41-
},
47+
codes,
4248
})

‎packages/json-render/test/create-view.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import type { StandardSchemaV1 } from '@standard-schema/spec'
21
import type { DevframeHost, DevframeNodeContext } from 'devframe'
2+
import type { StandardSchemaV1 } from 'devframe/utils/simple-schema'
33
import type { DevframeJsonRenderSpec } from '../src/types'
44
import { mkdtempSync } from 'node:fs'
55
import { tmpdir } from 'node:os'

‎packages/json-render/tsdown.config.ts‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,4 @@ export default defineConfig({
1212
tsconfig: '../../tsconfig.base.json',
1313
dts: true,
1414
platform: 'neutral',
15-
deps: {
16-
// Both are types-only in this package's public dts: `@standard-schema/spec`
17-
// (a devDependency) and `nostics` (reached via `devframe/utils/nostics`,
18-
// runtime import stays external on the devframe peer). Whitelisting them
19-
// lets the dts bundler inline the type declarations so consumers need
20-
// neither package installed for `@devframes/json-render`'s types.
21-
onlyBundle: [
22-
'@standard-schema/spec',
23-
'nostics',
24-
],
25-
},
2615
})

‎pnpm-lock.yaml‎

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)