Skip to content

Commit 2ad9389

Browse files
author
Robert Jackson
authored
Embroider Support: Moved app factory module out of fastboot-app-… (#714)
Embroider Support: Moved app factory module out of fastboot-app-module
2 parents 85a2aad + 617a17c commit 2ad9389

4 files changed

Lines changed: 40 additions & 15 deletions

File tree

index.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ const FastBootExpressMiddleware = require('fastboot-express-middleware');
99
const FastBoot = require('fastboot');
1010
const chalk = require('chalk');
1111

12-
const fastbootAppModule = require('./lib/utilities/fastboot-app-module');
12+
const fastbootAppBoot = require('./lib/utilities/fastboot-app-boot');
1313
const FastBootConfig = require('./lib/broccoli/fastboot-config');
14+
const fastbootAppFactoryModule = require('./lib/utilities/fastboot-app-factory-module');
1415
const migrateInitializers = require('./lib/build-utilities/migrate-initializers');
1516
const SilentError = require('silent-error');
1617

@@ -107,8 +108,8 @@ module.exports = {
107108
}
108109

109110
if (type === 'app-boot') {
110-
const isModuleUnification = (typeof this.project.isModuleUnification === 'function') && this.project.isModuleUnification();
111-
return fastbootAppModule(config.modulePrefix, JSON.stringify(config.APP || {}), isModuleUnification);
111+
const isModuleUnification = this._isModuleUnification();
112+
return fastbootAppBoot(config.modulePrefix, JSON.stringify(config.APP || {}), isModuleUnification);
112113
}
113114

114115
// if the fastboot addon is installed, we overwrite the config-module so that the config can be read
@@ -174,10 +175,11 @@ module.exports = {
174175
*/
175176
_getFastbootTree() {
176177
const appName = this._name;
178+
const isModuleUnification = this._isModuleUnification();
177179

178180
let fastbootTrees = [];
179-
this._processAddons(this.project.addons, fastbootTrees);
180181

182+
this._processAddons(this.project.addons, fastbootTrees);
181183
// check the parent containing the fastboot directory
182184
const projectFastbootPath = path.join(this.project.root, 'fastboot');
183185
if (this.existsSync(projectFastbootPath)) {
@@ -189,19 +191,28 @@ module.exports = {
189191
let mergedFastBootTree = new MergeTrees(fastbootTrees, {
190192
overwrite: true
191193
});
194+
192195
let funneledFastbootTrees = new Funnel(mergedFastBootTree, {
193196
destDir: appName
194197
});
195198
const processExtraTree = p.preprocessJs(funneledFastbootTrees, '/', this._name, {
196199
registry: this._appRegistry
197200
});
198201

202+
// FastBoot app factory module
203+
const writeFile = require('broccoli-file-creator');
204+
let appFactoryModuleTree = writeFile("app-factory.js", fastbootAppFactoryModule(appName, this._isModuleUnification()));
205+
206+
let newProcessExtraTree = new MergeTrees([processExtraTree, appFactoryModuleTree], {
207+
overwrite: true
208+
});
209+
199210
function stripLeadingSlash(filePath) {
200211
return filePath.replace(/^\//, '');
201212
}
202213

203214
let appFilePath = stripLeadingSlash(this.app.options.outputPaths.app.js);
204-
let finalFastbootTree = new Concat(processExtraTree, {
215+
let finalFastbootTree = new Concat(newProcessExtraTree, {
205216
outputFile: appFilePath.replace(/\.js$/, '-fastboot.js')
206217
});
207218

@@ -362,4 +373,8 @@ module.exports = {
362373

363374
return checker.for('ember', 'bower');
364375
},
376+
377+
_isModuleUnification() {
378+
return (typeof this.project.isModuleUnification === 'function') && this.project.isModuleUnification();
379+
}
365380
};

lib/utilities/fastboot-app-boot.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict'
2+
3+
// Added as app boot code to app.js that allows booting of the application
4+
// in browser. This code is injected during app-boot type of contentFor hook for ember-cli.
5+
module.exports = function fastbootAppBoot(prefix, configAppAsString, isModuleUnification) {
6+
var appSuffix = isModuleUnification ? "src/main" : "app";
7+
return [
8+
"",
9+
"if (typeof FastBoot === 'undefined') {",
10+
" if (!runningTests) {",
11+
" require('{{MODULE_PREFIX}}/" + appSuffix + "')['default'].create({{CONFIG_APP}});",
12+
" }",
13+
"}",
14+
""
15+
].join("\n").replace(/\{\{MODULE_PREFIX\}\}/g, prefix).replace(/\{\{CONFIG_APP\}\}/g, configAppAsString);
16+
};

lib/utilities/fastboot-app-module.js renamed to lib/utilities/fastboot-app-factory-module.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,9 @@
77
// The module defined here is prefixed with a `~` to make it less
88
// likely to collide with user code, since it is not possible to
99
// define a module with a name like this in the file system.
10-
module.exports = function fastbootAppModule(prefix, configAppAsString, isModuleUnification) {
10+
module.exports = function fastBootAppFactoryModule(prefix, isModuleUnification) {
1111
var appSuffix = isModuleUnification ? "src/main" : "app";
1212
return [
13-
"",
14-
"if (typeof FastBoot === 'undefined') {",
15-
" if (!runningTests) {",
16-
" require('{{MODULE_PREFIX}}/" + appSuffix + "')['default'].create({{CONFIG_APP}});",
17-
" }",
18-
"}",
19-
"",
2013
"define('~fastboot/app-factory', ['{{MODULE_PREFIX}}/" + appSuffix + "', '{{MODULE_PREFIX}}/config/environment'], function(App, config) {",
2114
" App = App['default'];",
2215
" config = config['default'];",
@@ -28,5 +21,5 @@ module.exports = function fastbootAppModule(prefix, configAppAsString, isModuleU
2821
" };",
2922
"});",
3023
""
31-
].join("\n").replace(/\{\{MODULE_PREFIX\}\}/g, prefix).replace(/\{\{CONFIG_APP\}\}/g, configAppAsString);
24+
].join("\n").replace(/\{\{MODULE_PREFIX\}\}/g, prefix);
3225
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@
7474
"release-it": "^12.0.1",
7575
"release-it-lerna-changelog": "^1.0.2",
7676
"request": "^2.88.0",
77-
"rsvp": "^4.8.3"
77+
"rsvp": "^4.8.3",
78+
"broccoli-file-creator": "^1.1.1"
7879
},
7980
"engines": {
8081
"node": "6.* || 8.* || >= 10.*"

0 commit comments

Comments
 (0)