Skip to content

Commit c9bf7de

Browse files
committed
refactor(types): mark internal API exports and exclude from d.ts
BREAKING CHANGE: Internal APIs are now excluded from type decalrations.
1 parent a5bb1d0 commit c9bf7de

28 files changed

+209
-96
lines changed

packages/compiler-core/api-extractor.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"extends": "../../api-extractor.json",
33
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
44
"dtsRollup": {
5-
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
5+
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
66
}
77
}

packages/compiler-dom/api-extractor.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"extends": "../../api-extractor.json",
33
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
44
"dtsRollup": {
5-
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
5+
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
66
}
7-
}
7+
}

packages/compiler-sfc/api-extractor.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"extends": "../../api-extractor.json",
33
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
44
"dtsRollup": {
5-
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
5+
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
66
}
7-
}
7+
}

packages/compiler-ssr/api-extractor.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"extends": "../../api-extractor.json",
33
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
44
"dtsRollup": {
5-
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
5+
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
66
}
7-
}
7+
}

packages/reactivity/api-extractor.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"extends": "../../api-extractor.json",
33
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
44
"dtsRollup": {
5-
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
5+
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
66
}
77
}

packages/runtime-core/api-extractor.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
"extends": "../../api-extractor.json",
33
"mainEntryPointFilePath": "./dist/packages/<unscopedPackageName>/src/index.d.ts",
44
"dtsRollup": {
5-
"untrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
5+
"publicTrimmedFilePath": "./dist/<unscopedPackageName>.d.ts"
66
}
77
}

packages/runtime-core/src/component.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,11 @@ type CompileFunction = (
417417

418418
let compile: CompileFunction | undefined
419419

420-
// exported method uses any to avoid d.ts relying on the compiler types.
420+
/**
421+
* For runtime-dom to register the compiler.
422+
* Note the exported method uses any to avoid d.ts relying on the compiler types.
423+
* @internal
424+
*/
421425
export function registerRuntimeCompiler(_compile: any) {
422426
compile = _compile
423427
}

packages/runtime-core/src/directives.ts

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ export type DirectiveArguments = Array<
8080
| [Directive, any, string, DirectiveModifiers]
8181
>
8282

83+
/**
84+
* Adds directives to a VNode.
85+
* @internal
86+
*/
8387
export function withDirectives<T extends VNode>(
8488
vnode: T,
8589
directives: DirectiveArguments

packages/runtime-core/src/helpers/createSlots.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ interface CompiledSlotDescriptor {
66
fn: Slot
77
}
88

9+
/**
10+
* Compiler runtime helper for creating dynamic slots object
11+
* @internal
12+
*/
913
export function createSlots(
1014
slots: Record<string, Slot>,
1115
dynamicSlots: (

packages/runtime-core/src/helpers/renderList.ts

+20-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,46 @@
11
import { VNodeChild } from '../vnode'
22
import { isArray, isString, isObject } from '@vue/shared'
33

4-
// v-for string
4+
/**
5+
* v-for string
6+
* @internal
7+
*/
58
export function renderList(
69
source: string,
710
renderItem: (value: string, index: number) => VNodeChild
811
): VNodeChild[]
912

10-
// v-for number
13+
/**
14+
* v-for number
15+
* @internal
16+
*/
1117
export function renderList(
1218
source: number,
1319
renderItem: (value: number, index: number) => VNodeChild
1420
): VNodeChild[]
1521

16-
// v-for array
22+
/**
23+
* v-for array
24+
* @internal
25+
*/
1726
export function renderList<T>(
1827
source: T[],
1928
renderItem: (value: T, index: number) => VNodeChild
2029
): VNodeChild[]
2130

22-
// v-for iterable
31+
/**
32+
* v-for iterable
33+
* @internal
34+
*/
2335
export function renderList<T>(
2436
source: Iterable<T>,
2537
renderItem: (value: T, index: number) => VNodeChild
2638
): VNodeChild[]
2739

28-
// v-for object
40+
/**
41+
* v-for object
42+
* @internal
43+
*/
2944
export function renderList<T>(
3045
source: T,
3146
renderItem: <K extends keyof T>(

packages/runtime-core/src/helpers/renderSlot.ts

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import {
1010
import { PatchFlags } from '@vue/shared'
1111
import { warn } from '../warning'
1212

13+
/**
14+
* Compiler runtime helper for rendering <slot/>
15+
* @internal
16+
*/
1317
export function renderSlot(
1418
slots: Slots,
1519
name: string,

packages/runtime-core/src/helpers/resolveAssets.ts

+9
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ import { warn } from '../warning'
1212
const COMPONENTS = 'components'
1313
const DIRECTIVES = 'directives'
1414

15+
/**
16+
* @internal
17+
*/
1518
export function resolveComponent(name: string): Component | string | undefined {
1619
return resolveAsset(COMPONENTS, name) || name
1720
}
1821

1922
export const NULL_DYNAMIC_COMPONENT = Symbol()
2023

24+
/**
25+
* @internal
26+
*/
2127
export function resolveDynamicComponent(
2228
component: unknown
2329
): Component | string | typeof NULL_DYNAMIC_COMPONENT {
@@ -29,6 +35,9 @@ export function resolveDynamicComponent(
2935
}
3036
}
3137

38+
/**
39+
* @internal
40+
*/
3241
export function resolveDirective(name: string): Directive | undefined {
3342
return resolveAsset(DIRECTIVES, name)
3443
}

packages/runtime-core/src/helpers/scopeId.ts

+9
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,24 @@ import { withCtx } from './withRenderContext'
77
export let currentScopeId: string | null = null
88
const scopeIdStack: string[] = []
99

10+
/**
11+
* @internal
12+
*/
1013
export function pushScopeId(id: string) {
1114
scopeIdStack.push((currentScopeId = id))
1215
}
1316

17+
/**
18+
* @internal
19+
*/
1420
export function popScopeId() {
1521
scopeIdStack.pop()
1622
currentScopeId = scopeIdStack[scopeIdStack.length - 1] || null
1723
}
1824

25+
/**
26+
* @internal
27+
*/
1928
export function withScopeId(id: string): <T extends Function>(fn: T) => T {
2029
return ((fn: Function) =>
2130
withCtx(function(this: any) {

packages/runtime-core/src/helpers/toHandlers.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import { isObject } from '@vue/shared'
22
import { warn } from '../warning'
33

4-
// For prefixing keys in v-on="obj" with "on"
4+
/**
5+
* For prefixing keys in v-on="obj" with "on"
6+
* @internal
7+
*/
58
export function toHandlers(obj: Record<string, any>): Record<string, any> {
69
const ret: Record<string, any> = {}
710
if (__DEV__ && !isObject(obj)) {

packages/runtime-core/src/helpers/withRenderContext.ts

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {
55
} from '../componentRenderUtils'
66
import { ComponentInternalInstance } from '../component'
77

8+
/**
9+
* Wrap a slot function to memoize current rendering instance
10+
* @internal
11+
*/
812
export function withCtx(
913
fn: Slot,
1014
ctx: ComponentInternalInstance | null = currentRenderingInstance

packages/runtime-core/src/index.ts

+61-53
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ export { useCSSModule } from './helpers/useCssModule'
7474
// SSR context
7575
export { useSSRContext, ssrContextKey } from './helpers/useSsrContext'
7676

77-
// Internal API ----------------------------------------------------------------
77+
// Custom Renderer API ---------------------------------------------------------
7878

79-
// For custom renderers
8079
export { createRenderer, createHydrationRenderer } from './renderer'
8180
export { queuePostFlushCb } from './scheduler'
8281
export { warn } from './warning'
@@ -92,57 +91,6 @@ export {
9291
setTransitionHooks
9392
} from './components/BaseTransition'
9493

95-
// For compiler generated code
96-
// should sync with '@vue/compiler-core/src/runtimeConstants.ts'
97-
export { withCtx } from './helpers/withRenderContext'
98-
export { withDirectives } from './directives'
99-
export {
100-
resolveComponent,
101-
resolveDirective,
102-
resolveDynamicComponent
103-
} from './helpers/resolveAssets'
104-
export { renderList } from './helpers/renderList'
105-
export { toHandlers } from './helpers/toHandlers'
106-
export { renderSlot } from './helpers/renderSlot'
107-
export { createSlots } from './helpers/createSlots'
108-
export { pushScopeId, popScopeId, withScopeId } from './helpers/scopeId'
109-
export {
110-
setBlockTracking,
111-
createTextVNode,
112-
createCommentVNode,
113-
createStaticVNode
114-
} from './vnode'
115-
export { toDisplayString, camelize } from '@vue/shared'
116-
117-
// For integration with runtime compiler
118-
export { registerRuntimeCompiler } from './component'
119-
120-
// For test-utils
121-
export { transformVNodeArgs } from './vnode'
122-
123-
// SSR -------------------------------------------------------------------------
124-
125-
import { createComponentInstance, setupComponent } from './component'
126-
import {
127-
renderComponentRoot,
128-
setCurrentRenderingInstance
129-
} from './componentRenderUtils'
130-
import { isVNode, normalizeVNode } from './vnode'
131-
import { normalizeSuspenseChildren } from './components/Suspense'
132-
133-
// SSR utils are only exposed in cjs builds.
134-
const _ssrUtils = {
135-
createComponentInstance,
136-
setupComponent,
137-
renderComponentRoot,
138-
setCurrentRenderingInstance,
139-
isVNode,
140-
normalizeVNode,
141-
normalizeSuspenseChildren
142-
}
143-
144-
export const ssrUtils = (__NODE_JS__ ? _ssrUtils : null) as typeof _ssrUtils
145-
14694
// Types -----------------------------------------------------------------------
14795

14896
export {
@@ -233,3 +181,63 @@ export {
233181
AsyncComponentLoader
234182
} from './apiAsyncComponent'
235183
export { HMRRuntime } from './hmr'
184+
185+
// Internal API ----------------------------------------------------------------
186+
187+
// **IMPORTANT** Internal APIs may change without notice between versions and
188+
// user code should avoid relying on them.
189+
190+
// For compiler generated code
191+
// should sync with '@vue/compiler-core/src/runtimeConstants.ts'
192+
export { withCtx } from './helpers/withRenderContext'
193+
export { withDirectives } from './directives'
194+
export {
195+
resolveComponent,
196+
resolveDirective,
197+
resolveDynamicComponent
198+
} from './helpers/resolveAssets'
199+
export { renderList } from './helpers/renderList'
200+
export { toHandlers } from './helpers/toHandlers'
201+
export { renderSlot } from './helpers/renderSlot'
202+
export { createSlots } from './helpers/createSlots'
203+
export { pushScopeId, popScopeId, withScopeId } from './helpers/scopeId'
204+
export {
205+
setBlockTracking,
206+
createTextVNode,
207+
createCommentVNode,
208+
createStaticVNode
209+
} from './vnode'
210+
export { toDisplayString, camelize } from '@vue/shared'
211+
// For integration with runtime compiler
212+
export { registerRuntimeCompiler } from './component'
213+
// For test-utils
214+
export { transformVNodeArgs } from './vnode'
215+
216+
// SSR -------------------------------------------------------------------------
217+
218+
// **IMPORTANT** These APIs are exposed solely for @vue/server-renderer and may
219+
// change without notice between versions. User code should never rely on them.
220+
221+
import { createComponentInstance, setupComponent } from './component'
222+
import {
223+
renderComponentRoot,
224+
setCurrentRenderingInstance
225+
} from './componentRenderUtils'
226+
import { isVNode, normalizeVNode } from './vnode'
227+
import { normalizeSuspenseChildren } from './components/Suspense'
228+
229+
const _ssrUtils = {
230+
createComponentInstance,
231+
setupComponent,
232+
renderComponentRoot,
233+
setCurrentRenderingInstance,
234+
isVNode,
235+
normalizeVNode,
236+
normalizeSuspenseChildren
237+
}
238+
239+
/**
240+
* SSR utils for \@vue/server-renderer. Only exposed in cjs builds.
241+
* @internal
242+
*/
243+
export const ssrUtils = (__NODE_JS__ ? _ssrUtils : null) as typeof _ssrUtils

0 commit comments

Comments
 (0)