Use modern JS tooling instead of Closure's deprecated Python scripts. (#8610)

pull/8664/head
Kelvin Jin 4 years ago committed by GitHub
parent 3069f82bbc
commit fd896ba23e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      js/README.md
  2. 2
      js/commonjs/export.js
  3. 2
      js/commonjs/export_asserts.js
  4. 2
      js/commonjs/export_testdeps.js
  5. 16
      js/compatibility_tests/v3.0.0/test.sh
  6. 36
      js/gulpfile.js
  7. 1
      js/package.json

@ -94,11 +94,8 @@ statements like:
var message = proto.my.package.MyMessage(); var message = proto.my.package.MyMessage();
If unfamiliar with Closure or its compiler, consider reviewing Closure documentation If unfamiliar with Closure or its compiler, consider reviewing
https://developers.google.com/closure/library/docs/tutorial [Closure documentation](https://developers.google.com/closure/library).
https://developers.google.com/closure/library/docs/closurebuilder
https://developers.google.com/closure/library/docs/depswriter
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.
CommonJS imports CommonJS imports
---------------- ----------------

@ -5,8 +5,6 @@
* the google-protobuf.js file that we build at distribution time. * the google-protobuf.js file that we build at distribution time.
*/ */
// Include a dummy provide statement so that closurebuilder.py does not skip over this
// file.
goog.provide('jspb.Export'); goog.provide('jspb.Export');
goog.require('goog.object'); goog.require('goog.object');

@ -6,8 +6,6 @@
* closure_asserts_commonjs.js that is only used at testing time. * closure_asserts_commonjs.js that is only used at testing time.
*/ */
// Include a dummy provide statement so that closurebuilder.py does not skip over this
// file.
goog.provide('jspb.ExportAsserts'); goog.provide('jspb.ExportAsserts');
goog.require('goog.testing.asserts'); goog.require('goog.testing.asserts');

@ -7,8 +7,6 @@
* export_asserts.js. * export_asserts.js.
*/ */
// Include a dummy provide statement so that closurebuilder.py does not skip over this
// file.
goog.provide('jspb.ExportTestDeps'); goog.provide('jspb.ExportTestDeps');
goog.require('goog.crypt.base64'); goog.require('goog.crypt.base64');

@ -53,8 +53,20 @@ for file in *_test.js binary/*_test.js; do
done done
cp commonjs/{jasmine.json,import_test.js} commonjs_out/ cp commonjs/{jasmine.json,import_test.js} commonjs_out/
mkdir -p commonjs_out/test_node_modules mkdir -p commonjs_out/test_node_modules
../../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 ../../node_modules/.bin/google-closure-compiler \
../../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 --entry_point=commonjs/export_asserts.js \
--js=commonjs/export_asserts.js \
--js=../../node_modules/google-closure-library/closure/goog/**.js \
--js=../../node_modules/google-closure-library/third_party/closure/goog/**.js \
> commonjs_out/test_node_modules/closure_asserts_commonjs.js
../../node_modules/.bin/google-closure-compiler \
--entry_point=commonjs/export_testdeps.js \
--js=commonjs/export_testdeps.js \
--js=../../binary/*.js \
--js=!../../binary/*_test.js \
--js=../../node_modules/google-closure-library/closure/goog/**.js \
--js=../../node_modules/google-closure-library/third_party/closure/goog/**.js \
> commonjs_out/test_node_modules/testdeps_commonjs.js
cp ../../google-protobuf.js commonjs_out/test_node_modules cp ../../google-protobuf.js commonjs_out/test_node_modules
cp -r ../../commonjs_out/node_modules commonjs_out cp -r ../../commonjs_out/node_modules commonjs_out

@ -140,21 +140,31 @@ gulp.task('genproto_group3_commonjs_strict', function (cb) {
}); });
function getClosureBuilderCommand(exportsFile, outputFile) { function getClosureCompilerCommand(exportsFile, outputFile) {
return './node_modules/google-closure-library/closure/bin/build/closurebuilder.py ' + const closureLib = 'node_modules/google-closure-library';
'--root node_modules ' + return [
'-o compiled ' + 'node_modules/.bin/google-closure-compiler',
'--compiler_jar node_modules/google-closure-compiler-java/compiler.jar ' + `--js=${closureLib}/closure/goog/**.js`,
'-i ' + exportsFile + ' ' + `--js=${closureLib}/third_party/closure/goog/**.js`,
'map.js message.js binary/arith.js binary/constants.js binary/decoder.js ' + '--js=map.js',
'binary/encoder.js binary/reader.js binary/utils.js binary/writer.js ' + '--js=message.js',
exportsFile + ' > ' + outputFile; '--js=binary/arith.js',
'--js=binary/constants.js',
'--js=binary/decoder.js',
'--js=binary/encoder.js',
'--js=binary/reader.js',
'--js=binary/utils.js',
'--js=binary/writer.js',
`--js=${exportsFile}`,
`--entry_point=${exportsFile}`,
`> ${outputFile}`
].join(' ');
} }
gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) { gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) {
// TODO(haberman): minify this more aggressively. // TODO(haberman): minify this more aggressively.
// Will require proper externs/exports. // Will require proper externs/exports.
exec(getClosureBuilderCommand('commonjs/export.js', 'google-protobuf.js'), exec(getClosureCompilerCommand('commonjs/export.js', 'google-protobuf.js'),
function (err, stdout, stderr) { function (err, stdout, stderr) {
console.log(stdout); console.log(stdout);
console.log(stderr); console.log(stderr);
@ -164,7 +174,7 @@ gulp.task('dist', gulp.series(['genproto_wellknowntypes'], function(cb) {
gulp.task('commonjs_asserts', function (cb) { gulp.task('commonjs_asserts', function (cb) {
exec('mkdir -p commonjs_out/test_node_modules && ' + exec('mkdir -p commonjs_out/test_node_modules && ' +
getClosureBuilderCommand( getClosureCompilerCommand(
'commonjs/export_asserts.js', 'commonjs/export_asserts.js',
'commonjs_out/test_node_modules/closure_asserts_commonjs.js'), 'commonjs_out/test_node_modules/closure_asserts_commonjs.js'),
function (err, stdout, stderr) { function (err, stdout, stderr) {
@ -176,7 +186,7 @@ gulp.task('commonjs_asserts', function (cb) {
gulp.task('commonjs_testdeps', function (cb) { gulp.task('commonjs_testdeps', function (cb) {
exec('mkdir -p commonjs_out/test_node_modules && ' + exec('mkdir -p commonjs_out/test_node_modules && ' +
getClosureBuilderCommand( getClosureCompilerCommand(
'commonjs/export_testdeps.js', 'commonjs/export_testdeps.js',
'commonjs_out/test_node_modules/testdeps_commonjs.js'), 'commonjs_out/test_node_modules/testdeps_commonjs.js'),
function (err, stdout, stderr) { function (err, stdout, stderr) {
@ -229,7 +239,7 @@ gulp.task(
], ],
function(cb) { function(cb) {
exec( exec(
'./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', './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',
function(err, stdout, stderr) { function(err, stdout, stderr) {
console.log(stdout); console.log(stdout);
console.log(stderr); console.log(stderr);

@ -10,6 +10,7 @@
"devDependencies": { "devDependencies": {
"glob": "~7.1.4", "glob": "~7.1.4",
"google-closure-compiler": "~20190819.0.0", "google-closure-compiler": "~20190819.0.0",
"google-closure-deps": "^20210406.0.0",
"google-closure-library": "~20190819.0.0", "google-closure-library": "~20190819.0.0",
"gulp": "~4.0.2", "gulp": "~4.0.2",
"jasmine": "~3.4.0" "jasmine": "~3.4.0"

Loading…
Cancel
Save