diff --git a/packages/ember-metal/lib/core.js b/packages/ember-metal/lib/core.js index c5fe55e360e..628ee5defb3 100644 --- a/packages/ember-metal/lib/core.js +++ b/packages/ember-metal/lib/core.js @@ -1,5 +1,7 @@ /*globals Ember:true,ENV,EmberENV */ +import require from 'require'; + /** @module ember @submodule ember-metal @@ -47,7 +49,7 @@ Ember.toString = function() { return 'Ember'; }; // The debug functions are exported to globals with `require` to // prevent babel-plugin-filter-imports from removing them. -let debugModule = Ember.__loader.require('ember-metal/debug'); +let debugModule = require('ember-metal/debug'); Ember.assert = debugModule.assert; Ember.warn = debugModule.warn; Ember.debug = debugModule.debug; diff --git a/packages/ember-metal/lib/index.js b/packages/ember-metal/lib/index.js index f90160fe214..0491f9bd2ca 100644 --- a/packages/ember-metal/lib/index.js +++ b/packages/ember-metal/lib/index.js @@ -4,6 +4,7 @@ */ // BEGIN IMPORTS +import require, { has } from 'require'; import Ember from 'ember-metal/core'; import { deprecateFunc } from 'ember-metal/debug'; import isEnabled, { FEATURES } from 'ember-metal/features'; @@ -358,8 +359,8 @@ Ember.onerror = null; // do this for side-effects of updating Ember.assert, warn, etc when // ember-debug is present // This needs to be called before any deprecateFunc -if (Ember.__loader.registry['ember-debug/index']) { - requireModule('ember-debug'); +if (has('ember-debug')) { + require('ember-debug'); } else { Ember.Debug = { }; diff --git a/packages/ember-runtime/lib/ext/rsvp.js b/packages/ember-runtime/lib/ext/rsvp.js index 4eb291b1cb2..d688bf52436 100644 --- a/packages/ember-runtime/lib/ext/rsvp.js +++ b/packages/ember-runtime/lib/ext/rsvp.js @@ -1,6 +1,7 @@ /* globals RSVP:true */ import Ember from 'ember-metal/core'; +import require, { has } from 'require'; import { assert } from 'ember-metal/debug'; import Logger from 'ember-metal/logger'; import run from 'ember-metal/run_loop'; @@ -57,8 +58,8 @@ export function onerrorDefault(reason) { if (error && error.name !== 'TransitionAborted') { if (Ember.testing) { // ES6TODO: remove when possible - if (!Test && Ember.__loader.registry[testModuleName]) { - Test = requireModule(testModuleName)['default']; + if (!Test && has(testModuleName)) { + Test = require(testModuleName)['default']; } if (Test && Test.adapter) { diff --git a/packages/ember-template-compiler/lib/compat/precompile.js b/packages/ember-template-compiler/lib/compat/precompile.js index 62f4f7f6dfc..99885ac3bb1 100644 --- a/packages/ember-template-compiler/lib/compat/precompile.js +++ b/packages/ember-template-compiler/lib/compat/precompile.js @@ -2,14 +2,14 @@ @module ember @submodule ember-template-compiler */ -import Ember from 'ember-metal/core'; +import require, { has } from 'require'; import compileOptions from 'ember-template-compiler/system/compile_options'; var compile, compileSpec; export default function(string) { - if ((!compile || !compileSpec) && Ember.__loader.registry['htmlbars-compiler/compiler']) { - var Compiler = requireModule('htmlbars-compiler/compiler'); + if ((!compile || !compileSpec) && has('htmlbars-compiler/compiler')) { + var Compiler = require('htmlbars-compiler/compiler'); compile = Compiler.compile; compileSpec = Compiler.compileSpec; diff --git a/packages/ember-template-compiler/lib/system/compile.js b/packages/ember-template-compiler/lib/system/compile.js index 1cf1ec0a83e..3ebf8c19529 100644 --- a/packages/ember-template-compiler/lib/system/compile.js +++ b/packages/ember-template-compiler/lib/system/compile.js @@ -3,7 +3,7 @@ @submodule ember-template-compiler */ -import Ember from 'ember-metal/core'; +import require, { has } from 'require'; import compileOptions from 'ember-template-compiler/system/compile_options'; import template from 'ember-template-compiler/system/template'; @@ -20,8 +20,8 @@ var compile; @param {Object} options This is an options hash to augment the compiler options. */ export default function(templateString, options) { - if (!compile && Ember.__loader.registry['htmlbars-compiler/compiler']) { - compile = requireModule('htmlbars-compiler/compiler').compile; + if (!compile && has('htmlbars-compiler/compiler')) { + compile = require('htmlbars-compiler/compiler').compile; } if (!compile) { diff --git a/packages/ember-template-compiler/lib/system/precompile.js b/packages/ember-template-compiler/lib/system/precompile.js index d5e62d30f23..ba126a1857a 100644 --- a/packages/ember-template-compiler/lib/system/precompile.js +++ b/packages/ember-template-compiler/lib/system/precompile.js @@ -2,7 +2,7 @@ @module ember @submodule ember-template-compiler */ -import Ember from 'ember-metal/core'; +import require, { has } from 'require'; import compileOptions from 'ember-template-compiler/system/compile_options'; var compileSpec; @@ -18,8 +18,8 @@ var compileSpec; @param {String} templateString This is the string to be compiled by HTMLBars. */ export default function(templateString, options) { - if (!compileSpec && Ember.__loader.registry['htmlbars-compiler/compiler']) { - compileSpec = requireModule('htmlbars-compiler/compiler').compileSpec; + if (!compileSpec && has('htmlbars-compiler/compiler')) { + compileSpec = require('htmlbars-compiler/compiler').compileSpec; } if (!compileSpec) { diff --git a/packages/ember/lib/index.js b/packages/ember/lib/index.js index 831efe63677..18d109d9ee9 100644 --- a/packages/ember/lib/index.js +++ b/packages/ember/lib/index.js @@ -10,17 +10,17 @@ import 'ember-htmlbars'; import 'ember-routing-htmlbars'; import 'ember-routing-views'; -import Ember from 'ember-metal/core'; +import require, { has } from 'require'; import { runLoadHooks } from 'ember-runtime/system/lazy_load'; -if (Ember.__loader.registry['ember-template-compiler/index']) { - requireModule('ember-template-compiler'); +if (has('ember-template-compiler')) { + require('ember-template-compiler'); } // do this to ensure that Ember.Test is defined properly on the global // if it is present. -if (Ember.__loader.registry['ember-testing/index']) { - requireModule('ember-testing'); +if (has('ember-testing')) { + require('ember-testing'); } runLoadHooks('Ember'); diff --git a/packages/loader/lib/index.js b/packages/loader/lib/index.js index b3b7cc47a54..3158e7b8762 100644 --- a/packages/loader/lib/index.js +++ b/packages/loader/lib/index.js @@ -32,8 +32,14 @@ var mainContext = this; requirejs = require = requireModule = function(name) { return internalRequire(name, null); } + + // setup `require` module require['default'] = require; + require.has = function registryHas(moduleName) { + return !!registry[moduleName] || !!registry[moduleName + '/index']; + }; + function missingModule(name, referrerName) { if (referrerName) { throw new Error('Could not find module ' + name + ' required by: ' + referrerName);