-
-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2066 from vuejs/ver-specific-eslint
Vue 2/3 eslint rules. Fix #2015
- Loading branch information
Showing
20 changed files
with
435 additions
and
262 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import * as path from 'path'; | ||
import { T_TypeScript } from '../dependencyService'; | ||
|
||
export enum VueVersion { | ||
VPre25, | ||
V25, | ||
V30 | ||
} | ||
|
||
function floatVersionToEnum(v: number) { | ||
if (v < 2.5) { | ||
return VueVersion.VPre25; | ||
} else if (v < 3.0) { | ||
return VueVersion.V25; | ||
} else { | ||
return VueVersion.V30; | ||
} | ||
} | ||
|
||
export function inferVueVersion(tsModule: T_TypeScript, workspacePath: string): VueVersion { | ||
const packageJSONPath = tsModule.findConfigFile(workspacePath, tsModule.sys.fileExists, 'package.json'); | ||
try { | ||
const packageJSON = packageJSONPath && JSON.parse(tsModule.sys.readFile(packageJSONPath)!); | ||
const vueDependencyVersion = packageJSON.dependencies.vue || packageJSON.devDependencies.vue; | ||
|
||
if (vueDependencyVersion) { | ||
// use a sloppy method to infer version, to reduce dep on semver or so | ||
const vueDep = vueDependencyVersion.match(/\d+\.\d+/)[0]; | ||
const sloppyVersion = parseFloat(vueDep); | ||
return floatVersionToEnum(sloppyVersion); | ||
} | ||
|
||
const nodeModulesVuePackagePath = tsModule.findConfigFile( | ||
path.resolve(workspacePath, 'node_modules/vue'), | ||
tsModule.sys.fileExists, | ||
'package.json' | ||
); | ||
const nodeModulesVuePackageJSON = | ||
nodeModulesVuePackagePath && JSON.parse(tsModule.sys.readFile(nodeModulesVuePackagePath)!); | ||
const nodeModulesVueVersion = parseFloat(nodeModulesVuePackageJSON.version.match(/\d+\.\d+/)[0]); | ||
|
||
return floatVersionToEnum(nodeModulesVueVersion); | ||
} catch (e) { | ||
return VueVersion.VPre25; | ||
} | ||
} |
Oops, something went wrong.