test-lib20260119 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/npm-publish.yml +35 -0
- package/npm-proxy.js +44 -0
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
publish:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Checkout
|
|
17
|
+
uses: actions/checkout@v4
|
|
18
|
+
|
|
19
|
+
- name: Setup Node
|
|
20
|
+
uses: actions/setup-node@v4
|
|
21
|
+
with:
|
|
22
|
+
node-version: "20"
|
|
23
|
+
registry-url: "https://registry.npmjs.org"
|
|
24
|
+
|
|
25
|
+
- name: Upgrade npm for OIDC support
|
|
26
|
+
run: npm i -g npm@11.5.1
|
|
27
|
+
|
|
28
|
+
- name: Install dependencies
|
|
29
|
+
run: npm ci
|
|
30
|
+
|
|
31
|
+
- name: Build (if needed)
|
|
32
|
+
run: npm run build --if-present
|
|
33
|
+
|
|
34
|
+
- name: Publish
|
|
35
|
+
run: npm publish
|
package/npm-proxy.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const http = require("http");
|
|
2
|
+
const https = require("https");
|
|
3
|
+
const { URL } = require("url");
|
|
4
|
+
|
|
5
|
+
const PORT = process.env.PORT;
|
|
6
|
+
if (!PORT) {
|
|
7
|
+
console.error("PORT is required");
|
|
8
|
+
process.exit(1);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const TARGET = new URL("https://registry.npmjs.org");
|
|
12
|
+
|
|
13
|
+
const server = http.createServer((req, res) => {
|
|
14
|
+
const targetUrl = new URL(req.url, TARGET);
|
|
15
|
+
const headers = { ...req.headers, host: TARGET.host };
|
|
16
|
+
const options = {
|
|
17
|
+
protocol: TARGET.protocol,
|
|
18
|
+
hostname: TARGET.hostname,
|
|
19
|
+
port: TARGET.port || 443,
|
|
20
|
+
method: req.method,
|
|
21
|
+
path: `${targetUrl.pathname}${targetUrl.search}`,
|
|
22
|
+
headers,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const proxyReq = https.request(options, (proxyRes) => {
|
|
26
|
+
res.writeHead(proxyRes.statusCode || 502, proxyRes.headers);
|
|
27
|
+
proxyRes.pipe(res);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
proxyReq.on("error", () => {
|
|
31
|
+
res.statusCode = 502;
|
|
32
|
+
res.end("Bad Gateway");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
req.pipe(proxyReq);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
server.on("clientError", (_err, socket) => {
|
|
39
|
+
socket.end("HTTP/1.1 400 Bad Request\r\n\r\n");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
server.listen(Number(PORT), "0.0.0.0", () => {
|
|
43
|
+
console.log(`npm proxy listening on :${PORT}`);
|
|
44
|
+
});
|