Skip to content

Commit a2540bf

Browse files
authored
Merge pull request #544 from SergeAstapov/recursive-fastbootConfigTree-extend
Allow to extend application FastBoot config via addon hook fastbootConfigTree
2 parents 98f441d + fcdecc5 commit a2540bf

11 files changed

Lines changed: 148 additions & 8 deletions

File tree

lib/broccoli/fastboot-config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
const fs = require('fs');
44
const fmt = require('util').format;
5-
const uniq = require('lodash.uniq');
5+
const uniq = require('ember-cli-lodash-subset').uniq;
6+
const merge = require('ember-cli-lodash-subset').merge;
67
const md5Hex = require('md5-hex');
78
const path = require('path');
89
const Plugin = require('broccoli-plugin');
@@ -94,7 +95,7 @@ module.exports = class FastBootConfig extends Plugin {
9495
throw new Error('`fastbootConfigTree` requires a map to be returned');
9596
}
9697

97-
Object.assign(this.fastbootConfig, configFromAddon);
98+
merge(this.fastbootConfig, configFromAddon);
9899
}
99100
});
100101
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
"broccoli-plugin": "^1.2.1",
2626
"chalk": "^2.0.1",
2727
"ember-cli-babel": "^6.7.2",
28+
"ember-cli-lodash-subset": "2.0.1",
2829
"ember-cli-version-checker": "^2.0.0",
2930
"fastboot": "^1.1.0",
3031
"fastboot-express-middleware": "^1.1.0",
3132
"fs-extra": "^4.0.0",
3233
"json-stable-stringify": "^1.0.1",
33-
"lodash.uniq": "^4.2.0",
3434
"md5-hex": "^2.0.0",
3535
"silent-error": "^1.0.0"
3636
},
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This fixture app has an addon that implements fastbootConfigTree that extends application config in FastBoot build.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/* jshint node: true */
2+
3+
module.exports = function(environment) {
4+
var ENV = {
5+
modulePrefix: 'fastboot-config',
6+
environment: environment,
7+
baseURL: '/',
8+
locationType: 'auto',
9+
EmberENV: {
10+
FEATURES: {
11+
// Here you can enable experimental features on an ember canary build
12+
// e.g. 'with-controller': true
13+
}
14+
},
15+
16+
APP: {
17+
// Here you can pass flags/options to your application instance
18+
// when it is created
19+
},
20+
21+
fastboot: {
22+
hostWhitelist: ['example.com', 'subdomain.example.com', /localhost:\d+/]
23+
}
24+
};
25+
26+
if (environment === 'development') {
27+
// ENV.APP.LOG_RESOLVER = true;
28+
// ENV.APP.LOG_ACTIVE_GENERATION = true;
29+
// ENV.APP.LOG_TRANSITIONS = true;
30+
// ENV.APP.LOG_TRANSITIONS_INTERNAL = true;
31+
// ENV.APP.LOG_VIEW_LOOKUPS = true;
32+
}
33+
34+
if (environment === 'test') {
35+
// Testem prefers this...
36+
ENV.baseURL = '/';
37+
ENV.locationType = 'none';
38+
39+
// keep test console output quieter
40+
ENV.APP.LOG_ACTIVE_GENERATION = false;
41+
ENV.APP.LOG_VIEW_LOOKUPS = false;
42+
43+
ENV.APP.rootElement = '#ember-testing';
44+
}
45+
46+
if (environment === 'production') {
47+
48+
}
49+
50+
return ENV;
51+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = function(defaults) {
2+
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
3+
var app = new EmberApp(defaults, {});
4+
5+
return app.toTree();
6+
};

test/fixtures/fastboot-config/node_modules/fake-addon-2/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/fastboot-config/node_modules/fake-addon-2/package.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/fastboot-config/node_modules/fake-addon/index.js

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/fastboot-config/node_modules/fake-addon/package.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/package-json-test.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ describe('generating package.json', function() {
8484
]);
8585
});
8686

87+
it('contains app name', function() {
88+
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));
89+
90+
expect(pkg.fastboot.appName).to.equal('module-whitelist');
91+
});
92+
8793
it('contains the application config', function() {
8894
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));
8995

@@ -99,16 +105,45 @@ describe('generating package.json', function() {
99105
});
100106
});
101107

102-
it('contains additional config from addons', function() {
108+
it('contains additional config from ember-fastboot-build-example addon', function() {
103109
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));
104110

105111
expect(pkg.fastboot.config['foo']).to.equal('bar');
106112
});
107113

108-
it('contains app name', function() {
109-
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));
110-
111-
expect(pkg.fastboot.appName).to.equal('module-whitelist');
114+
describe('with addon that implements fastbootConfigTree', function() {
115+
let app;
116+
117+
before(function() {
118+
app = new AddonTestApp();
119+
120+
return app.create('fastboot-config', {
121+
skipNpm: true
122+
})
123+
.then(addFastBootDeps)
124+
.then(function() {
125+
return app.run('npm', 'install');
126+
})
127+
.then(function() {
128+
return app.runEmberCommand('build');
129+
});
130+
});
131+
132+
it('it extends the application config', function() {
133+
let pkg = fs.readJsonSync(app.filePath('dist/package.json'));
134+
135+
expect(pkg.fastboot.config['fastboot-config']).to.deep.equal({
136+
foo: 'bar',
137+
modulePrefix: 'fastboot-config',
138+
environment: 'development',
139+
baseURL: '/',
140+
locationType: 'auto',
141+
EmberENV: { FEATURES: {} },
142+
APP: { name: 'fastboot-config', version: '0.0.0+', autoboot: false },
143+
fastboot: { hostWhitelist: [ 'example.com', 'subdomain.example.com', '/localhost:\\d+/' ] },
144+
exportApplicationGlobal: true
145+
});
146+
});
112147
});
113148
});
114149

0 commit comments

Comments
 (0)