Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Merge Conflicts #4

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b81cd17
bump babel-plugin, fixes #419
stefanpenner May 24, 2017
cd05ef3
Merge pull request #420 from ember-engines/fix-stuff
rwjblue May 24, 2017
fadebe9
Returning value from '_externalAliasMethod', so that transitionToExte…
catrider May 24, 2017
a8606e2
Cleaned up tests
catrider May 26, 2017
92af826
Merge pull request #421 from catrider/transition-to-external-fix
trentmwillis May 26, 2017
5106546
Update `lazyLoading` option to accept a hash
mike183 Jun 2, 2017
4458bd4
Pass entire lazyLoading object to calculateCacheKeyForTree
mike183 Jun 2, 2017
ba63949
Introduce `lazyLoading.includeRoutesInApplication` option
mike183 Jun 3, 2017
a28578a
Merge pull request #424 from status200/lazyloading-hash
rwjblue Jun 3, 2017
9757b83
Refactor `lazyLoading.includeRoutesInApplication` implementation
mike183 Jun 5, 2017
d4c1b8d
lazyLoading.includeRoutesInApplication Tests
mike183 Jun 5, 2017
f479c2a
blueprint updates to conform with latest cli style
Jun 6, 2017
9e5e79b
Merge pull request #427 from kellyselden/blueprint_updates
trentmwillis Jun 7, 2017
957b60a
Use new `lazyLoading` format in `in-repo-engine` blueprint
mike183 Jun 7, 2017
43508bf
Merge pull request #430 from status200/update-in-repo-engine-blueprint
rwjblue Jun 8, 2017
3d73a0a
moving lazy loading to completed
Jun 8, 2017
782fcd3
Merge pull request #431 from kellyselden/patch-1
trentmwillis Jun 9, 2017
b16f855
Use cacheKeyForTree to improve the addon dedup
May 25, 2017
1257b65
Wrap engineRoutesTree in debugTree
mike183 Jun 12, 2017
1ff177f
Merge pull request #422 from dnachev/cache-key-dedup
rwjblue Jun 12, 2017
6d98b75
v0.5.5
rwjblue Jun 12, 2017
b0e3d06
v0.5.6
rwjblue Jun 12, 2017
c6aff04
-Update so that addons can accept asset POJOs containing environment-…
Nov 8, 2016
add8c19
Copy `env` from original host to `target`.
rwjblue Mar 8, 2017
4500888
guard for undefined asset paths
buschtoens Jun 13, 2017
40eb025
Ensure routes are not incorrectly extracted
mike183 Jun 13, 2017
e892284
Merge pull request #434 from buschtoens/asset-objects
rwjblue Jun 13, 2017
ed929cc
v0.5.7
rwjblue Jun 13, 2017
a94cdac
Merge pull request #425 from status200/lazyloading-routes
trentmwillis Jun 13, 2017
dd2b0f8
v0.5.8
rwjblue Jun 13, 2017
11ce64c
fix merge conflict
devotox Jul 5, 2017
71dc5a2
update fastboot manifest hook to use enabled key
devotox Jul 7, 2017
55873dd
remove package lock
devotox Jul 7, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ consumers or providers of engines. The following functionality is supported:
* Sharing of dependencies from parents (applications or other engines) to
contained engines. Shared dependencies are currently limited to services
and route paths.
* Lazy loading of engines.

The following functionality will soon be supported:

* Lazy loading of engines.
* Route serializer modules that isolate serialization logic from the rest of
the route definition.

Expand Down
2 changes: 1 addition & 1 deletion addon/-private/route-ext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
function externalAlias(methodName) {
return function _externalAliasMethod(routeName, ...args) {
let externalRoute = getOwner(this)._getExternalRoute(routeName);
this.router[methodName](externalRoute, ...args);
return this.router[methodName](externalRoute, ...args);
};
}

Expand Down
1 change: 0 additions & 1 deletion blueprints/in-repo-engine/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module.exports = Object.assign({}, InRepoAddon, {
return {
name: name,
modulePrefix: name,
hasLazyFlag: typeof options.lazy !== 'undefined',
isLazy: !!options.lazy
};
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{{outlet}}
{{outlet}}
15 changes: 10 additions & 5 deletions blueprints/in-repo-engine/routable-files/lib/__name__/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/*jshint node:true*/
var EngineAddon = require('ember-engines/lib/engine-addon');
/* eslint-env node */
'use strict';

const EngineAddon = require('ember-engines/lib/engine-addon');

module.exports = EngineAddon.extend({
name: '<%= dasherizedModuleName %>',<% if (hasLazyFlag) { %>
name: '<%= dasherizedModuleName %>',

lazyLoading: <%= isLazy %>,<% } %>
lazyLoading: {
enabled: <%= isLazy %>
},

isDevelopingAddon: function() {
isDevelopingAddon() {
return true;
}
});
15 changes: 10 additions & 5 deletions blueprints/in-repo-engine/routeless-files/lib/__name__/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
/*jshint node:true*/
var EngineAddon = require('ember-engines/lib/engine-addon');
/* eslint-env node */
'use strict';

const EngineAddon = require('ember-engines/lib/engine-addon');

module.exports = EngineAddon.extend({
name: '<%= dasherizedModuleName %>',<% if (hasLazyFlag) { %>
name: '<%= dasherizedModuleName %>',

lazyLoading: <%= isLazy %>,<% } %>
lazyLoading: {
enabled: <%= isLazy %>
},

isDevelopingAddon: function() {
isDevelopingAddon() {
return true;
}
});
146 changes: 99 additions & 47 deletions lib/engine-addon.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function findHost() {
// Keep iterating upward until we don't have a grandparent.
// Has to do this grandparent check because at some point we hit the project.
do {
if (current.lazyLoading === true) { return current; }
if (current.lazyLoading.enabled === true) { return current; }
app = current.app || app;
} while (current.parent.parent && (current = current.parent));

Expand All @@ -79,7 +79,7 @@ function findHostsHost() {
// Keep iterating upward until we don't have a grandparent.
// Has to do this grandparent check because at some point we hit the project.
do {
if (current.lazyLoading === true) {
if (current.lazyLoading.enabled === true) {
if (foundHost) {
return current;
}
Expand Down Expand Up @@ -185,6 +185,29 @@ var buildEngineJSTreeWithoutRoutes = memoize(function buildEngineJSTreeWithoutRo
});
});

var buildEngineRoutesJSTree = memoize(function buildEngineRoutesJSTree() {
// Get complete engine JS tree
var engineAppTree = buildEngineJSTree.call(this);
// Separate routes
var engineRoutesTree = new DependencyFunnel(engineAppTree, {
include: true,
entry: this.name+'/routes.js',
external: ['ember-engines/routes']
});
// If babel options aren't defined, we need to transpile the modules.
if (!this.options || !this.options.babel) {
engineRoutesTree = processBabel(engineRoutesTree);
}
// Concatenate routes.js and its dependencies into a single file.
engineRoutesTree = concat(engineRoutesTree, {
allowNone: true,
inputFiles: ['**/*.js'],
outputFile: 'engines-dist/' + this.name + '/assets/routes.js'
});
// Return concatenated JS tree
return this.debugTree(engineRoutesTree, 'routes:output');
});

var buildVendorJSWithImports = memoize(function buildVendorJSWithImports(concatTranspiledVendorJSTree) {
var externalTree = buildExternalTree.call(this);
var combined = mergeTrees([externalTree, concatTranspiledVendorJSTree].filter(Boolean), { overwrite: true });
Expand Down Expand Up @@ -287,7 +310,7 @@ module.exports = {

options.cacheKeyForTree = function(treeType) {
// We do different things in the addon, public, and engine trees based on
// the value of `lazyLoading`, so we add it to the cache key
// the value of `lazyLoading.enabled`, so we add it to the cache key
if (treeType === 'addon' || treeType === 'public' || treeType === 'engine') {
return calculateCacheKeyForTree(treeType, this, [ this.lazyLoading ]);
} else {
Expand All @@ -296,12 +319,14 @@ module.exports = {
};

/**
* Gets a list of all the addons by name that are used by all hosts above
* Gets a map of all the addons that are used by all hosts above
* the current host.
*
* The key is the name of the addon and the value is first encountered instance of this addon.
*/
options.ancestorHostAddonNames = function() {
if (this._hostAddonNames) {
return this._hostAddonNames;
options.ancestorHostAddons = function() {
if (this._hostAddons) {
return this._hostAddons;
}

var host = findHostsHost.call(this);
Expand All @@ -310,43 +335,27 @@ module.exports = {
return [];
}

var hostIsEngine = !!host.ancestorHostAddonNames;
var hostIsEngine = !!host.ancestorHostAddons;

var addonNames = hostIsEngine ? host.ancestorHostAddonNames().slice() : [];
var hostAddons = hostIsEngine ? Object.assign({}, host.ancestorHostAddons()) : {};
var queue = hostIsEngine ? host.addons.slice() : host.project.addons.slice();

// Do a breadth-first walk of the addons in the host, ignoring those that
// have a different host (e.g., lazy engine)
while (queue.length) {
var addon = queue.pop();

if (addon.lazyLoading) { continue; }
if (addonNames.indexOf(addon.name) !== -1) { continue; }

addonNames.push(addon.name);
queue.push.apply(queue, addon.addons);
}

this._hostAddonNames = addonNames;
if (addon.lazyLoading && addon.lazyLoading.enabled) { continue; }

return addonNames;
};
if (hostAddons[addon.name]) { continue; }

/**
* Gets a list of addons that are not included by an ancestor host based on
* the addon's name.
*/
options.nonDuplicatedAddons = function() {
if (this._nonDuplicatedAddons) {
return this._nonDuplicatedAddons;
hostAddons[addon.name] = addon;
queue.push.apply(queue, addon.addons);
}

var hostAddonNames = this.ancestorHostAddonNames();
this._nonDuplicatedAddons = this.addons.filter(function(addon) {
return hostAddonNames.indexOf(addon.name) === -1;
});
this._hostAddons = hostAddons;

return this._nonDuplicatedAddons;
return hostAddons;
};

/**
Expand All @@ -358,12 +367,31 @@ module.exports = {
this.initializeAddons();

var invokeArguments = args || [];
var addons = this.nonDuplicatedAddons();
var hostAddons = this.ancestorHostAddons();

return addons.map(function(addon) {
if (addon[methodName]) {
return addon[methodName].apply(addon, invokeArguments);
return this.addons.map(function(addon) {
if (!addon[methodName]) {
// no method to call
return;
}
var hostAddon = hostAddons[addon.name];
if (hostAddon) {
switch(methodName) {
case 'treeFor':
var treeName = invokeArguments[0];
var hostAddonCacheKey = hostAddon.cacheKeyForTree(treeName);
var addonCacheKey = addon.cacheKeyForTree(treeName);
if (addonCacheKey != null && addonCacheKey === hostAddonCacheKey) {
// the addon specifies cache key and it is the same as host instance of the addon, skip the tree
return;
}
break;
default:
// the same addon exist in the parent as well, skip the invocation
return;
}
}
return addon[methodName].apply(addon, invokeArguments);
}).filter(Boolean);
};

Expand All @@ -372,6 +400,14 @@ module.exports = {
options.init = function() {
this.options = defaultsDeep(options, DEFAULT_CONFIG);

// Ensure lazyLoading is a hash, retain backwards compatibility with using
// a boolean value
if (typeof this.lazyLoading === "boolean") {
this.lazyLoading = {
enabled: this.lazyLoading
};
}

// NOTE: This is a beautiful hack to deal with core object calling toString on the function.
// It'll throw a deprecation warning if this isn't present because it doesn't see a `_super`
// invocation. Do not remove the following line!
Expand All @@ -390,7 +426,7 @@ module.exports = {

// Require that the user specify a lazyLoading property.
if (!('lazyLoading' in this)) {
this.ui.writeDeprecateLine(this.pkg.name + ' engine must specify the `lazyLoading` property to `true` or `false` as to whether the engine should be lazily loaded.');
this.ui.writeDeprecateLine(this.pkg.name + ' engine must specify the `lazyLoading.enabled` property as to whether the engine should be lazily loaded.');
}

if (shouldCompactReexports(this)) {
Expand Down Expand Up @@ -427,13 +463,22 @@ module.exports = {
var host = originalFindHost.call(this);
var target = this._findHost();

target.env = host.env;
target._import = host._import;
target._getAssetPath = host._getAssetPath;
target.otherAssets = host.otherAssets;
target._mergeTrees = host._mergeTrees;

// We're delegating to the upstream EmberApp behavior for eager engines.
if (this.lazyLoading !== true) {
if (this.lazyLoading.enabled !== true) {
// Asset can be an object with environment properties.
asset = target._getAssetPath(asset);

// The asset path can be undefined depending on `env`.
if (typeof asset !== 'string') {
return;
}

// This is hard-coded in Ember CLI, not tied to treePaths.
asset.replace(/^vendor/, '');
}
Expand All @@ -442,7 +487,7 @@ module.exports = {

var originalIncluded = this.included;
this.included = function() {
if (this.lazyLoading === true) {
if (this.lazyLoading.enabled === true) {
// Do this greedily so that it runs before the `included` hook.
this.import('engines-dist/' + this.name + '/assets/engine-vendor.js');
this.import('engines-dist/' + this.name + '/assets/engine-vendor.css');
Expand All @@ -467,7 +512,7 @@ module.exports = {
var stack = (new Error()).stack;
ui.writeWarnLine('`app.import` should be avoided and `this.import` should be used instead. ' +
'Using `app.import` forces the asset in question to be hoisted in all scenarios (' +
'regardless of `lazyLoading` flag).\n\n Import performed on `' + name + '`\'s `app` argument at:\n\n ' +
'regardless of `lazyLoading.enabled` flag).\n\n Import performed on `' + name + '`\'s `app` argument at:\n\n ' +
stack + '\n'
);
return originalHostImport.apply(this, arguments);
Expand All @@ -479,9 +524,15 @@ module.exports = {
this.nonDuplicatedAddonInvoke('included', [this]);
};

// The treeForEngine method constructs and returns a tree that represents
// the engines routes.js file and its dependencies. This is used later to
// promote the engines routes.js to the host.
//
// If the lazyLoading.includeRoutesInApplication option is false, we don't
// want to promote the routes into the host.
this.treeForEngine = function() {
// If this engine is lazy or any of its parents are lazy we need to promote its routes.
if (!this._hasLazyAncestor) { return; }
var extractRoutes = this._hasLazyAncestor && this.lazyLoading.includeRoutesInApplication !== false;
if (!extractRoutes) { return; }

// The only thing that we want to promote from a lazy engine is the
// routes.js file and all of its dependencies, which is why we build the
Expand All @@ -503,7 +554,7 @@ module.exports = {
// Replace `treeForAddon` so that we control how this engine gets built.
// We may or may not want it to be combined like a default addon.
this.treeForAddon = function() {
if (this.lazyLoading === true) { return; }
if (this.lazyLoading.enabled === true) { return; }

// NOT LAZY LOADING!
// This is the scenario where we want to act like an addon.
Expand All @@ -530,7 +581,8 @@ module.exports = {
// We only calculate our external tree for eager engines
// if they're going to be consumed by a lazy engine.
var externalTree;
if (this._findHost().lazyLoading === true) {
var hostLazyLoading = this._findHost().lazyLoading;
if (hostLazyLoading && hostLazyLoading.enabled === true) {
externalTree = buildExternalTree.call(this);
}

Expand Down Expand Up @@ -612,7 +664,7 @@ module.exports = {
this.treeForPublic = function() {
// NOT LAZY LOADING!
// In this scenario we just want to do the default behavior and bail.
if (this.lazyLoading !== true) {
if (this.lazyLoading.enabled !== true) {
return originalTreeForPublic.apply(this, arguments);
}

Expand Down Expand Up @@ -822,7 +874,7 @@ module.exports = {
* @override
*/
options.updateFastBootManifest = function(manifest) {
if (this.lazyLoading) {
if (this.lazyLoading.enabled === true) {
manifest.vendorFiles.push('engines-dist/' + options.name + '/assets/engine-vendor.js');
manifest.vendorFiles.push('engines-dist/' + options.name + '/assets/engine.js');
manifest.vendorFiles.push('engines-dist/' + options.name + '/config/environment.js');
Expand Down Expand Up @@ -885,8 +937,8 @@ module.exports = {
// when using deprecated 0.4 style processing, we allow the styles tree to be
// hoisted to the top level host
(this.useDeprecatedIncorrectCSSProcessing !== true && name === 'styles') ||
(name === 'addon' && this.lazyLoading === true) ||
(name === 'public' && this.lazyLoading === true)
(name === 'addon' && this.lazyLoading.enabled === true) ||
(name === 'public' && this.lazyLoading.enabled === true)
) {
trees = [];
} else {
Expand Down
Loading