diff --git a/CHANGELOG.md b/CHANGELOG.md index b6dd6b8f..0461d525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Changelog ========= +# 4.0.2 +- Fix issue with caching page results in production mode. + # 4.0.1 - Fix regression with the `getImageInfo` api. diff --git a/src/Lasso.js b/src/Lasso.js index 878bf3c0..44bebdee 100644 --- a/src/Lasso.js +++ b/src/Lasso.js @@ -28,7 +28,6 @@ const resolveFrom = require('resolve-from'); const LassoPrebuildResult = require('./LassoPrebuildResult'); const { buildPrebuildName, buildPrebuildFileName } = require('./util/prebuild.js'); const hashUtil = require('./util/hash'); -const stringifyAttrs = require('./util/stringify-attrs'); /** * Cache of prebuilds by path. If there are multiple slots for the same @@ -251,10 +250,10 @@ async function doLassoPage (theLasso, options, lassoContext) { function buildHtmlSlots (pageBundles) { pageBundles.forEachBundle(function (bundle) { - let html, + let attrs, url; - const htmlAttributes = bundle.getHtmlAttributes(); + const bundleAttrs = bundle.getHtmlAttributes(); if (bundle.isInline()) { if (fingerprintInlineCode) { @@ -274,20 +273,20 @@ async function doLassoPage (theLasso, options, lassoContext) { url = bundle.getUrl(lassoContext); if (bundle.isJavaScript()) { - html = theLasso.getJavaScriptDependencyHtml(url, htmlAttributes); + attrs = Object.assign({ src: url }, bundleAttrs); } else if (bundle.isStyleSheet()) { - html = theLasso.getCSSDependencyHtml(url, htmlAttributes); + attrs = Object.assign({ href: url }, bundleAttrs); } else if (!bundle.hasContent()) { // ignore this bundle because contentType is "none" return; } else { throw new Error('Invalid bundle content type: ' + bundle.getContentType()); } - slotTracker.addContent(bundle.getSlot(), bundle.getContentType(), html); + slotTracker.addContent(bundle.getSlot(), bundle.getContentType(), attrs); } }); - lassoPageResult.setHtmlBySlot(slotTracker.getHtmlBySlot()); + lassoPageResult.setSlotsByName(slotTracker.getSlotsByName()); lassoPageResult.setInlineCodeFingerprints(inlineCodeFingerprints); } @@ -724,14 +723,6 @@ Lasso.prototype = { return this.config; }, - getJavaScriptDependencyHtml: function(url, attributes) { - return data => ``; - }, - - getCSSDependencyHtml: function(url, attributes) { - return data => ``; - }, - _resolveflags: function(options) { const flagSet = flags.createFlagSet(); @@ -891,10 +882,9 @@ Lasso.prototype = { throw new Error(`No build could be found using flags: "${flagsStr}" for file at path "${path}"`); } - lassoPageResult = new LassoPageResult({ - htmlBySlot: build.slots, - resources: build.assets - }); + lassoPageResult = new LassoPageResult(); + lassoPageResult.setSlotsByName(build.slots); + lassoPageResult.resources = build.resources; prebuildToPath[path] = lassoPageResult; diff --git a/src/LassoPageResult.js b/src/LassoPageResult.js index 7fd69480..8b3c5edd 100644 --- a/src/LassoPageResult.js +++ b/src/LassoPageResult.js @@ -1,19 +1,15 @@ -const extend = require('raptor-util/extend'); -const toString = require('./util/to-string'); -const LassoPrebuild = require('./LassoPrebuild'); +const Slot = require('./Slot'); const EMPTY_OBJECT = {}; const hasOwn = Object.prototype.hasOwnProperty; -function LassoPageResult (options = {}) { - const { htmlBySlot, resources } = options; - +function LassoPageResult () { this.urlsBySlot = {}; this.urlsByContentType = {}; this.files = []; this.infoByBundleName = {}; this.infoByAsyncBundleName = {}; - this._htmlBySlot = htmlBySlot || {}; - this.resources = resources || []; + this.resources = []; + this._slotsByName = {}; /** * If Lasso is configured to fingerprint inline code for @@ -32,10 +28,7 @@ LassoPageResult.deserialize = function (reader) { json += data; }) .on('end', function () { - const o = JSON.parse(json); - const lassoPageResult = new LassoPageResult(); - extend(lassoPageResult, o); - resolve(lassoPageResult); + resolve(Object.assign(new LassoPageResult(), JSON.parse(json))); }) .on('error', function (err) { reject(err); @@ -68,8 +61,8 @@ LassoPageResult.prototype = { */ get htmlBySlot() { const htmlBySlot = {}; - for (const slotName in this._htmlBySlot) { - if (hasOwn.call(this._htmlBySlot, slotName)) { + for (const slotName in this._slotsByName) { + if (hasOwn.call(this._slotsByName, slotName)) { const slotHtml = this.getHtmlForSlot(slotName); htmlBySlot[slotName] = slotHtml; } @@ -95,7 +88,21 @@ LassoPageResult.prototype = { * @return {String} The HTML for the slot or an empty string if there is no HTML defined for the slot. */ getHtmlForSlot: function(slotName, data) { - return toString(this._htmlBySlot[slotName], data || EMPTY_OBJECT); + const slots = this._slotsByName[slotName]; + + if (slots) { + const slotData = data || EMPTY_OBJECT; + let html = ''; + let sep = ''; + for (const slot of slots) { + html += sep + Slot.render(slot, slotData); + sep = '\n'; + } + + return html; + } + + return ''; }, getHeadHtml: function(data) { @@ -113,23 +120,8 @@ LassoPageResult.prototype = { return this.getHtmlForSlot(slotName, data); }, - /** - * Returns the JSON representation of the return value of {@Link #getHtmlBySlot} - * @return {String} The JSON output - */ - htmlSlotsToJSON: function(indentation) { - return JSON.stringify(this.htmlBySlot, null, indentation); - }, - - toJSON: function() { - const clone = extend({}, this); - // Don't include the loaded templates when generating a JSON string - delete clone._htmlTemplatesBySlot; - return clone; - }, - - setHtmlBySlot: function(htmlBySlot) { - this._htmlBySlot = htmlBySlot; + setSlotsByName: function(slotsByName) { + this._slotsByName = slotsByName; }, registerBundle: function(bundle, async, lassoContext) { @@ -262,12 +254,12 @@ LassoPageResult.prototype = { }, toLassoPrebuild (name, flags) { - return new LassoPrebuild({ - slots: this.htmlBySlot, + return { + slots: this._slotsByName, assets: this.resources, name, flags - }); + }; } }; diff --git a/src/LassoPrebuild.js b/src/LassoPrebuild.js deleted file mode 100644 index eed02149..00000000 --- a/src/LassoPrebuild.js +++ /dev/null @@ -1,10 +0,0 @@ -class LassoPrebuild { - constructor ({ name, slots, assets, flags }) { - this.slots = slots; - this.assets = assets; - this.name = name; - this.flags = flags; - } -} - -module.exports = LassoPrebuild; diff --git a/src/Slot.js b/src/Slot.js index b0851b24..d30f8174 100644 --- a/src/Slot.js +++ b/src/Slot.js @@ -1,33 +1,5 @@ const ok = require('assert').ok; -const toString = require('./util/to-string'); const stringifyAttrs = require('./util/stringify-attrs'); -const inlineBuilders = { - js: (source) => (data) => { - const scriptAttrs = data.externalScriptAttrs; - const code = toString(source, data); - let result = ``; - - if (scriptAttrs) { - if (scriptAttrs.async) { - result += wrapInDocumentLoaded(code, true); - } else if (scriptAttrs.defer) { - result += wrapInDocumentLoaded(code); - } else { - result += code; - } - } else { - result += code; - } - - return `${result}`; - }, - css: (source) => (data) => { - return `${toString( - source, - data - )}`; - } -}; function Slot(contentType) { ok(contentType, 'contentType is required'); @@ -57,46 +29,62 @@ Slot.prototype = { inline: false, code: content }); - }, + } +}; - buildHtml: function() { - const output = []; - let isTemplate = false; - for (let i = 0, len = this.content.length; i < len; i++) { - const content = this.content[i]; - if (content.inline) { - const builder = inlineBuilders[this.contentType]; - - if (builder) { - isTemplate = true; - output.push(builder(content.code)); - } else { - throw new Error("Invalid inline content type '" + this.contentType + "'."); - } - } else { - isTemplate = isTemplate || typeof content.code === 'function'; - output.push(content.code); - } +Slot.render = function(slot, data) { + let html = ''; + let sep = ''; + + for (const content of slot.content) { + html += sep; + sep = '\n'; + + switch (slot.contentType) { + case 'js': + html += (content.inline ? inlineScript : externalScript)(content.code, data); + break; + case 'css': + html += (content.inline ? inlineStyle : externalStyle)(content.code, data); + break; + default: + throw new Error('Invalid content type: ' + slot.contentType); } + } - if (isTemplate) { - return data => { - let result = ''; - for (let i = 0; i < output.length; i++) { - if (i !== 0) { - result += '\n'; - } + return html; +}; - result += toString(output[i], data); - } +function inlineScript(content, data) { + const scriptAttrs = data.externalScriptAttrs; + let result = ``; - return result; - }; + if (scriptAttrs) { + if (scriptAttrs.async) { + result += wrapInDocumentLoaded(content, true); + } else if (scriptAttrs.defer) { + result += wrapInDocumentLoaded(content); + } else { + result += content; } - - return output.join('\n'); + } else { + result += content; } -}; + + return `${result}`; +} + +function inlineStyle(content, data) { + return `${content}`; +} + +function externalScript(attrs, data) { + return ``; +} + +function externalStyle(attrs, data) { + return ``; +} function wrapInDocumentLoaded(code, isAsync) { return ( diff --git a/src/SlotTracker.js b/src/SlotTracker.js index 83787a82..189f9d78 100644 --- a/src/SlotTracker.js +++ b/src/SlotTracker.js @@ -1,15 +1,14 @@ const Slot = require('./Slot'); const InlinePos = require('./InlinePos'); -const toString = require('./util/to-string'); function SlotTracker() { this.slots = {}; - this.slotNames = {}; + this.slotNames = new Set(); } SlotTracker.prototype = { addInlineCode: function(slotName, contentType, code, inlinePos, mergeInline) { - this.slotNames[slotName] = true; + this.slotNames.add(slotName); let slotKey = contentType + ':' + slotName; if (inlinePos === InlinePos.BEGINNING) { @@ -23,46 +22,34 @@ SlotTracker.prototype = { }, addContent: function(slotName, contentType, content) { - this.slotNames[slotName] = true; + this.slotNames.add(slotName); + const slotKey = contentType + ':' + slotName; const slot = this.slots[slotKey] || (this.slots[slotKey] = new Slot(contentType)); slot.addContent(content); }, - getHtmlBySlot: function() { - const htmlBySlot = {}; + getSlotsByName: function() { + const slotsByName = {}; const slots = this.slots; - function addCode(slotName, lookup) { - const slot = slots[lookup]; - - if (!slot) { - return; - } - - const html = htmlBySlot[slotName]; - const newHtml = slot.buildHtml(); - htmlBySlot[slotName] = - html == null - ? newHtml - : (data) => - `${toString(html, data)}\n${toString(newHtml, data)}`; + function addCode(slotList, key) { + const slot = slots[key]; + if (slot) slotList.push(slot); } - const slotNames = Object.keys(this.slotNames); - for (let i = 0, len = slotNames.length; i < len; i++) { - const slotName = slotNames[i]; - - addCode(slotName, 'css:' + slotName + ':before'); - addCode(slotName, 'css:' + slotName); - addCode(slotName, 'css:' + slotName + ':after'); + for (const slotName of this.slotNames) { + const slotList = slotsByName[slotName] = []; + addCode(slotList, 'css:' + slotName + ':before'); + addCode(slotList, 'css:' + slotName); + addCode(slotList, 'css:' + slotName + ':after'); - addCode(slotName, 'js:' + slotName + ':before'); - addCode(slotName, 'js:' + slotName); - addCode(slotName, 'js:' + slotName + ':after'); + addCode(slotList, 'js:' + slotName + ':before'); + addCode(slotList, 'js:' + slotName); + addCode(slotList, 'js:' + slotName + ':after'); } - return htmlBySlot; + return slotsByName; } }; diff --git a/src/util/to-string.js b/src/util/to-string.js deleted file mode 100644 index 37156bca..00000000 --- a/src/util/to-string.js +++ /dev/null @@ -1,8 +0,0 @@ -const EMPTY_OBJECT = {}; -module.exports = function toString(val, data) { - if (typeof val === 'function') { - val = val(data || EMPTY_OBJECT); - } - - return '' + (val || ''); -}; diff --git a/test/autotests/load-prebuild/error-no-build/page.prebuild.json b/test/autotests/load-prebuild/error-no-build/page.prebuild.json index 89b4bb32..fbba8739 100644 --- a/test/autotests/load-prebuild/error-no-build/page.prebuild.json +++ b/test/autotests/load-prebuild/error-no-build/page.prebuild.json @@ -1,8 +1,8 @@ [ { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "assets": [], "name": "page", diff --git a/test/autotests/load-prebuild/load-valid-prebuild-multi-flags/page.prebuild.json b/test/autotests/load-prebuild/load-valid-prebuild-multi-flags/page.prebuild.json index 91db081c..0f491dce 100644 --- a/test/autotests/load-prebuild/load-valid-prebuild-multi-flags/page.prebuild.json +++ b/test/autotests/load-prebuild/load-valid-prebuild-multi-flags/page.prebuild.json @@ -1,16 +1,16 @@ [ { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "assets": [], "name": "page" }, { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test1.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "flags": ["mobile", "test"], "assets": [], @@ -18,8 +18,8 @@ }, { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test2.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "flags": [], "assets": [], diff --git a/test/autotests/load-prebuild/load-valid-prebuild-multi-no-flags/page.prebuild.json b/test/autotests/load-prebuild/load-valid-prebuild-multi-no-flags/page.prebuild.json index 91db081c..0f491dce 100644 --- a/test/autotests/load-prebuild/load-valid-prebuild-multi-no-flags/page.prebuild.json +++ b/test/autotests/load-prebuild/load-valid-prebuild-multi-no-flags/page.prebuild.json @@ -1,16 +1,16 @@ [ { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "assets": [], "name": "page" }, { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test1.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "flags": ["mobile", "test"], "assets": [], @@ -18,8 +18,8 @@ }, { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test2.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "flags": [], "assets": [], diff --git a/test/autotests/load-prebuild/load-valid-prebuild/page.prebuild.json b/test/autotests/load-prebuild/load-valid-prebuild/page.prebuild.json index 62d7e727..2d684a8d 100644 --- a/test/autotests/load-prebuild/load-valid-prebuild/page.prebuild.json +++ b/test/autotests/load-prebuild/load-valid-prebuild/page.prebuild.json @@ -1,8 +1,8 @@ [ { "slots": { - "body": "", - "head": "" + "body": [{ "contentType": "js", "content": [{ "code": { "src": "./test.js" } }] }], + "head": [{ "contentType": "css", "content": [{ "code": { "href": "./style.css" }}] }] }, "assets": [], "name": "page" diff --git a/test/autotests/prebuild-page/multi-prebuild/page.prebuild.expected.json b/test/autotests/prebuild-page/multi-prebuild/page.prebuild.expected.json index 0f24f157..4b8598d8 100644 --- a/test/autotests/prebuild-page/multi-prebuild/page.prebuild.expected.json +++ b/test/autotests/prebuild-page/multi-prebuild/page.prebuild.expected.json @@ -1,9 +1,19 @@ [ { "slots": { - "body": "" + "body": [{ + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/page/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/a.js" + } + } + ] + }] }, "assets": [], "name": "page" } -] +] \ No newline at end of file diff --git a/test/autotests/prebuild-page/multi-prebuild/page.prebuild.json b/test/autotests/prebuild-page/multi-prebuild/page.prebuild.json index 5b1cc322..a396d222 100644 --- a/test/autotests/prebuild-page/multi-prebuild/page.prebuild.json +++ b/test/autotests/prebuild-page/multi-prebuild/page.prebuild.json @@ -1,7 +1,19 @@ [ { "slots": { - "body": "" + "body": [ + { + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/page/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/a.js" + } + } + ] + } + ] }, "assets": [], "name": "page" diff --git a/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.expected.json b/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.expected.json index 24016e36..324e58d7 100644 --- a/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.expected.json +++ b/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.expected.json @@ -1,9 +1,19 @@ [ { "slots": { - "body": "" + "body": [{ + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/page1/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/b.js" + } + } + ] + }] }, "assets": [], "name": "page1" } -] +] \ No newline at end of file diff --git a/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.json b/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.json index ba7b21fa..9b19cdb1 100644 --- a/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.json +++ b/test/autotests/prebuild-page/multi-prebuild/page1.prebuild.json @@ -1,7 +1,19 @@ [ { "slots": { - "body": "" + "body": [ + { + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/page1/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/b.js" + } + } + ] + } + ] }, "assets": [], "name": "page1" diff --git a/test/autotests/prebuild-page/multi-prebuild/static/page/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/a.js b/test/autotests/prebuild-page/multi-prebuild/static/page/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/a.js new file mode 100644 index 00000000..b26e4428 --- /dev/null +++ b/test/autotests/prebuild-page/multi-prebuild/static/page/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/a.js @@ -0,0 +1 @@ +var a = true; diff --git a/test/autotests/prebuild-page/multi-prebuild/static/page1/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/b.js b/test/autotests/prebuild-page/multi-prebuild/static/page1/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/b.js new file mode 100644 index 00000000..da0f23d1 --- /dev/null +++ b/test/autotests/prebuild-page/multi-prebuild/static/page1/lasso$4.0.1/test/autotests/prebuild-page/multi-prebuild/b.js @@ -0,0 +1 @@ +var b = true; diff --git a/test/autotests/prebuild-page/prebuild-resource/static/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png b/test/autotests/prebuild-page/prebuild-resource/static/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png new file mode 100644 index 00000000..c5bc364b Binary files /dev/null and b/test/autotests/prebuild-page/prebuild-resource/static/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png differ diff --git a/test/autotests/prebuild-page/prebuild-resource/static/test-page/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png.js b/test/autotests/prebuild-page/prebuild-resource/static/test-page/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png.js new file mode 100644 index 00000000..bcba0ca8 --- /dev/null +++ b/test/autotests/prebuild-page/prebuild-resource/static/test-page/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png.js @@ -0,0 +1 @@ +$_mod.def("/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png", {"url":"/static/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png","width":174,"height":30}); \ No newline at end of file diff --git a/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.expected.json b/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.expected.json index 4b683fdc..54e57330 100644 --- a/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.expected.json +++ b/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.expected.json @@ -1,9 +1,37 @@ [ { "slots": { - "body": "\n\n" + "body": [ + { + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/test-page/lasso-modules-client$2.0.7/src/index.js" + } + }, + { + "inline": false, + "code": { + "src": "/static/test-page/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png.js" + } + } + ] + }, + { + "contentType": "js", + "content": [ + { + "inline": true, + "code": "$_mod.ready();", + "merge": true + } + ] + } + ] }, "assets": [], "name": "test-page" } -] +] \ No newline at end of file diff --git a/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.json b/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.json index 26b4bb47..54e57330 100644 --- a/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.json +++ b/test/autotests/prebuild-page/prebuild-resource/test-page.prebuild.json @@ -1,7 +1,35 @@ [ { "slots": { - "body": "\n\n" + "body": [ + { + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/test-page/lasso-modules-client$2.0.7/src/index.js" + } + }, + { + "inline": false, + "code": { + "src": "/static/test-page/lasso$4.0.1/test/autotests/prebuild-page/prebuild-resource/ebay.png.js" + } + } + ] + }, + { + "contentType": "js", + "content": [ + { + "inline": true, + "code": "$_mod.ready();", + "merge": true + } + ] + } + ] }, "assets": [], "name": "test-page" diff --git a/test/autotests/prebuild-page/valid-prebuild/static/test-page-1/lasso$4.0.1/test/autotests/prebuild-page/valid-prebuild/a.js b/test/autotests/prebuild-page/valid-prebuild/static/test-page-1/lasso$4.0.1/test/autotests/prebuild-page/valid-prebuild/a.js new file mode 100644 index 00000000..b26e4428 --- /dev/null +++ b/test/autotests/prebuild-page/valid-prebuild/static/test-page-1/lasso$4.0.1/test/autotests/prebuild-page/valid-prebuild/a.js @@ -0,0 +1 @@ +var a = true; diff --git a/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.expected.json b/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.expected.json index e11b2c99..6f2edc34 100644 --- a/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.expected.json +++ b/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.expected.json @@ -1,9 +1,19 @@ [ { "slots": { - "body": "" + "body": [{ + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/test-page-1/lasso$4.0.1/test/autotests/prebuild-page/valid-prebuild/a.js" + } + } + ] + }] }, "assets": [], "name": "test-page-1" } -] +] \ No newline at end of file diff --git a/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.json b/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.json index ca10342b..c7ecf476 100644 --- a/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.json +++ b/test/autotests/prebuild-page/valid-prebuild/test-page-1.prebuild.json @@ -1,7 +1,19 @@ [ { "slots": { - "body": "" + "body": [ + { + "contentType": "js", + "content": [ + { + "inline": false, + "code": { + "src": "/static/test-page-1/lasso$4.0.1/test/autotests/prebuild-page/valid-prebuild/a.js" + } + } + ] + } + ] }, "assets": [], "name": "test-page-1" diff --git a/test/fixtures/file.json b/test/fixtures/file.json index ea50c5dc..d095d04a 100644 --- a/test/fixtures/file.json +++ b/test/fixtures/file.json @@ -1,3 +1,3 @@ -{ +[{ "hello": "world" -} +}] diff --git a/test/prebuild-page-test.js b/test/prebuild-page-test.js index 427a0f73..c397847e 100644 --- a/test/prebuild-page-test.js +++ b/test/prebuild-page-test.js @@ -8,14 +8,26 @@ const lasso = require('lasso'); const expect = require('chai').expect; function replaceLassoVersion (str) { - return str.replace(/lasso[^?=\\\/]*/g, 'lasso'); + return str?.replace(/lasso[^?=\\\/]*/g, 'lasso'); } +function replaceLassoURLS (slot) { + for (const content of slot.content) { + if (typeof content.code === "object") { + content.code.href = replaceLassoVersion(content.code.href); + content.code.src = replaceLassoVersion(content.code.src); + } else { + content.code = replaceLassoVersion(content.code); + } + } +} + function replaceLassoSlotVersion (prebuild) { for (let i = 0; i < prebuild.length; i++) { - for (let slot in prebuild[i].slots) { - const replaced = replaceLassoVersion(prebuild[i].slots[slot]); - prebuild[i].slots[slot] = replaced; + for (const name in prebuild[i].slots) { + for (const slot of prebuild[i].slots[name]) { + replaceLassoURLS(slot); + } } }