Skip to content

Commit c7aeeec

Browse files
committed
validate extension version
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent ae956d0 commit c7aeeec

7 files changed

+46
-12
lines changed

Diff for: errors/GitProjectAlreadyExists.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
### Git Project Already Exists
1+
### Git Remote Already Exists
22

3-
CodeRoad requires an empty Git project.
3+
Have you started this tutorial before in this workspace? The Git remote already exists.
44

5-
Open a new workspace to start a tutorial.
5+
Consider deleting your `.git` folder and restarting.

Diff for: errors/GitRemoteAlreadyExists.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
### Git Project Already Exists
2+
3+
CodeRoad requires an empty Git project.
4+
5+
Open a new workspace to start a tutorial.

Diff for: errors/UnmetExtensionVersion.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Unmet Tutorial Dependency
2+
3+
This tutorial requires a different version of CodeRoad.

Diff for: errors/UnmetTutorialDependency.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
### Unmet Tutorial Dependency
22

3-
### Unmet Tutorial Dependency
4-
53
Tutorial cannot reun because a dependency version doesn't match. Install the correct dependency and click "Check Again".

Diff for: src/channel/index.ts

+23-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as T from 'typings'
22
import * as TT from 'typings/tutorial'
33
import * as E from 'typings/error'
44
import * as vscode from 'vscode'
5+
import { satisfies } from 'semver'
56
import saveCommit from '../actions/saveCommit'
67
import setupActions from '../actions/setupActions'
78
import solutionActions from '../actions/solutionActions'
@@ -110,6 +111,25 @@ class Channel implements Channel {
110111
case 'EDITOR_TUTORIAL_CONFIG':
111112
try {
112113
const data: TT.Tutorial = action.payload.tutorial
114+
115+
// validate extension version
116+
const expectedAppVersion = data.config?.appVersions?.coderoadVSCode
117+
if (expectedAppVersion) {
118+
const extension = vscode.extensions.getExtension('coderoad.coderoad')
119+
if (extension) {
120+
const currentAppVersion = extension.packageJSON.version
121+
const satisfied = satisfies(currentAppVersion, expectedAppVersion)
122+
if (!satisfied) {
123+
const error: E.ErrorMessage = {
124+
type: 'UnmetExtensionVersion',
125+
message: `Expected CodeRoad v${expectedAppVersion}, but found ${currentAppVersion}`,
126+
}
127+
this.send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } })
128+
return
129+
}
130+
}
131+
}
132+
113133
// setup tutorial config (save watcher, test runner, etc)
114134
await this.context.setTutorial(this.workspaceState, data)
115135

@@ -121,7 +141,7 @@ class Channel implements Channel {
121141
const currentVersion: string | null = await version(dep.name)
122142
if (!currentVersion) {
123143
// use a custom error message
124-
const error = {
144+
const error: E.ErrorMessage = {
125145
type: 'MissingTutorialDependency',
126146
message:
127147
dep.message || `Process "${dep.name}" is required but not found. It may need to be installed`,
@@ -140,7 +160,7 @@ class Channel implements Channel {
140160
const satisfiedDependency = await compareVersions(currentVersion, dep.version)
141161

142162
if (!satisfiedDependency) {
143-
const error = {
163+
const error: E.ErrorMessage = {
144164
type: 'UnmetTutorialDependency',
145165
message: `Expected ${dep.name} to have version ${dep.version}, but found version ${currentVersion}`,
146166
actions: [
@@ -155,7 +175,7 @@ class Channel implements Channel {
155175
}
156176

157177
if (satisfiedDependency !== true) {
158-
const error = satisfiedDependency || {
178+
const error: E.ErrorMessage = satisfiedDependency || {
159179
type: 'UnknownError',
160180
message: `Something went wrong comparing dependency for ${name}`,
161181
actions: [

Diff for: typings/error.d.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
export type ErrorMessageView = 'FULL_PAGE' | 'NOTIFY' | 'NONE'
22

33
export type ErrorMessageType =
4-
| 'UnknownError'
5-
| 'NoWorkspaceFound'
6-
| 'GitNotFound'
7-
| 'WorkspaceNotEmpty'
84
| 'FailedToConnectToGitRepo'
5+
| 'GitNotFound'
96
| 'GitProjectAlreadyExists'
107
| 'GitRemoteAlreadyExists'
8+
| 'MissingTutorialDependency'
9+
| 'NoWorkspaceFound'
10+
| 'UnknownError'
11+
| 'UnmetExtensionVersion'
12+
| 'UnmetTutorialDependency'
13+
| 'WorkspaceNotEmpty'
1114

1215
export type ErrorAction = {
1316
label: string

Diff for: typings/tutorial.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type Maybe<T> = T | null
22

33
export type TutorialConfig = {
4+
appVersions: TutorialAppVersions
45
testRunner: TutorialTestRunner
56
repo: TutorialRepo
67
dependencies?: TutorialDependency[]
@@ -64,3 +65,7 @@ export interface TutorialDependency {
6465
version: string
6566
message?: string
6667
}
68+
69+
export interface TutorialAppVersions {
70+
coderoadVSCode: string
71+
}

0 commit comments

Comments
 (0)