com.jimuwd.xian.registry-proxy 1.0.16 → 1.0.17
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/dist/index.js +12 -5
- package/package.json +1 -1
- package/src/index.ts +19 -13
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createServer } from 'http';
|
|
3
3
|
import { createServer as createHttpsServer } from 'https';
|
|
4
|
-
import {
|
|
4
|
+
import { promises as fsPromises, readFileSync } from 'fs';
|
|
5
5
|
import { load } from 'js-yaml';
|
|
6
6
|
import fetch from 'node-fetch';
|
|
7
7
|
import { homedir } from 'os';
|
|
@@ -39,13 +39,21 @@ const limiter = new ConcurrencyLimiter(5); // 限制为 5 个并发请求
|
|
|
39
39
|
function normalizeUrl(url) {
|
|
40
40
|
try {
|
|
41
41
|
const urlObj = new URL(url);
|
|
42
|
+
// 规范化端口
|
|
42
43
|
if (urlObj.protocol === 'http:' && (urlObj.port === '80' || urlObj.port === '')) {
|
|
43
44
|
urlObj.port = '';
|
|
44
45
|
}
|
|
45
46
|
else if (urlObj.protocol === 'https:' && (urlObj.port === '443' || urlObj.port === '')) {
|
|
46
47
|
urlObj.port = '';
|
|
47
48
|
}
|
|
48
|
-
|
|
49
|
+
// 处理路径末尾斜杠
|
|
50
|
+
const pathname = urlObj.pathname;
|
|
51
|
+
if (pathname.endsWith('.tgz') || pathname.endsWith('.tgz/')) {
|
|
52
|
+
// tarball 文件,去除末尾斜杠
|
|
53
|
+
urlObj.pathname = pathname.replace(/\/+$/, '');
|
|
54
|
+
}
|
|
55
|
+
else if (!pathname.endsWith('/')) {
|
|
56
|
+
// 注册表根路径,确保末尾有斜杠
|
|
49
57
|
urlObj.pathname += '/';
|
|
50
58
|
}
|
|
51
59
|
console.debug(`Normalized URL: ${url} -> ${urlObj.toString()}`);
|
|
@@ -53,12 +61,11 @@ function normalizeUrl(url) {
|
|
|
53
61
|
}
|
|
54
62
|
catch (e) {
|
|
55
63
|
console.error(`Invalid URL: ${url}`, e);
|
|
56
|
-
return url.endsWith('/') ? url :
|
|
64
|
+
return url.endsWith('/') ? url.slice(0, -1) : url; // 默认去除末尾斜杠
|
|
57
65
|
}
|
|
58
66
|
}
|
|
59
67
|
function resolvePath(path) {
|
|
60
|
-
|
|
61
|
-
return resolved;
|
|
68
|
+
return path.startsWith('~/') ? join(homedir(), path.slice(2)) : resolve(path);
|
|
62
69
|
}
|
|
63
70
|
function removeRegistryPrefix(tarballUrl, registries) {
|
|
64
71
|
try {
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import fetch, {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
2
|
+
import {createServer, Server as HttpServer} from 'http';
|
|
3
|
+
import {createServer as createHttpsServer, Server as HttpsServer} from 'https';
|
|
4
|
+
import {promises as fsPromises, readFileSync} from 'fs';
|
|
5
|
+
import {AddressInfo} from 'net';
|
|
6
|
+
import {load} from 'js-yaml';
|
|
7
|
+
import fetch, {Response} from 'node-fetch';
|
|
8
|
+
import {homedir} from 'os';
|
|
9
|
+
import {join, resolve} from 'path';
|
|
10
|
+
import {URL} from 'url';
|
|
11
11
|
|
|
12
12
|
const { readFile, writeFile } = fsPromises;
|
|
13
13
|
|
|
@@ -59,25 +59,31 @@ const limiter = new ConcurrencyLimiter(5); // 限制为 5 个并发请求
|
|
|
59
59
|
function normalizeUrl(url: string): string {
|
|
60
60
|
try {
|
|
61
61
|
const urlObj = new URL(url);
|
|
62
|
+
// 规范化端口
|
|
62
63
|
if (urlObj.protocol === 'http:' && (urlObj.port === '80' || urlObj.port === '')) {
|
|
63
64
|
urlObj.port = '';
|
|
64
65
|
} else if (urlObj.protocol === 'https:' && (urlObj.port === '443' || urlObj.port === '')) {
|
|
65
66
|
urlObj.port = '';
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
// 处理路径末尾斜杠
|
|
69
|
+
const pathname = urlObj.pathname;
|
|
70
|
+
if (pathname.endsWith('.tgz') || pathname.endsWith('.tgz/')) {
|
|
71
|
+
// tarball 文件,去除末尾斜杠
|
|
72
|
+
urlObj.pathname = pathname.replace(/\/+$/, '');
|
|
73
|
+
} else if (!pathname.endsWith('/')) {
|
|
74
|
+
// 注册表根路径,确保末尾有斜杠
|
|
68
75
|
urlObj.pathname += '/';
|
|
69
76
|
}
|
|
70
77
|
console.debug(`Normalized URL: ${url} -> ${urlObj.toString()}`);
|
|
71
78
|
return urlObj.toString();
|
|
72
79
|
} catch (e) {
|
|
73
80
|
console.error(`Invalid URL: ${url}`, e);
|
|
74
|
-
return url.endsWith('/') ? url :
|
|
81
|
+
return url.endsWith('/') ? url.slice(0, -1) : url; // 默认去除末尾斜杠
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
function resolvePath(path: string): string {
|
|
79
|
-
|
|
80
|
-
return resolved;
|
|
86
|
+
return path.startsWith('~/') ? join(homedir(), path.slice(2)) : resolve(path);
|
|
81
87
|
}
|
|
82
88
|
|
|
83
89
|
function removeRegistryPrefix(tarballUrl: string, registries: RegistryInfo[]): string {
|