Skip to content

Commit

Permalink
support resolving protobufjs as peer or local dependency everywhere i…
Browse files Browse the repository at this point in the history
…n the cli package
  • Loading branch information
taylorcode committed Jun 1, 2019
1 parent e5a3b0b commit ad99d66
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 25 deletions.
8 changes: 5 additions & 3 deletions cli/pbjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
var path = require("path"),
fs = require("fs"),
pkg = require("./package.json"),
util = require("./util");
util = require("./util"),
peerdepPaths = require("./peerdep-paths");

var protobuf = require(util.pathToProtobufJs),
minimist = require("minimist"),
var minimist = require("minimist"),
chalk = require("chalk"),
glob = require("glob");

var protobuf = require(peerdepPaths.pathToProtobufJs);

var targets = util.requireAll("./targets");

/**
Expand Down
9 changes: 9 additions & 0 deletions cli/peerdep-paths.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

try {
// installed as a peer dependency
require.resolve("protobufjs");
exports.pathToProtobufJs = "protobufjs";
} catch (e) {
// local development, i.e. forked from github
exports.pathToProtobufJs = "..";
}
3 changes: 2 additions & 1 deletion cli/targets/json-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = json_module;

var util = require("../util");

var protobuf = require("../..");
var peerdepPaths = require("../peerdep-paths");
var protobuf = require(peerdepPaths.pathToProtobufJs);

json_module.description = "JSON representation as a module";

Expand Down
3 changes: 2 additions & 1 deletion cli/targets/proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module.exports = proto_target;

proto_target.private = true;

var protobuf = require("../..");
var peerdepPaths = require("../peerdep-paths");
var protobuf = require(peerdepPaths.pathToProtobufJs);

var Namespace = protobuf.Namespace,
Enum = protobuf.Enum,
Expand Down
3 changes: 2 additions & 1 deletion cli/targets/proto2.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use strict";
module.exports = proto2_target;

var protobuf = require("../..");
var peerdepPaths = require("../peerdep-paths");
var protobuf = require(peerdepPaths.pathToProtobufJs);

proto2_target.description = "Protocol Buffers, Version 2";

Expand Down
3 changes: 2 additions & 1 deletion cli/targets/proto3.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
"use strict";
module.exports = proto3_target;

var protobuf = require("../..");
var peerdepPaths = require("../peerdep-paths");
var protobuf = require(peerdepPaths.pathToProtobufJs);

proto3_target.description = "Protocol Buffers, Version 3";

Expand Down
5 changes: 3 additions & 2 deletions cli/targets/static-module.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ module.exports = static_module_target;
// - CommonJS modules depend on the minimal build for reduced package size with browserify.
// - AMD and global scope depend on the full library for now.

var util = require("../util");
var util = require("../util"),
peerdepPaths = require("../peerdep-paths");

var protobuf = require("../..");
var protobuf = require(peerdepPaths.pathToProtobufJs);

static_module_target.description = "Static code without reflection as a module";

Expand Down
12 changes: 7 additions & 5 deletions cli/targets/static.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"use strict";
module.exports = static_target;

var protobuf = require("../.."),
UglifyJS = require("uglify-js"),
espree = require("espree"),
escodegen = require("escodegen"),
estraverse = require("estraverse");
var UglifyJS = require("uglify-js"),
espree = require("espree"),
escodegen = require("escodegen"),
estraverse = require("estraverse"),
peerdepPaths = require("../peerdep-paths");

var protobuf = require(peerdepPaths.pathToProtobufJs);

var Type = protobuf.Type,
Service = protobuf.Service,
Expand Down
14 changes: 3 additions & 11 deletions cli/util.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
"use strict";
var fs = require("fs"),
path = require("path");
path = require("path"),
peerdepPaths = require("./peerdep-paths");

try {
// installed as a peer dependency
require.resolve("protobufjs");
exports.pathToProtobufJs = "protobufjs";
} catch (e) {
// local development, i.e. forked from github
exports.pathToProtobufJs = "..";
}

var protobuf = require(exports.pathToProtobufJs);
var protobuf = require(peerdepPaths.pathToProtobufJs);

function basenameCompare(a, b) {
var aa = String(a).replace(/\.\w+$/, "").split(/(-?\d*\.?\d+)/g),
Expand Down

0 comments on commit ad99d66

Please sign in to comment.