Fixes #22 : Call to apply can be asynchronous, but the ‘emit’ callback function shall only be used once from the main class.

This commit is contained in:
chabou-san 2018-01-16 13:24:46 +01:00
parent ee443b5db9
commit a00a1fb1cc
5 changed files with 2526 additions and 2281 deletions

File diff suppressed because it is too large Load diff

View file

@ -18,20 +18,15 @@ export default class AutoIncreaseVersion {
* @protected
* @returns {Promise}
*/
apply() {
async apply() {
// when runInWatchMode
// we have to register AutoIncreaseVersion instead of firing it straight away
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) {
if (this.context.compiler) {
this.context.compiler.plugin('emit', async (compilation, cb) => {
await new Promise((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
this.start();
});
cb();
});
}
return null;
}

View file

@ -24,10 +24,9 @@ export default class InjectAsComment {
* @returns {Promise}
*/
apply() {
this.context.compiler.plugin('emit', (compilation, cb) => {
for (let basename in compilation.assets) {
for (let basename in this.context.compilation.assets) {
let ext = path.extname(basename);
let asset = compilation.assets[basename];
let asset = this.context.compilation.assets[basename];
switch (ext) {
case '.js' :
this.injectIntoJs(asset);
@ -43,8 +42,7 @@ export default class InjectAsComment {
}
log.info(`InjectAsComment : match : ${basename} : injected : ${this.context.version}`);
}
cb();
});
return new Promise((resolve) => { resolve(); });
}

View file

@ -22,13 +22,12 @@ export default class InjectByTag {
* @returns {Promise}
*/
apply() {
this.context.compiler.plugin('emit', (compilation, cb) => {
// for every output file
for (let basename in compilation.assets) {
for (let basename in this.context.compilation.assets) {
// only if match regex
if (this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) {
let replaced = 0;
let asset = compilation.assets[basename];
let asset = this.context.compilation.assets[basename];
const originalSource = asset.source();
if (!originalSource || typeof originalSource.replace !== 'function') {
@ -63,8 +62,6 @@ export default class InjectByTag {
log.info(`InjectByTag : match : ${basename} : replaced : ${replaced}`);
}
}
cb();
});
return new Promise((resolve) => { resolve(); });
}
}

View file

@ -49,9 +49,13 @@ export default class WebpackAutoInject {
* @param compiler
* @protected
*/
async apply(compiler) {
apply(compiler) {
this.compiler = compiler;
compiler.plugin('emit', async (compilation, cb) => {
this.compilation = compilation;
await this.executeWebpackComponents();
cb();
});
}
/**