aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2016-06-16 11:59:08 -0700
committerFeng Xiao <xfxyjwf@gmail.com>2016-06-17 11:25:02 -0700
commita0f490370c49106cb68b704a3dd12ea6d0de83d8 (patch)
tree89f4560d60c54e8d928b710f991ccb0cddd1f6c4
parent343363aa6cec41aaccaff47b9faabe5c12e79227 (diff)
downloadprotobuf-a0f490370c49106cb68b704a3dd12ea6d0de83d8.tar.gz
protobuf-a0f490370c49106cb68b704a3dd12ea6d0de83d8.tar.bz2
protobuf-a0f490370c49106cb68b704a3dd12ea6d0de83d8.zip
JS: import well-known types from google-protobuf package.
-rw-r--r--js/gulpfile.js27
-rwxr-xr-xsrc/google/protobuf/compiler/js/js_generator.cc8
2 files changed, 33 insertions, 2 deletions
diff --git a/js/gulpfile.js b/js/gulpfile.js
index c5220153..d94d4a14 100644
--- a/js/gulpfile.js
+++ b/js/gulpfile.js
@@ -8,6 +8,20 @@ function exec(command, cb) {
var protoc = process.env.PROTOC || '../src/protoc';
+var wellKnownTypes = [
+ '../src/google/protobuf/any.proto',
+ '../src/google/protobuf/api.proto',
+ '../src/google/protobuf/descriptor.proto',
+ '../src/google/protobuf/duration.proto',
+ '../src/google/protobuf/empty.proto',
+ '../src/google/protobuf/field_mask.proto',
+ '../src/google/protobuf/source_context.proto',
+ '../src/google/protobuf/struct.proto',
+ '../src/google/protobuf/timestamp.proto',
+ '../src/google/protobuf/type.proto',
+ '../src/google/protobuf/wrappers.proto',
+];
+
gulp.task('genproto_closure', function (cb) {
exec(protoc + ' --js_out=library=testproto_libs,binary:. -I ../src -I . *.proto ../src/google/protobuf/descriptor.proto',
function (err, stdout, stderr) {
@@ -18,7 +32,16 @@ gulp.task('genproto_closure', function (cb) {
});
gulp.task('genproto_commonjs', function (cb) {
- exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . *.proto commonjs/test*/*.proto ../src/google/protobuf/descriptor.proto',
+ exec('mkdir -p commonjs_out && ' + protoc + ' --js_out=import_style=commonjs,binary:commonjs_out -I ../src -I commonjs -I . *.proto commonjs/test*/*.proto ../src/google/protobuf/descriptor.proto' + wellKnownTypes.join(' '),
+ function (err, stdout, stderr) {
+ console.log(stdout);
+ console.log(stderr);
+ cb(err);
+ });
+});
+
+gulp.task('genproto_wellknowntypes', function (cb) {
+ exec(protoc + ' --js_out=import_style=commonjs,binary:. -I ../src ' + wellKnownTypes.join(' '),
function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
@@ -26,7 +49,7 @@ gulp.task('genproto_commonjs', function (cb) {
});
});
-gulp.task('dist', function (cb) {
+gulp.task('dist', ['genproto_wellknowntypes'], function (cb) {
// TODO(haberman): minify this more aggressively.
// Will require proper externs/exports.
exec('./node_modules/google-closure-library/closure/bin/calcdeps.py -i message.js -i binary/reader.js -i binary/writer.js -i commonjs/export.js -p . -p node_modules/google-closure-library/closure -o compiled --compiler_jar node_modules/google-closure-compiler/compiler.jar > google-protobuf.js',
diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc
index 3de61e80..5d1ba598 100755
--- a/src/google/protobuf/compiler/js/js_generator.cc
+++ b/src/google/protobuf/compiler/js/js_generator.cc
@@ -160,6 +160,14 @@ string GetJSFilename(const string& filename) {
// Given a filename like foo/bar/baz.proto, returns the root directory
// path ../../
string GetRootPath(const string& filename) {
+ if (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(filename.begin(), filename.end(), '/');
if (slashes == 0) {
return "./";