dxkj 0.1.1 → 0.1.2
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/package.json +1 -1
- package/src/cli.js +1 -2
- package/src/lib/installer.js +2 -1
- package/src/lib/registry.js +2 -1
- package/src/lib/version.js +8 -0
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -7,8 +7,7 @@ import { validateItem, formatReport } from './lib/validator.js';
|
|
|
7
7
|
import { renderList, renderDetail } from './lib/format.js';
|
|
8
8
|
import { resolveTargetDir } from './lib/targets.js';
|
|
9
9
|
import { downloadToTemp, extractZip, writeManifest, cleanup } from './lib/installer.js';
|
|
10
|
-
|
|
11
|
-
const VERSION = '0.1.0';
|
|
10
|
+
import { VERSION } from './lib/version.js';
|
|
12
11
|
|
|
13
12
|
const OPTIONS = {
|
|
14
13
|
source: { type: 'string' },
|
package/src/lib/installer.js
CHANGED
|
@@ -3,6 +3,7 @@ import os from 'node:os';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { pipeline } from 'node:stream/promises';
|
|
5
5
|
import AdmZip from 'adm-zip';
|
|
6
|
+
import { USER_AGENT } from './version.js';
|
|
6
7
|
|
|
7
8
|
export const MANIFEST = '.dxkj.json';
|
|
8
9
|
|
|
@@ -12,7 +13,7 @@ export async function downloadToTemp(url) {
|
|
|
12
13
|
const target = path.join(tmp, 'package.zip');
|
|
13
14
|
|
|
14
15
|
if (/^https?:\/\//i.test(url)) {
|
|
15
|
-
const res = await fetch(url, { headers: { 'User-Agent':
|
|
16
|
+
const res = await fetch(url, { headers: { 'User-Agent': USER_AGENT } });
|
|
16
17
|
if (!res.ok) throw new Error(`下载失败 HTTP ${res.status}:${url}`);
|
|
17
18
|
await pipeline(res.body, fs.createWriteStream(target));
|
|
18
19
|
} else {
|
package/src/lib/registry.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { loadConfig, resolveServerUrl, REGISTRY_PATH } from './config.js';
|
|
4
|
+
import { USER_AGENT } from './version.js';
|
|
4
5
|
|
|
5
6
|
/** 去除 Windows 写文件常见的 UTF-8 BOM,避免 JSON.parse 失败 */
|
|
6
7
|
export function stripBom(text) {
|
|
@@ -52,7 +53,7 @@ export async function loadRegistry(opts = {}, cfg = loadConfig()) {
|
|
|
52
53
|
try {
|
|
53
54
|
const res = await fetch(source, {
|
|
54
55
|
signal: controller.signal,
|
|
55
|
-
headers: { 'User-Agent':
|
|
56
|
+
headers: { 'User-Agent': USER_AGENT, Accept: 'application/json' }
|
|
56
57
|
});
|
|
57
58
|
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
58
59
|
json = await res.json();
|