Skip to content

Commit 0313fd1

Browse files
committed
chore: package.json validation in zip
1 parent df63cf7 commit 0313fd1

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/api/publishGithubRelease.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,30 @@ function _validateGitHubReleaseAssets(githubReleaseDetails, issueMessages) {
151151
async function _downloadAndValidateExtensionZip(githubReleaseTag, extensionZipAsset, issueMessages) {
152152
const targetPath = `${EXTENSION_DOWNLOAD_DIR}/${githubReleaseTag.owner}_${githubReleaseTag.repo}_${githubReleaseTag.tag}_${extensionZipAsset.name}`;
153153
await downloader.downloadFile(extensionZipAsset.browser_download_url, targetPath);
154-
const {packageJSON, error} = await ZipUtils.getExtensionPackageJSON(targetPath);
154+
let {packageJSON, error} = await ZipUtils.getExtensionPackageJSON(targetPath);
155155
if(error) {
156156
issueMessages.push(error);
157157
throw {status: HTTP_STATUS_CODES.BAD_REQUEST,
158158
updatePublishErrors: true,
159159
error};
160160
}
161+
let requiredParams = ["name", "title", "description", "homepage", "version", "author", "license"];
162+
let missingParams = [];
163+
for(let param of requiredParams){
164+
if(!packageJSON[param]){
165+
missingParams.push(param);
166+
}
167+
}
168+
if(!packageJSON?.engines?.brackets){
169+
missingParams.push(`"engines":{"brackets":<version Eg. ">=0.34.0"}>`);
170+
}
171+
if(missingParams.length){
172+
error = "Required parameters missing in package.json: " + missingParams;
173+
issueMessages.push(error);
174+
throw {status: HTTP_STATUS_CODES.BAD_REQUEST,
175+
updatePublishErrors: true,
176+
error};
177+
}
161178
return targetPath;
162179
}
163180

test/unit/data/packagejson.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,47 @@ export const VALID_PACKAGE_JSON = {
1818
"brackets": ">=0.34.0"
1919
}
2020
};
21+
22+
export const REGISTRY_PACKAGE_JSON = {
23+
"metadata": {
24+
"name": "angular.moduler",
25+
"title": "Angular Module generator",
26+
"description": "Generate an angular module. Conforms with Angular Style Guide of John Papa",
27+
"homepage": "https://github.com/louiealmeda/brackets-angular-moduler",
28+
"version": "0.0.1",
29+
"author": {
30+
"name": "Louie Almeda"
31+
},
32+
"license": "MIT",
33+
"categories": "",
34+
"keywords": [
35+
"angular", "module", "generate"
36+
],
37+
"files": [
38+
"main.js",
39+
"README.md"
40+
],
41+
"engines": {
42+
"brackets": ">=0.34.0"
43+
}
44+
},
45+
"owner": "github:louiealmeda",
46+
"versions": [
47+
{
48+
"version": "0.0.1",
49+
"published": "2016-10-06T05:48:09.634Z",
50+
"brackets": ">=0.34.0",
51+
"downloads": 9189
52+
}
53+
],
54+
"totalDownloads": 9189,
55+
"recent": {
56+
"20180905": 2,
57+
"20180906": 5,
58+
"20180907": 5,
59+
"20180908": 5,
60+
"20180909": 103,
61+
"20180910": 85,
62+
"20180911": 10
63+
}
64+
};

0 commit comments

Comments
 (0)