From 6d6e7008dba3799dcabc554e011d476ab9bd2c71 Mon Sep 17 00:00:00 2001 From: houfeng Date: Sat, 28 Mar 2020 13:25:08 +0800 Subject: [PATCH] Ignore fastboot build output file if app unused/disable fastboot (#468) Ignore fastboot build output file if app unused/disable fastboot --- index.js | 5 ++- test/without-fastboot-build-test.js | 57 +++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/without-fastboot-build-test.js diff --git a/index.js b/index.js index a738814c..d5071b82 100644 --- a/index.js +++ b/index.js @@ -141,7 +141,10 @@ module.exports = { // Only include public/fetch-fastboot.js if top level addon treeForPublic() { - return !this.parent.parent ? this._super.treeForPublic.apply(this, arguments) : null; + const fastbootEnabled = process.env.FASTBOOT_DISABLED !== 'true' + && !!this.project.findAddonByName('ember-cli-fastboot'); + return !this.parent.parent && fastbootEnabled + ? this._super.treeForPublic.apply(this, arguments) : null; }, cacheKeyForTree(treeType) { diff --git a/test/without-fastboot-build-test.js b/test/without-fastboot-build-test.js new file mode 100644 index 00000000..c42bd136 --- /dev/null +++ b/test/without-fastboot-build-test.js @@ -0,0 +1,57 @@ +'use strict'; +const chai = require('chai'); +const expect = chai.expect; +chai.use(require('chai-fs')); + +const AddonTestApp = require('ember-cli-addon-tests').AddonTestApp; + +describe('it builds without ember-cli-fastboot', function() { + this.timeout(300000); + + let app; + + beforeEach(function() { + app = new AddonTestApp(); + }); + + it('builds no exist dist/ember-fetch/fetch-fastboot.js', function() { + return app + .create('dummy', { skipNpm: true }) + .then((app) => + app.editPackageJSON((pkg) => { + delete pkg.devDependencies['ember-cli-fastboot']; + }) + ) + .then(() => app.run('npm', 'install')) + .then(() => app.runEmberCommand('build')) + .then(function() { + expect(app.filePath('dist/index.html')).to.be.a.file(); + expect(app.filePath('dist/ember-fetch')).to.not.be.a.path(); + }); + }); + + it('build with process.env.FASTBOOT_DISABLED', function() { + process.env.FASTBOOT_DISABLED = 'true'; + return app + .create('dummy', { skipNpm: true }) + .then((app) => + app.editPackageJSON((pkg) => { + pkg.devDependencies['ember-cli-fastboot'] = '*'; + }) + ) + .then(() => app.run('npm', 'install')) + .then(() => app.runEmberCommand('build')) + .then(function() { + expect(app.filePath('dist/index.html')).to.be.a.file(); + expect(app.filePath('dist/ember-fetch')).to.not.be.a.path(); + }) + .then( + function() { + delete process.env.FASTBOOT_DISABLED; + }, + function() { + delete process.env.FASTBOOT_DISABLED; + } + ); + }); +});