kopia lustrzana https://github.com/c9/core
Validate package name only contains valid characters. Unblacklist publish test as it works now
rodzic
5c264663da
commit
ef86a4f4bc
|
@ -108,6 +108,8 @@
|
|||
"c9.ide.save": "#e00549cb0f",
|
||||
"c9.ide.scm": "#38d2b48b31",
|
||||
"c9.ide.terminal.monitor": "#b76f1c9f24",
|
||||
"c9.ide.test": "#d312a01ac6",
|
||||
"c9.ide.test.mocha": "#79ff886c04",
|
||||
"c9.ide.theme.flat": "#2de8414db7",
|
||||
"c9.ide.threewaymerge": "#229382aa0b",
|
||||
"c9.ide.undo": "#b028bcb4d5",
|
||||
|
|
|
@ -108,7 +108,7 @@ define(function(require, exports, module) {
|
|||
process.exit(1);
|
||||
}
|
||||
else if (!dryRun) {
|
||||
console.log("Succesfully published version", data.version);
|
||||
console.log("Successfully published version", data.version);
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
|
@ -194,7 +194,7 @@ define(function(require, exports, module) {
|
|||
process.exit(1);
|
||||
}
|
||||
else {
|
||||
console.log("Succesfully disabled package");
|
||||
console.log("Successfully disabled package");
|
||||
process.exit(0);
|
||||
}
|
||||
});
|
||||
|
@ -234,6 +234,29 @@ define(function(require, exports, module) {
|
|||
return (verbose ? JSON.stringify(err, 4, " ") : (typeof err == "string" ? err : err.message));
|
||||
}
|
||||
|
||||
function validateConfig(json) {
|
||||
var cwd = process.cwd();
|
||||
|
||||
// Basic Validation
|
||||
if (json.private)
|
||||
return new Error("ERROR: Private flag in package.json prevents from publishing");
|
||||
if (!json.name)
|
||||
return new Error("ERROR: Missing name property in package.json");
|
||||
if (!json.name.match(/^[\w\._]+$/))
|
||||
return new Error("ERROR: Package name can only contain Alphanumeric characters, periods and underscores");
|
||||
if (basename(cwd) != json.name) {
|
||||
console.warn("WARNING: The name property in package.json is not equal to the directory name, which is " + basename(cwd));
|
||||
if (!force)
|
||||
return new Error("Use --force to ignore this warning.");
|
||||
}
|
||||
if (!json.repository)
|
||||
return new Error("ERROR: Missing repository property in package.json");
|
||||
if (!json.repository.url)
|
||||
return new Error("ERROR: Missing repository.url property in package.json");
|
||||
if (!json.categories || json.categories.length == 0)
|
||||
return new Error("ERROR: At least one category is required in package.json");
|
||||
}
|
||||
|
||||
function publish(options, callback) {
|
||||
if (typeof options != "object")
|
||||
options = {version: options};
|
||||
|
@ -250,22 +273,8 @@ define(function(require, exports, module) {
|
|||
return callback(new Error("ERROR: Could not parse package.json: ", e.message));
|
||||
}
|
||||
|
||||
// Basic Validation
|
||||
if (json.private)
|
||||
return callback(new Error("ERROR: Private flag in package.json prevents from publishing"));
|
||||
if (!json.name)
|
||||
return callback(new Error("ERROR: Missing name property in package.json"));
|
||||
if (basename(cwd) != json.name) {
|
||||
console.warn("WARNING: The name property in package.json is not equal to the directory name, which is " + basename(cwd));
|
||||
if (!force)
|
||||
return callback(new Error("Use --force to ignore this warning."));
|
||||
}
|
||||
if (!json.repository)
|
||||
return callback(new Error("ERROR: Missing repository property in package.json"));
|
||||
if (!json.repository.url)
|
||||
return callback(new Error("ERROR: Missing repository.url property in package.json"));
|
||||
if (!json.categories || json.categories.length == 0)
|
||||
return callback(new Error("ERROR: At least one category is required in package.json"));
|
||||
var validationError = validateConfig(json);
|
||||
if (validationError) return callback(validationError);
|
||||
|
||||
var description = json.description;
|
||||
|
||||
|
@ -694,9 +703,10 @@ define(function(require, exports, module) {
|
|||
pricing: json.pricing || {}
|
||||
}
|
||||
}, function(err, pkg){
|
||||
if (err)
|
||||
if (err) {
|
||||
return callback(new Error("ERROR: Failed to upload new package to API - "
|
||||
+ stringifyError(err)));
|
||||
}
|
||||
|
||||
next(pkg);
|
||||
});
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
"use strict";
|
||||
"use server";
|
||||
|
||||
"use blacklist";
|
||||
|
||||
require("c9/inline-mocha")(module);
|
||||
|
||||
if (typeof define === "undefined") {
|
||||
|
@ -116,6 +114,13 @@ describe("cli.publish", function(){
|
|||
done();
|
||||
});
|
||||
});
|
||||
it("should fail if the name in the package.json contains invalid characters", function(done){
|
||||
fs.writeFileSync(packagePath, packageJson.replace('c9.ide.example', 'c9-ide-example'));
|
||||
runCLI("publish", ["major"], function(err, stdout, stderr){
|
||||
expect(stderr).to.match(/ERROR: Package name can only contain/);
|
||||
done();
|
||||
});
|
||||
});
|
||||
it("should fail if the name in the package.json is not equal to the directory", function(done){
|
||||
fs.writeFileSync(packagePath, packageJson.replace('"name": "c9.ide.example"', '"name": "wrongname"'));
|
||||
runCLI("publish", ["major"], function(err, stdout, stderr){
|
||||
|
|
Ładowanie…
Reference in New Issue