Skip to content

Commit

Permalink
enable includePath option via Builder option
Browse files Browse the repository at this point in the history
  • Loading branch information
umegaya committed Nov 2, 2016
1 parent 8d1a9bc commit 0ce8f4c
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 220 deletions.
34 changes: 22 additions & 12 deletions dist/protobuf-light.js
Original file line number Diff line number Diff line change
Expand Up @@ -3791,18 +3791,28 @@
var importFilename = json['imports'][i];
if (importFilename === "google/protobuf/descriptor.proto")
continue; // Not needed and therefore not used
importFilename = importRoot + delim + importFilename;
if (this.files[importFilename] === true)
continue; // Already imported
if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto) // If this is a light build
importFilename = importFilename.replace(/\.proto$/, ".json"); // always load the JSON file
var contents = ProtoBuf.Util.fetch(importFilename);
if (contents === null)
throw Error("failed to import '"+importFilename+"' in '"+filename+"': file not found");
if (/\.json$/i.test(importFilename)) // Always possible
this["import"](JSON.parse(contents+""), importFilename); // May throw
else
this["import"](ProtoBuf.DotProto.Parser.parse(contents), importFilename); // May throw
var tmpImportRoot = importRoot;
var tmpImportPathIndex = 0;
while (true) {
var tmpImportFilename = tmpImportRoot + delim + importFilename;
if (this.files[tmpImportFilename] === true)
break; // Already imported
if (/\.proto$/i.test(tmpImportFilename) && !ProtoBuf.DotProto) // If this is a light build
tmpImportFilename = tmpImportFilename.replace(/\.proto$/, ".json"); // always load the JSON file
var contents = ProtoBuf.Util.fetch(tmpImportFilename);
if (contents === null) {
if (this.options.includePath && this.options.includePath.length > tmpImportPathIndex) {
tmpImportRoot = this.options.includePath[tmpImportPathIndex++];
continue;
}
throw Error("failed to import '"+(importRoot + delim + importFilename)+"' in '"+filename+"': file not found");
}
if (/\.json$/i.test(tmpImportFilename)) // Always possible
this["import"](JSON.parse(contents+""), tmpImportFilename); // May throw
else
this["import"](ProtoBuf.DotProto.Parser.parse(contents), tmpImportFilename); // May throw
break;
}
} else // Import structure
if (!filename)
this["import"](json['imports'][i]);
Expand Down
164 changes: 85 additions & 79 deletions dist/protobuf-light.min.js

Large diffs are not rendered by default.

Binary file modified dist/protobuf-light.min.js.gz
Binary file not shown.
8 changes: 4 additions & 4 deletions dist/protobuf-light.min.map

Large diffs are not rendered by default.

34 changes: 22 additions & 12 deletions dist/protobuf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4703,18 +4703,28 @@
var importFilename = json['imports'][i];
if (importFilename === "google/protobuf/descriptor.proto")
continue; // Not needed and therefore not used
importFilename = importRoot + delim + importFilename;
if (this.files[importFilename] === true)
continue; // Already imported
if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto) // If this is a light build
importFilename = importFilename.replace(/\.proto$/, ".json"); // always load the JSON file
var contents = ProtoBuf.Util.fetch(importFilename);
if (contents === null)
throw Error("failed to import '"+importFilename+"' in '"+filename+"': file not found");
if (/\.json$/i.test(importFilename)) // Always possible
this["import"](JSON.parse(contents+""), importFilename); // May throw
else
this["import"](ProtoBuf.DotProto.Parser.parse(contents), importFilename); // May throw
var tmpImportRoot = importRoot;
var tmpImportPathIndex = 0;
while (true) {
var tmpImportFilename = tmpImportRoot + delim + importFilename;
if (this.files[tmpImportFilename] === true)
break; // Already imported
if (/\.proto$/i.test(tmpImportFilename) && !ProtoBuf.DotProto) // If this is a light build
tmpImportFilename = tmpImportFilename.replace(/\.proto$/, ".json"); // always load the JSON file
var contents = ProtoBuf.Util.fetch(tmpImportFilename);
if (contents === null) {
if (this.options.includePath && this.options.includePath.length > tmpImportPathIndex) {
tmpImportRoot = this.options.includePath[tmpImportPathIndex++];
continue;
}
throw Error("failed to import '"+(importRoot + delim + importFilename)+"' in '"+filename+"': file not found");
}
if (/\.json$/i.test(tmpImportFilename)) // Always possible
this["import"](JSON.parse(contents+""), tmpImportFilename); // May throw
else
this["import"](ProtoBuf.DotProto.Parser.parse(contents), tmpImportFilename); // May throw
break;
}
} else // Import structure
if (!filename)
this["import"](json['imports'][i]);
Expand Down
Loading

0 comments on commit 0ce8f4c

Please sign in to comment.