@@ -3,7 +3,6 @@ import { parse } from '@babel/parser'
3
3
import { existsSync , readdirSync , readFileSync , writeFileSync } from 'fs'
4
4
import MagicString from 'magic-string'
5
5
import dts from 'rollup-plugin-dts'
6
- import { walk } from 'estree-walker'
7
6
8
7
if ( ! existsSync ( 'temp/packages' ) ) {
9
8
console . warn (
@@ -41,12 +40,11 @@ export default targetPackages.map(pkg => {
41
40
42
41
/**
43
42
* Patch the dts generated by rollup-plugin-dts
44
- * 1. remove exports marked as @internal
45
- * 2. Convert all types to inline exports
43
+ * 1. Convert all types to inline exports
46
44
* and remove them from the big export {} declaration
47
45
* otherwise it gets weird in vitepress `defineComponent` call with
48
46
* "the inferred type cannot be named without a reference"
49
- * 3 . Append custom augmentations (jsx, macros)
47
+ * 2 . Append custom augmentations (jsx, macros)
50
48
* @returns {import('rollup').Plugin }
51
49
*/
52
50
function patchTypes ( pkg ) {
@@ -73,64 +71,12 @@ function patchTypes(pkg) {
73
71
return
74
72
}
75
73
shouldRemoveExport . add ( name )
76
- if ( ! removeInternal ( parentDecl || node ) ) {
77
- if ( isExported . has ( name ) ) {
78
- // @ts -ignore
79
- s . prependLeft ( ( parentDecl || node ) . start , `export ` )
80
- }
81
- // traverse further for internal properties
82
- if (
83
- node . type === 'TSInterfaceDeclaration' ||
84
- node . type === 'ClassDeclaration'
85
- ) {
86
- node . body . body . forEach ( removeInternal )
87
- } else if ( node . type === 'TSTypeAliasDeclaration' ) {
88
- // @ts -ignore
89
- walk ( node . typeAnnotation , {
90
- enter ( node ) {
91
- // @ts -ignore
92
- if ( removeInternal ( node ) ) this . skip ( )
93
- }
94
- } )
95
- }
74
+ if ( isExported . has ( name ) ) {
75
+ // @ts -ignore
76
+ s . prependLeft ( ( parentDecl || node ) . start , `export ` )
96
77
}
97
78
}
98
79
99
- /**
100
- * @param {import('@babel/types').Node } node
101
- * @returns {boolean }
102
- */
103
- function removeInternal ( node ) {
104
- if (
105
- node . leadingComments &&
106
- node . leadingComments . some ( c => {
107
- return c . type === 'CommentBlock' && / @ i n t e r n a l \b / . test ( c . value )
108
- } )
109
- ) {
110
- /** @type {any } */
111
- const n = node
112
- let id
113
- if ( n . id && n . id . type === 'Identifier' ) {
114
- id = n . id . name
115
- } else if ( n . key && n . key . type === 'Identifier' ) {
116
- id = n . key . name
117
- }
118
- if ( id ) {
119
- s . overwrite (
120
- // @ts -ignore
121
- node . leadingComments [ 0 ] . start ,
122
- node . end ,
123
- `/* removed internal: ${ id } */`
124
- )
125
- } else {
126
- // @ts -ignore
127
- s . remove ( node . leadingComments [ 0 ] . start , node . end )
128
- }
129
- return true
130
- }
131
- return false
132
- }
133
-
134
80
const isExported = new Set ( )
135
81
const shouldRemoveExport = new Set ( )
136
82
@@ -146,7 +92,7 @@ function patchTypes(pkg) {
146
92
}
147
93
}
148
94
149
- // pass 1: remove internals + add exports
95
+ // pass 1: add exports
150
96
for ( const node of ast . program . body ) {
151
97
if ( node . type === 'VariableDeclaration' ) {
152
98
processDeclaration ( node . declarations [ 0 ] , node )
@@ -167,10 +113,6 @@ function patchTypes(pkg) {
167
113
node . type === 'ClassDeclaration'
168
114
) {
169
115
processDeclaration ( node )
170
- } else if ( removeInternal ( node ) ) {
171
- throw new Error (
172
- `unhandled export type marked as @internal: ${ node . type } `
173
- )
174
116
}
175
117
}
176
118
@@ -213,12 +155,6 @@ function patchTypes(pkg) {
213
155
}
214
156
code = s . toString ( )
215
157
216
- if ( / @ i n t e r n a l / . test ( code ) ) {
217
- throw new Error (
218
- `unhandled @internal declarations detected in ${ chunk . fileName } .`
219
- )
220
- }
221
-
222
158
// append pkg specific types
223
159
const additionalTypeDir = `packages/${ pkg } /types`
224
160
if ( existsSync ( additionalTypeDir ) ) {
0 commit comments