From 9a0d6df42c819eade6d614d5fe84350a57e0fb5b Mon Sep 17 00:00:00 2001 From: Christopher Allen Date: Wed, 24 Nov 2021 16:33:47 +0000 Subject: [PATCH] refactor(build): Use chunked compilation by default Remove old "compressed" gulp tasks in favour of new "compiled" task. --- gulpfile.js | 4 - package.json | 11 +- scripts/gulpfiles/build_tasks.js | 196 +------------------------------ 3 files changed, 6 insertions(+), 205 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 29d10be05..ce88f71ce 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -27,12 +27,8 @@ module.exports = { generateLangfiles: buildTasks.generateLangfiles, build: buildTasks.build, buildDeps: buildTasks.deps, - buildCore: buildTasks.core, - buildBlocks: buildTasks.blocks, buildLangfiles: buildTasks.langfiles, buildCompiled: buildTasks.compiled, - buildCompressed: buildTasks.compressed, - buildGenerators: buildTasks.generators, buildAdvancedCompilationTest: buildTasks.advancedCompilationTest, checkin: gulp.parallel(buildTasks.checkinBuilt, typings.checkinTypings), checkinBuilt: buildTasks.checkinBuilt, diff --git a/package.json b/package.json index e87a486e4..7c9027436 100644 --- a/package.json +++ b/package.json @@ -20,16 +20,13 @@ "build": "gulp build", "build:blocks": "gulp buildBlocks", "build:compiled": "gulp buildCompiled", - "build:compiled:debug": "gulp buildCompiled --verbose --debug", - "build:compressed": "gulp buildCompressed", - "build:core": "gulp buildCore", - "build:debug": "gulp buildCompressed --verbose --debug", + "build:compressed": "npm run build:compiled", + "build:debug": "gulp buildCompiled --verbose --debug", "build:debug:log": "npm run build:debug > build-debug.log 2>&1 && tail -3 build-debug.log", "build:deps": "gulp buildDeps", - "build:strict": "gulp buildCompressed --verbose --strict", - "build:strict:log": "npm run build:strict > build-debug.log 2>&1 && tail -3 build-debug.log", - "build:generators": "gulp buildGenerators", "build:langfiles": "gulp buildLangfiles", + "build:strict": "gulp buildCompiled --verbose --strict", + "build:strict:log": "npm run build:strict > build-debug.log 2>&1 && tail -3 build-debug.log", "bump": "npm --no-git-tag-version version 4.$(date +'%Y%m%d').0", "clean": "gulp clean", "clean:build": "gulp cleanBuildDir", diff --git a/scripts/gulpfiles/build_tasks.js b/scripts/gulpfiles/build_tasks.js index f97d0452d..d1455c254 100644 --- a/scripts/gulpfiles/build_tasks.js +++ b/scripts/gulpfiles/build_tasks.js @@ -209,182 +209,6 @@ function maybeAddClosureLibrary(srcs) { return srcs; } -/** - * A helper method to return an closure compiler output wrapper that wraps the - * body in a Universal Module Definition. - * @param {string} namespace The export namespace. - * @param {Array} dependencies An array of dependencies to inject. - */ -function outputWrapperUMD(namespace, dependencies) { - const amdDeps = dependencies.map(d => '\'' + d.amd + '\'' ).join(', '); - const cjsDeps = dependencies.map(d => `require('${d.cjs}')`).join(', '); - const browserDeps = dependencies.map(d => 'root.' + d.name).join(', '); - const imports = dependencies.map(d => d.name).join(', '); - return `// Do not edit this file; automatically generated by gulp. - -/* eslint-disable */ -;(function(root, factory) { - if (typeof define === 'function' && define.amd) { // AMD - define([${amdDeps}], factory); - } else if (typeof exports === 'object') { // Node.js - module.exports = factory(${cjsDeps}); - } else { // Browser - root.${namespace} = factory(${browserDeps}); - } -}(this, function(${imports}) { - %output% -return ${namespace}; -})); -`; -}; - -/** - * This task builds Blockly's core files. - * blockly_compressed.js - */ -function buildCompressed() { - var packageJson = getPackageJson(); - const defines = 'Blockly.VERSION="' + packageJson.version + '"'; - return gulp.src(maybeAddClosureLibrary(['core/**/**/*.js']), {base: './'}) - .pipe(stripApacheLicense()) - .pipe(gulp.sourcemaps.init()) - // Directories in Blockly are used to group similar files together - // but are not used to limit access with @package, instead the - // method means something is internal to Blockly and not a public - // API. - // Flatten all files so they're in the same directory, but ensure that - // files with the same name don't conflict. - .pipe(gulp.rename(function(p) { - var dirname = p.dirname.replace( - new RegExp(path.sep.replace(/\\/, '\\\\'), "g"), "-"); - p.dirname = ""; - p.basename = dirname + "-" + p.basename; - })) - .pipe(compile( - { - dependency_mode: 'PRUNE', - entry_point: './core-requires.js', - js_output_file: 'blockly_compressed.js', - externs: ['./externs/svg-externs.js', './externs/goog-externs.js'], - define: defines, - output_wrapper: outputWrapperUMD('Blockly', []) - }, - argv.verbose, argv.debug, argv.strict)) - .pipe(gulp.sourcemaps.mapSources(function(sourcePath, file) { - return sourcePath.replace(/-/g, '/'); - })) - .pipe( - gulp.sourcemaps.write('.', {includeContent: false, sourceRoot: './'})) - .pipe(gulp.dest(BUILD_DIR)); -}; - -/** - * This task builds the Blockly's built in blocks. - * blocks_compressed.js - */ -function buildBlocks() { - return gulp.src(['blocks/*.js'], {base: './'}) - .pipe(stripApacheLicense()) - .pipe(gulp.sourcemaps.init()) - .pipe(compile({ - dependency_mode: 'SORT_ONLY', - externs: ['./externs/goog-externs.js', './externs/block-externs.js'], - js_output_file: 'blocks_compressed.js', - output_wrapper: outputWrapperUMD('Blockly.Blocks', [{ - name: 'Blockly', - amd: './blockly_compressed.js', - cjs: './blockly_compressed.js' - }]) - }, argv.verbose, argv.debug, argv.strict)) - .pipe(gulp.sourcemaps.write('.', { - includeContent: false, - sourceRoot: './' - })) - .pipe(gulp.dest(BUILD_DIR)); -}; - -/** - * A helper method for building a Blockly code generator. - * @param {string} language Generator language. - * @param {string} namespace Language namespace. - */ -function buildGenerator(language, namespace) { - return gulp.src([`generators/${language}.js`, `generators/${language}/*.js`], {base: './'}) - .pipe(stripApacheLicense()) - .pipe(gulp.sourcemaps.init()) - .pipe(compile({ - dependency_mode: 'SORT_ONLY', - externs: ['./externs/goog-externs.js', './externs/generator-externs.js'], - js_output_file: `${language}_compressed.js`, - output_wrapper: outputWrapperUMD(`Blockly.${namespace}`, [{ - name: 'Blockly', - amd: './blockly_compressed.js', - cjs: './blockly_compressed.js' - }]) - }, argv.verbose, argv.debug, argv.strict)) - .pipe(gulp.sourcemaps.write('.', { - includeContent: false, - sourceRoot: './' - })) - .pipe(gulp.dest(BUILD_DIR)); -}; - -/** - * This task builds the javascript generator. - * javascript_compressed.js - */ -function buildJavascript() { - return buildGenerator('javascript', 'JavaScript'); -}; - -/** - * This task builds the python generator. - * python_compressed.js - */ -function buildPython() { - return buildGenerator('python', 'Python'); -}; - -/** - * This task builds the php generator. - * php_compressed.js - */ -function buildPHP() { - return buildGenerator('php', 'PHP'); -}; - -/** - * This task builds the lua generator. - * lua_compressed.js - */ -function buildLua() { - return buildGenerator('lua', 'Lua'); -}; - -/** - * This task builds the dart generator: - * dart_compressed.js - */ -function buildDart() { - return buildGenerator('dart', 'Dart'); -}; - -/** - * This tasks builds all the generators: - * javascript_compressed.js - * python_compressed.js - * php_compressed.js - * lua_compressed.js - * dart_compressed.js - */ -const buildGenerators = gulp.parallel( - buildJavascript, - buildPython, - buildPHP, - buildLua, - buildDart -); - /** * This task updates tests/deps.js, used by blockly_uncompressed.js * when loading Blockly in uncompiled mode. @@ -708,18 +532,6 @@ function buildAdvancedCompilationTest() { .pipe(gulp.dest('./tests/compile/')); } -/** - * This tasks builds Blockly's core files: - * blockly_compressed.js - * blocks_compressed.js - * blockly_uncompressed.js - */ -const buildCore = gulp.parallel( - buildDeps, - buildCompressed, - buildBlocks, - ); - /** * This task builds all of Blockly: * blockly_compressed.js @@ -731,10 +543,10 @@ const buildCore = gulp.parallel( * dart_compressed.js * blockly_uncompressed.js * msg/json/*.js + * test/deps*.js */ const build = gulp.parallel( - buildCore, - buildGenerators, + gulp.series(buildDeps, buildCompiled), buildLangfiles, ); @@ -774,14 +586,10 @@ function format() { module.exports = { build: build, deps: buildDeps, - core: buildCore, - blocks: buildBlocks, generateLangfiles: generateLangfiles, langfiles: buildLangfiles, compiled: buildCompiled, - compressed: buildCompressed, format: format, - generators: buildGenerators, checkinBuilt: checkinBuilt, cleanBuildDir: cleanBuildDir, advancedCompilationTest: buildAdvancedCompilationTest,