Skip to content

Commit e0c3d06

Browse files
authored
Merge pull request #546 from ef4/simplify-asset-rev
Disentangle from broccoli-asset-rev
2 parents efbebad + 158af9e commit e0c3d06

4 files changed

Lines changed: 626 additions & 501 deletions

File tree

index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const chalk = require('chalk');
1212
const fastbootAppModule = require('./lib/utilities/fastboot-app-module');
1313
const FastBootConfig = require('./lib/broccoli/fastboot-config');
1414
const migrateInitializers = require('./lib/build-utilities/migrate-initializers');
15+
const SilentError = require('silent-error');
1516

1617
const Concat = require('broccoli-concat');
1718
const Funnel = require('broccoli-funnel');
@@ -48,17 +49,18 @@ module.exports = {
4849
* See: https://ember-cli.com/user-guide/#integration
4950
*/
5051
included(app) {
52+
53+
let assetRev = this.project.addons.find(addon => addon.name === 'broccoli-asset-rev');
54+
if(assetRev && !assetRev.supportsFastboot) {
55+
throw new SilentError("This version of ember-cli-fastboot requires a newer version of broccoli-asset-rev");
56+
}
57+
5158
// set autoRun to false since we will conditionally include creating app when app files
5259
// is eval'd in app-boot
5360
app.options.autoRun = false;
5461

55-
if (app.options.fingerprint) {
56-
// set generateAssetMap to be true so that manifest files can be correctly written
57-
// in package.json
58-
app.options.fingerprint.generateAssetMap = true;
59-
}
60-
6162
app.import('vendor/experimental-render-mode-rehydrate.js');
63+
6264
// get the app registry object and app name so that we can build the fastboot
6365
// tree
6466
this._appRegistry = app.registry;
@@ -285,7 +287,6 @@ module.exports = {
285287
let fastbootAppConfig = appConfig.fastboot;
286288

287289
return new FastBootConfig(tree, {
288-
assetMapPath: this.assetMapPath,
289290
project: this.project,
290291
name: this.app.name,
291292
outputPaths: this.app.options.outputPaths,

lib/broccoli/fastboot-config.js

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-env node */
12
'use strict';
23

34
const fs = require('fs');
@@ -7,7 +8,6 @@ const merge = require('ember-cli-lodash-subset').merge;
78
const md5Hex = require('md5-hex');
89
const path = require('path');
910
const Plugin = require('broccoli-plugin');
10-
const SilentError = require('silent-error');
1111

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

@@ -23,7 +23,6 @@ module.exports = class FastBootConfig extends Plugin {
2323
this.project = options.project;
2424

2525
this.name = options.name;
26-
this.assetMapEnabled = options.assetMapEnabled;
2726
this.ui = options.ui;
2827
this.fastbootAppConfig = options.fastbootAppConfig;
2928
this.outputPaths = options.outputPaths;
@@ -39,22 +38,6 @@ module.exports = class FastBootConfig extends Plugin {
3938
this.htmlFile = 'index.html';
4039
}
4140

42-
let defaultAssetMapPath = 'assets/assetMap.json';
43-
let assetRev = this.project.addons.find(addon => addon.name === 'broccoli-asset-rev');
44-
45-
if (assetRev && assetRev.options) {
46-
this.assetMapEnabled = !!(assetRev.options.enabled && assetRev.options.generateAssetMap);
47-
48-
if (assetRev.options.assetMapPath) {
49-
this.assetMapPath = assetRev.options.assetMapPath;
50-
}
51-
52-
if (assetRev.options.fingerprintAssetMap) {
53-
defaultAssetMapPath = 'assets/assetMap-*.json'
54-
}
55-
}
56-
57-
this.assetMapPath = this.assetMapPath || options.assetMapPath || defaultAssetMapPath;
5841
}
5942

6043

@@ -145,19 +128,6 @@ module.exports = class FastBootConfig extends Plugin {
145128
this.moduleWhitelist = uniq(moduleWhitelist);
146129
}
147130

148-
readAssetManifest() {
149-
let assetMapPath = path.join(this.inputPaths[0], this.assetMapPath);
150-
151-
try {
152-
let assetMap = JSON.parse(fs.readFileSync(assetMapPath));
153-
return assetMap;
154-
} catch (e) {
155-
if (this.assetMapEnabled) {
156-
throw new SilentError("assetMap.json not found at: %s. Make sure `generateAssetMap` is set to true", assetMapPath);
157-
}
158-
}
159-
}
160-
161131
updateFastBootManifest(manifest) {
162132
this.project.addons.forEach(addon =>{
163133
if (addon.updateFastBootManifest) {
@@ -187,21 +157,7 @@ module.exports = class FastBootConfig extends Plugin {
187157
htmlFile: this.htmlFile
188158
};
189159

190-
manifest = this.updateFastBootManifest(manifest);
191-
192-
let rewrittenAssets = this.readAssetManifest();
193-
194-
if (rewrittenAssets) {
195-
// update the vendor file with the fingerprinted file
196-
let rewrittenVendorFiles = manifest['vendorFiles'].map(file => rewrittenAssets.assets[file] || file);
197-
manifest['vendorFiles'] = rewrittenVendorFiles;
198-
199-
// update the app files array with fingerprinted files
200-
let rewrittenAppFiles = manifest['appFiles'].map(file => rewrittenAssets.assets[file] || file);
201-
manifest['appFiles'] = rewrittenAppFiles;
202-
}
203-
204-
this.manifest = manifest;
160+
this.manifest = this.updateFastBootManifest(manifest);
205161
}
206162

207163
buildHostWhitelist() {

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"devDependencies": {
4141
"body-parser": "^1.18.1",
42-
"broccoli-asset-rev": "^2.4.5",
42+
"broccoli-asset-rev": "^2.7.0",
4343
"broccoli-test-helper": "^1.1.0",
4444
"chai": "^4.1.0",
4545
"chai-fs": "^2.0.0",
@@ -77,9 +77,6 @@
7777
},
7878
"ember-addon": {
7979
"configPath": "tests/dummy/config",
80-
"after": [
81-
"broccoli-asset-rev"
82-
],
8380
"before": [
8481
"broccoli-serve-files"
8582
]

0 commit comments

Comments
 (0)