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

Several fixes for the module unification feature flag #6908

Merged
merged 8 commits into from Jul 8, 2017
114 changes: 99 additions & 15 deletions lib/broccoli/ember-app.js
Expand Up @@ -196,7 +196,13 @@ class EmberApp {
let srcPath = this._resolveLocal('src');
let srcTree = existsSync(srcPath) ? new WatchedDir(srcPath) : null;

let appTree = new WatchedDir(this._resolveLocal('app'));
let appPath = this._resolveLocal('app');
let appTree;
if (experiments.MODULE_UNIFICATION) {
appTree = existsSync(appPath) ? new WatchedDir(appPath) : null;
} else {
appTree = new WatchedDir(appPath);
}

let testsPath = this._resolveLocal('tests');
let testsTree = existsSync(testsPath) ? new WatchedDir(testsPath) : null;
Expand Down Expand Up @@ -692,7 +698,6 @@ class EmberApp {
let index;
if (!experiments.MODULE_UNIFICATION || !this.trees.src) {
index = this._rawAppIndex(htmlName);

} else {
let appIndex = this._rawAppIndex(htmlName, true);
let srcIndex = this._rawSrcIndex(htmlName);
Expand All @@ -707,6 +712,8 @@ class EmberApp {
}

_rawAppIndex(outputPath, optional) {
if (!this.trees.app) { return; }

return new Funnel(this.trees.app, {
[optional ? 'include' : 'files']: ['index.html'],
getDestinationPath: () => outputPath,
Expand All @@ -730,6 +737,10 @@ class EmberApp {
@return {Tree}
*/
_filterAppTree() {
if (!this.trees.app) {
return;
}

if (!this._cachedFilterAppTree) {
let podPatterns = this._podTemplatePatterns();
let excludePatterns = podPatterns.concat([
Expand Down Expand Up @@ -853,8 +864,12 @@ class EmberApp {
@return
*/
_processedAppTree() {
let addonTrees = this.addonTreesFor('app');
let mergedApp = this._mergeTrees(addonTrees.concat(this._filterAppTree()), {
let appTrees = [].concat(
this.addonTreesFor('app'),
this._filterAppTree()
).filter(Boolean);

let mergedApp = this._mergeTrees(appTrees, {
overwrite: true,
annotation: 'TreeMerger (app)',
});
Expand All @@ -866,6 +881,50 @@ class EmberApp {
});
}

/**
@private
@method _processedSrcTree
@return
*/
_processedSrcTree() {
if (!experiments.MODULE_UNIFICATION) {
return null;
}
// styles
// templates
let rawSrcTree = this.trees.src;

if (!rawSrcTree) { return; }

let srcNamespacedTree = new Funnel(rawSrcTree, {
destDir: 'src',
});

let srcAfterPreprocessTreeHook = this.addonPreprocessTree('src', srcNamespacedTree);

let options = {
outputPaths: this.options.outputPaths.app.css,
registry: this.registry,
};

// TODO: This isn't quite correct (but it does function properly in most cases),
// and should be re-evaluated before enabling the `MODULE_UNIFICATION` feature
this._srcAfterStylePreprocessing = preprocessCss(srcAfterPreprocessTreeHook, '/src/ui/styles', '/assets', options);

let srcAfterTemplatePreprocessing = preprocessTemplates(srcAfterPreprocessTreeHook, {
registry: this.registry,
annotation: 'Process Templates: src',
});

let srcAfterPostprocessTreeHook = this.addonPostprocessTree('src', srcAfterTemplatePreprocessing);

return new Funnel(srcAfterPostprocessTreeHook, {
srcDir: '/',
destDir: `${this.name}`,
annotation: 'Funnel: src',
});
}

/**
@private
@method _processedTemplatesTree
Expand Down Expand Up @@ -1127,8 +1186,11 @@ class EmberApp {
let config = this._configTree();
let templates = this._processedTemplatesTree();

let srcTree = this._processedSrcTree();
let trees = [this._processedAppTree(), srcTree, templates].filter(Boolean);

let app = this.addonPreprocessTree('js', this._mergeTrees(
[this._processedAppTree(), templates],
trees,
{
annotation: 'TreeMerger (preprocessedApp & templates)',
overwrite: true,
Expand Down Expand Up @@ -1206,16 +1268,34 @@ class EmberApp {
@return {Array}
*/
lintTestTrees() {
let lintedApp = this.addonLintTree('app', this._filterAppTree());
let lintTrees = [];

let appTree = this._filterAppTree();
if (appTree) {
let lintedApp = this.addonLintTree('app', appTree);
lintedApp = processModulesOnly(new Funnel(lintedApp, {
srcDir: '/',
destDir: `${this.name}/tests/`,
annotation: 'Funnel (lint app)',
}), 'Babel: lintTree(app)');

lintTrees.push(lintedApp);
}

if (experiments.MODULE_UNIFICATION && this.trees.src) {
let lintedSrc = this.addonLintTree('src', this.trees.src);
lintedSrc = processModulesOnly(new Funnel(lintedSrc, {
srcDir: '/',
destDir: `${this.name}/tests/src/`,
annotation: 'Funnel (lint src)',
}), 'Babel: lintTree(src)');

lintTrees.push(lintedSrc);
}

let lintedTests = this.addonLintTree('tests', this.trees.tests);
let lintedTemplates = this.addonLintTree('templates', this._templatesTree());

lintedApp = processModulesOnly(new Funnel(lintedApp, {
srcDir: '/',
destDir: `${this.name}/tests/`,
annotation: 'Funnel (lint app)',
}), 'Babel: lintTree(app)');

lintedTests = processModulesOnly(new Funnel(lintedTests, {
srcDir: '/',
destDir: `${this.name}/tests/`,
Expand All @@ -1228,7 +1308,7 @@ class EmberApp {
annotation: 'Funnel (lint templates)',
}), 'Babel: lintTree(templates)');

return [lintedApp, lintedTests, lintedTemplates];
return [lintedTests, lintedTemplates].concat(lintTrees);
}

/**
Expand Down Expand Up @@ -1696,9 +1776,11 @@ class EmberApp {
this.index(),
this.javascript(),
this.styles(),
// undefined when `experiments.MODULE_UNIFICATION` is not available
this._srcAfterStylePreprocessing,
this.otherAssets(),
this.publicTree(),
];
].filter(Boolean);

if (this.tests && this.trees.tests) {
sourceTrees = sourceTrees.concat(this.testIndex(), this.test());
Expand Down Expand Up @@ -1824,8 +1906,10 @@ class EmberApp {
*/
_contentForAppBoot(content, config) {
if (this.options.autoRun) {
let shouldUseSrc = experiments.MODULE_UNIFICATION && !!this.trees.src;
let moduleToRequire = `${config.modulePrefix}/${shouldUseSrc ? 'src/main' : 'app'}`;
content.push('if (!runningTests) {');
content.push(` require("${config.modulePrefix}/app")["default"].create(${calculateAppConfig(config)});`);
content.push(` require("${moduleToRequire}")["default"].create(${calculateAppConfig(config)});`);
content.push('}');
}
}
Expand Down
19 changes: 2 additions & 17 deletions tests/unit/broccoli/ember-app-test.js
Expand Up @@ -632,10 +632,12 @@ describe('EmberApp', function() {
});

it('calls each addon postprocessTree hook', function() {
app.index = td.function();
app._processedTemplatesTree = td.function();

td.when(app._processedTemplatesTree(), { ignoreExtraArgs: true }).thenReturn('x');
td.when(addon.postprocessTree(), { ignoreExtraArgs: true }).thenReturn('blap');
td.when(app.index(), { ignoreExtraArgs: true }).thenReturn(null);

expect(app.toTree()).to.equal('blap');

Expand Down Expand Up @@ -1062,23 +1064,6 @@ describe('EmberApp', function() {
expect(project.ui.output).to.not.contain('EmberApp.concatFiles() is deprecated');
});

describe('podTemplates', function() {
it('works', function() {
let app = new EmberApp({
project,
});

let wasCalledCount = 0;
app.podTemplates = function() {
wasCalledCount++;
};

expect(wasCalledCount).to.eql(0);
app._templatesTree();
expect(wasCalledCount).to.eql(1);
});
});

describe('concat order', function() {
let count = 0;
let args = [];
Expand Down