Skip to content

Commit 8c431c6

Browse files
authored
fix: Dependency upgrades, remove vulnerable serve (#115)
* chore: dependency upgrades * chore: remove vulnerable dependency, write own test server
1 parent 5d2fb93 commit 8c431c6

File tree

6 files changed

+1001
-1024
lines changed

6 files changed

+1001
-1024
lines changed

jest-puppeteer.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export default {
22
server: {
3-
command: "npx serve -l 8080",
3+
command: "node test/serve.js 8080",
44
port: 8080,
55
},
66
launch: {

package.json

+13-13
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66
"type": "module",
77
"license": "MIT",
88
"devDependencies": {
9-
"@babel/core": "^7.25.2",
10-
"@babel/plugin-external-helpers": "^7.24.7",
11-
"@babel/preset-env": "^7.25.4",
9+
"@babel/core": "^7.25.7",
10+
"@babel/plugin-external-helpers": "^7.25.7",
11+
"@babel/preset-env": "^7.25.7",
1212
"@jest/globals": "^29.7.0",
1313
"@rollup/plugin-babel": "^6.0.4",
14-
"@rollup/plugin-node-resolve": "^15.2.3",
15-
"@rollup/plugin-replace": "^5.0.7",
14+
"@rollup/plugin-node-resolve": "^15.3.0",
15+
"@rollup/plugin-replace": "^6.0.1",
1616
"@rollup/plugin-terser": "^0.4.4",
17+
"@types/node": "^20.16.11",
1718
"jest": "^29.7.0",
18-
"jest-puppeteer": "^10.1.0",
19+
"jest-puppeteer": "^10.1.1",
1920
"prettier": "^3.3.3",
20-
"puppeteer": "^23.2.2",
21-
"rollup": "^4.21.2",
22-
"rollup-plugin-import-css": "^3.5.1",
23-
"semantic-release": "^24.1.2",
24-
"serve": "^14.2.3"
21+
"puppeteer": "^23.5.2",
22+
"rollup": "^4.24.0",
23+
"rollup-plugin-import-css": "^3.5.4",
24+
"semantic-release": "^24.1.2"
2525
},
2626
"scripts": {
2727
"test": "yarn run test:prettier && yarn run test:jest",
2828
"test:jest": "yarn run build && jest",
29-
"test:prettier": "prettier --check src/**/*.js",
30-
"test:serve": "serve -l 8081",
29+
"test:prettier": "prettier --check **/*.js",
30+
"test:serve": "node test/serve.js",
3131
"build": "rollup -c",
3232
"watch": "rollup -c -w",
3333
"prepack": "yarn run build",

rollup.config.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,13 @@ export default {
1010
resolve(),
1111
replace({
1212
values: {
13-
'__VERSION': process.env.npm_package_version,
13+
__VERSION: process.env.npm_package_version,
1414
},
1515
preventAssignment: true,
1616
}),
1717
css({ minify: true, output: "applause-button.css" }),
1818
babel({
19-
presets: [
20-
[
21-
"@babel/preset-env"
22-
]
23-
],
19+
presets: [["@babel/preset-env"]],
2420
babelHelpers: "bundled",
2521
}),
2622
terser(),
File renamed without changes.

test/serve.js

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env node
2+
import { createReadStream, existsSync } from "node:fs";
3+
import http from "node:http";
4+
import { dirname, join } from "node:path";
5+
import { fileURLToPath } from "node:url";
6+
7+
/*
8+
* Simple node server, restricted to serving only the assets we expect.
9+
*
10+
* Listens on port 8081 by default; provide port on commandline to override:
11+
*
12+
* > node test/serve.js 3000
13+
*/
14+
15+
const __dirname = dirname(fileURLToPath(import.meta.url));
16+
const port = +process.argv[2] || 8081;
17+
const pathToContentType = {
18+
"index.html": "text/html; charset=utf-8",
19+
"dist/applause-button.js": "text/javascript",
20+
"dist/applause-button.css": "text/css",
21+
};
22+
23+
(() => {
24+
const server = http.createServer((req, res) => {
25+
if (req.method !== "GET") {
26+
res.writeHead(405);
27+
res.end();
28+
return;
29+
}
30+
// Find file from URL path
31+
const path = req.url?.substring(1) || "index.html"; //chop off leading slash
32+
if (!Object.hasOwn(pathToContentType, path)) {
33+
res.writeHead(404);
34+
res.end();
35+
return;
36+
}
37+
const file = join(__dirname, "..", path);
38+
if (!existsSync(file)) {
39+
res.writeHead(404);
40+
res.write("Did you forget to build?");
41+
res.end();
42+
return;
43+
}
44+
45+
res.setHeader("Content-Type", pathToContentType[path]);
46+
res.writeHead(200);
47+
createReadStream(file).pipe(res);
48+
});
49+
50+
server.listen(port, () => {
51+
console.log(`Server listening on http://localhost:${port}`);
52+
});
53+
})();

0 commit comments

Comments
 (0)