From 725bba0a790a126f6a9d6cfdd255899ff09fa5ce Mon Sep 17 00:00:00 2001 From: Jeremy Danyow Date: Sat, 12 May 2018 16:58:34 -0700 Subject: [PATCH 1/2] add dependencies referenced by posthtml-include fixes #488 closes #1226 --- src/transforms/posthtml.js | 6 ++++++ test/html.js | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/transforms/posthtml.js b/src/transforms/posthtml.js index 1ac294085c2..ae47055c904 100644 --- a/src/transforms/posthtml.js +++ b/src/transforms/posthtml.js @@ -23,6 +23,12 @@ async function getConfig(asset) { return; } + if (config && config.plugins && config.plugins['posthtml-include']) { + config.plugins['posthtml-include'].addDependencyTo = { + addDependency: src => asset.addDependency(src, {includedInParent: true}) + }; + } + config = Object.assign({}, config); config.plugins = await loadPlugins(config.plugins, asset.name); config.skipParse = true; diff --git a/test/html.js b/test/html.js index ca9a65e466b..16cefe46877 100644 --- a/test/html.js +++ b/test/html.js @@ -102,6 +102,16 @@ describe('html', function() { }); }); + it('should add dependencies referenced by posthtml-include', async () => { + const b = await bundle( + __dirname + '/integration/posthtml-assets/index.html' + ); + const asset = b.assets.values().next().value; + const other = __dirname + '/integration/posthtml-assets/other.html'; + assert(asset.dependencies.has(other)); + assert(asset.dependencies.get(other).includedInParent); + }); + it('should insert sibling CSS bundles for JS files in the HEAD', async function() { let b = await bundle(__dirname + '/integration/html-css/index.html'); From 7281e013a9ed41497ae755d86ac4c84f3a728376 Mon Sep 17 00:00:00 2001 From: Jeremy Danyow Date: Sun, 20 May 2018 19:42:11 -0700 Subject: [PATCH 2/2] provide addDependency to all posthtml plugins --- src/transforms/posthtml.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/transforms/posthtml.js b/src/transforms/posthtml.js index ae47055c904..66b7015bac4 100644 --- a/src/transforms/posthtml.js +++ b/src/transforms/posthtml.js @@ -23,14 +23,18 @@ async function getConfig(asset) { return; } - if (config && config.plugins && config.plugins['posthtml-include']) { - config.plugins['posthtml-include'].addDependencyTo = { - addDependency: src => asset.addDependency(src, {includedInParent: true}) + config = Object.assign({}, config); + const plugins = config.plugins; + if (typeof plugins === 'object') { + const depConfig = { + addDependencyTo: { + addDependency: name => + asset.addDependency(name, {includedInParent: true}) + } }; + Object.keys(plugins).forEach(p => Object.assign(plugins[p], depConfig)); } - - config = Object.assign({}, config); - config.plugins = await loadPlugins(config.plugins, asset.name); + config.plugins = await loadPlugins(plugins, asset.name); config.skipParse = true; return config; }