Skip to content

Commit c4d2dbc

Browse files
committed
properly ignore files that should not execute in fastboot
1 parent 74a7c59 commit c4d2dbc

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

packages/ember-cli-fastboot/lib/broccoli/html-writer.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,10 @@ module.exports = class BasePageWriter extends Filter {
2626
let dom = new JSDOM(content);
2727
let scriptTags = dom.window.document.querySelectorAll('script');
2828

29-
// In fastboot-config.js the paths are transformed with stripLeadingSlash
30-
// do we need to concat rootURL here?
31-
let rootURL = this._rootURL;
32-
33-
ignoreUnexpectedScripts(scriptTags, this._expectedFiles);
29+
this._ignoreUnexpectedScripts(scriptTags);
3430

3531
let fastbootScripts = this._findFastbootScriptToInsert(scriptTags);
36-
37-
let appJsTag = findAppJsTag(scriptTags, this._appJsPath, rootURL);
38-
32+
let appJsTag = findAppJsTag(scriptTags, this._appJsPath, this._rootURL);
3933
insertFastbootScriptsBeforeAppJsTags(fastbootScripts, appJsTag);
4034

4135
return dom.serialize();
@@ -53,6 +47,16 @@ module.exports = class BasePageWriter extends Filter {
5347
.map(src => urlWithin(src, rootURL))
5448
.filter(src => !scriptSrcs.includes(src));
5549
}
50+
51+
_ignoreUnexpectedScripts(scriptTags) {
52+
let expectedFiles = this._expectedFiles;
53+
let rootURL = this._rootURL;
54+
for (let element of scriptTags) {
55+
if (!expectedFiles.includes(urlWithin(element.getAttribute('src'), rootURL))) {
56+
element.setAttribute('data-fastboot-ignore', '');
57+
}
58+
}
59+
}
5660
};
5761

5862
function expectedFiles(outputPaths) {
@@ -66,14 +70,6 @@ function expectedFiles(outputPaths) {
6670
return [appFilePath, appFastbootFilePath, vendorFilePath];
6771
}
6872

69-
function ignoreUnexpectedScripts(scriptTags, expectedFiles) {
70-
for (let element of scriptTags) {
71-
if (!expectedFiles.includes(urlWithin(element.getAttribute('src')))) {
72-
element.setAttribute('data-fastboot-ignore', '');
73-
}
74-
}
75-
}
76-
7773
function getRootURL(appName, config) {
7874
let rootURL = (config[appName] && config[appName].rootURL) || '/';
7975
if (!rootURL.endsWith('/')) {
@@ -118,6 +114,7 @@ class NodeRange {
118114
let newTag = this.end.ownerDocument.createElement('fastboot-script');
119115
newTag.setAttribute('src', src);
120116
this.insertNode(newTag);
117+
this.insertNode(this.end.ownerDocument.createTextNode('\n'));
121118
}
122119

123120
insertNode(node) {

test-packages/integration-tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "3.2.0-beta.1",
55
"repository": "",
66
"scripts": {
7+
"clean": "node helpers/clean-dists.js",
78
"test": "node helpers/clean-dists.js && mocha"
89
},
910
"devDependencies": {

0 commit comments

Comments
 (0)