Skip to content

Commit

Permalink
Load dependency graph from tests/deps.js in uncompiled mode
Browse files Browse the repository at this point in the history
* New gulp task buildDeps (npm run build:deps) to create tests/deps.js.
* Old gulp task buildUncompressed is deleted.
* blockly_uncompressed.js is now handwritten.
  * And simplified; in particular, BLOCKLY_BOOT is gone.
  * And linted!
* For consistency with the Closure documentation and base.js,
  consistently refer to what blockly_uncompressed.js is used for as
  "uncompiled mode" rather than "uncompressed mode" (but don't yet
  rename it to blockly_uncompiled.js)
  • Loading branch information
cpcallen committed Jul 12, 2021
1 parent 214492c commit c50f4bb
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 322 deletions.
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*_compressed*.js
*_uncompressed*.js
gulpfile.js
/msg/*
/dist/*
Expand Down
276 changes: 43 additions & 233 deletions blockly_uncompressed.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ module.exports = {
default: buildTasks.build,
generateLangfiles: buildTasks.generateLangfiles,
build: buildTasks.build,
buildDeps: buildTasks.deps,
buildCore: buildTasks.core,
buildBlocks: buildTasks.blocks,
buildLangfiles: buildTasks.langfiles,
buildUncompressed: buildTasks.uncompressed,
buildCompressed: buildTasks.compressed,
buildGenerators: buildTasks.generators,
buildAdvancedCompilationTest: buildTasks.advancedCompilationTest,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"build:core": "gulp buildCore",
"build:debug": "gulp buildCompressed --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:uncompressed": "gulp buildUncompressed",
"bump": "npm --no-git-tag-version version 4.$(date +'%Y%m%d').0",
"clean": "gulp clean",
"clean:build": "gulp cleanBuildDir",
Expand Down
108 changes: 22 additions & 86 deletions scripts/gulpfiles/build_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ gulp.sourcemaps = require('gulp-sourcemaps');

var path = require('path');
var fs = require('fs');
var execSync = require('child_process').execSync;
var through2 = require('through2');

var closureCompiler = require('google-closure-compiler').gulp();
Expand All @@ -24,6 +23,7 @@ var argv = require('yargs').argv;
var rimraf = require('rimraf');

var {BUILD_DIR} = require('./config');
var {exec, execSync} = require('child_process');
var {getPackageJson} = require('./helper_tasks');

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -330,84 +330,20 @@ const buildGenerators = gulp.parallel(
);

/**
* This task builds Blockly's uncompressed file.
* blockly_uncompressed.js
* This task updates tests/deps.js, used by blockly_uncompressed.js
* when loading Blockly in uncompiled mode.
*/
function buildUncompressed() {
function buildDeps(done) {
const closurePath = argv.closureLibrary ?
'node_modules/google-closure-library/closure/goog' :
'closure/goog';
const header = `// Do not edit this file; automatically generated by gulp.
'use strict';
this.IS_NODE_JS = !!(typeof module !== 'undefined' && module.exports);
this.BLOCKLY_DIR = (function(root) {
if (!root.IS_NODE_JS) {
// Find name of current directory.
var scripts = document.getElementsByTagName('script');
var re = new RegExp('(.+)[\\\/]blockly_(.*)uncompressed\\\.js$');
for (var i = 0, script; script = scripts[i]; i++) {
var match = re.exec(script.src);
if (match) {
return match[1];
}
}
alert('Could not detect Blockly\\'s directory name.');
}
return '';
})(this);
this.BLOCKLY_BOOT = function(root) {
// Execute after Closure has loaded.
`;
const footer = `
delete root.BLOCKLY_DIR;
delete root.BLOCKLY_BOOT;
delete root.IS_NODE_JS;
};
if (this.IS_NODE_JS) {
this.BLOCKLY_BOOT(this);
module.exports = Blockly;
} else {
document.write('<script src="' + this.BLOCKLY_DIR +
'/${closurePath}/base.js"></script>');
document.write('<script>this.BLOCKLY_BOOT(this);</script>');
}
`;

let deps = [];
return gulp.src(maybeAddClosureLibrary(['core/**/**/*.js']))
.pipe(through2.obj((file, _enc, cb) => {
const result = closureDeps.parser.parseFile(file.path);
for (const dep of result.dependencies) {
deps.push(dep);
}
cb(null);
}))
.on('end', () => {
// Update the path to closure for any files that we don't know the full path
// of (parsed from a goog.addDependency call).
for (const dep of deps) {
dep.setClosurePath(closurePath);
}

const addDependency = closureDeps.depFile
.getDepFileText(closurePath, deps)
.replace(/\\/g, '\/');

const requires = `goog.addDependency("base.js", [], []);
// Load Blockly.
goog.require('Blockly.requires');
`;
fs.writeFileSync('blockly_uncompressed.js',
header +
addDependency +
requires +
footer);
});
'node_modules/google-closure-library/closure/goog' :
'closure/goog';
const roots = [
closurePath,
'core',
'blocks',
];
const args = roots.map(root => `--root '${root}' `).join('');
exec(`closure-make-deps ${args} > tests/deps.js`, done);
};

/**
Expand Down Expand Up @@ -517,10 +453,10 @@ function buildAdvancedCompilationTest() {
* blockly_uncompressed.js
*/
const buildCore = gulp.parallel(
buildCompressed,
buildBlocks,
buildUncompressed
);
buildDeps,
buildCompressed,
buildBlocks,
);

/**
* This task builds all of Blockly:
Expand All @@ -535,10 +471,10 @@ const buildCore = gulp.parallel(
* msg/json/*.js
*/
const build = gulp.parallel(
buildCore,
buildGenerators,
buildLangfiles
);
buildCore,
buildGenerators,
buildLangfiles,
);

/**
* This task copies built files from BUILD_DIR back to the repository
Expand Down Expand Up @@ -566,11 +502,11 @@ function cleanBuildDir(done) {

module.exports = {
build: build,
deps: buildDeps,
core: buildCore,
blocks: buildBlocks,
generateLangfiles: generateLangfiles,
langfiles: buildLangfiles,
uncompressed: buildUncompressed,
compressed: buildCompressed,
generators: buildGenerators,
checkinBuilt: checkinBuilt,
Expand Down
Loading

0 comments on commit c50f4bb

Please sign in to comment.