Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify include path to resolve imported file #474

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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