Skip to content

Commit 3e4bef2

Browse files
authored
Remove axios dependency from extension client (#333)
Closes #332 * Refactor code structure for improved readability and maintainability * Add pretest-compile script to package.json for dependency installation * Replace axios with native fetch API (#332) * Add Jest test suite (jest, ts-jest, jest-fetch-mock) with 18 tests covering all modified HTTP code paths * Bump minimum VS Code engine requirement to ^1.76.0 * Fix TS2322: wrap iconPath strings with Uri.file() * test(vscode-mock): add `Uri.file` to `client/__mocks__/vscode.ts` * chore(vscode): configure Jest and prevent auto-opening test results * test(Utils): update comment to remove axios-specific reference * fix(HoverProvider): initialize knownItems and preserve array on error * refactor(hover): remove unused singleton field * Temporarily skip failing serverJS ItemCompletion start/event tests (tracked in #335) * Document npm usage: add test scripts and dev:help helper * fix(things-explorer): clarify error message when reloading things * refactor(eslint): consolidate ESLint config into single .eslintrc.cjs file * chore: improve VS Code launch and task configuration clarity * chore(workspace): remove tumido.cron-explained from recommended extensions * fix(tests+utils): replace async/await with promise chains to satisfy lint rule --------- Signed-off-by: Patrik Gfeller <patrik.gfeller@proton.me>
1 parent f9a4e78 commit 3e4bef2

33 files changed

Lines changed: 7582 additions & 1260 deletions

.eslintrc.cjs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
node: true
5+
},
6+
extends: [
7+
'prettier',
8+
'prettier/@typescript-eslint'
9+
],
10+
parser: '@typescript-eslint/parser',
11+
parserOptions: {
12+
sourceType: 'module'
13+
},
14+
plugins: ['@typescript-eslint'],
15+
rules: {
16+
'no-restricted-syntax': [
17+
'warn',
18+
{
19+
selector: 'AwaitExpression',
20+
message: 'Use Promise chains (.then/.catch) instead of async/await'
21+
}
22+
],
23+
// Disabled due to existing violations. See issue #334
24+
curly: 'off',
25+
eqeqeq: 'off',
26+
'no-redeclare': 'error'
27+
},
28+
overrides: [
29+
{
30+
files: ['**/*.ts', '**/*.tsx'],
31+
parserOptions: {
32+
project: ['tsconfig.json', 'client/tsconfig.json', 'client/tsconfig.test.json'],
33+
tsconfigRootDir: __dirname
34+
},
35+
rules: {
36+
'@typescript-eslint/member-delimiter-style': [
37+
'off',
38+
{
39+
multiline: { delimiter: 'none', requireLast: true },
40+
singleline: { delimiter: 'semi', requireLast: false }
41+
}
42+
],
43+
// Disabled due to existing violations. See issue #334
44+
'@typescript-eslint/naming-convention': 'off',
45+
'@typescript-eslint/no-unused-expressions': 'error',
46+
'@typescript-eslint/semi': ['off', null]
47+
}
48+
}
49+
]
50+
};

.eslintrc.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,4 @@ $RECYCLE.BIN/
184184
*.lnk
185185

186186
# End of https://www.gitignore.io/api/node,linux,macos,windows,visualstudiocode
187+

.vscode/extensions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
"dbaeumer.vscode-eslint",
44
"esbenp.prettier-vscode",
55
"max-beckenbauer.oh-alignment-tool",
6-
"tumido.cron-explained"
6+
"orta.vscode-jest"
77
]
88
}

.vscode/launch.json

Lines changed: 53 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
// A launch configuration that compiles the extension and then opens it inside a new window
21
{
32
"version": "0.2.0",
43
"configurations": [
54
{
6-
"name": "Launch Extension",
7-
"type": "extensionHost",
5+
"name": "Jest Tests (Client)",
6+
"type": "node",
87
"request": "launch",
9-
"runtimeExecutable": "${execPath}",
10-
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11-
"stopOnEntry": false,
12-
"sourceMaps": true,
13-
"outFiles": [
14-
"${workspaceRoot}/client/out/**/*.js",
15-
"${workspaceRoot}/serverJS/out/**/*.js"
8+
"cwd": "${workspaceFolder}/client",
9+
"program": "${workspaceFolder}/client/node_modules/jest/bin/jest.js",
10+
"args": [
11+
"--runInBand",
12+
"--testPathPattern",
13+
"${jest.testFilePattern}"
1614
],
17-
"preLaunchTask": "npm: watch"
15+
"console": "integratedTerminal",
16+
"internalConsoleOptions": "neverOpen"
1817
},
1918
{
20-
"name": "Launch Tests",
21-
"type": "extensionHost",
19+
"name": "Jest Tests (Server)",
20+
"type": "node",
2221
"request": "launch",
23-
"runtimeExecutable": "${execPath}",
24-
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
25-
"stopOnEntry": false,
26-
"sourceMaps": true,
27-
"outFiles": [ "${workspaceRoot}/client/out/test/**/*.js" ],
28-
"preLaunchTask": "npm"
22+
"cwd": "${workspaceFolder}/serverJS",
23+
"program": "${workspaceFolder}/serverJS/node_modules/jest/bin/jest.js",
24+
"args": [
25+
"--runInBand",
26+
"--testPathPattern",
27+
"${jest.testFilePattern}"
28+
],
29+
"console": "integratedTerminal",
30+
"internalConsoleOptions": "neverOpen"
2931
},
3032
{
33+
"name": "Jest Tests (LSP Server)",
3134
"type": "node",
32-
"name": "lsp-server-jest-tests",
3335
"request": "launch",
3436
"program": "${workspaceFolder}/serverJS/node_modules/jest/bin/jest",
3537
"args": [
@@ -39,6 +41,36 @@
3941
"cwd": "${workspaceFolder}/serverJS",
4042
"console": "integratedTerminal",
4143
"internalConsoleOptions": "neverOpen"
44+
},
45+
{
46+
"name": "Launch Extension (Development)",
47+
"type": "extensionHost",
48+
"request": "launch",
49+
"runtimeExecutable": "${execPath}",
50+
"args": [
51+
"--extensionDevelopmentPath=${workspaceRoot}"
52+
],
53+
"sourceMaps": true,
54+
"outFiles": [
55+
"${workspaceRoot}/client/out/**/*.js",
56+
"${workspaceRoot}/serverJS/out/**/*.js"
57+
],
58+
"preLaunchTask": "npm: watch"
59+
},
60+
{
61+
"name": "Launch Extension with Tests",
62+
"type": "extensionHost",
63+
"request": "launch",
64+
"runtimeExecutable": "${execPath}",
65+
"args": [
66+
"--extensionDevelopmentPath=${workspaceRoot}",
67+
"--extensionTestsPath=${workspaceRoot}/out/test"
68+
],
69+
"sourceMaps": true,
70+
"outFiles": [
71+
"${workspaceRoot}/client/out/test/**/*.js"
72+
],
73+
"preLaunchTask": "npm"
4274
}
4375
]
44-
}
76+
}

.vscode/settings.json

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1-
// Place your settings in this file to overwrite default and user settings.
21
{
3-
"files.exclude": {
4-
"out": false // set this to true to hide the "out" folder with the compiled JS files
2+
"jest.runMode": {
3+
"type": "on-demand",
4+
"deferred": true
55
},
6-
"search.exclude": {
7-
"out": true // set this to false to include "out" folder in search results
8-
}
6+
"jest.jestCommandLine": "npm test --",
7+
"jest.outputConfig": "terminal-based",
8+
"testing.automaticallyOpenTestResults": "neverOpen",
9+
"jest.monitorLongRun": 120000,
10+
"jest.coverageFormatter": "DefaultFormatter",
11+
"jest.coverageColors": {
12+
"uncovered": "rgba(255,99,71,0.15)",
13+
"partially-covered": "rgba(255,215,0,0.15)",
14+
"covered": "rgba(0,200,0,0.12)"
15+
},
16+
"jest.virtualFolders": [
17+
{
18+
"name": "client",
19+
"rootPath": "client",
20+
"jestCommandLine": "npm test --",
21+
"runMode": "watch"
22+
},
23+
{
24+
"name": "serverJS",
25+
"rootPath": "serverJS",
26+
"jestCommandLine": "npm run test-unit --",
27+
"runMode": "on-demand"
28+
}
29+
]
930
}

.vscode/tasks.json

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,43 @@
55
// ${fileDirname}: the current opened file's dirname
66
// ${fileExtname}: the current opened file's extension
77
// ${cwd}: the current working directory of the spawned process
8-
98
// A task runner that calls a custom npm script that compiles the extension.
109
{
1110
"version": "2.0.0",
12-
1311
"tasks": [
1412
{
15-
"label": "npm",
13+
"label": "npm watch (shell)",
1614
"type": "shell",
1715
"command": "npm",
18-
"args": ["run", "watch"], //custom script "watch" as defined in package.json
16+
"args": [
17+
"run",
18+
"watch"
19+
], //custom script "watch" as defined in package.json
1920
"presentation": {
2021
"echo": false,
21-
"reveal":"silent",
22+
"reveal": "silent",
2223
"focus": false,
2324
"panel": "shared",
2425
"clear": false
2526
},
2627
"isBackground": true, // tsc compiler is started in watching mode
27-
"problemMatcher": ["$tsc-watch"]
28+
"problemMatcher": [
29+
"$tsc-watch"
30+
]
2831
},
2932
{
30-
"type": "npm",
31-
"script": "watch",
32-
"problemMatcher": "$tsc-watch",
33-
"isBackground": true,
34-
"presentation": {
35-
"reveal": "never"
36-
},
37-
"group": {
38-
"kind": "build",
39-
"isDefault": true
40-
}
41-
}
42-
33+
"label": "npm watch (default)",
34+
"type": "npm",
35+
"script": "watch",
36+
"problemMatcher": "$tsc-watch",
37+
"isBackground": true,
38+
"presentation": {
39+
"reveal": "never"
40+
},
41+
"group": {
42+
"kind": "build",
43+
"isDefault": true
44+
}
45+
}
4346
]
44-
}
47+
}

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
- Update GitHub Actions (actions/checkout, actions/setup-node, actions/stale) to latest maintained versions
1212
- Add preinstall script for Node version validation and Volta configuration
1313
- Add Volta pinning to package.json for consistent development environment
14-
- Update dependencies: axios (0.21.2 → 1.6.0), TypeScript (3.9.7 → 4.9.5), ts-loader (6.2.2 → 9.5.0), webpack-cli (3.3.12 → 4.10.0)
14+
- Update dependencies: TypeScript (3.9.7 → 4.9.5), ts-loader (6.2.2 → 9.5.0), webpack-cli (3.3.12 → 4.10.0)
1515
- Update type definitions: @types/lodash (4.14.167 → 4.14.195), @types/node (8.10.66 → 20.0.0)
16+
- Replace axios with native fetch API for all REST calls (#332)
17+
- Bump minimum VS Code engine requirement to ^1.76.0 (required for native fetch support)
18+
- Add Jest test suite for client-side HTTP code (jest, ts-jest, jest-fetch-mock)
1619

1720
### Fixed
1821

@@ -21,7 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2124

2225
### Security
2326

24-
- Remove deprecated request library, use axios instead
27+
- Remove axios dependency, use native fetch API instead (#332)
2528
- Update GitHub Actions versions to receive security patches
2629

2730
## [1.0.0] - 2021-04-12

client/__mocks__/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../tsconfig.test.json"
3+
}

0 commit comments

Comments
 (0)