1 Star 0 Fork 0

Vue.js/ecosystem-ci

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
language-tools.ts 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
import path from 'node:path'
import fs from 'node:fs'
import { runInRepo } from '../utils.ts'
import { RunOptions } from '../types.ts'
import { REGISTRY_ADDRESS } from '../registry.ts'
import YAML from 'yaml'
export async function test(options: RunOptions) {
await runInRepo({
...options,
repo: 'vuejs/language-tools',
branch: 'master',
beforeBuild: `pnpm dedupe --registry=${REGISTRY_ADDRESS}`,
build: 'build',
test: 'test',
overrideVueVersion: '@^3.5.2',
patchFiles: {
// Exclude "Auto import" and "#5847" tests which rely on TypeScript's module resolution
// and get polluted by ecosystem-ci's node_modules
'vitest.config.ts': (content) => {
return content.replace(
/test:\s*\{/,
`test: {\n\t\ttestNamePattern: /^(?!Auto import|#5847)/,`,
)
},
'package.json': (content) => {
const pkg = JSON.parse(content)
const versions = resolveTypeScriptVersion(options)
if (versions.typescript)
pkg.devDependencies.typescript = versions.typescript
return JSON.stringify(pkg, null, 2)
},
'test-workspace/package.json': (content) => {
const pkg = JSON.parse(content)
const versions = resolveTypeScriptVersion(options, 'test-workspace', [
'typescript-stable',
'typescript-next',
])
if (versions['typescript-stable'])
pkg.devDependencies['typescript-stable'] =
versions['typescript-stable']
if (versions['typescript-next'])
pkg.devDependencies['typescript-next'] = versions['typescript-next']
return JSON.stringify(pkg, null, 2)
},
},
})
}
function resolveTypeScriptVersion(
options: RunOptions,
importer = '.',
pkgNames = ['typescript'],
): Record<string, string> {
const data = resolveLockFile(options)
if (!data) return {}
return pkgNames.reduce(
(acc, pkgName) => {
const version =
data.importers[importer]?.devDependencies?.[pkgName]?.version
if (version) {
acc[pkgName] = `npm:typescript@~${version.split('@').pop()}`
}
return acc
},
{} as Record<string, string>,
)
}
let lockFileCache: any
function resolveLockFile(options: RunOptions, dirName = 'language-tools'): any {
if (lockFileCache) return lockFileCache
const filePath = path.resolve(options.workspace, dirName, 'pnpm-lock.yaml')
try {
const content = fs.readFileSync(filePath, 'utf-8')
return (lockFileCache = YAML.parse(content))
} catch (error) {
console.error('Error reading lockfile:', error)
return null
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/vuejs/ecosystem-ci.git
git@gitee.com:vuejs/ecosystem-ci.git
vuejs
ecosystem-ci
ecosystem-ci
main

搜索帮助