Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit21d2799

Browse files
committed
cleanup tutorial dependency checks
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent37ed10b commit21d2799

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

‎src/channel/index.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,16 @@ class Channel implements Channel {
9696
awaitthis.context.setTutorial(this.workspaceState,data)
9797

9898
// validate dependencies
99-
if(data.config.dependencies){
100-
for(constdepofdata.config.dependencies){
99+
constdependencies=data.config.dependencies
100+
if(dependencies&&dependencies.length){
101+
for(constdepofdependencies){
101102
// check dependency is installed
102-
constcurrentVersion:string|null=awaitversion(name)
103+
constcurrentVersion:string|null=awaitversion(dep.name)
103104
if(!currentVersion){
104105
// use a custom error message
105106
consterror={
106107
type:'MissingTutorialDependency',
107-
message:dep.message||`Process${name} is required but not found. It may need to be installed`,
108+
message:dep.message||`Process"${dep.name}" is required but not found. It may need to be installed`,
108109
actions:[
109110
{
110111
label:'Check Again',
@@ -117,16 +118,23 @@ class Channel implements Channel {
117118
}
118119

119120
// check dependency version
120-
constsatisfiedDependency=awaitcompareVersions(currentVersion,dep.version).catch((error:Error)=>({
121-
type:'UnmetTutorialDependency',
122-
message:error.message,
123-
actions:[
124-
{
125-
label:'Check Again',
126-
transition:'TRY_AGAIN',
127-
},
128-
],
129-
}))
121+
constsatisfiedDependency=awaitcompareVersions(currentVersion,dep.version)
122+
123+
if(!satisfiedDependency){
124+
consterror={
125+
type:'UnmetTutorialDependency',
126+
message:`Expected${dep.name} to have version${dep.version}, but found version${currentVersion}`,
127+
actions:[
128+
{
129+
label:'Check Again',
130+
transition:'TRY_AGAIN',
131+
},
132+
],
133+
}
134+
this.send({type:'TUTORIAL_CONFIGURE_FAIL',payload:{ error}})
135+
return
136+
}
137+
130138
if(satisfiedDependency!==true){
131139
consterror=satisfiedDependency||{
132140
type:'UnknownError',
@@ -247,7 +255,7 @@ class Channel implements Channel {
247255

248256
if(errorMarkdown){
249257
// add a clearer error message for the user
250-
error.message=`${errorMarkdown}\n${error.message}`
258+
error.message=`${errorMarkdown}\n\n${error.message}`
251259
}
252260
}
253261

‎src/services/dependencies/index.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
1-
import*asTTfrom'typings/tutorial'
21
import{satisfies}from'semver'
32
importnodefrom'../node'
43

54
constsemverRegex=/(?<=^v?|\sv?)(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*)(?:\.(?:0|[1-9]\d*|[\da-z-]*[a-z-][\da-z-]*))*)?(?:\+[\da-z-]+(?:\.[\da-z-]+)*)?(?=$|\s)/gi
65

76
exportconstversion=async(name:string):Promise<string|null>=>{
8-
const{ stdout, stderr}=awaitnode.exec(`${name} --version`)
9-
if(!stderr){
10-
constmatch=stdout.match(semverRegex)
11-
if(match){
12-
returnmatch[0]
7+
try{
8+
const{ stdout, stderr}=awaitnode.exec(`${name} --version`)
9+
if(!stderr){
10+
constmatch=stdout.match(semverRegex)
11+
if(match){
12+
returnmatch[0]
13+
}
1314
}
15+
returnnull
16+
}catch(error){
17+
returnnull
1418
}
15-
returnnull
1619
}
1720

1821
exportconstcompareVersions=async(currentVersion:string,expectedVersion:string):Promise<never|boolean>=>{
1922
// see node-semver docs: https://github.com/npm/node-semver
20-
constsatisfied:boolean=satisfies(currentVersion,expectedVersion)
21-
if(!satisfied){
22-
thrownewError(`Expected${name} to have version${expectedVersion}, but found version${currentVersion}`)
23-
}
24-
returntrue
23+
returnsatisfies(currentVersion,expectedVersion)
2524
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp