vtools-core 0.0.0
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.d.ts +16 -0
- package/dist/index.js +71 -0
- package/package.json +43 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/marketplace.d.ts
|
|
2
|
+
type ExtensionRef = {
|
|
3
|
+
publisher: string;
|
|
4
|
+
name: string;
|
|
5
|
+
};
|
|
6
|
+
type ResolvedExtension = ExtensionRef & {
|
|
7
|
+
version: string;
|
|
8
|
+
displayName?: string;
|
|
9
|
+
publisherDisplayName?: string;
|
|
10
|
+
};
|
|
11
|
+
declare function parseExtensionInput(raw: string): ExtensionRef | null;
|
|
12
|
+
declare function resolveExtension(ref: ExtensionRef): Promise<ResolvedExtension>;
|
|
13
|
+
declare function buildDownloadUrl(ref: ExtensionRef, version: string): string;
|
|
14
|
+
declare function buildVsixFilename(ref: ExtensionRef, version: string): string;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ExtensionRef, ResolvedExtension, buildDownloadUrl, buildVsixFilename, parseExtensionInput, resolveExtension };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/marketplace.ts
|
|
2
|
+
const MARKETPLACE_ORIGIN = "https://marketplace.visualstudio.com";
|
|
3
|
+
function parseExtensionInput(raw) {
|
|
4
|
+
const input = raw.trim();
|
|
5
|
+
if (!input) return null;
|
|
6
|
+
let itemName = input;
|
|
7
|
+
if (input.includes("itemName=")) try {
|
|
8
|
+
const url = new URL(input.startsWith("http") ? input : `https://${input}`);
|
|
9
|
+
const param = url.searchParams.get("itemName");
|
|
10
|
+
if (param) itemName = param;
|
|
11
|
+
} catch {
|
|
12
|
+
const match = input.match(/itemName=([^&\s]+)/);
|
|
13
|
+
if (match) itemName = decodeURIComponent(match[1]);
|
|
14
|
+
}
|
|
15
|
+
const dot = itemName.indexOf(".");
|
|
16
|
+
if (dot <= 0 || dot === itemName.length - 1) return null;
|
|
17
|
+
const publisher = itemName.slice(0, dot).trim();
|
|
18
|
+
const name = itemName.slice(dot + 1).trim();
|
|
19
|
+
if (!publisher || !name) return null;
|
|
20
|
+
return {
|
|
21
|
+
publisher,
|
|
22
|
+
name
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
async function resolveExtension(ref) {
|
|
26
|
+
const itemName = `${ref.publisher}.${ref.name}`;
|
|
27
|
+
const body = {
|
|
28
|
+
filters: [{
|
|
29
|
+
criteria: [{
|
|
30
|
+
filterType: 8,
|
|
31
|
+
value: "Microsoft.VisualStudio.Code"
|
|
32
|
+
}, {
|
|
33
|
+
filterType: 7,
|
|
34
|
+
value: itemName
|
|
35
|
+
}],
|
|
36
|
+
pageNumber: 1,
|
|
37
|
+
pageSize: 1,
|
|
38
|
+
sortBy: 0,
|
|
39
|
+
sortOrder: 0
|
|
40
|
+
}],
|
|
41
|
+
flags: 513
|
|
42
|
+
};
|
|
43
|
+
const response = await fetch(`${MARKETPLACE_ORIGIN}/_apis/public/gallery/extensionquery`, {
|
|
44
|
+
method: "POST",
|
|
45
|
+
headers: {
|
|
46
|
+
"Content-Type": "application/json",
|
|
47
|
+
Accept: "application/json;api-version=3.0-preview.1"
|
|
48
|
+
},
|
|
49
|
+
body: JSON.stringify(body)
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) throw new Error(`Marketplace API 请求失败(HTTP ${response.status})`);
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
const extension = data.results?.[0]?.extensions?.[0];
|
|
54
|
+
const version = extension?.versions?.[0]?.version;
|
|
55
|
+
if (!extension || !version) throw new Error(`未找到扩展 "${itemName}",请检查名称是否正确`);
|
|
56
|
+
return {
|
|
57
|
+
...ref,
|
|
58
|
+
version,
|
|
59
|
+
displayName: extension.displayName,
|
|
60
|
+
publisherDisplayName: extension.publisher?.displayName
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function buildDownloadUrl(ref, version) {
|
|
64
|
+
return `${MARKETPLACE_ORIGIN}/_apis/public/gallery/publishers/${ref.publisher}/vsextensions/${ref.name}/${version}/vspackage`;
|
|
65
|
+
}
|
|
66
|
+
function buildVsixFilename(ref, version) {
|
|
67
|
+
return `${ref.publisher}.${ref.name}-${version}.vsix`;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//#endregion
|
|
71
|
+
export { buildDownloadUrl, buildVsixFilename, parseExtensionInput, resolveExtension };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vtools-core",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Shared VS Code Marketplace logic for vtools (parse, resolve, build download URL).",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/stekovinbranturry/vtools.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public",
|
|
13
|
+
"provenance": true
|
|
14
|
+
},
|
|
15
|
+
"type": "module",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"files": ["dist"],
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "tsdown",
|
|
27
|
+
"dev": "tsdown --watch",
|
|
28
|
+
"check-types": "tsgo --noEmit",
|
|
29
|
+
"test": "ava",
|
|
30
|
+
"prepublishOnly": "pnpm run build"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@typescript/native-preview": "latest",
|
|
34
|
+
"ava": "^5.2.0",
|
|
35
|
+
"ts-node": "^10.9.1",
|
|
36
|
+
"tsdown": "^0.9.0",
|
|
37
|
+
"typescript": "5.9.2"
|
|
38
|
+
},
|
|
39
|
+
"ava": {
|
|
40
|
+
"extensions": {"ts": "module"},
|
|
41
|
+
"nodeArguments": ["--loader=ts-node/esm"]
|
|
42
|
+
}
|
|
43
|
+
}
|