Skip to content

Commit

Permalink
Remember loaded files earlier to prevent race conditions, fixes #501
Browse files Browse the repository at this point in the history
  • Loading branch information
dcodeIO committed Nov 29, 2016
1 parent 4012a00 commit 3c16e46
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 19 deletions.
21 changes: 11 additions & 10 deletions dist/protobuf.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/protobuf.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions dist/protobuf.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf.min.js.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion dist/protobuf.min.js.map

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions src/root.js
Expand Up @@ -80,12 +80,10 @@ RootPrototype.load = function load(filename, callback) {
try {
if (util.isString(source) && source.charAt(0) === "{")
source = JSON.parse(source);
if (!util.isString(source)) {
if (!util.isString(source))
self.setOptions(source.options).addJSON(source.nested);
self.files.push(filename);
} else {
else {
var parsed = require("./parse")(source, self);
self.files.push(filename);
if (parsed.imports)
parsed.imports.forEach(function(name) {
fetch(self.resolvePath(filename, name));
Expand Down Expand Up @@ -117,6 +115,7 @@ RootPrototype.load = function load(filename, callback) {
// Skip if already loaded
if (self.files.indexOf(filename) > -1)
return;
self.files.push(filename);

// Shortcut bundled definitions
if (filename in common) {
Expand Down
3 changes: 3 additions & 0 deletions tests/data/common.proto
Expand Up @@ -5,3 +5,6 @@ import "google/protobuf/duration.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/timestamp.proto";

message Something {
}
1 change: 1 addition & 0 deletions tests/data/file1.proto
@@ -0,0 +1 @@
import "common.proto";
1 change: 1 addition & 0 deletions tests/data/file2.proto
@@ -0,0 +1 @@
import "common.proto";

0 comments on commit 3c16e46

Please sign in to comment.