fix(build): fix types (#4254)

* fix: add devDependencies

* fix(build): fix generate types definitions
This commit is contained in:
三咲智子 2021-11-06 10:47:03 +08:00 committed by GitHub
parent 3afcb91a14
commit 7f38d3942f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 15 deletions

View File

@ -6,10 +6,9 @@ import glob from 'fast-glob'
import { bold } from 'chalk'
import { green, red, yellow } from './utils/log'
import { buildOutput, pkgRoot, projRoot } from './utils/paths'
import { buildOutput, epRoot, pkgRoot, projRoot } from './utils/paths'
import { excludeFiles, pathRewriter } from './utils/pkg'
import { run } from './utils/process'
import type { SourceFile } from 'ts-morph'
const TSCONFIG_PATH = path.resolve(projRoot, 'tsconfig.json')
@ -37,16 +36,22 @@ export const generateTypesDefinitions = async () => {
})
const filePaths = excludeFiles(
await glob('**/*.{js,ts,vue}', {
await glob(['**/*.{js,ts,vue}', '!element-plus/**/*'], {
cwd: pkgRoot,
absolute: true,
onlyFiles: true,
})
)
const epPaths = excludeFiles(
await glob('**/*.{js,ts,vue}', {
cwd: epRoot,
onlyFiles: true,
})
)
const sourceFiles: SourceFile[] = []
await Promise.all(
filePaths.map(async (file) => {
await Promise.all([
...filePaths.map(async (file) => {
if (file.endsWith('.vue')) {
const content = await fs.readFile(file, 'utf-8')
const sfc = vueCompiler.parse(content)
@ -71,12 +76,18 @@ export const generateTypesDefinitions = async () => {
)
sourceFiles.push(sourceFile)
}
} else if (file.endsWith('.ts')) {
} else {
const sourceFile = project.addSourceFileAtPath(file)
sourceFiles.push(sourceFile)
}
})
)
}),
...epPaths.map(async (file) => {
const content = await fs.readFile(path.resolve(epRoot, file), 'utf-8')
sourceFiles.push(
project.createSourceFile(path.resolve(pkgRoot, file), content)
)
}),
])
const diagnostics = project.getPreEmitDiagnostics()
console.log(project.formatDiagnosticsWithColorAndContext(diagnostics))
@ -115,11 +126,4 @@ export const generateTypesDefinitions = async () => {
})
await Promise.all(tasks)
const epFiles = await glob('**/*', {
cwd: path.resolve(outDir, 'element-plus'),
absolute: true,
})
await run(`mv ${epFiles.join(' ')} ${outDir}`)
await run(`rmdir ${path.resolve(outDir, 'element-plus')}`)
}

View File

@ -55,6 +55,11 @@
"memoize-one": "^6.0.0",
"normalize-wheel-es": "^1.1.0"
},
"devDependencies": {
"@types/node": "*",
"csstype": "^2.6.0",
"vue-router": "^4.0.0"
},
"vetur": {
"tags": "tags.json",
"attributes": "attributes.json"

View File

@ -188,12 +188,15 @@ importers:
specifiers:
'@element-plus/icons': ^0.0.11
'@popperjs/core': ^2.10.2
'@types/node': '*'
'@vueuse/core': ^6.7.3
async-validator: ^4.0.7
csstype: ^2.6.0
dayjs: ^1.10.7
lodash: ^4.17.21
memoize-one: ^6.0.0
normalize-wheel-es: ^1.1.0
vue-router: ^4.0.0
dependencies:
'@element-plus/icons': 0.0.11
'@popperjs/core': 2.10.2
@ -203,6 +206,10 @@ importers:
lodash: 4.17.21
memoize-one: 6.0.0
normalize-wheel-es: 1.1.0
devDependencies:
'@types/node': 16.11.6
csstype: 2.6.18
vue-router: 4.0.12_vue@3.2.21
packages/hooks:
specifiers: {}
@ -1767,6 +1774,10 @@ packages:
resolution: {integrity: sha512-TMgXmy0v2xWyuCSCJM6NCna2snndD8yvQF67J29ipdzMcsPa9u+o0tjF5+EQNdhcuZplYuouYqpc4zcd5I6amQ==}
dev: true
/@types/node/16.11.6:
resolution: {integrity: sha512-ua7PgUoeQFjmWPcoo9khiPum3Pd60k4/2ZGXt18sm2Slk0W0xZTqt5Y0Ny1NyBiN1EVQ/+FaF9NcY4Qe6rwk5w==}
dev: true
/@types/normalize-package-data/2.4.0:
resolution: {integrity: sha512-f5j5b/Gf71L+dbqxIpQ4Z2WlmI/mPJ0fOkGGmFgtb6sAu97EPczzbS3/tJKxmcYDj55OX6ssqwDAWOHIYDRDGA==}
dev: true

View File

@ -5,5 +5,9 @@
matchPaths: ['docs/package.json'],
extends: ['config:js-app'],
},
{
matchPaths: ['packages/element-plus/package.json'],
extends: ['config:base', ':preserveSemverRanges'],
},
],
}