Skip to content

Commit

Permalink
properly ignore files that should not execute in fastboot
Browse files Browse the repository at this point in the history
  • Loading branch information
xg-wang committed Apr 8, 2021
1 parent 74a7c59 commit c4d2dbc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
29 changes: 13 additions & 16 deletions packages/ember-cli-fastboot/lib/broccoli/html-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,10 @@ module.exports = class BasePageWriter extends Filter {
let dom = new JSDOM(content);
let scriptTags = dom.window.document.querySelectorAll('script');

// In fastboot-config.js the paths are transformed with stripLeadingSlash
// do we need to concat rootURL here?
let rootURL = this._rootURL;

ignoreUnexpectedScripts(scriptTags, this._expectedFiles);
this._ignoreUnexpectedScripts(scriptTags);

let fastbootScripts = this._findFastbootScriptToInsert(scriptTags);

let appJsTag = findAppJsTag(scriptTags, this._appJsPath, rootURL);

let appJsTag = findAppJsTag(scriptTags, this._appJsPath, this._rootURL);
insertFastbootScriptsBeforeAppJsTags(fastbootScripts, appJsTag);

return dom.serialize();
Expand All @@ -53,6 +47,16 @@ module.exports = class BasePageWriter extends Filter {
.map(src => urlWithin(src, rootURL))
.filter(src => !scriptSrcs.includes(src));
}

_ignoreUnexpectedScripts(scriptTags) {
let expectedFiles = this._expectedFiles;
let rootURL = this._rootURL;
for (let element of scriptTags) {
if (!expectedFiles.includes(urlWithin(element.getAttribute('src'), rootURL))) {
element.setAttribute('data-fastboot-ignore', '');
}
}
}
};

function expectedFiles(outputPaths) {
Expand All @@ -66,14 +70,6 @@ function expectedFiles(outputPaths) {
return [appFilePath, appFastbootFilePath, vendorFilePath];
}

function ignoreUnexpectedScripts(scriptTags, expectedFiles) {
for (let element of scriptTags) {
if (!expectedFiles.includes(urlWithin(element.getAttribute('src')))) {
element.setAttribute('data-fastboot-ignore', '');
}
}
}

function getRootURL(appName, config) {
let rootURL = (config[appName] && config[appName].rootURL) || '/';
if (!rootURL.endsWith('/')) {
Expand Down Expand Up @@ -118,6 +114,7 @@ class NodeRange {
let newTag = this.end.ownerDocument.createElement('fastboot-script');
newTag.setAttribute('src', src);
this.insertNode(newTag);
this.insertNode(this.end.ownerDocument.createTextNode('\n'));
}

insertNode(node) {
Expand Down
1 change: 1 addition & 0 deletions test-packages/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "3.2.0-beta.1",
"repository": "",
"scripts": {
"clean": "node helpers/clean-dists.js",
"test": "node helpers/clean-dists.js && mocha"
},
"devDependencies": {
Expand Down

0 comments on commit c4d2dbc

Please sign in to comment.