File tree Expand file tree Collapse file tree 4 files changed +56
-4
lines changed
src/services/dependencies Expand file tree Collapse file tree 4 files changed +56
-4
lines changed Original file line number Diff line number Diff line change 3939 "@types/jest" : " ^25.2.1" ,
4040 "@types/jsdom" : " ^16.2.0" ,
4141 "@types/node" : " ^13.11.0" ,
42+ "@types/semver" : " ^7.1.0" ,
4243 "@typescript-eslint/eslint-plugin" : " ^2.26.0" ,
4344 "@typescript-eslint/parser" : " ^2.26.0" ,
4445 "chokidar" : " ^3.3.0" ,
4950 "jest" : " ^25.2.7" ,
5051 "jsdom" : " ^16.2.2" ,
5152 "prettier" : " ^2.0.2" ,
53+ "semver" : " ^7.2.2" ,
5254 "ts-jest" : " ^25.3.1" ,
5355 "typescript" : " ^3.8.3"
5456 },
Original file line number Diff line number Diff line change 1+ import * as TT from 'typings/tutorial'
2+ import { satisfies } from 'semver'
13import node from '../node'
24
35const semverRegex = / (?< = ^ v ? | \s v ? ) (?: 0 | [ 1 - 9 ] \d * ) \. (?: 0 | [ 1 - 9 ] \d * ) \. (?: 0 | [ 1 - 9 ] \d * ) (?: - (?: 0 | [ 1 - 9 ] \d * | [ \d a - z - ] * [ a - z - ] [ \d a - z - ] * ) (?: \. (?: 0 | [ 1 - 9 ] \d * | [ \d a - z - ] * [ a - z - ] [ \d a - z - ] * ) ) * ) ? (?: \+ [ \d a - z - ] + (?: \. [ \d a - z - ] + ) * ) ? (? = $ | \s ) / gi
46
5- export const getVersion = async ( name : string ) : Promise < string | null > => {
7+ export const version = async ( name : string ) : Promise < string | null > => {
68 const { stdout, stderr } = await node . exec ( `${ name } --version` )
79 if ( ! stderr ) {
810 const match = stdout . match ( semverRegex )
@@ -12,3 +14,24 @@ export const getVersion = async (name: string): Promise<string | null> => {
1214 }
1315 return null
1416}
17+
18+ export const compareVersions = async ( {
19+ name,
20+ version : expectedVersion ,
21+ message,
22+ } : TT . TutorialDependency ) : Promise < boolean > => {
23+ const currentVersion = await version ( name )
24+ if ( ! currentVersion ) {
25+ // use a custom error message
26+ if ( message ) {
27+ throw new Error ( message )
28+ }
29+ throw new Error ( `Process ${ name } is required but not found. It may need to be installed` )
30+ }
31+ // see node-semver docs: https://github.com/npm/node-semver
32+ const satisfied : boolean = satisfies ( currentVersion , expectedVersion )
33+ if ( ! satisfied ) {
34+ throw new Error ( `Expected ${ name } to have version ${ expectedVersion } , but found version ${ currentVersion } ` )
35+ }
36+ return true
37+ }
Original file line number Diff line number Diff line change @@ -62,4 +62,5 @@ export interface TutorialRepo {
6262export interface TutorialDependency {
6363 name : string
6464 version : string
65+ message ?: string
6566}
You can’t perform that action at this time.
0 commit comments