Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix node 6 support
  • Loading branch information
SimenB committed Feb 20, 2021
commit daa88cad9042d7d90cef9a4f186350d80d9e8990
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"eslint-config-simenb-base": "^15.0.1",
"eslint_d": "^7.1.0",
"express": "^4.17.1",
"html-webpack-plugin": "^4.0.0-0",
"html-webpack-plugin": "^4.0.0",
"husky": "^1.0.1",
"jest": "^24.0.0",
"jest-watch-typeahead": "^0.2.0",
Expand All @@ -67,7 +67,7 @@
"webpack-cli": "^3.1.0"
},
"peerDependencies": {
"html-webpack-plugin": "^3.0.4 || ^4.0.0-0 || ^5.0.0-0",
"html-webpack-plugin": "^3.0.4 || ^4.0.0-0 || ^5.0.0",
"webpack": "^4.0.0 || ^5.0.0"
},
"engines": {
Expand Down
21 changes: 11 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@ import pEachSeries from 'p-each-series';
import micromatch from 'micromatch';
import crypto from 'crypto';
import globby from 'globby';
import fs from 'fs';
import path from 'path';
import webpack from 'webpack';
import { promisify } from 'util';
import {
ensureTrailingSlash,
fsReadFileAsync,
handleUrl,
resolveOutput,
resolvePublicPath,
} from './utils';

const fsReadFileAsync = promisify(fs.readFile);

/* istanbul ignore next: webpack 5 not in unit test mocks */
/**
* Pushes the content of the given filename to the compilation assets
* @param {string} filename
Expand Down Expand Up @@ -135,9 +133,11 @@ export default class AddAssetHtmlPlugin {
}
}

const addedFilename = await (
htmlPluginData.plugin.addFileToAssets || addFileToAssetsWebpack5
)(filepath, compilation);
const addFileToAssets =
htmlPluginData.plugin.addFileToAssets ||
/* istanbul ignore next: webpack 5 not in unit test mocks */ addFileToAssetsWebpack5;

const addedFilename = await addFileToAssets(filepath, compilation);

let suffix = '';
if (hash) {
Expand All @@ -162,9 +162,10 @@ export default class AddAssetHtmlPlugin {
const relatedFiles = await globby(`${filepath}.*`);
await Promise.all(
relatedFiles.sort().map(async relatedFile => {
const addedMapFilename = await (
htmlPluginData.plugin.addFileToAssets || addFileToAssetsWebpack5
)(relatedFile, compilation);
const addedMapFilename = await addFileToAssets(
relatedFile,
compilation,
);
resolveOutput(compilation, addedMapFilename, outputPath);
}),
);
Expand Down
14 changes: 14 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import globby from 'globby';
import fs from 'fs';

export function ensureTrailingSlash(string) {
if (string.length && string.substr(-1, 1) !== '/') {
Expand Down Expand Up @@ -30,6 +31,19 @@ export function resolveOutput(compilation, addedFilename, outputPath) {
}
}

/* istanbul ignore next: webpack 5 not in unit test mocks */
export function fsReadFileAsync(filePath) {
return new Promise((resolve, reject) => {
fs.readFile(filePath, (err, res) => {
if (err) {
reject(err);
} else {
resolve(res);
}
});
});
}

/**
* handle globby filepath and return an array with all matched assets.
*
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3869,7 +3869,7 @@ html-minifier-terser@^5.0.1:
relateurl "^0.2.7"
terser "^4.6.3"

html-webpack-plugin@^4.0.0-0:
html-webpack-plugin@^4.0.0:
version "4.5.2"
resolved "https://registry.yarnpkg.com/html-webpack-plugin/-/html-webpack-plugin-4.5.2.tgz#76fc83fa1a0f12dd5f7da0404a54e2699666bc12"
integrity sha512-q5oYdzjKUIPQVjOosjgvCHQOv9Ett9CYYHlgvJeXG0qQvdSojnBq4vAdQBwn1+yGveAwHCoe/rMR86ozX3+c2A==
Expand Down