ovsx 0.10.1 → 0.10.3
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/CHANGELOG.md +26 -0
- package/lib/create-namespace-options.d.ts +17 -0
- package/lib/create-namespace-options.d.ts.map +1 -0
- package/lib/create-namespace-options.js +12 -0
- package/lib/create-namespace-options.js.map +1 -0
- package/lib/create-namespace.d.ts +1 -7
- package/lib/create-namespace.d.ts.map +1 -1
- package/lib/create-namespace.js +2 -1
- package/lib/create-namespace.js.map +1 -1
- package/lib/get-options.d.ts +33 -0
- package/lib/get-options.d.ts.map +1 -0
- package/lib/get-options.js +12 -0
- package/lib/get-options.js.map +1 -0
- package/lib/get.d.ts +1 -23
- package/lib/get.d.ts.map +1 -1
- package/lib/get.js +2 -2
- package/lib/get.js.map +1 -1
- package/lib/index.d.ts +8 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/login-options.d.ts +17 -0
- package/lib/login-options.d.ts.map +1 -0
- package/lib/login-options.js +3 -0
- package/lib/login-options.js.map +1 -0
- package/lib/login.d.ts +1 -7
- package/lib/login.d.ts.map +1 -1
- package/lib/login.js +2 -1
- package/lib/login.js.map +1 -1
- package/lib/logout.d.ts.map +1 -1
- package/lib/logout.js +9 -0
- package/lib/logout.js.map +1 -1
- package/lib/pat.d.ts +16 -0
- package/lib/pat.d.ts.map +1 -0
- package/lib/pat.js +39 -0
- package/lib/pat.js.map +1 -0
- package/lib/publish-options.d.ts +56 -0
- package/lib/publish-options.d.ts.map +1 -0
- package/lib/publish-options.js +3 -0
- package/lib/publish-options.js.map +1 -0
- package/lib/publish.d.ts +1 -47
- package/lib/publish.d.ts.map +1 -1
- package/lib/publish.js +2 -1
- package/lib/publish.js.map +1 -1
- package/lib/registry-options.d.ts +36 -0
- package/lib/registry-options.d.ts.map +1 -0
- package/lib/registry-options.js +12 -0
- package/lib/registry-options.js.map +1 -0
- package/lib/registry.d.ts +1 -26
- package/lib/registry.d.ts.map +1 -1
- package/lib/registry.js +9 -11
- package/lib/registry.js.map +1 -1
- package/lib/store.d.ts.map +1 -1
- package/lib/store.js +9 -0
- package/lib/store.js.map +1 -1
- package/lib/util.d.ts +2 -6
- package/lib/util.d.ts.map +1 -1
- package/lib/util.js +11 -38
- package/lib/util.js.map +1 -1
- package/lib/verify-pat-options.d.ts +17 -0
- package/lib/verify-pat-options.d.ts.map +1 -0
- package/lib/verify-pat-options.js +12 -0
- package/lib/verify-pat-options.js.map +1 -0
- package/lib/verify-pat.d.ts +1 -8
- package/lib/verify-pat.d.ts.map +1 -1
- package/lib/verify-pat.js +3 -14
- package/lib/verify-pat.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/zip.d.ts +0 -1
- package/lib/zip.d.ts.map +1 -1
- package/lib/zip.js +24 -24
- package/lib/zip.js.map +1 -1
- package/package.json +4 -4
- package/src/create-namespace-options.ts +18 -0
- package/src/create-namespace.ts +4 -9
- package/src/get-options.ts +34 -0
- package/src/get.ts +5 -27
- package/src/index.ts +8 -0
- package/src/login-options.ts +17 -0
- package/src/login.ts +3 -9
- package/src/logout.ts +9 -0
- package/src/pat.ts +52 -0
- package/src/publish-options.ts +61 -0
- package/src/publish.ts +21 -70
- package/src/registry-options.ts +36 -0
- package/src/registry.ts +16 -44
- package/src/store.ts +9 -0
- package/src/util.ts +14 -47
- package/src/verify-pat-options.ts +18 -0
- package/src/verify-pat.ts +3 -20
- package/src/version.ts +1 -1
- package/src/zip.ts +26 -31
package/src/registry.ts
CHANGED
|
@@ -12,7 +12,8 @@ import * as http from 'http';
|
|
|
12
12
|
import * as fs from 'fs';
|
|
13
13
|
import * as querystring from 'querystring';
|
|
14
14
|
import * as followRedirects from 'follow-redirects';
|
|
15
|
-
import {
|
|
15
|
+
import { RegistryOptions } from './registry-options';
|
|
16
|
+
import { rejectError, statusError } from './util';
|
|
16
17
|
|
|
17
18
|
export const DEFAULT_URL = 'https://open-vsx.org';
|
|
18
19
|
export const DEFAULT_NAMESPACE_SIZE = 1024;
|
|
@@ -53,17 +54,17 @@ export class Registry {
|
|
|
53
54
|
'Content-Type': 'application/json'
|
|
54
55
|
}, this.maxNamespaceSize);
|
|
55
56
|
} catch (err) {
|
|
56
|
-
return
|
|
57
|
+
return rejectError(err);
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
verifyPat(namespace: string, pat: string): Promise<Response> {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
try {
|
|
63
|
+
const query: { [key: string]: string } = { token: pat };
|
|
64
|
+
return this.getJson(this.getUrl(`api/${namespace}/verify-pat`, query));
|
|
65
|
+
} catch (err) {
|
|
66
|
+
return rejectError(err);
|
|
67
|
+
}
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
publish(file: string, pat: string): Promise<Extension> {
|
|
@@ -74,7 +75,7 @@ export class Registry {
|
|
|
74
75
|
'Content-Type': 'application/octet-stream'
|
|
75
76
|
}, this.maxPublishSize);
|
|
76
77
|
} catch (err) {
|
|
77
|
-
return
|
|
78
|
+
return rejectError(err);
|
|
78
79
|
}
|
|
79
80
|
}
|
|
80
81
|
|
|
@@ -86,7 +87,7 @@ export class Registry {
|
|
|
86
87
|
}
|
|
87
88
|
return this.getJson(this.getUrl(path));
|
|
88
89
|
} catch (err) {
|
|
89
|
-
return
|
|
90
|
+
return rejectError(err);
|
|
90
91
|
}
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -105,11 +106,11 @@ export class Registry {
|
|
|
105
106
|
});
|
|
106
107
|
response.pipe(stream);
|
|
107
108
|
});
|
|
108
|
-
stream.on('error', err => {
|
|
109
|
+
stream.on('error', (err: Error) => {
|
|
109
110
|
request.abort();
|
|
110
111
|
reject(err);
|
|
111
112
|
});
|
|
112
|
-
request.on('error', err => {
|
|
113
|
+
request.on('error', (err: Error) => {
|
|
113
114
|
stream.close();
|
|
114
115
|
reject(err);
|
|
115
116
|
});
|
|
@@ -144,11 +145,11 @@ export class Registry {
|
|
|
144
145
|
const requestOptions = this.getRequestOptions('POST', headers, maxBodyLength);
|
|
145
146
|
const request = this.getProtocol(url)
|
|
146
147
|
.request(url, requestOptions, this.getJsonResponse<T>(resolve, reject));
|
|
147
|
-
stream.on('error', err => {
|
|
148
|
+
stream.on('error', (err: Error) => {
|
|
148
149
|
request.abort();
|
|
149
150
|
reject(err);
|
|
150
151
|
});
|
|
151
|
-
request.on('error', err => {
|
|
152
|
+
request.on('error', (err: Error) => {
|
|
152
153
|
stream.close();
|
|
153
154
|
reject(err);
|
|
154
155
|
});
|
|
@@ -171,9 +172,7 @@ export class Registry {
|
|
|
171
172
|
|
|
172
173
|
private getRequestOptions(method?: string, headers?: http.OutgoingHttpHeaders, maxBodyLength?: number): http.RequestOptions {
|
|
173
174
|
if (this.username && this.password) {
|
|
174
|
-
|
|
175
|
-
headers = {};
|
|
176
|
-
}
|
|
175
|
+
headers ??= {};
|
|
177
176
|
const credentials = Buffer.from(this.username + ':' + this.password).toString('base64');
|
|
178
177
|
headers['Authorization'] = 'Basic ' + credentials;
|
|
179
178
|
}
|
|
@@ -219,33 +218,6 @@ export class Registry {
|
|
|
219
218
|
|
|
220
219
|
}
|
|
221
220
|
|
|
222
|
-
export interface RegistryOptions {
|
|
223
|
-
/**
|
|
224
|
-
* The base URL of the registry API.
|
|
225
|
-
*/
|
|
226
|
-
registryUrl?: string;
|
|
227
|
-
/**
|
|
228
|
-
* Personal access token.
|
|
229
|
-
*/
|
|
230
|
-
pat?: string;
|
|
231
|
-
/**
|
|
232
|
-
* User name for basic authentication.
|
|
233
|
-
*/
|
|
234
|
-
username?: string;
|
|
235
|
-
/**
|
|
236
|
-
* Password for basic authentication.
|
|
237
|
-
*/
|
|
238
|
-
password?: string;
|
|
239
|
-
/**
|
|
240
|
-
* Maximal request body size for creating namespaces.
|
|
241
|
-
*/
|
|
242
|
-
maxNamespaceSize?: number;
|
|
243
|
-
/**
|
|
244
|
-
* Maximal request body size for publishing.
|
|
245
|
-
*/
|
|
246
|
-
maxPublishSize?: number;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
221
|
export interface Response {
|
|
250
222
|
success?: string;
|
|
251
223
|
warning?: string;
|
package/src/store.ts
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2024 Precies. Software and others
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
9
|
+
********************************************************************************/
|
|
1
10
|
import * as fs from 'fs';
|
|
2
11
|
import * as path from 'path';
|
|
3
12
|
import { homedir } from 'os';
|
package/src/util.ts
CHANGED
|
@@ -13,27 +13,15 @@ import * as path from 'path';
|
|
|
13
13
|
import * as tmp from 'tmp';
|
|
14
14
|
import * as http from 'http';
|
|
15
15
|
import * as readline from 'readline';
|
|
16
|
-
import { RegistryOptions } from './registry';
|
|
17
|
-
import { VerifyPatOptions, doVerifyPat } from './verify-pat';
|
|
18
|
-
import { PublishOptions } from './publish';
|
|
19
|
-
import { openDefaultStore } from './store';
|
|
20
|
-
import { CreateNamespaceOptions } from './create-namespace';
|
|
16
|
+
import { RegistryOptions } from './registry-options';
|
|
21
17
|
|
|
22
18
|
export { promisify } from 'util';
|
|
23
19
|
|
|
24
20
|
export function addEnvOptions(options: RegistryOptions): void {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
options.pat = process.env.OVSX_PAT;
|
|
30
|
-
}
|
|
31
|
-
if (!options.username) {
|
|
32
|
-
options.username = process.env.OVSX_USERNAME;
|
|
33
|
-
}
|
|
34
|
-
if (!options.password) {
|
|
35
|
-
options.password = process.env.OVSX_PASSWORD;
|
|
36
|
-
}
|
|
21
|
+
options.registryUrl ??= process.env.OVSX_REGISTRY_URL;
|
|
22
|
+
options.pat ??= process.env.OVSX_PAT;
|
|
23
|
+
options.username ??= process.env.OVSX_USERNAME;
|
|
24
|
+
options.password ??= process.env.OVSX_PASSWORD;
|
|
37
25
|
}
|
|
38
26
|
|
|
39
27
|
export function matchExtensionId(id: string): RegExpExecArray | null {
|
|
@@ -51,7 +39,7 @@ export function makeDirs(path: fs.PathLike): Promise<void> {
|
|
|
51
39
|
if (fs.existsSync(path)) {
|
|
52
40
|
resolve();
|
|
53
41
|
} else {
|
|
54
|
-
fs.mkdir(path, { recursive: true }, err => {
|
|
42
|
+
fs.mkdir(path, { recursive: true }, (err: NodeJS.ErrnoException | null) => {
|
|
55
43
|
if (err)
|
|
56
44
|
reject(err);
|
|
57
45
|
else
|
|
@@ -63,7 +51,7 @@ export function makeDirs(path: fs.PathLike): Promise<void> {
|
|
|
63
51
|
|
|
64
52
|
export function createTempFile(options: tmp.TmpNameOptions): Promise<string> {
|
|
65
53
|
return new Promise((resolve, reject) => {
|
|
66
|
-
tmp.tmpName(options, (err, name) => {
|
|
54
|
+
tmp.tmpName(options, (err: Error | null, name: string) => {
|
|
67
55
|
if (err)
|
|
68
56
|
reject(err);
|
|
69
57
|
else
|
|
@@ -72,6 +60,11 @@ export function createTempFile(options: tmp.TmpNameOptions): Promise<string> {
|
|
|
72
60
|
});
|
|
73
61
|
}
|
|
74
62
|
|
|
63
|
+
export function rejectError(err: any) {
|
|
64
|
+
const reason = err instanceof Error ? err : new Error(String(err));
|
|
65
|
+
return Promise.reject(reason);
|
|
66
|
+
}
|
|
67
|
+
|
|
75
68
|
export function handleError(debug?: boolean, additionalMessage?: string, exit: boolean = true): (reason: any) => void {
|
|
76
69
|
return reason => {
|
|
77
70
|
if (reason instanceof Error && !debug) {
|
|
@@ -105,7 +98,7 @@ export function readFile(name: string, packagePath?: string, encoding: BufferEnc
|
|
|
105
98
|
fs.readFile(
|
|
106
99
|
path.join(packagePath ?? process.cwd(), name),
|
|
107
100
|
{ encoding },
|
|
108
|
-
(err, content) => {
|
|
101
|
+
(err: NodeJS.ErrnoException | null, content: string) => {
|
|
109
102
|
if (err) {
|
|
110
103
|
reject(err);
|
|
111
104
|
} else {
|
|
@@ -139,7 +132,7 @@ export function writeFile(name: string, content: string, packagePath?: string, e
|
|
|
139
132
|
path.join(packagePath ?? process.cwd(), name),
|
|
140
133
|
content,
|
|
141
134
|
{ encoding },
|
|
142
|
-
err => {
|
|
135
|
+
(err: NodeJS.ErrnoException | null) => {
|
|
143
136
|
if (err) {
|
|
144
137
|
reject(err);
|
|
145
138
|
} else {
|
|
@@ -186,30 +179,4 @@ export async function getUserChoice<R extends string>(text: string, values: R[],
|
|
|
186
179
|
}
|
|
187
180
|
}
|
|
188
181
|
return defaultValue;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
export async function requestPAT(namespace: string, options: CreateNamespaceOptions | PublishOptions | VerifyPatOptions, verify: boolean = true): Promise<string> {
|
|
192
|
-
const pat = await getUserInput(`Personal Access Token for namespace '${namespace}':`);
|
|
193
|
-
if (verify) {
|
|
194
|
-
await doVerifyPat({ ...options, namespace, pat });
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
return pat;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export async function getPAT(namespace: string, options: CreateNamespaceOptions | PublishOptions | VerifyPatOptions, verify: boolean = true): Promise<string> {
|
|
201
|
-
if (options?.pat) {
|
|
202
|
-
return options.pat;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const store = await openDefaultStore();
|
|
206
|
-
let pat = store.get(namespace);
|
|
207
|
-
if (pat) {
|
|
208
|
-
return pat;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
pat = await requestPAT(namespace, options, verify);
|
|
212
|
-
await store.add(namespace, pat);
|
|
213
|
-
|
|
214
|
-
return pat;
|
|
215
182
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2022 Anibal Solon and others
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
|
|
11
|
+
import { RegistryOptions } from './registry-options';
|
|
12
|
+
|
|
13
|
+
export interface VerifyPatOptions extends RegistryOptions {
|
|
14
|
+
/**
|
|
15
|
+
* Name of the namespace.
|
|
16
|
+
*/
|
|
17
|
+
namespace?: string
|
|
18
|
+
}
|
package/src/verify-pat.ts
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
* SPDX-License-Identifier: EPL-2.0
|
|
9
9
|
********************************************************************************/
|
|
10
10
|
|
|
11
|
-
import {
|
|
12
|
-
import { readManifest, addEnvOptions
|
|
11
|
+
import { getPAT, doVerifyPat } from './pat';
|
|
12
|
+
import { readManifest, addEnvOptions } from './util';
|
|
13
|
+
import { VerifyPatOptions } from './verify-pat-options';
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Validates that a Personal Access Token can publish to a namespace.
|
|
@@ -35,21 +36,3 @@ export async function verifyPat(options: VerifyPatOptions): Promise<void> {
|
|
|
35
36
|
options.pat = await getPAT(options.namespace, options, false);
|
|
36
37
|
await doVerifyPat(options);
|
|
37
38
|
}
|
|
38
|
-
|
|
39
|
-
export async function doVerifyPat(options: VerifyPatOptions) {
|
|
40
|
-
const registry = new Registry(options);
|
|
41
|
-
const namespace = options.namespace as string;
|
|
42
|
-
const pat = options.pat as string;
|
|
43
|
-
const result = await registry.verifyPat(namespace, pat);
|
|
44
|
-
if (result.error) {
|
|
45
|
-
throw new Error(result.error);
|
|
46
|
-
}
|
|
47
|
-
console.log(`\ud83d\ude80 PAT valid to publish at ${namespace}`);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface VerifyPatOptions extends RegistryOptions {
|
|
51
|
-
/**
|
|
52
|
-
* Name of the namespace.
|
|
53
|
-
*/
|
|
54
|
-
namespace?: string
|
|
55
|
-
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "0.10.
|
|
1
|
+
export const LIB_VERSION = "0.10.3";
|
package/src/zip.ts
CHANGED
|
@@ -1,4 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2024 Precies. Software and others
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
* http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
*
|
|
8
|
+
* SPDX-License-Identifier: EPL-2.0
|
|
9
|
+
********************************************************************************/
|
|
10
|
+
import * as yauzl from 'yauzl-promise';
|
|
2
11
|
import { Readable } from 'stream';
|
|
3
12
|
import { Manifest } from './util';
|
|
4
13
|
|
|
@@ -11,37 +20,23 @@ async function bufferStream(stream: Readable): Promise<Buffer> {
|
|
|
11
20
|
});
|
|
12
21
|
}
|
|
13
22
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const result = new Map<string, Buffer>();
|
|
21
|
-
|
|
22
|
-
zipfile.once('close', () => resolve(result));
|
|
23
|
-
|
|
24
|
-
zipfile.readEntry();
|
|
25
|
-
zipfile.on('entry', (entry: Entry) => {
|
|
26
|
-
const name = entry.fileName.toLowerCase();
|
|
27
|
-
|
|
23
|
+
async function readZip(packagePath: string, filter: (name: string) => boolean): Promise<Map<string, Buffer>> {
|
|
24
|
+
const result = new Map<string, Buffer>();
|
|
25
|
+
const zipfile = await yauzl.open(packagePath);
|
|
26
|
+
try {
|
|
27
|
+
for await (const entry of zipfile) {
|
|
28
|
+
const name = entry.filename.toLowerCase();
|
|
28
29
|
if (filter(name)) {
|
|
29
|
-
zipfile.openReadStream(entry
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return reject(err);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
bufferStream(stream).then(buffer => {
|
|
36
|
-
result.set(name, buffer);
|
|
37
|
-
zipfile.readEntry();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
zipfile.readEntry();
|
|
30
|
+
const stream = await zipfile.openReadStream(entry);
|
|
31
|
+
const buffer = await bufferStream(stream);
|
|
32
|
+
result.set(name, buffer);
|
|
42
33
|
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
34
|
+
}
|
|
35
|
+
} finally {
|
|
36
|
+
await zipfile.close();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return result;
|
|
45
40
|
}
|
|
46
41
|
|
|
47
42
|
export async function readVSIXPackage(packagePath: string): Promise<Manifest> {
|
|
@@ -51,5 +46,5 @@ export async function readVSIXPackage(packagePath: string): Promise<Manifest> {
|
|
|
51
46
|
throw new Error('Manifest not found.');
|
|
52
47
|
}
|
|
53
48
|
|
|
54
|
-
|
|
49
|
+
return JSON.parse(rawManifest.toString('utf8')) as Manifest;
|
|
55
50
|
}
|