-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
html-oriented manifest format ----------------------------- In the new schema format, which is defined in ember-fastboot/fastboot@3fd5bc9 the manifest is written into HTML and later extracted by fastboot on server side instead of previously reading from dist/package.json Note: The new schema in fastboot does not handle fastboot config https://github.com/ember-fastboot/ember-cli-fastboot/tree/e4d0b7c7bcdf82def0dc8726835b49d707673f41#providing-additional-config This commit changes to read Fastboot.config from dist/package.json instead of ignoring it Allow to require module path from whitelisted dependency ------------------------------------------------------- Incrementing schema to 5 also included the changes in schema 4 strictWhitelist See ember-fastboot/fastboot#200
- Loading branch information
Showing
8 changed files
with
179 additions
and
66 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 was deleted.
Oops, something went wrong.
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,94 @@ | ||
'use strict'; | ||
|
||
const Filter = require('broccoli-persistent-filter'); | ||
const { JSDOM } = require('jsdom'); | ||
|
||
module.exports = class BasePageWriter extends Filter { | ||
constructor(inputNodes, { annotation, fastbootConfig, appName, manifest, appJsPath }) { | ||
super(inputNodes, { | ||
annotation, | ||
extensions: ['html'], | ||
targetExtension: 'html', | ||
}); | ||
this._manifest = manifest; | ||
this._rootURL = getRootURL(fastbootConfig, appName); | ||
this._appJsPath = appJsPath; | ||
} | ||
|
||
getDestFilePath() { | ||
let filteredRelativePath = super.getDestFilePath(...arguments); | ||
|
||
return filteredRelativePath === this._manifest.htmlFile ? filteredRelativePath : null; | ||
} | ||
|
||
processString(content) { | ||
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; | ||
|
||
let scriptSrcs = []; | ||
for (let element of scriptTags) { | ||
scriptSrcs.push(urlWithin(element.getAttribute('src'), rootURL)); | ||
} | ||
|
||
let fastbootScripts = this._manifest.vendorFiles | ||
.concat(this._manifest.appFiles) | ||
.map(src => urlWithin(src, rootURL)) | ||
.filter(src => !scriptSrcs.includes(src)); | ||
|
||
let appJsTag = findAppJsTag(scriptTags, this._appJsPath, rootURL); | ||
let range = new NodeRange(appJsTag); | ||
|
||
for (let src of fastbootScripts) { | ||
range.insertAsScriptTag(src); | ||
} | ||
|
||
return dom.serialize(); | ||
} | ||
}; | ||
|
||
function getRootURL(appName, config) { | ||
let rootURL = (config[appName] && config[appName].rootURL) || '/'; | ||
if (!rootURL.endsWith('/')) { | ||
rootURL = rootURL + '/'; | ||
} | ||
return rootURL; | ||
} | ||
|
||
function urlWithin(candidate, root) { | ||
let candidateURL = new URL(candidate, 'http://_the_current_origin_'); | ||
let rootURL = new URL(root, 'http://_the_current_origin_'); | ||
if (candidateURL.href.startsWith(rootURL.href)) { | ||
return candidateURL.href.slice(rootURL.href.length); | ||
} | ||
} | ||
|
||
function findAppJsTag(scriptTags, appJsPath, rootURL) { | ||
appJsPath = urlWithin(appJsPath, rootURL); | ||
for (let e of scriptTags) { | ||
if (urlWithin(e.getAttribute('src'), rootURL) === appJsPath) { | ||
return e; | ||
} | ||
} | ||
} | ||
|
||
class NodeRange { | ||
constructor(initial) { | ||
this.start = initial.ownerDocument.createTextNode(''); | ||
initial.parentElement.insertBefore(this.start, initial); | ||
this.end = initial; | ||
} | ||
|
||
insertAsScriptTag(src) { | ||
let newTag = this.end.ownerDocument.createElement('fastboot-script'); | ||
newTag.setAttribute('src', src); | ||
this.insertNode(newTag); | ||
} | ||
|
||
insertNode(node) { | ||
this.end.parentElement.insertBefore(node, this.end); | ||
} | ||
} |
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
Oops, something went wrong.