Skip to content

Commit 3a05624

Browse files
committed
CLI: Reuse specified root name in pbjs to be able to split definitions over multiple files more easily, see #653
1 parent 301f776 commit 3a05624

File tree

13 files changed

+20
-21
lines changed

13 files changed

+20
-21
lines changed

.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"typescript.tsdk": "./node_modules/typescript/lib"
2+
"typescript.tsdk": "./node_modules/typescript/lib",
3+
"vsicons.presets.angular": false
34
}

cli/targets/static.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ function static_target(root, options, callback) {
3939
else
4040
push("// Exported root namespace");
4141
}
42-
push("var $root = {};");
42+
var rootName = config.root || "default";
43+
push("var $root = $protobuf.roots[" + JSON.stringify(rootName) + "] || ($protobuf.roots[" + JSON.stringify(rootName) + "] = {});");
4344
buildNamespace(null, root);
4445
push("");
4546
if (config.comments)

cli/util.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ exports.wrap = function(OUTPUT, options) {
124124
// otherwise fetch the custom one
125125
wrap = fs.readFileSync(path.resolve(process.cwd(), name)).toString("utf8");
126126
}
127-
wrap = wrap.replace(/%ROOT%/g, JSON.stringify(options.root || "default"));
128127
wrap = wrap.replace(/%DEPENDENCY%/g, JSON.stringify(options.dependency || "protobufjs"));
129128
wrap = wrap.replace(/( *)%OUTPUT%/, function($0, $1) {
130129
return $1.length ? OUTPUT.replace(/^/mg, $1) : OUTPUT;

cli/wrappers/amd.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ define(["protobuf"], function($protobuf) {
33

44
%OUTPUT%
55

6-
return $protobuf.roots[%ROOT%] = $root;
6+
return $root;
77
});

cli/wrappers/commonjs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ var $protobuf = require(%DEPENDENCY%);
44

55
%OUTPUT%
66

7-
module.exports = $protobuf.roots[%ROOT%] = $root;
7+
module.exports = $root;

cli/wrappers/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111

1212
%OUTPUT%
1313

14-
return $protobuf.roots[%ROOT%] = $root;
14+
return $root;
1515
});

cli/wrappers/es6.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ import * as $protobuf from "protobufjs";
22

33
%OUTPUT%
44

5-
$protobuf.roots[%ROOT%] = $root;
6-
75
export { $root as default };

tests/data/comments.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
1212
var $lazyTypes = [];
1313

1414
// Exported root namespace
15-
var $root = {};
15+
var $root = $protobuf.roots["test_comments"] || ($protobuf.roots["test_comments"] = {});
1616

1717
$root.Test1 = (function() {
1818

@@ -47,7 +47,7 @@ $root.Test1 = (function() {
4747
Test1.prototype.field2 = 0;
4848

4949
/**
50-
* Field with a comment.
50+
* Field with a comment and a <a href="http://example.com/foo/">link</a>
5151
* @type {boolean}
5252
*/
5353
Test1.prototype.field3 = false;
@@ -377,4 +377,4 @@ $root.Test3 = (function() {
377377
// Resolve lazy type references to actual types
378378
$util.lazyResolve($root, $lazyTypes);
379379

380-
module.exports = $protobuf.roots["test_comments"] = $root;
380+
module.exports = $root;

tests/data/convert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
1212
var $lazyTypes = [];
1313

1414
// Exported root namespace
15-
var $root = {};
15+
var $root = $protobuf.roots["test_convert"] || ($protobuf.roots["test_convert"] = {});
1616

1717
$root.Message = (function() {
1818

@@ -520,4 +520,4 @@ $root.Message = (function() {
520520
// Resolve lazy type references to actual types
521521
$util.lazyResolve($root, $lazyTypes);
522522

523-
module.exports = $protobuf.roots["test_convert"] = $root;
523+
module.exports = $root;

tests/data/mapbox/vector_tile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
1212
var $lazyTypes = [];
1313

1414
// Exported root namespace
15-
var $root = {};
15+
var $root = $protobuf.roots["test_vector_tile"] || ($protobuf.roots["test_vector_tile"] = {});
1616

1717
$root.vector_tile = (function() {
1818

@@ -1182,4 +1182,4 @@ $root.vector_tile = (function() {
11821182
// Resolve lazy type references to actual types
11831183
$util.lazyResolve($root, $lazyTypes);
11841184

1185-
module.exports = $protobuf.roots["test_vector_tile"] = $root;
1185+
module.exports = $root;

0 commit comments

Comments
 (0)