Permalink
Browse files

Removed need for some globals

  • Loading branch information...
1 parent 458a2fe commit c62e2d131e73120cf3aee88f4e763b4688c52d46 @ryanwilliams committed Jun 4, 2012
Showing with 9 additions and 19 deletions.
  1. +3 −2 lib/jah/compiler.js
  2. +6 −17 lib/jah/module_js
View
@@ -19,7 +19,7 @@ var DEFAULT_JAH_JSON = { mainModule: 'main'
var JAH_ROOT = path.normalize(path.dirname(path.join(__dirname, '../')))
-var TEMPLATES = { code: new T('function (exports, require, module, __filename, __dirname) {${data}}')
+var TEMPLATES = { code: new T('function (exports, require, resource, module, __filename, __dirname) {${data}}')
, jahFooter: new T(fs.readFileSync(path.join(__dirname, 'module_js'), 'utf8'))
, resource: new T('__jah__.resources["${filename}"] = {data: ${data}, mimetype: "${mimetype}", remote: ${remote}};')
}
@@ -400,7 +400,8 @@ Compiler.prototype.collectAssetFilenames = function (filename, mountRoot) {
}
Compiler.prototype.jahHeader = function () {
- return 'if (!window.__jah__) window.__jah__ = {resources:{}, assetURL: ' + JSON.stringify(this.config.assetPath) + '};\n'
+ return 'if (typeof __jah__ == "undefined") ' +
+ 'window.__jah__ = {resources:{}, assetURL: ' + JSON.stringify(this.config.assetPath) + '};\n'
}
Compiler.prototype.jahFooter = function () {
View
@@ -9,7 +9,11 @@ var process = {}
, modulePaths = ['/__builtin__', '/__builtin__/libs', '/libs']
, path; // path module, we will load this later
-window.resource = function(resourcePath) {
+function require (request, parent) {
+ return loadModule(request, parent).exports;
+}
+
+function resource (resourcePath) {
var remotes = require('remote_resources')
var res = __jah__.resources[resourcePath]
@@ -126,7 +130,7 @@ Module.prototype._initialize = function (filename) {
var mod = __jah__.resources[this.filename]
if (mod) {
- mod.data.apply(this.exports, [this.exports, require, this, this.filename, this.dirname]);
+ mod.data.apply(this.exports, [this.exports, require, resource, this, this.filename, this.dirname]);
} else {
throw new Error("Unable to find module: " + this.filename)
}
@@ -142,12 +146,6 @@ var util = loadModule('/__builtin__/').exports;
// Browser's DOM is ready for action
util.ready(function () {
- // Add a global require. Useful in the debug console.
- window.require = function require(request, parent) {
- return loadModule(request, parent).exports;
- };
- window.require.paths = modulePaths;
-
// Initialise the libs
var key, lib
for (key in __jah__.resources) {
@@ -164,15 +162,6 @@ util.ready(function () {
// Initialise the main module
process.mainModule = loadModule(__main_module_name__);
- window.require.main = process.mainModule;
-
- // Attempt to add global 'requite' to top frame
- try {
- if (!top.window.require) {
- top.window.require = window.require
- }
- } catch (e) {
- }
// Run application's main function
if (process.mainModule.exports.main) {

0 comments on commit c62e2d1

Please sign in to comment.