Skip to content

Commit

Permalink
CLI: Reuse specified root name in pbjs to be able to split definition…
Browse files Browse the repository at this point in the history
…s over multiple files more easily, see #653
  • Loading branch information
dcodeIO committed Jan 24, 2017
1 parent 301f776 commit 3a05624
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"typescript.tsdk": "./node_modules/typescript/lib"
"typescript.tsdk": "./node_modules/typescript/lib",
"vsicons.presets.angular": false
}
3 changes: 2 additions & 1 deletion cli/targets/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ function static_target(root, options, callback) {
else
push("// Exported root namespace");
}
push("var $root = {};");
var rootName = config.root || "default";
push("var $root = $protobuf.roots[" + JSON.stringify(rootName) + "] || ($protobuf.roots[" + JSON.stringify(rootName) + "] = {});");
buildNamespace(null, root);
push("");
if (config.comments)
Expand Down
1 change: 0 additions & 1 deletion cli/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ exports.wrap = function(OUTPUT, options) {
// otherwise fetch the custom one
wrap = fs.readFileSync(path.resolve(process.cwd(), name)).toString("utf8");
}
wrap = wrap.replace(/%ROOT%/g, JSON.stringify(options.root || "default"));
wrap = wrap.replace(/%DEPENDENCY%/g, JSON.stringify(options.dependency || "protobufjs"));
wrap = wrap.replace(/( *)%OUTPUT%/, function($0, $1) {
return $1.length ? OUTPUT.replace(/^/mg, $1) : OUTPUT;
Expand Down
2 changes: 1 addition & 1 deletion cli/wrappers/amd.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ define(["protobuf"], function($protobuf) {

%OUTPUT%

return $protobuf.roots[%ROOT%] = $root;
return $root;
});
2 changes: 1 addition & 1 deletion cli/wrappers/commonjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ var $protobuf = require(%DEPENDENCY%);

%OUTPUT%

module.exports = $protobuf.roots[%ROOT%] = $root;
module.exports = $root;
2 changes: 1 addition & 1 deletion cli/wrappers/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

%OUTPUT%

return $protobuf.roots[%ROOT%] = $root;
return $root;
});
2 changes: 0 additions & 2 deletions cli/wrappers/es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ import * as $protobuf from "protobufjs";

%OUTPUT%

$protobuf.roots[%ROOT%] = $root;

export { $root as default };
6 changes: 3 additions & 3 deletions tests/data/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
var $lazyTypes = [];

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

$root.Test1 = (function() {

Expand Down Expand Up @@ -47,7 +47,7 @@ $root.Test1 = (function() {
Test1.prototype.field2 = 0;

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

module.exports = $protobuf.roots["test_comments"] = $root;
module.exports = $root;
4 changes: 2 additions & 2 deletions tests/data/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
var $lazyTypes = [];

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

$root.Message = (function() {

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

module.exports = $protobuf.roots["test_convert"] = $root;
module.exports = $root;
4 changes: 2 additions & 2 deletions tests/data/mapbox/vector_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
var $lazyTypes = [];

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

$root.vector_tile = (function() {

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

module.exports = $protobuf.roots["test_vector_tile"] = $root;
module.exports = $root;
4 changes: 2 additions & 2 deletions tests/data/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
var $lazyTypes = [];

// Exported root namespace
var $root = {};
var $root = $protobuf.roots["test_package"] || ($protobuf.roots["test_package"] = {});

$root.Package = (function() {

Expand Down Expand Up @@ -824,4 +824,4 @@ $root.Package = (function() {
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);

module.exports = $protobuf.roots["test_package"] = $root;
module.exports = $root;
4 changes: 2 additions & 2 deletions tests/data/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
var $lazyTypes = [];

// Exported root namespace
var $root = {};
var $root = $protobuf.roots["test_rpc"] || ($protobuf.roots["test_rpc"] = {});

$root.MyService = (function() {

Expand Down Expand Up @@ -399,4 +399,4 @@ $root.MyResponse = (function() {
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);

module.exports = $protobuf.roots["test_rpc"] = $root;
module.exports = $root;
4 changes: 2 additions & 2 deletions tests/data/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var $Reader = $protobuf.Reader,
var $lazyTypes = [];

// Exported root namespace
var $root = {};
var $root = $protobuf.roots["test_test"] || ($protobuf.roots["test_test"] = {});

$root.jspb = (function() {

Expand Down Expand Up @@ -14121,4 +14121,4 @@ $root.google = (function() {
// Resolve lazy type references to actual types
$util.lazyResolve($root, $lazyTypes);

module.exports = $protobuf.roots["test_test"] = $root;
module.exports = $root;

0 comments on commit 3a05624

Please sign in to comment.