From c4d2dbcf6034499ef4e7e1ed93c8c5c130085d32 Mon Sep 17 00:00:00 2001 From: Thomas Wang Date: Wed, 7 Apr 2021 20:14:25 -0700 Subject: [PATCH] properly ignore files that should not execute in fastboot --- .../lib/broccoli/html-writer.js | 29 +++++++++---------- test-packages/integration-tests/package.json | 1 + 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/packages/ember-cli-fastboot/lib/broccoli/html-writer.js b/packages/ember-cli-fastboot/lib/broccoli/html-writer.js index 74846512..07bdff38 100644 --- a/packages/ember-cli-fastboot/lib/broccoli/html-writer.js +++ b/packages/ember-cli-fastboot/lib/broccoli/html-writer.js @@ -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(); @@ -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) { @@ -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('/')) { @@ -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) { diff --git a/test-packages/integration-tests/package.json b/test-packages/integration-tests/package.json index 2b556967..51bb68b5 100644 --- a/test-packages/integration-tests/package.json +++ b/test-packages/integration-tests/package.json @@ -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": {