mirror of https://github.com/vuejs/core.git
build: use `stripInternal` (#9379)
Unlike our custom plugin, TypeScript won't automatically remove re-exports of internal types, so we need to explicitly mark them as `@internal`.
This commit is contained in:
parent
2857a59e61
commit
0a8be4537a
|
@ -73,8 +73,13 @@ export {
|
|||
defineSlots,
|
||||
defineModel,
|
||||
withDefaults,
|
||||
useModel,
|
||||
// internal
|
||||
useModel
|
||||
} from './apiSetupHelpers'
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
export {
|
||||
mergeDefaults,
|
||||
mergeModels,
|
||||
createPropsRestProxy,
|
||||
|
@ -111,7 +116,9 @@ export { useSSRContext, ssrContextKey } from './helpers/useSsrContext'
|
|||
|
||||
export { createRenderer, createHydrationRenderer } from './renderer'
|
||||
export { queuePostFlushCb } from './scheduler'
|
||||
export { warn, assertNumber } from './warning'
|
||||
export { warn } from './warning'
|
||||
/** @internal */
|
||||
export { assertNumber } from './warning'
|
||||
export {
|
||||
handleError,
|
||||
callWithErrorHandling,
|
||||
|
|
|
@ -3,7 +3,6 @@ import { parse } from '@babel/parser'
|
|||
import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs'
|
||||
import MagicString from 'magic-string'
|
||||
import dts from 'rollup-plugin-dts'
|
||||
import { walk } from 'estree-walker'
|
||||
|
||||
if (!existsSync('temp/packages')) {
|
||||
console.warn(
|
||||
|
@ -41,12 +40,11 @@ export default targetPackages.map(pkg => {
|
|||
|
||||
/**
|
||||
* Patch the dts generated by rollup-plugin-dts
|
||||
* 1. remove exports marked as @internal
|
||||
* 2. Convert all types to inline exports
|
||||
* 1. Convert all types to inline exports
|
||||
* and remove them from the big export {} declaration
|
||||
* otherwise it gets weird in vitepress `defineComponent` call with
|
||||
* "the inferred type cannot be named without a reference"
|
||||
* 3. Append custom augmentations (jsx, macros)
|
||||
* 2. Append custom augmentations (jsx, macros)
|
||||
* @returns {import('rollup').Plugin}
|
||||
*/
|
||||
function patchTypes(pkg) {
|
||||
|
@ -73,64 +71,12 @@ function patchTypes(pkg) {
|
|||
return
|
||||
}
|
||||
shouldRemoveExport.add(name)
|
||||
if (!removeInternal(parentDecl || node)) {
|
||||
if (isExported.has(name)) {
|
||||
// @ts-ignore
|
||||
s.prependLeft((parentDecl || node).start, `export `)
|
||||
}
|
||||
// traverse further for internal properties
|
||||
if (
|
||||
node.type === 'TSInterfaceDeclaration' ||
|
||||
node.type === 'ClassDeclaration'
|
||||
) {
|
||||
node.body.body.forEach(removeInternal)
|
||||
} else if (node.type === 'TSTypeAliasDeclaration') {
|
||||
// @ts-ignore
|
||||
walk(node.typeAnnotation, {
|
||||
enter(node) {
|
||||
// @ts-ignore
|
||||
if (removeInternal(node)) this.skip()
|
||||
}
|
||||
})
|
||||
}
|
||||
if (isExported.has(name)) {
|
||||
// @ts-ignore
|
||||
s.prependLeft((parentDecl || node).start, `export `)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {import('@babel/types').Node} node
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function removeInternal(node) {
|
||||
if (
|
||||
node.leadingComments &&
|
||||
node.leadingComments.some(c => {
|
||||
return c.type === 'CommentBlock' && /@internal\b/.test(c.value)
|
||||
})
|
||||
) {
|
||||
/** @type {any} */
|
||||
const n = node
|
||||
let id
|
||||
if (n.id && n.id.type === 'Identifier') {
|
||||
id = n.id.name
|
||||
} else if (n.key && n.key.type === 'Identifier') {
|
||||
id = n.key.name
|
||||
}
|
||||
if (id) {
|
||||
s.overwrite(
|
||||
// @ts-ignore
|
||||
node.leadingComments[0].start,
|
||||
node.end,
|
||||
`/* removed internal: ${id} */`
|
||||
)
|
||||
} else {
|
||||
// @ts-ignore
|
||||
s.remove(node.leadingComments[0].start, node.end)
|
||||
}
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const isExported = new Set()
|
||||
const shouldRemoveExport = new Set()
|
||||
|
||||
|
@ -146,7 +92,7 @@ function patchTypes(pkg) {
|
|||
}
|
||||
}
|
||||
|
||||
// pass 1: remove internals + add exports
|
||||
// pass 1: add exports
|
||||
for (const node of ast.program.body) {
|
||||
if (node.type === 'VariableDeclaration') {
|
||||
processDeclaration(node.declarations[0], node)
|
||||
|
@ -167,10 +113,6 @@ function patchTypes(pkg) {
|
|||
node.type === 'ClassDeclaration'
|
||||
) {
|
||||
processDeclaration(node)
|
||||
} else if (removeInternal(node)) {
|
||||
throw new Error(
|
||||
`unhandled export type marked as @internal: ${node.type}`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,12 +155,6 @@ function patchTypes(pkg) {
|
|||
}
|
||||
code = s.toString()
|
||||
|
||||
if (/@internal/.test(code)) {
|
||||
throw new Error(
|
||||
`unhandled @internal declarations detected in ${chunk.fileName}.`
|
||||
)
|
||||
}
|
||||
|
||||
// append pkg specific types
|
||||
const additionalTypeDir = `packages/${pkg}/types`
|
||||
if (existsSync(additionalTypeDir)) {
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
"extends": "./tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"emitDeclarationOnly": true
|
||||
"emitDeclarationOnly": true,
|
||||
"stripInternal": true
|
||||
},
|
||||
"exclude": [
|
||||
"packages/*/__tests__",
|
||||
|
|
Loading…
Reference in New Issue