Skip to content
Merged
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
6 changes: 4 additions & 2 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Protobuf JS runtime
# Protobuf JavaScript runtime
#
# See also code generation logic under generator/

load("@rules_pkg//:mappings.bzl", "pkg_attributes", "pkg_files", "strip_prefix")
load("@rules_pkg//:pkg.bzl", "pkg_tar", "pkg_zip")
load("//:protobuf_javascript_release.bzl", "package_naming")

exports_files(["generate-version-header.js", "package.json"])

config_setting(
name = "x64_x86_windows",
values = {"cpu": "x64_x86_windows"},
Expand Down Expand Up @@ -55,7 +57,7 @@ pkg_files(
srcs = glob([
"google/protobuf/*.js",
"google/protobuf/compiler/*.js"
]) + [
], allow_empty = True) + [
"google-protobuf.js",
"package.json",
"README.md",
Expand Down
10 changes: 6 additions & 4 deletions MODULE.bazel.lock

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

2 changes: 1 addition & 1 deletion conformance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"LICENSE.md"
],
"dependencies": {
"google-protobuf": "file:../google-protobuf-3.21.4.tgz"
"google-protobuf": "file:../google-protobuf-4.0.0.tgz"
},
"author": "Google Protocol Buffers Team",
"license": "BSD-3-Clause"
Expand Down
14 changes: 14 additions & 0 deletions generate-version-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');

const version = require('./package.json').version;
const headerContent = `// Generated by generate-version-header.js
#ifndef PROTOBUF_JAVASCRIPT_VERSION_H__
#define PROTOBUF_JAVASCRIPT_VERSION_H__

const char* const kProtobufJavascriptVersion = "${version}";

#endif // PROTOBUF_JAVASCRIPT_VERSION_H__
`;

fs.writeFileSync(process.argv[2], headerContent);
9 changes: 9 additions & 0 deletions generator/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
genrule(
name = "generate_version_header",
srcs = ["//:package.json"],
outs = ["version.h"],
cmd = "node $(location //:generate-version-header.js) $(OUTS)",
tools = ["//:generate-version-header.js"],
)

cc_binary(
name = "protoc-gen-js",
srcs = [
Expand All @@ -6,6 +14,7 @@ cc_binary(
"protoc-gen-js.cc",
"well_known_types_embed.cc",
"well_known_types_embed.h",
":version.h",
],
visibility = ["//visibility:public"],
deps = [
Expand Down
9 changes: 9 additions & 0 deletions generator/protoc-gen-js.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,19 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <google/protobuf/compiler/plugin.h>
#include <iostream>
#include <string>

#include "generator/js_generator.h"
#include "generator/version.h"

int main(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
if (std::string(argv[i]) == "--version") {
std::cout << "protoc-gen-js version " << kProtobufJavascriptVersion << std::endl;
return 0;
}
}
std::unique_ptr<google::protobuf::compiler::CodeGenerator> generator(
new google::protobuf::compiler::js::Generator());
return google::protobuf::compiler::PluginMain(argc, argv, generator.get());
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"jasmine": "~3.5.0"
},
"scripts": {
"prebuild": "node update-bazel-versions.js",
"build": "node ./node_modules/gulp/bin/gulp.js dist",
"test": "node ./node_modules/gulp/bin/gulp.js test",
"clean": "node ./node_modules/gulp/bin/gulp.js clean"
Expand Down
28 changes: 28 additions & 0 deletions update-bazel-versions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require('fs');
const path = require('path');

const version = require('./package.json').version;

// Update MODULE.bazel
const moduleBazelPath = path.join(__dirname, 'MODULE.bazel');
let moduleBazelContent = fs.readFileSync(moduleBazelPath, 'utf8');
moduleBazelContent = moduleBazelContent.replace(/version = ".*"/, `version = "${version}"`);
fs.writeFileSync(moduleBazelPath, moduleBazelContent);

// Update protobuf_javascript_release.bzl
const releaseBzlPath = path.join(__dirname, 'protobuf_javascript_release.bzl');
let releaseBzlContent = fs.readFileSync(releaseBzlPath, 'utf8');
releaseBzlContent = releaseBzlContent.replace(/_PROTOBUF_JAVASCRIPT_VERSION = ".*"/, `_PROTOBUF_JAVASCRIPT_VERSION = "${version}"`);
fs.writeFileSync(releaseBzlPath, releaseBzlContent);

// Update conformance/package.json
const conformancePackageJsonPath =
path.join(__dirname, 'conformance', 'package.json');
let conformancePackageJsonContent =
fs.readFileSync(conformancePackageJsonPath, 'utf8');
const conformancePackageJson = JSON.parse(conformancePackageJsonContent);
conformancePackageJson.dependencies['google-protobuf'] =
`file:../google-protobuf-${version}.tgz`;
fs.writeFileSync(
conformancePackageJsonPath,
JSON.stringify(conformancePackageJson, null, 2) + '\n');