Skip to content
This repository has been archived by the owner on Mar 8, 2020. It is now read-only.

Commit

Permalink
drop support for node 6
Browse files Browse the repository at this point in the history
  • Loading branch information
brunocodutra committed Jul 6, 2019
1 parent 78f3feb commit 8c21d26
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '6'
- '8'
- node

os:
Expand Down
40 changes: 20 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '</head>').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 + '</head>').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);
}
});
}
}
18 changes: 10 additions & 8 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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;
13 changes: 7 additions & 6 deletions src/rule_loader.js
Original file line number Diff line number Diff line change
@@ -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);
}
};
7 changes: 4 additions & 3 deletions test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '')}`)
);
}

0 comments on commit 8c21d26

Please sign in to comment.