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 FastBoot 1.0 #1098

Merged
merged 2 commits into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ env:
- EMBER_TRY_SCENARIO=ember-release
- EMBER_TRY_SCENARIO=ember-beta
- EMBER_TRY_SCENARIO=ember-canary
- EMBER_TRY_SCENARIO=fastboot-tests

matrix:
fast_finish: true
Expand Down
3 changes: 3 additions & 0 deletions app/initializers/ember-cli-mirage.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export function startMirage(env = ENV) {
}

function _shouldUseMirage(env, addonConfig) {
if (typeof FastBoot !== 'undefined') {
return false;
}
let userDeclaredEnabled = typeof addonConfig.enabled !== 'undefined';
let defaultEnabled = _defaultEnabled(env, addonConfig);

Expand Down
7 changes: 7 additions & 0 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ module.exports = {
'ember': 'canary'
}
}
},
{
name: 'fastboot-tests',
command: 'ember fastboot:test',
npm: {
devDependencies: {}
}
}
]
};
12 changes: 12 additions & 0 deletions fastboot-tests/fixtures/fastboot/app/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Ember from 'ember';
import config from './config/environment';

const Router = Ember.Router.extend({
location: config.locationType,
rootURL: config.rootURL
});

Router.map(function() {
});

export default Router;
1 change: 1 addition & 0 deletions fastboot-tests/fixtures/fastboot/app/templates/index.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>ember-fastboot-addon-tests</h1>
24 changes: 24 additions & 0 deletions fastboot-tests/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';

const expect = require('chai').expect;
const setupTest = require('ember-fastboot-addon-tests').setupTest;

describe('index', function() {
setupTest('fastboot', {
emberVersion: '2.13.3'
});

it('renders', function() {
return this.visit('/')
.then(function(res) {
let $ = res.jQuery;
let response = res.response;

// add your real tests here
expect(response.statusCode).to.equal(200);
expect($('body').length).to.equal(1);
expect($('h1').text().trim()).to.equal('ember-fastboot-addon-tests');
});
});

});
43 changes: 24 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-env node */
'use strict';
var path = require('path');
var mergeTrees = require('broccoli-merge-trees');
var Funnel = require('broccoli-funnel');
const path = require('path');
const mergeTrees = require('broccoli-merge-trees');
const Funnel = require('broccoli-funnel');
const map = require('broccoli-stew').map;

module.exports = {
name: 'ember-cli-mirage',
Expand All @@ -19,8 +20,8 @@ module.exports = {
}
},

included: function included() {
var app;
included() {
let app;

// If the addon has the _findHost() method (in ember-cli >= 2.7.0), we'll just
// use that.
Expand All @@ -29,7 +30,7 @@ module.exports = {
} else {
// Otherwise, we'll use this implementation borrowed from the _findHost()
// method in ember-cli.
var current = this;
let current = this;
do {
app = current.app || app;
} while (current.parent.parent && (current = current.parent));
Expand Down Expand Up @@ -60,20 +61,20 @@ module.exports = {
}
},

blueprintsPath: function() {
blueprintsPath() {
return path.join(__dirname, 'blueprints');
},

treeFor: function(name) {
treeFor(name) {
if (!this._shouldIncludeFiles()) {
return;
}

return this._super.treeFor.apply(this, arguments);
},

_lintMirageTree: function(mirageTree) {
var lintedMirageTrees;
_lintMirageTree(mirageTree) {
let lintedMirageTrees;
// _eachProjectAddonInvoke was added in ember-cli@2.5.0
// this conditional can be removed when we no longer support
// versions older than 2.5.0
Expand All @@ -87,7 +88,7 @@ module.exports = {
}).filter(Boolean);
}

var lintedMirage = mergeTrees(lintedMirageTrees, {
let lintedMirage = mergeTrees(lintedMirageTrees, {
overwrite: true,
annotation: 'TreeMerger (mirage-lint)'
});
Expand All @@ -97,9 +98,9 @@ module.exports = {
});
},

treeForApp: function(appTree) {
var trees = [ appTree ];
var mirageFilesTree = new Funnel(this.mirageDirectory, {
treeForApp(appTree) {
let trees = [ appTree ];
let mirageFilesTree = new Funnel(this.mirageDirectory, {
destDir: 'mirage'
});
trees.push(mirageFilesTree);
Expand All @@ -111,14 +112,14 @@ module.exports = {
return mergeTrees(trees);
},

_shouldIncludeFiles: function() {
_shouldIncludeFiles() {
if (process.env.EMBER_CLI_FASTBOOT) {
return false;
}

var environment = this.app.env;
var enabledInProd = environment === 'production' && this.addonConfig.enabled;
var explicitExcludeFiles = this.addonConfig.excludeFilesFromBuild;
let environment = this.app.env;
let enabledInProd = environment === 'production' && this.addonConfig.enabled;
let explicitExcludeFiles = this.addonConfig.excludeFilesFromBuild;
if (enabledInProd && explicitExcludeFiles) {
throw new Error('Mirage was explicitly enabled in production, but its files were excluded '
+ 'from the build. Please, use only ENV[\'ember-cli-mirage\'].enabled in '
Expand All @@ -132,7 +133,11 @@ function npmAsset(filePath) {
return function() {
return {
enabled: this._shouldIncludeFiles(),
import: [filePath]
import: [filePath],
// guard against usage in FastBoot 1.0, where process.env.EMBER_CLI_FASTBOOT is not available
_processTree(input) {
return map(input, content => `if (typeof FastBoot !== 'undefined') { ${content} }`)
}
};
};
}
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"active-model-adapter": "^2.0.3",
"broccoli-asset-rev": "^2.4.5",
"chai": "2.0.0",
"chai": "^4.0.1",
"ember-ajax": "^2.4.1",
"ember-cli": "^2.9.1",
"ember-cli-app-version": "^2.0.0",
Expand All @@ -46,6 +46,7 @@
"ember-disable-prototype-extensions": "^1.1.0",
"ember-disable-proxy-controllers": "^1.0.1",
"ember-export-application-global": "^1.0.5",
"ember-fastboot-addon-tests": "^0.4.0",
"ember-load-initializers": "^0.5.1",
"ember-resolver": "^2.0.3",
"ember-sinon": "0.5.1",
Expand All @@ -66,12 +67,13 @@
"dependencies": {
"broccoli-funnel": "^1.0.2",
"broccoli-merge-trees": "^1.1.0",
"broccoli-stew": "^1.5.0",
"broccoli-unwatched-tree": "^0.1.1",
"chalk": "^1.1.1",
"ember-cli-babel": "^5.1.7",
"ember-cli-node-assets": "^0.1.4",
"ember-inflector": "^2.0.0",
"ember-get-config": "0.2.1",
"ember-inflector": "^2.0.0",
"ember-lodash": "^4.17.3",
"exists-sync": "0.0.3",
"fake-xml-http-request": "^1.4.0",
Expand Down