Skip to content

Commit 81c04cb

Browse files
fix(1.7.1): prevent fail-fast on version check (#170)
* patch(1.7.1): prevent fail-fast on version check * feat: improve error messages
1 parent 96c9a5e commit 81c04cb

File tree

6 files changed

+80
-32
lines changed

6 files changed

+80
-32
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
88

99
## [Released]
1010

11+
##[1.7.1])(#v1.7.1) (2022-11-07)
12+
13+
### Fixed
14+
15+
- `freeCodeCamp: Run Course` checks for new version of curriculum from `raw.githubusercontent.com`. Prevent fail-fast if fetch fails.
16+
1117
##[1.7.0](#v1.7.0) (2022-10-24)
1218

1319
### Added

package-lock.json

+18-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "freecodecamp-courses",
33
"displayName": "freeCodeCamp - Courses",
44
"description": "Provides tooling for quick and easy selection of courses offered by freeCodeCamp",
5-
"version": "1.7.0",
5+
"version": "1.7.1",
66
"author": "freeCodeCamp",
77
"publisher": "freeCodeCamp",
88
"galleryBanner": {
@@ -11,7 +11,7 @@
1111
},
1212
"icon": "images/logo-128X128.png",
1313
"engines": {
14-
"vscode": "^1.72.0",
14+
"vscode": "^1.73.0",
1515
"node": ">=18.0.0"
1616
},
1717
"categories": [
@@ -83,7 +83,7 @@
8383
"@types/glob": "7.2.0",
8484
"@types/mocha": "9.1.1",
8585
"@types/node": "18.11.9",
86-
"@types/vscode": "1.72.0",
86+
"@types/vscode": "1.73.0",
8787
"@typescript-eslint/eslint-plugin": "5.42.0",
8888
"@typescript-eslint/parser": "5.42.0",
8989
"@vscode/test-electron": "2.2.0",
@@ -92,7 +92,7 @@
9292
"mocha": "9.2.2",
9393
"ts-loader": "9.4.1",
9494
"typescript": "4.8.4",
95-
"vsce": "2.13.0",
95+
"vsce": "2.14.0",
9696
"webpack": "5.74.0",
9797
"webpack-cli": "4.10.0"
9898
},
@@ -105,6 +105,6 @@
105105
"url": "https://github.com/freeCodeCamp/courses-vscode-extension/issues"
106106
},
107107
"dependencies": {
108-
"node-fetch": "^3.2.10"
108+
"node-fetch": "3.2.10"
109109
}
110110
}

src/commands/develop-course.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
import { handleConfig } from "../handles";
22
import { handleMessage } from "../flash";
33
import { FlashTypes } from "../typings";
4-
import { getConfig } from "../usefuls";
4+
import { getConfig, getPackageJson } from "../usefuls";
5+
import { checkForCourseUpdates } from "../updates";
56

67
export default async function developCourse() {
78
try {
89
const config = await getConfig();
10+
const rootPackage = await getPackageJson();
11+
const githubLink = rootPackage.repository.url;
12+
const isCourseUpdates = await checkForCourseUpdates(githubLink, config);
13+
if (isCourseUpdates) {
14+
handleMessage({
15+
message:
16+
"This course has been updated. It is recommended you re-clone the repository.",
17+
type: FlashTypes.WARNING,
18+
});
19+
}
920
handleConfig(config, "develop-course");
1021
} catch (e) {
1122
console.error("freeCodeCamp > runCourse: ", e);
1223
return handleMessage({
13-
message: "Unable to find a `freecodecamp.conf.json` file in workspace.",
24+
message: "Unable to develop course. See dev console for more details.",
1425
type: FlashTypes.ERROR,
1526
});
1627
}

src/commands/run-course.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default async function runCourse() {
2121
} catch (e) {
2222
console.error("freeCodeCamp > runCourse: ", e);
2323
return handleMessage({
24-
message: "Unable to find a `freecodecamp.conf.json` file in workspace.",
24+
message: "Unable to run course. See dev console for more details.",
2525
type: FlashTypes.ERROR,
2626
});
2727
}

src/updates.ts

+37-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
import { join } from "path";
22
import fetch from "node-fetch";
3-
import { Config } from "./typings";
3+
import { Config, FlashTypes } from "./typings";
4+
import { handleMessage } from "./flash";
45

56
export async function checkForCourseUpdates(
67
githubLink: string,
78
config: Config
89
): Promise<boolean> {
910
const currentVersion = config.version;
11+
if (!currentVersion) {
12+
handleMessage({
13+
message:
14+
"Unable to find curriculum version from `freecodecamp.conf.json` file",
15+
type: FlashTypes.WARNING,
16+
});
17+
return false;
18+
}
19+
1020
const repoConfig = await getConfigFromGitHub(githubLink);
21+
if (!repoConfig) {
22+
return false;
23+
}
24+
1125
const repoVersion = repoConfig.version;
12-
if (!repoVersion || currentVersion) {
13-
console.error("Unable to get curriculum version for: ", githubLink);
26+
if (!repoVersion) {
27+
handleMessage({
28+
message: "Unable to get curriculum version from upstream",
29+
type: FlashTypes.WARNING,
30+
});
1431
return false;
1532
}
33+
1634
const [currMajor, currMinor, currPatch] = semVer(currentVersion);
1735
const [repoMajor, repoMinor, repoPatch] = semVer(repoVersion);
1836
return (
@@ -34,9 +52,22 @@ function semVer(version: string) {
3452
async function getConfigFromGitHub(githubLink: string) {
3553
// Example: https://raw.githubusercontent.com/freeCodeCamp/web3-curriculum/main/freecodecamp.conf.json
3654
const url = githubLinkToURL(githubLink);
37-
const res = await fetch(url.href);
38-
const config = (await res.json()) as Config;
39-
return config;
55+
try {
56+
const res = await fetch(url.href);
57+
const config = (await res.json()) as Config;
58+
return config;
59+
} catch (e) {
60+
console.error(e);
61+
handleMessage({
62+
message: `Unable to check for latest curriculum version: ${url.href}`,
63+
type: FlashTypes.WARNING,
64+
opts: {
65+
detail:
66+
"You might be running a version of the curriculum that does not have bug fixes or new features.",
67+
},
68+
});
69+
}
70+
return null;
4071
}
4172

4273
function githubLinkToURL(githubLink: string) {

0 commit comments

Comments
 (0)