Skip to content

Commit

Permalink
Other: Added version scheme warning to everything CLI so that we don'…
Browse files Browse the repository at this point in the history
…t need this overly explicit in README
  • Loading branch information
dcodeIO committed Jan 18, 2017
1 parent afef1e6 commit cbaaae9
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 10 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ Usage
$> npm install protobufjs [--save --save-prefix=~]
```

**Note:** protobuf.js uses a [semver](https://semver.org)-incompatible versioning scheme currently. For API compatibility, just prefix its version with a `~` instead of a `^` in your package.json's dependencies. If you want to access the semver website, just prefix its address with `http:` instead of `https:`.

```js
var protobuf = require("protobufjs");
```
Expand Down
1 change: 1 addition & 0 deletions cli/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ exports.setup = function() {
install.push(name + "@" + version);
}
});
require("../scripts/postinstall"); // emit postinstall warning, if any
if (!install.length)
return;
modInstall(install);
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "protobufjs",
"version": "6.5.1",
"versionScheme": "~",
"description": "Protocol Buffers for JavaScript (& TypeScript).",
"author": "Daniel Wirtz <[email protected]>",
"license": "BSD-3-Clause",
Expand Down Expand Up @@ -33,6 +34,7 @@
"lint": "eslint src runtime",
"pages": "node scripts/pages",
"prepublish": "node scripts/prepublish",
"postinstall": "node scripts/postinstall",
"prof": "node bench/prof",
"test": "tape -r ./lib/tape-adapter tests/*.js tests/node/*.js | tap-spec",
"types": "node bin/pbts --main --global protobuf --out index.d.ts src && tsc tests/comp_typescript.ts --lib es2015 --noEmit --strictNullChecks && tsc tests/data/test.ts --lib es2015 --noEmit --strictNullChecks",
Expand Down
30 changes: 30 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var path = require("path"),
pkg = require(path.join(__dirname, "..", "package.json"));

if (!pkg.versionScheme)
return;

var fs = require("fs");

var warn = process.stderr.isTTY
? "\x1b[30m\x1b[43mWARN\x1b[0m \x1b[35m" + path.basename(process.argv[1], ".js") + "\x1b[0m"
: "WARN " + path.basename(process.argv[1], ".js");

var basePkg;
try {
basePkg = JSON.parse(fs.readFileSync(path.join(__dirname, "..", "..", "package.json")));
} catch (e) {
return;
}

[
"dependencies",
"devDependencies",
"optionalDependencies",
"peerDependencies"
]
.forEach(function(check) {
var version = basePkg && basePkg[check] && basePkg[check][pkg.name];
if (typeof version === "string" && version.charAt(0) !== pkg.versionScheme)
process.stderr.write(pkg.name + " " + warn + " " + pkg.name + "@" + version + " is configured as a dependency of " + basePkg.name + ". use " + pkg.name + "@" + pkg.versionScheme + version.substring(1) + " instead for API compatibility.\n");
});
31 changes: 25 additions & 6 deletions tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ $root.Package = (function() {
*/
Package.prototype.version = "";

/**
* Package versionScheme.
* @type {string}
*/
Package.prototype.versionScheme = "";

/**
* Package description.
* @type {string}
Expand Down Expand Up @@ -134,7 +140,7 @@ $root.Package = (function() {

// Lazily resolved type references
var $types = {
5: "Package.Repository"
6: "Package.Repository"
}; $lazyTypes.push($types);

/**
Expand All @@ -159,14 +165,16 @@ $root.Package = (function() {
writer.uint32(/* id 1, wireType 2 =*/10).string(message.name);
if (message.version !== undefined && message.hasOwnProperty("version"))
writer.uint32(/* id 2, wireType 2 =*/18).string(message.version);
if (message.versionScheme !== undefined && message.hasOwnProperty("versionScheme"))
writer.uint32(/* id 19, wireType 2 =*/154).string(message.versionScheme);
if (message.description !== undefined && message.hasOwnProperty("description"))
writer.uint32(/* id 3, wireType 2 =*/26).string(message.description);
if (message.author !== undefined && message.hasOwnProperty("author"))
writer.uint32(/* id 4, wireType 2 =*/34).string(message.author);
if (message.license !== undefined && message.hasOwnProperty("license"))
writer.uint32(/* id 5, wireType 2 =*/42).string(message.license);
if (message.repository !== undefined && message.hasOwnProperty("repository"))
$types[5].encode(message.repository, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim();
$types[6].encode(message.repository, writer.uint32(/* id 6, wireType 2 =*/50).fork()).ldelim();
if (message.bugs !== undefined && message.hasOwnProperty("bugs"))
writer.uint32(/* id 7, wireType 2 =*/58).string(message.bugs);
if (message.homepage !== undefined && message.hasOwnProperty("homepage"))
Expand Down Expand Up @@ -228,6 +236,9 @@ $root.Package = (function() {
case 2:
message.version = reader.string();
break;
case 19:
message.versionScheme = reader.string();
break;
case 3:
message.description = reader.string();
break;
Expand All @@ -238,7 +249,7 @@ $root.Package = (function() {
message.license = reader.string();
break;
case 6:
message.repository = $types[5].decode(reader, reader.uint32());
message.repository = $types[6].decode(reader, reader.uint32());
break;
case 7:
message.bugs = reader.string();
Expand Down Expand Up @@ -333,6 +344,9 @@ $root.Package = (function() {
if (message.version !== undefined)
if (!$util.isString(message.version))
return "version: string expected";
if (message.versionScheme !== undefined)
if (!$util.isString(message.versionScheme))
return "versionScheme: string expected";
if (message.description !== undefined)
if (!$util.isString(message.description))
return "description: string expected";
Expand All @@ -343,7 +357,7 @@ $root.Package = (function() {
if (!$util.isString(message.license))
return "license: string expected";
if (message.repository !== undefined && message.repository !== null) {
var error = $types[5].verify(message.repository);
var error = $types[6].verify(message.repository);
if (error)
return "repository." + error;
}
Expand Down Expand Up @@ -427,14 +441,16 @@ $root.Package = (function() {
message.name = String(object.name);
if (object.version !== undefined && object.version !== null)
message.version = String(object.version);
if (object.versionScheme !== undefined && object.versionScheme !== null)
message.versionScheme = String(object.versionScheme);
if (object.description !== undefined && object.description !== null)
message.description = String(object.description);
if (object.author !== undefined && object.author !== null)
message.author = String(object.author);
if (object.license !== undefined && object.license !== null)
message.license = String(object.license);
if (object.repository !== undefined && object.repository !== null)
message.repository = $types[5].fromObject(object.repository);
message.repository = $types[6].fromObject(object.repository);
if (object.bugs !== undefined && object.bugs !== null)
message.bugs = String(object.bugs);
if (object.homepage !== undefined && object.homepage !== null)
Expand Down Expand Up @@ -513,6 +529,7 @@ $root.Package = (function() {
if (options.defaults) {
object.name = "";
object.version = "";
object.versionScheme = "";
object.description = "";
object.author = "";
object.license = "";
Expand All @@ -526,14 +543,16 @@ $root.Package = (function() {
object.name = message.name;
if (message.version !== undefined && message.version !== null && message.hasOwnProperty("version"))
object.version = message.version;
if (message.versionScheme !== undefined && message.versionScheme !== null && message.hasOwnProperty("versionScheme"))
object.versionScheme = message.versionScheme;
if (message.description !== undefined && message.description !== null && message.hasOwnProperty("description"))
object.description = message.description;
if (message.author !== undefined && message.author !== null && message.hasOwnProperty("author"))
object.author = message.author;
if (message.license !== undefined && message.license !== null && message.hasOwnProperty("license"))
object.license = message.license;
if (message.repository !== undefined && message.repository !== null && message.hasOwnProperty("repository"))
object.repository = $types[5].toObject(message.repository, options);
object.repository = $types[6].toObject(message.repository, options);
if (message.bugs !== undefined && message.bugs !== null && message.hasOwnProperty("bugs"))
object.bugs = message.bugs;
if (message.homepage !== undefined && message.homepage !== null && message.hasOwnProperty("homepage"))
Expand Down
1 change: 1 addition & 0 deletions tests/data/package.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
message Package {
string name = 1;
string version = 2;
string versionScheme = 19;
string description = 3;
string author = 4;
string license = 5;
Expand Down
2 changes: 0 additions & 2 deletions tests/other_package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ var tape = require("tape");
var protobuf = require(".."),
pkg = require("../package.json");

process.stdout._handle.setBlocking(true);

tape.test("package.json", function(test) {

protobuf.load("tests/data/package.proto", function(err, root) {
Expand Down

0 comments on commit cbaaae9

Please sign in to comment.