From 83460a5c82260fc87fc0a2dd83ba8e91a5802d3f Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Wed, 25 Nov 2015 23:08:23 -0500 Subject: [PATCH 1/4] Move `packages/**/lib/main.js` to `packages/**/lib/index.js`. --- packages/container/lib/{main.js => index.js} | 0 packages/ember-application/lib/{main.js => index.js} | 0 packages/ember-debug/lib/{main.js => index.js} | 0 packages/ember-extension-support/lib/{main.js => index.js} | 0 packages/ember-htmlbars/lib/{main.js => index.js} | 0 packages/ember-metal-views/lib/{main.js => index.js} | 0 packages/ember-metal/lib/{main.js => index.js} | 0 packages/ember-routing-htmlbars/lib/{main.js => index.js} | 0 packages/ember-routing-views/lib/{main.js => index.js} | 0 packages/ember-routing/lib/{main.js => index.js} | 0 packages/ember-runtime/lib/{main.js => index.js} | 0 packages/ember-template-compiler/lib/{main.js => index.js} | 0 packages/ember-testing/lib/{main.js => index.js} | 0 packages/ember-views/lib/{main.js => index.js} | 0 packages/ember/lib/{main.js => index.js} | 0 packages/loader/lib/{main.js => index.js} | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename packages/container/lib/{main.js => index.js} (100%) rename packages/ember-application/lib/{main.js => index.js} (100%) rename packages/ember-debug/lib/{main.js => index.js} (100%) rename packages/ember-extension-support/lib/{main.js => index.js} (100%) rename packages/ember-htmlbars/lib/{main.js => index.js} (100%) rename packages/ember-metal-views/lib/{main.js => index.js} (100%) rename packages/ember-metal/lib/{main.js => index.js} (100%) rename packages/ember-routing-htmlbars/lib/{main.js => index.js} (100%) rename packages/ember-routing-views/lib/{main.js => index.js} (100%) rename packages/ember-routing/lib/{main.js => index.js} (100%) rename packages/ember-runtime/lib/{main.js => index.js} (100%) rename packages/ember-template-compiler/lib/{main.js => index.js} (100%) rename packages/ember-testing/lib/{main.js => index.js} (100%) rename packages/ember-views/lib/{main.js => index.js} (100%) rename packages/ember/lib/{main.js => index.js} (100%) rename packages/loader/lib/{main.js => index.js} (100%) diff --git a/packages/container/lib/main.js b/packages/container/lib/index.js similarity index 100% rename from packages/container/lib/main.js rename to packages/container/lib/index.js diff --git a/packages/ember-application/lib/main.js b/packages/ember-application/lib/index.js similarity index 100% rename from packages/ember-application/lib/main.js rename to packages/ember-application/lib/index.js diff --git a/packages/ember-debug/lib/main.js b/packages/ember-debug/lib/index.js similarity index 100% rename from packages/ember-debug/lib/main.js rename to packages/ember-debug/lib/index.js diff --git a/packages/ember-extension-support/lib/main.js b/packages/ember-extension-support/lib/index.js similarity index 100% rename from packages/ember-extension-support/lib/main.js rename to packages/ember-extension-support/lib/index.js diff --git a/packages/ember-htmlbars/lib/main.js b/packages/ember-htmlbars/lib/index.js similarity index 100% rename from packages/ember-htmlbars/lib/main.js rename to packages/ember-htmlbars/lib/index.js diff --git a/packages/ember-metal-views/lib/main.js b/packages/ember-metal-views/lib/index.js similarity index 100% rename from packages/ember-metal-views/lib/main.js rename to packages/ember-metal-views/lib/index.js diff --git a/packages/ember-metal/lib/main.js b/packages/ember-metal/lib/index.js similarity index 100% rename from packages/ember-metal/lib/main.js rename to packages/ember-metal/lib/index.js diff --git a/packages/ember-routing-htmlbars/lib/main.js b/packages/ember-routing-htmlbars/lib/index.js similarity index 100% rename from packages/ember-routing-htmlbars/lib/main.js rename to packages/ember-routing-htmlbars/lib/index.js diff --git a/packages/ember-routing-views/lib/main.js b/packages/ember-routing-views/lib/index.js similarity index 100% rename from packages/ember-routing-views/lib/main.js rename to packages/ember-routing-views/lib/index.js diff --git a/packages/ember-routing/lib/main.js b/packages/ember-routing/lib/index.js similarity index 100% rename from packages/ember-routing/lib/main.js rename to packages/ember-routing/lib/index.js diff --git a/packages/ember-runtime/lib/main.js b/packages/ember-runtime/lib/index.js similarity index 100% rename from packages/ember-runtime/lib/main.js rename to packages/ember-runtime/lib/index.js diff --git a/packages/ember-template-compiler/lib/main.js b/packages/ember-template-compiler/lib/index.js similarity index 100% rename from packages/ember-template-compiler/lib/main.js rename to packages/ember-template-compiler/lib/index.js diff --git a/packages/ember-testing/lib/main.js b/packages/ember-testing/lib/index.js similarity index 100% rename from packages/ember-testing/lib/main.js rename to packages/ember-testing/lib/index.js diff --git a/packages/ember-views/lib/main.js b/packages/ember-views/lib/index.js similarity index 100% rename from packages/ember-views/lib/main.js rename to packages/ember-views/lib/index.js diff --git a/packages/ember/lib/main.js b/packages/ember/lib/index.js similarity index 100% rename from packages/ember/lib/main.js rename to packages/ember/lib/index.js diff --git a/packages/loader/lib/main.js b/packages/loader/lib/index.js similarity index 100% rename from packages/loader/lib/main.js rename to packages/loader/lib/index.js From 80270f186a7863ea3c946ee2d14ca6118dd7e3a8 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 26 Nov 2015 00:07:25 -0500 Subject: [PATCH 2/4] Add fallback for `${moduleName}/index`. This follows suit with changes made in ember-cli/loader.js@v3.5.0. --- packages/ember-metal/lib/index.js | 2 +- packages/ember/lib/index.js | 4 ++-- packages/loader/lib/index.js | 15 +++++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/ember-metal/lib/index.js b/packages/ember-metal/lib/index.js index fb9e1321914..f90160fe214 100644 --- a/packages/ember-metal/lib/index.js +++ b/packages/ember-metal/lib/index.js @@ -358,7 +358,7 @@ 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']) { +if (Ember.__loader.registry['ember-debug/index']) { requireModule('ember-debug'); } else { Ember.Debug = { }; diff --git a/packages/ember/lib/index.js b/packages/ember/lib/index.js index a739c3e5f9d..831efe63677 100644 --- a/packages/ember/lib/index.js +++ b/packages/ember/lib/index.js @@ -13,13 +13,13 @@ import 'ember-routing-views'; import Ember from 'ember-metal/core'; import { runLoadHooks } from 'ember-runtime/system/lazy_load'; -if (Ember.__loader.registry['ember-template-compiler']) { +if (Ember.__loader.registry['ember-template-compiler/index']) { requireModule('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']) { +if (Ember.__loader.registry['ember-testing/index']) { requireModule('ember-testing'); } diff --git a/packages/loader/lib/index.js b/packages/loader/lib/index.js index 86e7cb5644f..b3b7cc47a54 100644 --- a/packages/loader/lib/index.js +++ b/packages/loader/lib/index.js @@ -42,7 +42,15 @@ var mainContext = this; } } - function internalRequire(name, referrerName) { + function internalRequire(_name, referrerName) { + var name = _name; + var mod = registry[name]; + + if (!mod) { + name = name + '/index'; + mod = registry[name]; + } + var exports = seen[name]; if (exports !== undefined) { @@ -51,11 +59,10 @@ var mainContext = this; exports = seen[name] = {}; - if (!registry[name]) { - missingModule(name, referrerName); + if (!mod) { + missingModule(_name, referrerName); } - var mod = registry[name]; var deps = mod.deps; var callback = mod.callback; var length = deps.length; From 0770bdd792533c7d6ee0d04df710c7a90ee6c166 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 27 Nov 2015 11:22:57 -0500 Subject: [PATCH 3/4] Update emberjs-build to reduce wasted `main.js` manipulation. --- npm-shrinkwrap.json | 18 +++++++++--------- package.json | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 6d9bb8e78df..1f63c7b7087 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1454,7 +1454,8 @@ "dependencies": { "esprima-fb": { "version": "15001.1001.0-dev-harmony-fb", - "from": "esprima-fb@>=15001.1001.0-dev-harmony-fb <15001.1002.0" + "from": "esprima-fb@15001.1001.0-dev-harmony-fb", + "resolved": "https://registry.npmjs.org/esprima-fb/-/esprima-fb-15001.1001.0-dev-harmony-fb.tgz" } } }, @@ -1539,7 +1540,7 @@ }, "ember-cli": { "version": "1.13.13", - "from": "ember-cli@1.13.13", + "from": "ember-cli@>=1.13.13 <2.0.0", "resolved": "https://registry.npmjs.org/ember-cli/-/ember-cli-1.13.13.tgz", "dependencies": { "ansi-regex": { @@ -1616,7 +1617,7 @@ }, "lodash": { "version": "2.4.2", - "from": "lodash@2.4.2", + "from": "lodash@>=2.4.1 <2.5.0", "resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz" }, "strip-ansi": { @@ -1809,9 +1810,8 @@ } }, "emberjs-build": { - "version": "0.4.7", - "from": "emberjs-build@0.4.7", - "resolved": "https://registry.npmjs.org/emberjs-build/-/emberjs-build-0.4.7.tgz", + "version": "0.5.2", + "from": "emberjs-build@0.5.2", "dependencies": { "assert-plus": { "version": "0.1.2", @@ -1841,9 +1841,9 @@ "resolved": "https://registry.npmjs.org/broccoli-funnel/-/broccoli-funnel-0.2.15.tgz", "dependencies": { "rimraf": { - "version": "2.4.3", + "version": "2.4.4", "from": "rimraf@>=2.4.3 <3.0.0", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.4.3.tgz" + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.4.4.tgz" } } }, @@ -1950,7 +1950,7 @@ "dependencies": { "git-repo-info": { "version": "1.1.2", - "from": "git-repo-info@1.1.2", + "from": "git-repo-info@>=1.0.4 <2.0.0", "resolved": "https://registry.npmjs.org/git-repo-info/-/git-repo-info-1.1.2.tgz" } } diff --git a/package.json b/package.json index 4d196c6d2e5..b1307b6954f 100644 --- a/package.json +++ b/package.json @@ -23,12 +23,12 @@ "babel-plugin-filter-imports": "~0.2.0", "bower": "~1.3.2", "chalk": "^0.5.1", - "ember-cli-dependency-checker": "^1.0.1", "ember-cli": "^1.13.13", + "ember-cli-dependency-checker": "^1.0.1", "ember-cli-sauce": "^1.4.2", "ember-cli-yuidoc": "0.7.0", "ember-publisher": "0.0.7", - "emberjs-build": "0.4.7", + "emberjs-build": "0.5.2", "express": "^4.5.0", "finalhandler": "^0.4.0", "github": "^0.2.3", From 89f0516c78af31fbd2ef3c9e7a6b84b497be6105 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Fri, 27 Nov 2015 16:43:42 -0500 Subject: [PATCH 4/4] Remove internal usage of `Ember.__loader`. --- packages/ember-metal/lib/core.js | 4 +++- packages/ember-metal/lib/index.js | 5 +++-- packages/ember-runtime/lib/ext/rsvp.js | 5 +++-- .../ember-template-compiler/lib/compat/precompile.js | 6 +++--- packages/ember-template-compiler/lib/system/compile.js | 6 +++--- .../ember-template-compiler/lib/system/precompile.js | 6 +++--- packages/ember/lib/index.js | 10 +++++----- packages/loader/lib/index.js | 6 ++++++ 8 files changed, 29 insertions(+), 19 deletions(-) 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);