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

Validate tutorial dependencies#245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ShMcK merged 6 commits intomasterfromfeature/validate-tutorial-deps
Apr 11, 2020
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletionserrors/MissingTutorialDependency.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
### Missing Tutorial Dependency

The tutorial cannot run because it a dependency is not yet installed. Install the dependency and click "Check Again".
5 changes: 5 additions & 0 deletionserrors/UnmetTutorialDependency.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
### Unmet Tutorial Dependency

### Unmet Tutorial Dependency

Tutorial cannot reun because a dependency version doesn't match. Install the correct dependency and click "Check Again".
32 changes: 29 additions & 3 deletionspackage-lock.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

2 changes: 2 additions & 0 deletionspackage.json
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,6 +39,7 @@
"@types/jest": "^25.2.1",
"@types/jsdom": "^16.2.0",
"@types/node": "^13.11.0",
"@types/semver": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^2.26.0",
"@typescript-eslint/parser": "^2.26.0",
"chokidar": "^3.3.0",
Expand All@@ -49,6 +50,7 @@
"jest": "^25.2.7",
"jsdom": "^16.2.2",
"prettier": "^2.0.2",
"semver": "^7.2.2",
"ts-jest": "^25.3.1",
"typescript": "^3.8.3"
},
Expand Down
64 changes: 61 additions & 3 deletionssrc/channel/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -9,11 +9,12 @@ import tutorialConfig from '../actions/tutorialConfig'
import { COMMANDS } from '../editor/commands'
import logger from '../services/logger'
import Context from './context'
import { version as gitVersion} from '../services/git'
import { version, compareVersions} from '../services/dependencies'
import { openWorkspace, checkWorkspaceEmpty } from '../services/workspace'
import { readFile } from 'fs'
import { join } from 'path'
import { promisify } from 'util'
import { compare } from 'semver'

const readFileAsync = promisify(readFile)

Expand DownExpand Up@@ -94,6 +95,63 @@ class Channel implements Channel {
// setup tutorial config (save watcher, test runner, etc)
await this.context.setTutorial(this.workspaceState, data)

// validate dependencies
const dependencies = data.config.dependencies
if (dependencies && dependencies.length) {
for (const dep of dependencies) {
// check dependency is installed
const currentVersion: string | null = await version(dep.name)
if (!currentVersion) {
// use a custom error message
const error = {
type: 'MissingTutorialDependency',
message: dep.message || `Process "${dep.name}" is required but not found. It may need to be installed`,
actions: [
{
label: 'Check Again',
transition: 'TRY_AGAIN',
},
],
}
this.send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } })
return
}

// check dependency version
const satisfiedDependency = await compareVersions(currentVersion, dep.version)

if (!satisfiedDependency) {
const error = {
type: 'UnmetTutorialDependency',
message: `Expected ${dep.name} to have version ${dep.version}, but found version ${currentVersion}`,
actions: [
{
label: 'Check Again',
transition: 'TRY_AGAIN',
},
],
}
this.send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } })
return
}

if (satisfiedDependency !== true) {
const error = satisfiedDependency || {
type: 'UnknownError',
message: `Something went wrong comparing dependency for ${name}`,
actions: [
{
label: 'Try Again',
transition: 'TRY_AGAIN',
},
],
}
this.send({ type: 'TUTORIAL_CONFIGURE_FAIL', payload: { error } })
return
}
}
}

const error: E.ErrorMessage | void = await tutorialConfig({ config: data.config }).catch((error: Error) => ({
type: 'UnknownError',
message: `Location: tutorial config.\n\n${error.message}`,
Expand DownExpand Up@@ -144,7 +202,7 @@ class Channel implements Channel {
}
// 2. check Git is installed.
// Should wait for workspace before running otherwise requires access to root folder
const isGitInstalled = awaitgitVersion()
const isGitInstalled = awaitversion('git')
if (!isGitInstalled) {
const error: E.ErrorMessage = {
type: 'GitNotFound',
Expand DownExpand Up@@ -197,7 +255,7 @@ class Channel implements Channel {

if (errorMarkdown) {
// add a clearer error message for the user
error.message = `${errorMarkdown}\n${error.message}`
error.message = `${errorMarkdown}\n\n${error.message}`
}
}

Expand Down
24 changes: 24 additions & 0 deletionssrc/services/dependencies/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
import { satisfies } from 'semver'
import node from '../node'

const semverRegex = /(?<=^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

export const version = async (name: string): Promise<string | null> => {
try {
const { stdout, stderr } = await node.exec(`${name} --version`)
if (!stderr) {
const match = stdout.match(semverRegex)
if (match) {
return match[0]
}
}
return null
} catch (error) {
return null
}
}

export const compareVersions = async (currentVersion: string, expectedVersion: string): Promise<never | boolean> => {
// see node-semver docs: https://github.com/npm/node-semver
return satisfies(currentVersion, expectedVersion)
}
13 changes: 0 additions & 13 deletionssrc/services/git/index.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -69,19 +69,6 @@ export async function clear(): Promise<Error | void> {
throw new Error('Error cleaning up current unsaved work')
}

export async function version(): Promise<string | null> {
const { stdout, stderr } = await node.exec('git --version')
if (!stderr) {
const match = stdout.match(/^git version (\d+\.)?(\d+\.)?(\*|\d+)/)
if (match) {
// eslint-disable-next-line
const [_, major, minor, patch] = match
return `${major}${minor}${patch}`
}
}
return null
}

async function init(): Promise<Error | void> {
const { stderr } = await node.exec('git init')
if (stderr) {
Expand Down
7 changes: 7 additions & 0 deletionstypings/tutorial.d.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ export type Maybe<T> = T | null
export type TutorialConfig = {
testRunner: TutorialTestRunner
repo: TutorialRepo
dependencies?: TutorialDependency[]
}

/** Logical groupings of tasks */
Expand DownExpand Up@@ -57,3 +58,9 @@ export interface TutorialRepo {
uri: string
branch: string
}

export interface TutorialDependency {
name: string
version: string
message?: string
}

[8]ページ先頭

©2009-2025 Movatter.jp