forked from ember-cli/broccoli-asset-rev
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Maintain correctness when rewriting fastboot-capable apps
Apps that are built with fastboot support contain a fastboot.manifest in their package.json. The manifest includes the names of JS and HTML files. These files may be renamed by broccoli-asset-rev. Up until now, ember-cli-fastboot has been doing hacks to handle adjusting those references itself. But this requires it to have too much knowledge of broccoli-asset-rev, and it forces ember-cli-fastboot to run *after* broccoli-asset-rev, which is problematic for use-cases like ef4/prember#2. This PR reverses that approach by considering fastboot.manifest a standard part of the built ember app that broccoli-asset-rev should know how to update for consistency when renaming files. This PR includes a flag on the addon itself that we can use to migrate ember-cli-fastboot away from its hacky behavior.
- Loading branch information
Showing
17 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* jshint node: true */ | ||
"use strict"; | ||
|
||
var Filter = require('broccoli-persistent-filter'); | ||
var fs = require('fs'); | ||
|
||
module.exports = class FastbootManifestRewrite extends Filter { | ||
constructor(inputNode, assetMap) { | ||
super(inputNode, { annotation: 'broccoli-asset-rev/fastboot-manifest-rewrite'}); | ||
this.assetMap = assetMap; | ||
this.extensions = ['json']; | ||
} | ||
|
||
getDestFilePath(relativePath) { | ||
if (relativePath === 'package.json') { | ||
return relativePath; | ||
} | ||
} | ||
|
||
processString(contents, relativePath) { | ||
var pkg = JSON.parse(contents); | ||
if (pkg.fastboot && pkg.fastboot.manifest) { | ||
var manifest = pkg.fastboot.manifest; | ||
this._process(manifest, 'appFiles', true); | ||
this._process(manifest, 'vendorFiles', true); | ||
this._process(manifest, 'htmlFile', false); | ||
return JSON.stringify(pkg); | ||
} | ||
return contents; | ||
} | ||
|
||
_process(manifest, key, asArray) { | ||
if (manifest[key]) { | ||
if (asArray) { | ||
var assetMap = this.assetMap; | ||
manifest[key] = manifest[key].map(function(filename){ return assetMap[filename] || filename; }); | ||
} else { | ||
manifest[key] = this.assetMap[manifest[key]] || manifest[key]; | ||
} | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const translations = { | ||
en: 'translations/en.json' | ||
}; | ||
|
||
console.log('Hello World'); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-us"> | ||
<head> | ||
<meta charset="utf-8"> | ||
|
||
<title>Application</title> | ||
|
||
<link rel="stylesheet" href="/styles.css"> | ||
<link rel="icon" href="/images/icons/favicon.png"> | ||
</head> | ||
<body> | ||
<script type="text/javascript" src="/assets/application.js"></script> | ||
<script type="text/javascript" src=/assets/application.js></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"fastboot": { | ||
"manifest": { | ||
"appFiles": ["assets/application.js"], | ||
"htmlFile": "index.html", | ||
"vendorFiles": [] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.sample-img { | ||
width: 50px; | ||
height: 50px; | ||
background-image: url(images/sample.png); | ||
} | ||
|
||
.sample-img2 { | ||
width: 50px; | ||
height: 50px; | ||
background-image: url('images/sample.png'); | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/fastboot/output/assets/application-b55acd2e0e4c88b3d29cb7fdbc768eb5.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const translations = { | ||
en: 'translations/en.json' | ||
}; | ||
|
||
console.log('Hello World'); |
Binary file added
BIN
+937 Bytes
...tures/fastboot/output/images/icons/favicon-9243e67fccd0c5e08a3d2c158af6500d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+937 Bytes
tests/fixtures/fastboot/output/images/sample-1f6b78f1b4667adc7e397f7bf94041ab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-us"> | ||
<head> | ||
<meta charset="utf-8"> | ||
|
||
<title>Application</title> | ||
|
||
<link rel="stylesheet" href="/styles-0315ae5ce5f11670cbdea72c9bea621a.css"> | ||
<link rel="icon" href="/images/icons/favicon-9243e67fccd0c5e08a3d2c158af6500d.png"> | ||
</head> | ||
<body> | ||
<script type="text/javascript" src="/assets/application-b55acd2e0e4c88b3d29cb7fdbc768eb5.js"></script> | ||
<script type="text/javascript" src=/assets/application-b55acd2e0e4c88b3d29cb7fdbc768eb5.js></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"fastboot":{"manifest":{"appFiles":["assets/application-b55acd2e0e4c88b3d29cb7fdbc768eb5.js"],"htmlFile":"index.html","vendorFiles":[]}}} |
11 changes: 11 additions & 0 deletions
11
tests/fixtures/fastboot/output/styles-0315ae5ce5f11670cbdea72c9bea621a.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.sample-img { | ||
width: 50px; | ||
height: 50px; | ||
background-image: url(images/sample-1f6b78f1b4667adc7e397f7bf94041ab.png); | ||
} | ||
|
||
.sample-img2 { | ||
width: 50px; | ||
height: 50px; | ||
background-image: url('images/sample-1f6b78f1b4667adc7e397f7bf94041ab.png'); | ||
} |