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

Increment latest schema version to 5 #822

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
99 changes: 77 additions & 22 deletions packages/ember-cli-fastboot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const chalk = require('chalk');

const fastbootAppBoot = require('./lib/utilities/fastboot-app-boot');
const FastBootConfig = require('./lib/broccoli/fastboot-config');
const BasePageWriter = require('./lib/broccoli/base-page-writer');
const fastbootAppFactoryModule = require('./lib/utilities/fastboot-app-factory-module');
const migrateInitializers = require('./lib/build-utilities/migrate-initializers');
const SilentError = require('silent-error');
Expand Down Expand Up @@ -60,7 +61,9 @@ module.exports = {
* See: https://ember-cli.com/user-guide/#integration
*/
included(app) {
let assetRev = this.project.addons.find(addon => addon.name === 'broccoli-asset-rev');
let assetRev = this.project.addons.find(
(addon) => addon.name === 'broccoli-asset-rev'
);
if (assetRev && !assetRev.supportsFastboot) {
throw new SilentError(
'This version of ember-cli-fastboot requires a newer version of broccoli-asset-rev'
Expand Down Expand Up @@ -109,7 +112,10 @@ module.exports = {
}

if (type === 'app-boot') {
return fastbootAppBoot(config.modulePrefix, JSON.stringify(config.APP || {}));
return fastbootAppBoot(
config.modulePrefix,
JSON.stringify(config.APP || {})
);
}

// if the fastboot addon is installed, we overwrite the config-module so that the config can be read
Expand All @@ -134,15 +140,19 @@ module.exports = {

// check the ember version and conditionally patch the DOM api
if (this._getEmberVersion().lt('2.10.0-alpha.1')) {
fastbootHtmlBarsTree = this.treeGenerator(path.resolve(__dirname, 'fastboot-app-lt-2-9'));
return tree ? new MergeTrees([tree, fastbootHtmlBarsTree]) : fastbootHtmlBarsTree;
fastbootHtmlBarsTree = this.treeGenerator(
path.resolve(__dirname, 'fastboot-app-lt-2-9')
);
return tree
? new MergeTrees([tree, fastbootHtmlBarsTree])
: fastbootHtmlBarsTree;
}

return tree;
},

_processAddons(addons, fastbootTrees) {
addons.forEach(addon => {
addons.forEach((addon) => {
this._processAddon(addon, fastbootTrees);
});
},
Expand Down Expand Up @@ -182,7 +192,10 @@ module.exports = {
// check the parent containing the fastboot directory
const projectFastbootPath = path.join(this.project.root, 'fastboot');
// ignore the project's fastboot folder if we are an addon, as that is already handled above
if (!this.project.isEmberCLIAddon() && this.existsSync(projectFastbootPath)) {
if (
!this.project.isEmberCLIAddon() &&
this.existsSync(projectFastbootPath)
) {
let fastbootTree = this.treeGenerator(projectFastbootPath);
fastbootTrees.push(fastbootTree);
}
Expand All @@ -195,17 +208,28 @@ module.exports = {
let funneledFastbootTrees = new Funnel(mergedFastBootTree, {
destDir: appName,
});
const processExtraTree = p.preprocessJs(funneledFastbootTrees, '/', this._name, {
registry: this._appRegistry,
});
const processExtraTree = p.preprocessJs(
funneledFastbootTrees,
'/',
this._name,
{
registry: this._appRegistry,
}
);

// FastBoot app factory module
const writeFile = require('broccoli-file-creator');
let appFactoryModuleTree = writeFile('app-factory.js', fastbootAppFactoryModule(appName));

let newProcessExtraTree = new MergeTrees([processExtraTree, appFactoryModuleTree], {
overwrite: true,
});
let appFactoryModuleTree = writeFile(
'app-factory.js',
fastbootAppFactoryModule(appName)
);

let newProcessExtraTree = new MergeTrees(
[processExtraTree, appFactoryModuleTree],
{
overwrite: true,
}
);

function stripLeadingSlash(filePath) {
return filePath.replace(/^\//, '');
Expand All @@ -219,6 +243,7 @@ module.exports = {
return finalFastbootTree;
},

// Note: this hook is ignored when built with embroider
treeForPublic(tree) {
let fastbootTree = this._getFastbootTree();
let trees = [];
Expand All @@ -229,7 +254,8 @@ module.exports = {

let newTree = new MergeTrees(trees);

let fastbootConfigTree = this._buildFastbootConfigTree(newTree);
let fastbootConfigTree = (this._fastbootConfigTree =
this._buildFastbootConfigTree(newTree));

// Merge the package.json with the existing tree
return new MergeTrees([newTree, fastbootConfigTree], { overwrite: true });
Expand Down Expand Up @@ -294,18 +320,41 @@ module.exports = {

_buildFastbootConfigTree(tree) {
let appConfig = this._getHostAppConfig();
let fastbootAppConfig = appConfig.fastboot;

return new FastBootConfig(tree, {
project: this.project,
name: this.app.name,
outputPaths: this.app.options.outputPaths,
ui: this.ui,
fastbootAppConfig: fastbootAppConfig,
appConfig: appConfig,
appConfig,
});
},

_buildHTMLWriter(tree) {
let appConfig = this._getHostAppConfig();

return new BasePageWriter(tree, {
project: this.project,
appConfig,
appJsPath: this.app.options.outputPaths.app.js,
outputPaths: this.app.options.outputPaths,
});
},

/**
* Write fastboot-script tags to the html file
*/
postprocessTree(type, tree) {
this._super(...arguments);
if (type === 'all') {
let fastbootHTMLTree = this._buildHTMLWriter(tree);

// Merge the package.json with the existing tree
return new MergeTrees([tree, fastbootHTMLTree], { overwrite: true });
}

return tree;
},

serverMiddleware(options) {
let emberCliVersion = this._getEmberCliVersion();
let app = options.app;
Expand All @@ -316,8 +365,11 @@ module.exports = {

app.use((req, resp, next) => {
const fastbootQueryParam =
req.query.hasOwnProperty('fastboot') && req.query.fastboot === 'false' ? false : true;
const enableFastBootServe = !process.env.FASTBOOT_DISABLED && fastbootQueryParam;
req.query.hasOwnProperty('fastboot') && req.query.fastboot === 'false'
? false
: true;
const enableFastBootServe =
!process.env.FASTBOOT_DISABLED && fastbootQueryParam;

if (req.serveUrl && enableFastBootServe) {
// if it is a base page request, then have fastboot serve the base page
Expand Down Expand Up @@ -384,7 +436,10 @@ module.exports = {
* TODO Allow add-ons to provide own options and merge them with the application's options.
*/
_fastbootOptionsFor(environment, project) {
const configPath = path.join(path.dirname(project.configPath()), 'fastboot.js');
const configPath = path.join(
path.dirname(project.configPath()),
'fastboot.js'
);

if (fs.existsSync(configPath)) {
return require(configPath)(environment);
Expand Down