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:
parent
ee443b5db9
commit
a00a1fb1cc
5 changed files with 2526 additions and 2281 deletions
4043
dist/WebpackAutoInjectVersion.js
vendored
4043
dist/WebpackAutoInjectVersion.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -18,20 +18,15 @@ export default class AutoIncreaseVersion {
|
||||||
* @protected
|
* @protected
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
apply() {
|
async apply() {
|
||||||
// when runInWatchMode
|
// when runInWatchMode
|
||||||
// we have to register AutoIncreaseVersion instead of firing it straight away
|
// we have to register AutoIncreaseVersion instead of firing it straight away
|
||||||
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) {
|
if (config.componentsOptions.AutoIncreaseVersion.runInWatchMode) {
|
||||||
if (this.context.compiler) {
|
|
||||||
this.context.compiler.plugin('emit', async (compilation, cb) => {
|
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
this.resolve = resolve;
|
this.resolve = resolve;
|
||||||
this.reject = reject;
|
this.reject = reject;
|
||||||
this.start();
|
this.start();
|
||||||
});
|
});
|
||||||
cb();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,10 +24,9 @@ export default class InjectAsComment {
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
apply() {
|
apply() {
|
||||||
this.context.compiler.plugin('emit', (compilation, cb) => {
|
for (let basename in this.context.compilation.assets) {
|
||||||
for (let basename in compilation.assets) {
|
|
||||||
let ext = path.extname(basename);
|
let ext = path.extname(basename);
|
||||||
let asset = compilation.assets[basename];
|
let asset = this.context.compilation.assets[basename];
|
||||||
switch (ext) {
|
switch (ext) {
|
||||||
case '.js' :
|
case '.js' :
|
||||||
this.injectIntoJs(asset);
|
this.injectIntoJs(asset);
|
||||||
|
@ -43,8 +42,7 @@ export default class InjectAsComment {
|
||||||
}
|
}
|
||||||
log.info(`InjectAsComment : match : ${basename} : injected : ${this.context.version}`);
|
log.info(`InjectAsComment : match : ${basename} : injected : ${this.context.version}`);
|
||||||
}
|
}
|
||||||
cb();
|
|
||||||
});
|
|
||||||
return new Promise((resolve) => { resolve(); });
|
return new Promise((resolve) => { resolve(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,13 +22,12 @@ export default class InjectByTag {
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
*/
|
*/
|
||||||
apply() {
|
apply() {
|
||||||
this.context.compiler.plugin('emit', (compilation, cb) => {
|
|
||||||
// for every output file
|
// for every output file
|
||||||
for (let basename in compilation.assets) {
|
for (let basename in this.context.compilation.assets) {
|
||||||
// only if match regex
|
// only if match regex
|
||||||
if (this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) {
|
if (this.context.config.componentsOptions.InjectByTag.fileRegex.test(basename)) {
|
||||||
let replaced = 0;
|
let replaced = 0;
|
||||||
let asset = compilation.assets[basename];
|
let asset = this.context.compilation.assets[basename];
|
||||||
|
|
||||||
const originalSource = asset.source();
|
const originalSource = asset.source();
|
||||||
if (!originalSource || typeof originalSource.replace !== 'function') {
|
if (!originalSource || typeof originalSource.replace !== 'function') {
|
||||||
|
@ -63,8 +62,6 @@ export default class InjectByTag {
|
||||||
log.info(`InjectByTag : match : ${basename} : replaced : ${replaced}`);
|
log.info(`InjectByTag : match : ${basename} : replaced : ${replaced}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cb();
|
|
||||||
});
|
|
||||||
return new Promise((resolve) => { resolve(); });
|
return new Promise((resolve) => { resolve(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,9 +49,13 @@ export default class WebpackAutoInject {
|
||||||
* @param compiler
|
* @param compiler
|
||||||
* @protected
|
* @protected
|
||||||
*/
|
*/
|
||||||
async apply(compiler) {
|
apply(compiler) {
|
||||||
this.compiler = compiler;
|
this.compiler = compiler;
|
||||||
|
compiler.plugin('emit', async (compilation, cb) => {
|
||||||
|
this.compilation = compilation;
|
||||||
await this.executeWebpackComponents();
|
await this.executeWebpackComponents();
|
||||||
|
cb();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue