ovsx 0.5.1 → 0.6.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/src/util.ts CHANGED
@@ -68,7 +68,7 @@ export function createTempFile(options: tmp.TmpNameOptions): Promise<string> {
68
68
  });
69
69
  }
70
70
 
71
- export function handleError(debug?: boolean, additionalMessage?: string): (reason: any) => void {
71
+ export function handleError(debug?: boolean, additionalMessage?: string, exit: boolean = true): (reason: any) => void {
72
72
  return reason => {
73
73
  if (reason instanceof Error && !debug) {
74
74
  console.error(`\u274c ${reason.message}`);
@@ -82,7 +82,10 @@ export function handleError(debug?: boolean, additionalMessage?: string): (reaso
82
82
  } else {
83
83
  console.error('An unknown error occurred.');
84
84
  }
85
- process.exit(1);
85
+
86
+ if (exit) {
87
+ process.exit(1);
88
+ }
86
89
  };
87
90
  }
88
91
 
@@ -0,0 +1,52 @@
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 { Registry, RegistryOptions } from './registry';
12
+ import { readManifest, addEnvOptions } from './util';
13
+
14
+ /**
15
+ * Validates that a Personal Access Token can publish to a namespace.
16
+ */
17
+ export async function verifyPat(options: VerifyPatOptions): Promise<void> {
18
+ addEnvOptions(options);
19
+ if (!options.pat) {
20
+ throw new Error("A personal access token must be given with the option '--pat'.");
21
+ }
22
+
23
+ if (!options.namespace) {
24
+ let error;
25
+ try {
26
+ options.namespace = (await readManifest()).publisher;
27
+ } catch (e) {
28
+ error = e;
29
+ }
30
+
31
+ if (!options.namespace) {
32
+ throw new Error(
33
+ `Unable to read the namespace's name. Please supply it as an argument or run ovsx from the extension folder.` +
34
+ (error ? `\n\n${error}` : '')
35
+ );
36
+ }
37
+ }
38
+
39
+ const registry = new Registry(options);
40
+ const result = await registry.verifyPat(options.namespace, options.pat);
41
+ if (result.error) {
42
+ throw new Error(result.error);
43
+ }
44
+ console.log(`\ud83d\ude80 PAT valid to publish at ${options.namespace}`);
45
+ }
46
+
47
+ export interface VerifyPatOptions extends RegistryOptions {
48
+ /**
49
+ * Name of the namespace.
50
+ */
51
+ namespace?: string
52
+ }