Skip to content

Commit

Permalink
fix: do not modify the version of @vue/compiler-sfc if it exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Chieffo2021 committed Jan 20, 2022
1 parent df214e0 commit 97ce233
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/generate/genePackageJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import chalk from 'chalk'
import * as constants from '../constants/constants'
import { recordConver } from '../utils/report'
import { minVersion, gt } from 'semver'
import { AstParsingResult } from '../ast-parse/astParse'
import type { AstParsingResult } from '../ast-parse/astParse'

// TODO: compatible with vue2 and vue3
export function genePackageJson (packageJsonPath: string, astParsingResult?: AstParsingResult): void {
Expand All @@ -24,7 +24,9 @@ export function genePackageJson (packageJsonPath: string, astParsingResult?: Ast

const vueVersion = getVueVersion(rootDir)
if (vueVersion === 3) {
packageJson.devDependencies['@vue/compiler-sfc'] = constants.VUE_COMPILER_SFC_VERSION
if (!packageJson.devDependencies['@vue/compiler-sfc']) {
packageJson.devDependencies['@vue/compiler-sfc'] = constants.VUE_COMPILER_SFC_VERSION
}
packageJson.devDependencies['@vitejs/plugin-vue'] = constants.VITE_PLUGIN_VUE_VERSION
packageJson.devDependencies['@vitejs/plugin-vue-jsx'] = constants.VITE_PLUGIN_VUE_JSX_VERSION
} else if (vueVersion === 2) {
Expand Down
2 changes: 1 addition & 1 deletion tests/genePackageJson.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('genePackageJson', () => {
const packageJsonContent = JSON.parse(readSync(packageJsonPath))
expect(packageJsonContent.devDependencies).toBe(
expect.objectContaining({
'@vue/compiler-sfc': expect.any(String),
'@vue/compiler-sfc': "^3.0.0",
'@vitejs/plugin-vue': expect.any(String),
'@vitejs/plugin-vue-jsx': expect.any(String)
})
Expand Down

0 comments on commit 97ce233

Please sign in to comment.