From 8c21d26eab0ccfadd0866e9d53fc72e85fb79d2b Mon Sep 17 00:00:00 2001 From: Bruno Dutra Date: Fri, 19 Apr 2019 13:14:41 +0200 Subject: [PATCH] drop support for node 6 --- .travis.yml | 2 +- src/index.js | 40 ++++++++++++++++++++-------------------- src/loader.js | 18 ++++++++++-------- src/rule_loader.js | 13 +++++++------ test/util.js | 7 ++++--- 5 files changed, 42 insertions(+), 38 deletions(-) diff --git a/.travis.yml b/.travis.yml index f171c91..2616b30 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: node_js node_js: -- '6' +- '8' - node os: diff --git a/src/index.js b/src/index.js index 2485e2d..cf5c727 100644 --- a/src/index.js +++ b/src/index.js @@ -64,26 +64,26 @@ module.exports = class WebappWebpackPlugin { || htmlPlugin.options.favicons !== false && htmlPlugin.options.inject && inject; } - tap(compiler, 'make', 'WebappWebpackPlugin', (compilation, callback) => - // Generate favicons - child.run(this.options, compiler.context, compilation) - .then(tags => { - this.tags.resolve(tags); + tap(compiler, 'make', 'WebappWebpackPlugin', async (compilation, callback) => { + try { + // Generate favicons + const tags = await child.run(this.options, compiler.context, compilation); + this.tags.resolve(tags); - // Hook into the html-webpack-plugin processing and add the html - tapHtml(compilation, 'WebappWebpackPlugin', (htmlPluginData, callback) => { - if (this.options.inject(htmlPluginData.plugin)) { - const idx = (htmlPluginData.html + '').search(/<\/head>/i); - htmlPluginData.html = [htmlPluginData.html.slice(0, idx), ...tags, htmlPluginData.html.slice(idx)].join(''); - } - return callback(null, htmlPluginData); - }); - return callback(); - }) - .catch(err => { - this.tags.reject(err); - return callback(err); - }) - ); + // Hook into the html-webpack-plugin processing and add the html + tapHtml(compilation, 'WebappWebpackPlugin', (htmlPluginData, callback) => { + if (this.options.inject(htmlPluginData.plugin)) { + const idx = (htmlPluginData.html + '').search(/<\/head>/i); + htmlPluginData.html = [htmlPluginData.html.slice(0, idx), ...tags, htmlPluginData.html.slice(idx)].join(''); + } + return callback(null, htmlPluginData); + }); + return callback(); + + } catch (err) { + this.tags.reject(err); + return callback(err); + } + }); } } diff --git a/src/loader.js b/src/loader.js index a4e3ea2..ed965c2 100644 --- a/src/loader.js +++ b/src/loader.js @@ -7,7 +7,7 @@ const pkg = require('../package.json') const trailingSlash = (path) => (path.substr(-1) !== '/') ? path + '/' : path; -module.exports = function (content) { +module.exports = async function (content) { /* istanbul ignore next */ if (!this.async) throw new Error('async is required'); @@ -19,13 +19,15 @@ module.exports = function (content) { content: msgpack.encode([content, query.options, pkg.version]), // hash must depend on logo + config + version })); const outputPath = query.outputPath ? trailingSlash(query.outputPath) : prefix; - // Generate icons - return favicons(content, Object.assign(query.options, { path: url.resolve(path, prefix) })) - .then(({ html: tags, images, files }) => { - const assets = [...images, ...files].map(({ name, contents }) => ({ name: outputPath + name, contents })); - return callback(null, `module.exports = '${msgpack.encode({ tags, assets }).toString('base64')}'`); - }) - .catch(callback); + + try { + // Generate icons + const { html: tags, images, files } = await favicons(content, Object.assign(query.options, { path: url.resolve(path, prefix) })) + const assets = [...images, ...files].map(({ name, contents }) => ({ name: outputPath + name, contents })); + return callback(null, `module.exports = '${msgpack.encode({ tags, assets }).toString('base64')}'`); + } catch (err) { + return callback(err); + } }; module.exports.raw = true; diff --git a/src/rule_loader.js b/src/rule_loader.js index 04bf44c..8daf392 100644 --- a/src/rule_loader.js +++ b/src/rule_loader.js @@ -1,10 +1,11 @@ -module.exports = function () { +module.exports = async function () { const callback = this.async(); const { plugin } = this.query; - plugin.tags.promise - .then(tags => { - callback(null, `module.exports = ['${tags.join("', '")}'];`); - }) - .catch(callback); + try { + const tags = await plugin.tags.promise; + return callback(null, `module.exports = ['${tags.join("', '")}'];`); + } catch (err) { + return callback(err); + } }; diff --git a/test/util.js b/test/util.js index cf76e4d..a863928 100644 --- a/test/util.js +++ b/test/util.js @@ -46,7 +46,8 @@ module.exports.run = (compiler) => new Promise((resolve, reject) => { module.exports.generate = (config) => module.exports.run(module.exports.compiler(config)); -module.exports.compare = (a, b) => dircompare.compare(a, b, { compareContent: true, excludeFilter: '*.js' }).then(diff => - diff.diffSet.filter(({ state }) => state !== 'equal') +module.exports.compare = async (a, b) => { + const diff = await dircompare.compare(a, b, { compareContent: true, excludeFilter: '*.js' }); + return diff.diffSet.filter(({ state }) => state !== 'equal') .map(({ path1, name1, path2, name2 }) => `${path.join(path1 || '', name1 + '')} ≠ ${path.join(path2 || '', name2 + '')}`) -); +}