Skip to content

Commit 446becc

Browse files
committed
test: remove node-static dependency
This library appears to be unmaintained and has transitive dependencies that have security advisories, which in turn trigger security advisories in https://github.com/clangd/node-clangd/security/dependabot. Thus replace it with a tiny HTTP handler and remove the bad dependencies.
1 parent a59bf3e commit 446becc

File tree

3 files changed

+34
-95
lines changed

3 files changed

+34
-95
lines changed

package-lock.json

Lines changed: 0 additions & 89 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,11 @@
3636
"devDependencies": {
3737
"@types/node": "^24.1.0",
3838
"@types/node-fetch": "^2.6.11",
39-
"@types/node-static": "^0.7.11",
4039
"@types/semver": "^7.5.8",
4140
"@types/tape": "^5.6.4",
4241
"@types/tmp": "^0.2.6",
4342
"@types/unzipper": "^0.10.11",
4443
"@types/which": "^3.0.4",
45-
"node-static": "^0.7.11",
4644
"prettier": "^3.3.3",
4745
"tap-spec": "^5.0.0",
4846
"tape": "^5.8.1",

test/index.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as fs from 'fs';
22
import * as http from 'http';
3-
import * as nodeStatic from 'node-static';
43
import * as os from 'os';
54
import * as path from 'path';
65
import tape from 'tape';
@@ -96,12 +95,43 @@ function test(
9695
tmp.withDir(
9796
async (dir) => {
9897
const ui = new FakeUI(dir.path);
99-
const files = new nodeStatic.Server('test/assets/');
10098
return new Promise((resolve, _reject) => {
10199
const server = http
102-
.createServer((req, res) => {
100+
.createServer(async (req, res) => {
103101
console.log('Fake github:', req.method, req.url);
104-
req.on('end', () => files.serve(req, res)).resume();
102+
if (!req.url) {
103+
res.statusCode = 400;
104+
res.end();
105+
return;
106+
}
107+
108+
req.resume();
109+
110+
const {pathname} = new URL(req.url, 'http://localhost');
111+
const filePath = path.resolve(assetsRoot, '.' + pathname);
112+
if (!filePath.startsWith(assetsRoot + path.sep)) {
113+
res.statusCode = 400;
114+
res.end();
115+
return;
116+
}
117+
118+
try {
119+
const handle = await fs.promises.open(filePath, 'r');
120+
const stat = await handle.stat();
121+
res.setHeader('Content-Length', stat.size);
122+
const stream = fs.createReadStream(filePath, {
123+
fd: handle,
124+
autoClose: true,
125+
});
126+
stream.on('error', (err: Error) => {
127+
res.statusCode = 500;
128+
res.end(String(err));
129+
});
130+
stream.pipe(res);
131+
} catch (err) {
132+
res.statusCode = 500;
133+
res.end(String(err));
134+
}
105135
})
106136
.listen(9999, '::', async () => {
107137
console.log('Fake github serving...');

0 commit comments

Comments
 (0)