aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2016-06-17 11:14:25 -0700
committerGitHub <noreply@github.com>2016-06-17 11:14:25 -0700
commitb7560df598f1c7c443b724403fbf102a2bbf75ba (patch)
treefae04f307b863ff8ce9592708c38fa0c97ee6f9a /src
parent8c20e55c57c90a1a84ac7cf4de96e65911c8212b (diff)
parent104723fccf4c9f7bf2398073e6b04390dcd2298a (diff)
downloadprotobuf-b7560df598f1c7c443b724403fbf102a2bbf75ba.tar.gz
protobuf-b7560df598f1c7c443b724403fbf102a2bbf75ba.tar.bz2
protobuf-b7560df598f1c7c443b724403fbf102a2bbf75ba.zip
Merge pull request #1696 from haberman/jswkt
JS: import well-known types from google-protobuf package.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index a72cf6a3..8fb24bed 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -159,8 +159,16 @@ string GetJSFilename(const string& filename) {
// Given a filename like foo/bar/baz.proto, returns the root directory
// path ../../
-string GetRootPath(const string& filename) {
- size_t slashes = std::count(filename.begin(), filename.end(), '/');
+string GetRootPath(const string& from_filename, const string& to_filename) {
+ if (to_filename.find("google/protobuf") == 0) {
+ // Well-known types (.proto files in the google/protobuf directory) are
+ // assumed to come from the 'google-protobuf' npm package. We may want to
+ // generalize this exception later by letting others put generated code in
+ // their own npm packages.
+ return "google-protobuf/";
+ }
+
+ size_t slashes = std::count(from_filename.begin(), from_filename.end(), '/');
if (slashes == 0) {
return "./";
}
@@ -2838,7 +2846,7 @@ void Generator::GenerateFile(const GeneratorOptions& options,
printer->Print(
"var $alias$ = require('$file$');\n",
"alias", ModuleAlias(name),
- "file", GetRootPath(file->name()) + GetJSFilename(name));
+ "file", GetRootPath(file->name(), name) + GetJSFilename(name));
}
}