Skip to content

Commit

Permalink
feat: patch VNode type (vuejs/core#1033)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibbng committed Mar 5, 2022
1 parent 442ea6d commit a38577c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions scripts/postinstall.js
Expand Up @@ -4,13 +4,16 @@ import { join } from 'path'
const require = createRequire(import.meta.url)
const runtime = require.resolve('@vue/runtime-core')
const runtimeDist = join(runtime, '../dist')
const files = (await readdir(runtimeDist)).filter(file => file.endsWith('.js'))
const files = await readdir(runtimeDist)
const exports = ['setCurrentInstance', 'unsetCurrentInstance', 'currentInstance', 'createHook']
const getExports = isEsm => exports.map(e => isEsm ? `export { ${e} };` : `exports.${e} = ${e};`).join('\n')
for (const file of files) {
let content = await readFile(join(runtimeDist, file), 'utf8')
if (content.match(/export.*setCurrentInstance/))
continue
content += `\n${getExports(file.includes('esm'))}`
if (file.endsWith('js') && !content.match(/export.*setCurrentInstance/))
content += `\n${getExports(file.includes('esm'))}`

if (file.endsWith('d.ts') && !content.match(/VNodeDisabled/))
content = content.replace(/export declare interface VNode/g, 'export declare interface VNodeDisabled')

writeFile(join(runtimeDist, file), content, 'utf8')
}

0 comments on commit a38577c

Please sign in to comment.