Skip to content

Commit 9883a96

Browse files
author
Taylor McIntyre
committed
support resolving protobufjs as peer or local dependency everywhere in the cli package
1 parent e5a3b0b commit 9883a96

File tree

9 files changed

+36
-27
lines changed

9 files changed

+36
-27
lines changed

cli/pbjs.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"use strict";
22
var path = require("path"),
33
fs = require("fs"),
4-
pkg = require("./package.json"),
5-
util = require("./util");
6-
7-
var protobuf = require(util.pathToProtobufJs),
84
minimist = require("minimist"),
95
chalk = require("chalk"),
10-
glob = require("glob");
6+
glob = require("glob"),
7+
pkg = require("./package.json"),
8+
util = require("./util"),
9+
peerdepPaths = require("./peerdep-paths");
10+
11+
var protobuf = require(peerdepPaths.pathToProtobufJs);
1112

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

cli/peerdep-paths.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
try {
3+
// installed as a peer dependency
4+
require.resolve("protobufjs");
5+
exports.pathToProtobufJs = "protobufjs";
6+
} catch (e) {
7+
// local development, i.e. forked from github
8+
exports.pathToProtobufJs = "..";
9+
}

cli/targets/json-module.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = json_module;
33

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

6-
var protobuf = require("../..");
6+
var peerdepPaths = require("../peerdep-paths");
7+
var protobuf = require(peerdepPaths.pathToProtobufJs);
78

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

cli/targets/proto.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ module.exports = proto_target;
33

44
proto_target.private = true;
55

6-
var protobuf = require("../..");
6+
var peerdepPaths = require("../peerdep-paths");
7+
var protobuf = require(peerdepPaths.pathToProtobufJs);
78

89
var Namespace = protobuf.Namespace,
910
Enum = protobuf.Enum,

cli/targets/proto2.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"use strict";
22
module.exports = proto2_target;
33

4-
var protobuf = require("../..");
4+
var peerdepPaths = require("../peerdep-paths");
5+
var protobuf = require(peerdepPaths.pathToProtobufJs);
56

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

cli/targets/proto3.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
"use strict";
22
module.exports = proto3_target;
33

4-
var protobuf = require("../..");
4+
var peerdepPaths = require("../peerdep-paths");
5+
var protobuf = require(peerdepPaths.pathToProtobufJs);
56

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

cli/targets/static-module.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ module.exports = static_module_target;
66
// - CommonJS modules depend on the minimal build for reduced package size with browserify.
77
// - AMD and global scope depend on the full library for now.
88

9-
var util = require("../util");
9+
var util = require("../util"),
10+
peerdepPaths = require("../peerdep-paths");
1011

11-
var protobuf = require("../..");
12+
var protobuf = require(peerdepPaths.pathToProtobufJs);
1213

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

cli/targets/static.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
"use strict";
22
module.exports = static_target;
33

4-
var protobuf = require("../.."),
5-
UglifyJS = require("uglify-js"),
6-
espree = require("espree"),
7-
escodegen = require("escodegen"),
8-
estraverse = require("estraverse");
4+
var UglifyJS = require("uglify-js"),
5+
espree = require("espree"),
6+
escodegen = require("escodegen"),
7+
estraverse = require("estraverse"),
8+
peerdepPaths = require("../peerdep-paths");
9+
10+
var protobuf = require(peerdepPaths.pathToProtobufJs);
911

1012
var Type = protobuf.Type,
1113
Service = protobuf.Service,

cli/util.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,9 @@
11
"use strict";
22
var fs = require("fs"),
3-
path = require("path");
3+
path = require("path"),
4+
peerdepPaths = require("./peerdep-paths");
45

5-
try {
6-
// installed as a peer dependency
7-
require.resolve("protobufjs");
8-
exports.pathToProtobufJs = "protobufjs";
9-
} catch (e) {
10-
// local development, i.e. forked from github
11-
exports.pathToProtobufJs = "..";
12-
}
13-
14-
var protobuf = require(exports.pathToProtobufJs);
6+
var protobuf = require(peerdepPaths.pathToProtobufJs);
157

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

0 commit comments

Comments
 (0)