Skip to content

Commit

Permalink
fix(build): Fix test failures caused by new build pipeline
Browse files Browse the repository at this point in the history
- Exclude closure/goog/base.js from compiler input; use
  externs/goog-externs.js instead.

- Have the build:debug and build:strict targets only build the first
  chunk (blockly_compressed.js).

- Fix namespace entries for blocks and generators.
  • Loading branch information
cpcallen committed Nov 24, 2021
1 parent af7b567 commit 5b112db
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions scripts/gulpfiles/build_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const COMPILED_SUFFIX = '_compressed';
*
* - .dependencies: a list of the chunks the chunk depends upon.
* - .wrapper: the chunk wrapper.
* - .js: an array of filenames of the JS files for the chunk.
*
* Output files will be named <chunk.name><COMPILED_SUFFIX>.js.
*/
Expand All @@ -63,28 +64,23 @@ const chunks = [
}, {
name: 'javascript',
entry: 'generators/javascript/all.js',
// dependsOn: ['blocks'],
namespace: 'JavaScript',
namespace: 'Blockly.JavaScript',
}, {
name: 'python',
entry: 'generators/python/all.js',
// dependsOn: ['blocks'],
namespace: 'Python',
namespace: 'Blockly.Python',
}, {
name: 'php',
entry: 'generators/php/all.js',
// dependsOn: ['blocks'],
namespace: 'PHP',
namespace: 'Blockly.PHP',
}, {
name: 'lua',
entry: 'generators/lua/all.js',
// dependsOn: ['blocks'],
namespace: 'Lua',
namespace: 'Blockly.Lua',
}, {
name: 'dart',
entry: 'generators/dart/all.js',
// dependsOn: ['blocks'],
namespace: 'Dart',
namespace: 'Blockly.Dart',
}
];

Expand Down Expand Up @@ -323,7 +319,7 @@ function chunkWrapper(chunk) {
root.${chunk.namespace} = factory(${browserDeps});
}
}(this, function(${imports}) {
%output%
%output%
return ${chunk.namespace};
}));
`;
Expand Down Expand Up @@ -370,34 +366,48 @@ function getChunkOptions() {
// }
//
// This is designed to be passed directly as-is as the options
// object to the Closure Compiler node API, but we want to replace
// the unhelpful entry-point based chunk names (let's call these
// "nicknames") with the ones from chunks. Luckily they will be in
// the same order that the entry points were supplied in - i.e.,
// they correspond 1:1 with the entries in chunks.
// object to the Closure Compiler node API, but we want to make a
// number of changes:
//
// - Replace the unhelpful entry-point based chunk names (let's call these
// "nicknames") with the ones from chunks. Luckily they will be in
// the same order that the entry points were supplied in - i.e.,
// they correspond 1:1 with the entries in chunks.
// - Remove base.js from the list of JS files for the first chunk.
const chunkByNickname = Object.create(null);
let jsFiles = rawOptions.js;
const chunkList = rawOptions.chunk.map((element, index) => {
const [nickname, numJsFiles, dependencyNicks] = element.split(':');
const chunk = chunks[index];

// Record js files for chunk, filtering out base.js.
chunk.js =
jsFiles.slice(0, numJsFiles).filter(f => !f.endsWith('goog/base.js'));
jsFiles = jsFiles.slice(numJsFiles);

// Replace nicknames with our names.
chunkByNickname[nickname] = chunk;
if (!dependencyNicks) { // Chunk has no dependencies.
chunk.dependencies = [];
return `${chunk.name}:${numJsFiles}`;
return `${chunk.name}:${chunk.js.length}`;
}
chunk.dependencies =
dependencyNicks.split(',').map(nick => chunkByNickname[nick]);
const dependencyNames =
chunk.dependencies.map(dependency => dependency.name).join(',');
return `${chunk.name}:${numJsFiles}:${dependencyNames}`;
return `${chunk.name}:${chunk.js.length}:${dependencyNames}`;
});

// Generate a chunk wrapper for each chunk.
for (const chunk of chunks) {
chunk.wrapper = chunkWrapper(chunk);
}

const chunkWrappers = chunks.map(chunk => `${chunk.name}:${chunk.wrapper}`);
return {chunk: chunkList, js: rawOptions.js, chunk_wrapper: chunkWrappers};

// Reconstitute js files list, after exclusions.
jsFiles = chunks.map(chunk => chunk.js).flat();

return {chunk: chunkList, js: jsFiles, chunk_wrapper: chunkWrappers};
}

/**
Expand Down Expand Up @@ -459,14 +469,21 @@ function buildCompiled() {
language_out: 'ECMASCRIPT5_STRICT',
rewrite_polyfills: true,
hide_warnings_for: 'node_modules',
externs: ['./externs/svg-externs.js'],
externs: ['./externs/goog-externs.js', './externs/svg-externs.js'],
define: 'Blockly.VERSION="' + packageJson.version + '"',
chunk: chunkOptions.chunk,
chunk_wrapper: chunkOptions.chunk_wrapper,
// Don't supply the list of source files in chunkOptions.js as an
// option to Closure Compiler; instead feed them as input via gulp.src.
};
if (argv.debug || argv.strict) {
// Tempororary hack: only compile first chunk, because there are
// too many errors in blocks and generators due to missing /
// extraneous requires.
options.chunk.length = 1;
options.chunk_wrapper.length = 1;
chunkOptions.js = chunks[0].js;

options.jscomp_error = [...JSCOMP_ERROR];
if (argv.strict) {
options.jscomp_error.push('strictCheckTypes');
Expand Down

0 comments on commit 5b112db

Please sign in to comment.