make build system worker compatible

This commit is contained in:
Fabian Jakobs 2011-01-26 17:08:34 +01:00
commit 4af6988ece
3 changed files with 105 additions and 89 deletions

View file

@ -91,11 +91,12 @@ copy({
{ {
root: aceHome + '/lib', root: aceHome + '/lib',
include: /.*\.js$/, include: /.*\.js$/,
exclude: /tests?\/|theme\/|mode\// exclude: /tests?\/|theme\/|mode\/|ace\/worker\/host\.js/
}, },
{ base: aceHome + '/lib/', path: 'ace/theme/textmate.js' }, { base: aceHome + '/lib/', path: 'ace/theme/textmate.js' },
{ base: aceHome + '/lib/', path: 'ace/mode/text.js' }, { base: aceHome + '/lib/', path: 'ace/mode/text.js' },
{ base: aceHome + '/lib/', path: 'ace/mode/javascript.js' }, { base: aceHome + '/lib/', path: 'ace/mode/javascript.js' },
{ base: aceHome + '/lib/', path: 'ace/mode/javascript_worker.js' },
{ base: aceHome + '/lib/', path: 'ace/mode/text_highlight_rules.js' }, { base: aceHome + '/lib/', path: 'ace/mode/text_highlight_rules.js' },
{ base: aceHome + '/lib/', path: 'ace/mode/javascript_highlight_rules.js' }, { base: aceHome + '/lib/', path: 'ace/mode/javascript_highlight_rules.js' },
{ base: aceHome + '/lib/', path: 'ace/mode/doc_comment_highlight_rules.js' }, { base: aceHome + '/lib/', path: 'ace/mode/doc_comment_highlight_rules.js' },
@ -121,7 +122,6 @@ copy({
source: [ source: [
'build_support/mini_require.js', 'build_support/mini_require.js',
pilot, pilot,
// cockpit,
ace, ace,
'build_support/boot.js' 'build_support/boot.js'
], ],
@ -146,7 +146,14 @@ copy({
dest: 'build/ace-uncompressed.js' dest: 'build/ace-uncompressed.js'
}); });
// Create worker bootstrap code
copy({
source: "lib/ace/worker/host.js",
filter: [function(data) {
return data + "\nimportScripts('ace-uncompressed.js')";
}],
dest: 'build/host.js'
});

View file

@ -35,15 +35,18 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
var deps = [ "pilot/fixoldbrowsers", "pilot/plugin_manager", "pilot/settings", // don't define it in a worker.
if (window.document) {
var deps = [ "pilot/fixoldbrowsers", "pilot/plugin_manager", "pilot/settings",
"pilot/environment" ]; "pilot/environment" ];
require(deps, function() { require(deps, function() {
var catalog = require("pilot/plugin_manager").catalog; var catalog = require("pilot/plugin_manager").catalog;
catalog.registerPlugins([ "pilot/index" ]); catalog.registerPlugins([ "pilot/index" ]);
}); });
var ace = { var ace = {
edit: function(el) { edit: function(el) {
if (typeof(el) == "string") { if (typeof(el) == "string") {
el = document.getElementById(el); el = document.getElementById(el);
@ -72,4 +75,5 @@ var ace = {
el.env = env; el.env = env;
}); });
} }
}; };
}

View file

@ -35,7 +35,10 @@
* *
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
function require(module, callback) { // don't define it in a worker. There we have a different implementation
if (window.document) {
window.require = function(module, callback) {
if (Array.isArray(module)) { if (Array.isArray(module)) {
var params = []; var params = [];
@ -55,10 +58,11 @@ function require(module, callback) {
} }
return payload; return payload;
} }
} }
require.modules = {}; require.modules = {};
require.packaged = true;
require._lookup = function(moduleName) { require._lookup = function(moduleName) {
var payload = require.modules[moduleName]; var payload = require.modules[moduleName];
var module_name = moduleName; var module_name = moduleName;
if (payload == null) { if (payload == null) {
@ -79,9 +83,9 @@ require._lookup = function(moduleName) {
} }
return payload; return payload;
}; };
function define(module, payload) { window.define = function(module, payload) {
if (typeof module !== 'string') { if (typeof module !== 'string') {
console.error('dropping module because define wasn\'t munged.'); console.error('dropping module because define wasn\'t munged.');
console.trace(); console.trace();
@ -90,4 +94,5 @@ function define(module, payload) {
// console.log('defining module: ' + module + ' as a ' + typeof payload); // console.log('defining module: ' + module + ' as a ' + typeof payload);
require.modules[module] = payload; require.modules[module] = payload;
}
} }