From ec14cc3ed8872419c55cd63bfb86c93fa5aa1b36 Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Wed, 7 Jul 2021 16:22:42 +0100 Subject: [PATCH] Package build output; fix node tests. - Reconfigure package_tasks.js to use BUILD_DIR from config.js (i.e., build/) rather than repository root as source of files to package. - Add check to packageTasks.package to ensure that certain required files exist in BUILD_DIR, to verify that buildTasks.build and typings.typings have been run. - Fix packageUMDBundle to use generated, rather than checked-in version of en.js. - Fix packageDTS to use the generated (rather than checked-in) versions of blockly.d.ts and msg/*.d.ts. - Modify run_all_tests.sh to run packageTasks.package before running node tests, since they depend on it. Previously this was only working because 'npm install' runs the 'prepare' script, which would run the 'package' script - so the code being tested by the node tests was not the current source but whatever precomipled code had previously been checked in. - Remove the 'prepare' script from package.json, since it is no longer needed (and is now broken, since it requires that build and typings have been done first.) Note that no scripts at all are included in the version of package.json that is created in dist/ and subsequently included in the published npms, so this deletion does not affect what happens when the Blockly npm in installed - it only affects what happens when 'npm install' is run after the blockly repo is cloned. - Factor out the actual recompilation steps from releaseTasks.recompile. - Rename releaseTasks.recomple to recompileDevelop, since it deals specifically with the develop branch. (The npm script name is unchanged.) - Ensure that a full recompile and repackage is done before publishing (beta and non-beta) npms. --- package.json | 1 - scripts/gulpfiles/package_tasks.js | 64 ++++++++++++++++++++++++------ scripts/gulpfiles/release_tasks.js | 27 ++++++++----- tests/run_all_tests.sh | 14 ++++--- 4 files changed, 76 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 41308cf5e..f43578ac3 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "license": "gulp checkLicenses", "lint": "eslint .", "package": "gulp package", - "prepare": "npm run package", "publish": "gulp publish", "publish:beta": "gulp publishBeta", "recompile": "gulp recompile", diff --git a/scripts/gulpfiles/package_tasks.js b/scripts/gulpfiles/package_tasks.js index 6fef12152..6b791d2e6 100644 --- a/scripts/gulpfiles/package_tasks.js +++ b/scripts/gulpfiles/package_tasks.js @@ -19,18 +19,11 @@ var path = require('path'); var fs = require('fs'); var rimraf = require('rimraf'); var {getPackageJson} = require('./helper_tasks'); -var {RELEASE_DIR} = require('./config'); +var {BUILD_DIR, RELEASE_DIR} = require('./config'); // Path to template files for gulp-umd. const TEMPLATE_DIR = 'scripts/package/templates'; -// Path from which to pull files to package. -// -// TODO(cpcallen): Use BUILD_DIR from config.js once release_tasks are -// updated to do build-package-release all in one go, instead of doing -// build-checkin and then package-release as separate steps. -var BUILD_DIR = '.'; - /** * A helper method for wrapping a file into a Universal Module Definition. * @param {string} namespace The export namespace. @@ -59,6 +52,41 @@ function packageCommonJS(namespace, dependencies) { }); }; +// Sanity check that the BUILD_DIR directory exists, and that certain +// files are in it. +function checkBuildDir(done) { + // Check that directory exists. + if (!fs.existsSync(BUILD_DIR)) { + done(new Error(`The ${BUILD_DIR} directory does not exist. ` + + 'Have both packageTasks.build and typingsTasks.typings been run?')); + return; + } + // Check files built by buildTasks.build exist in BUILD_DIR. + for (const fileName of [ + 'blockly_compressed.js', // buildTasks.buildCompressed + 'blocks_compressed.js', // buildTasks.buildBlocks + 'javascript_compressed.js', // buildTasks.buildGenerators + 'msg/js/en.js', // buildTaks.buildLangfiles + ]) { + if (!fs.existsSync(`${BUILD_DIR}/${fileName}`)) { + done(new Error( + `Your ${BUILD_DIR} directory does not contain ${fileName}. ` + + 'Has packageTasks.build been run? Try "npm run build".')); + return; + } + } + // Check files built by typings.typings exist in BUILD_DIR. + for (const fileName of ['blockly.d.ts', 'msg/en.d.ts']) { + if (!fs.existsSync(`${BUILD_DIR}/${fileName}`)) { + done(new Error( + `Your ${BUILD_DIR} directory does not contain ${fileName}. ` + + 'Has typings.typings been run? Try "npm run typings".')); + return; + } + } + done(); +} + /** * This task copies source files into the release directory. */ @@ -321,7 +349,7 @@ function packageLocales() { function packageUMDBundle() { var srcs = [ `${BUILD_DIR}/blockly_compressed.js`, - 'msg/js/en.js', + `${BUILD_DIR}/msg/js/en.js`, `${BUILD_DIR}/blocks_compressed.js`, `${BUILD_DIR}/javascript_compressed.js`, ]; @@ -360,7 +388,7 @@ function packageJSON(cb) { */ function packageReadme() { return gulp.src('scripts/package/README.md') - .pipe(gulp.dest(`${RELEASE_DIR}`)); + .pipe(gulp.dest(RELEASE_DIR)); }; /** @@ -369,9 +397,18 @@ function packageReadme() { * referenced in package.json in the types property. */ function packageDTS() { - return gulp.src(['typings/*.d.ts', 'typings/msg/*.d.ts'], - {base: './typings'}) - .pipe(gulp.dest(`${RELEASE_DIR}`)); + const handwrittenSrcs = [ + 'typings/*.d.ts', + '!typings/blockly.d.ts', // Exclude checked-in copy of blockly.d.ts. + 'typings/msg/msg.d.ts', + ]; + const builtSrcs = [ + `${BUILD_DIR}/blockly.d.ts`, // Use freshly-built one instead. + `${BUILD_DIR}/msg/*.d.ts`, + ]; + return gulp.src(handwrittenSrcs, {base: 'typings'}) + .pipe(gulp.src(builtSrcs, {base: BUILD_DIR})) + .pipe(gulp.dest(RELEASE_DIR)); }; /** @@ -390,6 +427,7 @@ function cleanReleaseDir(done) { * them into the release directory. */ const package = gulp.series( + checkBuildDir, cleanReleaseDir, gulp.parallel( packageIndex, diff --git a/scripts/gulpfiles/release_tasks.js b/scripts/gulpfiles/release_tasks.js index c4480f06c..a55edd380 100644 --- a/scripts/gulpfiles/release_tasks.js +++ b/scripts/gulpfiles/release_tasks.js @@ -149,8 +149,18 @@ function updateBetaVersion(done) { done(); } +// Build Blockly and prepare to check in the resulting built files. +const recompile = gulp.series( + buildTasks.cleanBuildDir, + buildTasks.build, + buildTasks.checkinBuilt, + typings.typings, + typings.checkinTypings, + ); + // Package and publish to npm. const publish = gulp.series( + recompile, packageTasks.package, checkBranch, checkReleaseDir, @@ -160,30 +170,25 @@ const publish = gulp.series( // Publish a beta version of Blockly. const publishBeta = gulp.series( updateBetaVersion, - buildTasks.cleanBuildDir, - buildTasks.build, - buildTasks.checkinBuilt, + recompile, packageTasks.package, checkBranch, checkReleaseDir, loginAndPublishBeta ); -// Switch to a new branch, update the version number, and build Blockly. -const recompile = gulp.series( +// Switch to a new branch, update the version number, build Blockly +// and check in the resulting built files. +const recompileDevelop = gulp.series( gitTasks.syncDevelop(), gitTasks.createRebuildBranch, updateVersionPrompt, - buildTasks.cleanBuildDir, - buildTasks.build, - buildTasks.checkinBuilt, - typings.typings, - typings.checkinTypings, + recompile, gitTasks.pushRebuildBranch ); module.exports = { - recompile: recompile, + recompile: recompileDevelop, publishBeta: publishBeta, publish: publish } diff --git a/tests/run_all_tests.sh b/tests/run_all_tests.sh index 5107a6ebf..f6c7c0f8c 100755 --- a/tests/run_all_tests.sh +++ b/tests/run_all_tests.sh @@ -51,14 +51,15 @@ run_test_command () { # Lint the codebase. run_test_command "eslint" "eslint ." -# Run the closure compiler. -run_test_command "compile" "npm run build" +# Run the full usual build process. +run_test_command "build" "npm run build" -# Run the closure compiler ensuring there are no compiler warnings / errors. -run_test_command "compile:warnings" "npm run build:debug" +# Run the debug build, to ensure there are no closure compiler +# warnings / errors. +run_test_command "build:debug" "npm run build:debug" # Generate TypeScript typings and ensure there are no errors. -run_test_command "typings" "tests/scripts/compile_typings.sh" +run_test_command "typings" "npm run typings" # Check the sizes of built files for unexpected growth. run_test_command "metadata" "tests/scripts/check_metadata.sh" @@ -69,6 +70,9 @@ run_test_command "mocha" "node tests/mocha/run_mocha_tests_in_browser.js" # Run generator tests inside a browser and check the results. run_test_command "generators" "tests/scripts/run_generators.sh" +# Run the package build process, as Node tests depend on it. +run_test_command "package" "npm run package" + # Run Node tests. run_test_command "node" "./node_modules/.bin/mocha tests/node --config tests/node/.mocharc.js"