1 | "use strict";
|
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3 | if (k2 === undefined) k2 = k;
|
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5 | }) : (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | o[k2] = m[k];
|
8 | }));
|
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
11 | }) : function(o, v) {
|
12 | o["default"] = v;
|
13 | });
|
14 | var __importStar = (this && this.__importStar) || function (mod) {
|
15 | if (mod && mod.__esModule) return mod;
|
16 | var result = {};
|
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
18 | __setModuleDefault(result, mod);
|
19 | return result;
|
20 | };
|
21 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
22 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
23 | };
|
24 | Object.defineProperty(exports, "__esModule", { value: true });
|
25 | exports.validateVSCodeTypesCompatibility = exports.validateEngineCompatibility = exports.validateVersion = exports.validateExtensionName = exports.validatePublisher = void 0;
|
26 | const semver = __importStar(require("semver"));
|
27 | const parse_semver_1 = __importDefault(require("parse-semver"));
|
28 | const nameRegex = /^[a-z0-9][a-z0-9\-]*$/i;
|
29 | function validatePublisher(publisher) {
|
30 | if (!publisher) {
|
31 | throw new Error(`Missing publisher name. Learn more: https://code.visualstudio.com/api/working-with-extensions/publishing-extension#publishing-extensions`);
|
32 | }
|
33 | if (!nameRegex.test(publisher)) {
|
34 | throw new Error(`Invalid publisher name '${publisher}'. Expected the identifier of a publisher, not its human-friendly name. Learn more: https://code.visualstudio.com/api/working-with-extensions/publishing-extension#publishing-extensions`);
|
35 | }
|
36 | }
|
37 | exports.validatePublisher = validatePublisher;
|
38 | function validateExtensionName(name) {
|
39 | if (!name) {
|
40 | throw new Error(`Missing extension name`);
|
41 | }
|
42 | if (!nameRegex.test(name)) {
|
43 | throw new Error(`Invalid extension name '${name}'`);
|
44 | }
|
45 | }
|
46 | exports.validateExtensionName = validateExtensionName;
|
47 | function validateVersion(version) {
|
48 | if (!version) {
|
49 | throw new Error(`Missing extension version`);
|
50 | }
|
51 | if (!semver.valid(version)) {
|
52 | throw new Error(`Invalid extension version '${version}'`);
|
53 | }
|
54 | }
|
55 | exports.validateVersion = validateVersion;
|
56 | function validateEngineCompatibility(version) {
|
57 | if (!version) {
|
58 | throw new Error(`Missing vscode engine compatibility version`);
|
59 | }
|
60 | if (!/^\*$|^(\^|>=)?((\d+)|x)\.((\d+)|x)\.((\d+)|x)(\-.*)?$/.test(version)) {
|
61 | throw new Error(`Invalid vscode engine compatibility version '${version}'`);
|
62 | }
|
63 | }
|
64 | exports.validateEngineCompatibility = validateEngineCompatibility;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 | function validateVSCodeTypesCompatibility(engineVersion, typeVersion) {
|
72 | if (engineVersion === '*') {
|
73 | return;
|
74 | }
|
75 | if (!typeVersion) {
|
76 | throw new Error(`Missing @types/vscode version`);
|
77 | }
|
78 | let plainEngineVersion, plainTypeVersion;
|
79 | try {
|
80 | const engineSemver = (0, parse_semver_1.default)(`vscode@${engineVersion}`);
|
81 | plainEngineVersion = engineSemver.version;
|
82 | }
|
83 | catch (err) {
|
84 | throw new Error('Failed to parse semver of engines.vscode');
|
85 | }
|
86 | try {
|
87 | const typeSemver = (0, parse_semver_1.default)(`@types/vscode@${typeVersion}`);
|
88 | plainTypeVersion = typeSemver.version;
|
89 | }
|
90 | catch (err) {
|
91 | throw new Error('Failed to parse semver of @types/vscode');
|
92 | }
|
93 |
|
94 | plainEngineVersion = plainEngineVersion.replace(/x/g, '0');
|
95 | const [typeMajor, typeMinor] = plainTypeVersion.split('.').map(x => {
|
96 | try {
|
97 | return parseInt(x);
|
98 | }
|
99 | catch (err) {
|
100 | return 0;
|
101 | }
|
102 | });
|
103 | const [engineMajor, engineMinor] = plainEngineVersion.split('.').map(x => {
|
104 | try {
|
105 | return parseInt(x);
|
106 | }
|
107 | catch (err) {
|
108 | return 0;
|
109 | }
|
110 | });
|
111 | const error = new Error(`@types/vscode ${typeVersion} greater than engines.vscode ${engineVersion}. Consider upgrade engines.vscode or use an older @types/vscode version`);
|
112 | if (typeMajor > engineMajor) {
|
113 | throw error;
|
114 | }
|
115 | if (typeMajor === engineMajor && typeMinor > engineMinor) {
|
116 | throw error;
|
117 | }
|
118 | }
|
119 | exports.validateVSCodeTypesCompatibility = validateVSCodeTypesCompatibility;
|
120 |
|
\ | No newline at end of file |