Skip to content

Commit

Permalink
Merge pull request #410 from ember-fastboot/fix-build-stability
Browse files Browse the repository at this point in the history
[BUGFIX] fix build stability
  • Loading branch information
stefanpenner authored Jun 1, 2017
2 parents dc43257 + 08b73e0 commit 22a446d
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 10 deletions.
11 changes: 7 additions & 4 deletions lib/broccoli/fastboot-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,21 @@ const md5Hex = require('md5-hex');
const path = require('path');
const Plugin = require('broccoli-plugin');

const stringify = require('json-stable-stringify');

const LATEST_SCHEMA_VERSION = 2;

module.exports = class FastBootConfig extends Plugin {
constructor(inputNode, options) {
super([inputNode], {
annotation: 'Generate: FastBoot package.json'
annotation: 'Generate: FastBoot package.json',
persistentOutput: true
});

this.project = options.project;
// what if app does not set generateAssetMap option? fastboot will be broken otherwise
let defaultAssetMapPath = 'assets/assetMap.json';
let assetRev = this.project.addons.filter(addon => addon.name === 'broccoli-asset-rev')[0];
let assetRev = this.project.addons.find(addon => addon.name === 'broccoli-asset-rev');

if (assetRev && assetRev.options) {
this.assetMapEnabled = !!(assetRev.options.enabled && assetRev.options.generateAssetMap);
Expand Down Expand Up @@ -68,7 +71,7 @@ module.exports = class FastBootConfig extends Plugin {
let previous = this._fileToChecksumMap[outputPath];
let next = md5Hex(content);

if (previous !== next || !fs.existsSync(outputPath)) {
if (previous !== next) {
fs.writeFileSync(outputPath, content);
this._fileToChecksumMap[outputPath] = next; // update map
}
Expand Down Expand Up @@ -185,7 +188,7 @@ module.exports = class FastBootConfig extends Plugin {
};

toJSONString() {
return JSON.stringify({
return stringify({
dependencies: this.dependencies,
fastboot: {
moduleWhitelist: this.moduleWhitelist,
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"express": "^4.8.5",
"fastboot": "1.0.0-rc.6",
"fastboot-express-middleware": "1.0.0-rc.7",
"json-stable-stringify": "^1.0.1",
"lodash.defaults": "^4.0.1",
"lodash.uniq": "^4.2.0",
"md5-hex": "^1.3.0",
Expand All @@ -42,8 +43,10 @@
},
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"broccoli-test-helper": "^1.1.0",
"chai": "^3.0.0",
"chai-fs": "^1.0.0",
"co": "^4.6.0",
"ember-ajax": "^2.4.1",
"ember-cli": "^2.13.1",
"ember-cli-addon-tests": "^0.7.0",
Expand Down
109 changes: 109 additions & 0 deletions test/new-package-json-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
'use strict';

const expect = require('chai').expect;
const helpers = require('broccoli-test-helper');
const createBuilder = helpers.createBuilder;
const createTempDir = helpers.createTempDir;
const co = require('co');
const FastbootConfig = require('../lib/broccoli/fastboot-config');

describe('FastbootConfig', function() {
let input;
let output;
let subject;
let project;

beforeEach(co.wrap(function* () {
input = yield createTempDir();
project = {
addons: [ ],
pkg: { }
};
subject = new FastbootConfig(input.path(), {
project,
outputPaths: {
app: { js: 'app.js' },
vendor: { js: 'vendor.js' }
}
});
output = createBuilder(subject);
}));

afterEach(co.wrap(function* () {
yield input.dispose();
yield output.dispose();
}));

it('it builds only when information changes', co.wrap(function* () {
input.write({
'index.js': `export { A } from "./lib/a";`,
'lib': {
'a.js': `export class A {};`,
'b.js': `export class B {};`,
'c.js': `export class C {};`
}
});

yield output.build();

expect(
output.read()
).to.deep.equal({
'package.json': `{"dependencies":{},"fastboot":{"manifest":{"appFiles":["assets/app.js","assets/app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["assets/vendor.js"]},"moduleWhitelist":[],"schemaVersion":2}}`
});

yield output.build();

expect(
output.changes()
).to.deep.equal({ });

project.pkg.fastbootDependencies = [
'apple',
'orange'
];

project.pkg.dependencies = {
apple: '*',
orange: '^1.0.0',
pizza: '^1.0.0'
};

yield output.build();

expect(
output.changes()
).to.deep.equal({
'package.json': 'change'
});

expect(
output.read()
).to.deep.equal({
'package.json': `{"dependencies":{"apple":"*","orange":"^1.0.0"},"fastboot":{"manifest":{"appFiles":["assets/app.js","assets/app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["assets/vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":2}}`
});

project.pkg.fastbootDependencies = [
'apple',
'orange'
];

project.pkg.dependencies.pizza = '^3.0.0';

yield output.build();

expect(
output.changes()
).to.deep.equal({ });

project.pkg.dependencies.apple = '^3.0.0';

yield output.build();

expect(
output.read()
).to.deep.equal({
'package.json': `{"dependencies":{"apple":"^3.0.0","orange":"^1.0.0"},"fastboot":{"manifest":{"appFiles":["assets/app.js","assets/app-fastboot.js"],"htmlFile":"index.html","vendorFiles":["assets/vendor.js"]},"moduleWhitelist":["apple","orange"],"schemaVersion":2}}`
});
}));
});
72 changes: 66 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@
dependencies:
"@glimmer/util" "^0.22.1"

"@types/rsvp@^3.0.0":
version "3.3.0"
resolved "https://registry.npmjs.org/@types/rsvp/-/rsvp-3.3.0.tgz#20c97372ebf32bda6a4817f7182ec672893947e6"

abbrev@1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
Expand Down Expand Up @@ -1277,6 +1281,10 @@ broccoli-middleware@^1.0.0-beta.8:
handlebars "^4.0.4"
mime "^1.2.11"

broccoli-node-info@1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/broccoli-node-info/-/broccoli-node-info-1.1.0.tgz#3aa2e31e07e5bdb516dd25214f7c45ba1c459412"

broccoli-persistent-filter@^1.0.1, broccoli-persistent-filter@^1.0.3, broccoli-persistent-filter@^1.1.6, broccoli-persistent-filter@^1.2.0:
version "1.3.1"
resolved "https://registry.yarnpkg.com/broccoli-persistent-filter/-/broccoli-persistent-filter-1.3.1.tgz#d02556a135c77dfb859bba7844bc3539be7168e1"
Expand Down Expand Up @@ -1313,6 +1321,10 @@ broccoli-plugin@^1.0.0, broccoli-plugin@^1.1.0, broccoli-plugin@^1.2.0, broccoli
rimraf "^2.3.4"
symlink-or-copy "^1.1.8"

broccoli-slow-trees@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/broccoli-slow-trees/-/broccoli-slow-trees-2.0.0.tgz#9741afe992787add64aec7f7c8211dfcc058278d"

broccoli-slow-trees@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/broccoli-slow-trees/-/broccoli-slow-trees-3.0.1.tgz#9bf2a9e2f8eb3ed3a3f2abdde988da437ccdc9b4"
Expand Down Expand Up @@ -1352,6 +1364,19 @@ broccoli-stew@^1.2.0, broccoli-stew@^1.3.3:
symlink-or-copy "^1.1.8"
walk-sync "^0.3.0"

broccoli-test-helper@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/broccoli-test-helper/-/broccoli-test-helper-1.1.0.tgz#7ec8a5efc33e2299b6592ca066f6f58645480bda"
dependencies:
"@types/rsvp" "^3.0.0"
broccoli "^1.1.0"
fixturify "^0.3.2"
fs-tree-diff "^0.5.6"
mktemp "^0.4.0"
rimraf "^2.5.4"
rsvp "^3.3.3"
walk-sync "^0.3.1"

broccoli-uglify-sourcemap@^1.0.0:
version "1.5.2"
resolved "https://registry.yarnpkg.com/broccoli-uglify-sourcemap/-/broccoli-uglify-sourcemap-1.5.2.tgz#04f84ab0db539031fa868ccfa563c9932d50cedb"
Expand All @@ -1373,6 +1398,26 @@ broccoli-writer@~0.1.1:
quick-temp "^0.1.0"
rsvp "^3.0.6"

broccoli@^1.1.0:
version "1.1.2"
resolved "https://registry.npmjs.org/broccoli/-/broccoli-1.1.2.tgz#9657bcee3b1e81f3a2fdbf6050355ba9163c7c11"
dependencies:
broccoli-node-info "1.1.0"
broccoli-slow-trees "^2.0.0"
broccoli-source "^1.1.0"
commander "^2.5.0"
connect "^3.3.3"
copy-dereference "^1.0.0"
findup-sync "^1.0.0"
handlebars "^4.0.4"
heimdalljs-logger "^0.1.7"
mime "^1.2.11"
rimraf "^2.4.3"
rsvp "^3.0.17"
sane "^1.4.1"
tmp "0.0.28"
underscore.string "^3.2.2"

browser-stdout@1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.0.tgz#f351d32969d32fa5d7a5567154263d928ae3bd1f"
Expand Down Expand Up @@ -1594,7 +1639,7 @@ clone@^2.0.0:

co@^4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"
resolved "https://registry.npmjs.org/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184"

code-point-at@^1.0.0:
version "1.1.0"
Expand Down Expand Up @@ -1696,6 +1741,15 @@ configstore@^3.0.0:
write-file-atomic "^2.0.0"
xdg-basedir "^3.0.0"

connect@^3.3.3:
version "3.6.2"
resolved "https://registry.npmjs.org/connect/-/connect-3.6.2.tgz#694e8d20681bfe490282c8ab886be98f09f42fe7"
dependencies:
debug "2.6.7"
finalhandler "1.0.3"
parseurl "~1.3.1"
utils-merge "1.0.0"

console-control-strings@^1.0.0, console-control-strings@~1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e"
Expand Down Expand Up @@ -2896,7 +2950,7 @@ fill-range@^2.1.0:
repeat-element "^1.1.2"
repeat-string "^1.5.2"

finalhandler@~1.0.3:
finalhandler@1.0.3, finalhandler@~1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/finalhandler/-/finalhandler-1.0.3.tgz#ef47e77950e999780e86022a560e3217e0d0cc89"
dependencies:
Expand Down Expand Up @@ -2946,6 +3000,12 @@ fireworm@^0.7.0:
lodash.flatten "^3.0.2"
minimatch "^3.0.2"

fixturify@^0.3.2:
version "0.3.3"
resolved "https://registry.npmjs.org/fixturify/-/fixturify-0.3.3.tgz#842eaa120564c9881e099ed06dc082a81e97fa71"
dependencies:
fs-extra "^0.30.0"

flat-cache@^1.2.1:
version "1.2.2"
resolved "https://registry.yarnpkg.com/flat-cache/-/flat-cache-1.2.2.tgz#fa86714e72c21db88601761ecf2f555d1abc6b96"
Expand Down Expand Up @@ -3749,7 +3809,7 @@ json-schema@0.2.3:

json-stable-stringify@^1.0.0, json-stable-stringify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af"
resolved "https://registry.npmjs.org/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af"
dependencies:
jsonify "~0.0.0"

Expand Down Expand Up @@ -4260,7 +4320,7 @@ mkdirp@0.5.1, mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdi
dependencies:
minimist "0.0.8"

mktemp@~0.4.0:
mktemp@^0.4.0, mktemp@~0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/mktemp/-/mktemp-0.4.0.tgz#6d0515611c8a8c84e484aa2000129b98e981ff0b"

Expand Down Expand Up @@ -5068,7 +5128,7 @@ samsam@1.x, samsam@^1.1.3:
version "1.2.1"
resolved "https://registry.yarnpkg.com/samsam/-/samsam-1.2.1.tgz#edd39093a3184370cb859243b2bdf255e7d8ea67"

sane@^1.1.1, sane@^1.6.0:
sane@^1.1.1, sane@^1.4.1, sane@^1.6.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/sane/-/sane-1.7.0.tgz#b3579bccb45c94cf20355cc81124990dfd346e30"
dependencies:
Expand Down Expand Up @@ -5683,7 +5743,7 @@ ultron@1.0.x:
version "1.0.2"
resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.0.2.tgz#ace116ab557cd197386a4e88f4685378c8b2e4fa"

underscore.string@~3.3.4:
underscore.string@^3.2.2, underscore.string@~3.3.4:
version "3.3.4"
resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-3.3.4.tgz#2c2a3f9f83e64762fdc45e6ceac65142864213db"
dependencies:
Expand Down

0 comments on commit 22a446d

Please sign in to comment.