Skip to content

Commit d1ba84c

Browse files
authored
Use modern JS tooling instead of Closure's deprecated Python scripts. (#8610)
1 parent bf14cde commit d1ba84c

7 files changed

Lines changed: 40 additions & 26 deletions

File tree

README.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,8 @@ statements like:
9494

9595
var message = proto.my.package.MyMessage();
9696

97-
If unfamiliar with Closure or its compiler, consider reviewing Closure documentation
98-
https://developers.google.com/closure/library/docs/tutorial
99-
https://developers.google.com/closure/library/docs/closurebuilder
100-
https://developers.google.com/closure/library/docs/depswriter
101-
At a high level, closurebuilder.py can walk dependencies, and compile your code, and all dependencies for Protobuf into a single .js file. Using depsbuilder.py to generate a dependency file can also be considered for non-production dev environments.
97+
If unfamiliar with Closure or its compiler, consider reviewing
98+
[Closure documentation](https://developers.google.com/closure/library).
10299

103100
CommonJS imports
104101
----------------

commonjs/export.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
* the google-protobuf.js file that we build at distribution time.
66
*/
77

8-
// Include a dummy provide statement so that closurebuilder.py does not skip over this
9-
// file.
108
goog.provide('jspb.Export');
119

1210
goog.require('goog.object');

commonjs/export_asserts.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
* closure_asserts_commonjs.js that is only used at testing time.
77
*/
88

9-
// Include a dummy provide statement so that closurebuilder.py does not skip over this
10-
// file.
119
goog.provide('jspb.ExportAsserts');
1210

1311
goog.require('goog.testing.asserts');

commonjs/export_testdeps.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
* export_asserts.js.
88
*/
99

10-
// Include a dummy provide statement so that closurebuilder.py does not skip over this
11-
// file.
1210
goog.provide('jspb.ExportTestDeps');
1311

1412
goog.require('goog.crypt.base64');

compatibility_tests/v3.0.0/test.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,20 @@ for file in *_test.js binary/*_test.js; do
5353
done
5454
cp commonjs/{jasmine.json,import_test.js} commonjs_out/
5555
mkdir -p commonjs_out/test_node_modules
56-
../../node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_asserts.js -p . -p ../../node_modules/google-closure-library/closure -o compiled --compiler_jar ../../node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/closure_asserts_commonjs.js
57-
../../node_modules/google-closure-library/closure/bin/calcdeps.py -i commonjs/export_testdeps.js -p ../.. -p ../../node_modules/google-closure-library/closure -o compiled --compiler_jar ../../node_modules/google-closure-compiler/compiler.jar > commonjs_out/test_node_modules/testdeps_commonjs.js
56+
../../node_modules/.bin/google-closure-compiler \
57+
--entry_point=commonjs/export_asserts.js \
58+
--js=commonjs/export_asserts.js \
59+
--js=../../node_modules/google-closure-library/closure/goog/**.js \
60+
--js=../../node_modules/google-closure-library/third_party/closure/goog/**.js \
61+
> commonjs_out/test_node_modules/closure_asserts_commonjs.js
62+
../../node_modules/.bin/google-closure-compiler \
63+
--entry_point=commonjs/export_testdeps.js \
64+
--js=commonjs/export_testdeps.js \
65+
--js=../../binary/*.js \
66+
--js=!../../binary/*_test.js \
67+
--js=../../node_modules/google-closure-library/closure/goog/**.js \
68+
--js=../../node_modules/google-closure-library/third_party/closure/goog/**.js \
69+
> commonjs_out/test_node_modules/testdeps_commonjs.js
5870
cp ../../google-protobuf.js commonjs_out/test_node_modules
5971
cp -r ../../commonjs_out/node_modules commonjs_out
6072

gulpfile.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,31 @@ gulp.task('genproto_group3_commonjs_strict', function (cb) {
140140
});
141141

142142

143-
function getClosureBuilderCommand(exportsFile, outputFile) {
144-
return './node_modules/google-closure-library/closure/bin/build/closurebuilder.py ' +
145-
'--root node_modules ' +
146-
'-o compiled ' +
147-
'--compiler_jar node_modules/google-closure-compiler-java/compiler.jar ' +
148-
'-i ' + exportsFile + ' ' +
149-
'map.js message.js binary/arith.js binary/constants.js binary/decoder.js ' +
150-
'binary/encoder.js binary/reader.js binary/utils.js binary/writer.js ' +
151-
exportsFile + ' > ' + outputFile;
143+
function getClosureCompilerCommand(exportsFile, outputFile) {
144+
const closureLib = 'node_modules/google-closure-library';
145+
return [
146+
'node_modules/.bin/google-closure-compiler',
147+
`--js=${closureLib}/closure/goog/**.js`,
148+
`--js=${closureLib}/third_party/closure/goog/**.js`,
149+
'--js=map.js',
150+
'--js=message.js',
151+
'--js=binary/arith.js',
152+
'--js=binary/constants.js',
153+
'--js=binary/decoder.js',
154+
'--js=binary/encoder.js',
155+
'--js=binary/reader.js',
156+
'--js=binary/utils.js',
157+
'--js=binary/writer.js',
158+
`--js=${exportsFile}`,
159+
`--entry_point=${exportsFile}`,
160+
`> ${outputFile}`
161+
].join(' ');
152162
}
153163

154164
gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) {
155165
// TODO(haberman): minify this more aggressively.
156166
// Will require proper externs/exports.
157-
exec(getClosureBuilderCommand('commonjs/export.js', 'google-protobuf.js'),
167+
exec(getClosureCompilerCommand('commonjs/export.js', 'google-protobuf.js'),
158168
function (err, stdout, stderr) {
159169
console.log(stdout);
160170
console.log(stderr);
@@ -164,7 +174,7 @@ gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) {
164174

165175
gulp.task('commonjs_asserts', function (cb) {
166176
exec('mkdir -p commonjs_out/test_node_modules && ' +
167-
getClosureBuilderCommand(
177+
getClosureCompilerCommand(
168178
'commonjs/export_asserts.js',
169179
'commonjs_out/test_node_modules/closure_asserts_commonjs.js'),
170180
function (err, stdout, stderr) {
@@ -176,7 +186,7 @@ gulp.task('commonjs_asserts', function (cb) {
176186

177187
gulp.task('commonjs_testdeps', function (cb) {
178188
exec('mkdir -p commonjs_out/test_node_modules && ' +
179-
getClosureBuilderCommand(
189+
getClosureCompilerCommand(
180190
'commonjs/export_testdeps.js',
181191
'commonjs_out/test_node_modules/testdeps_commonjs.js'),
182192
function (err, stdout, stderr) {
@@ -229,7 +239,7 @@ gulp.task(
229239
],
230240
function(cb) {
231241
exec(
232-
'./node_modules/google-closure-library/closure/bin/build/depswriter.py binary/arith.js binary/constants.js binary/decoder.js binary/encoder.js binary/reader.js binary/utils.js binary/writer.js debug.js map.js message.js node_loader.js test_bootstrap.js > deps.js',
242+
'./node_modules/.bin/closure-make-deps --closure-path=. --file=node_modules/google-closure-library/closure/goog/deps.js binary/arith.js binary/constants.js binary/decoder.js binary/encoder.js binary/reader.js binary/utils.js binary/writer.js debug.js map.js message.js node_loader.js test_bootstrap.js > deps.js',
233243
function(err, stdout, stderr) {
234244
console.log(stdout);
235245
console.log(stderr);

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"devDependencies": {
1111
"glob": "~7.1.4",
1212
"google-closure-compiler": "~20190819.0.0",
13+
"google-closure-deps": "^20210406.0.0",
1314
"google-closure-library": "~20190819.0.0",
1415
"gulp": "~4.0.2",
1516
"jasmine": "~3.4.0"

0 commit comments

Comments
 (0)