Merge pull request #9318 from jamesgeorge007/hotfix/ease-access-of-emitted-assets

chore: Makes it easier to access contents of emitted assets
This commit is contained in:
Tobias Koppers 2019-08-01 16:00:28 +02:00 committed by GitHub
commit ed7d815d61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 2 deletions

View File

@ -55,6 +55,8 @@ class Compiler extends Tapable {
run: new AsyncSeriesHook(["compiler"]),
/** @type {AsyncSeriesHook<Compilation>} */
emit: new AsyncSeriesHook(["compilation"]),
/** @type {AsyncSeriesHook<string, Buffer>} */
assetEmitted: new AsyncSeriesHook(["file", "content"]),
/** @type {AsyncSeriesHook<Compilation>} */
afterEmit: new AsyncSeriesHook(["compilation"]),
@ -430,7 +432,7 @@ class Compiler extends Tapable {
: targetFileGeneration + 1;
cacheEntry.writtenTo.set(targetPath, newGeneration);
this._assetEmittingWrittenFiles.set(targetPath, newGeneration);
callback();
this.hooks.assetEmitted.callAsync(file, content, callback);
});
} else {
if (source.existsAt === targetPath) {
@ -445,7 +447,10 @@ class Compiler extends Tapable {
source.existsAt = targetPath;
source.emitted = true;
this.outputFileSystem.writeFile(targetPath, content, callback);
this.outputFileSystem.writeFile(targetPath, content, err => {
if (err) return callback(err);
this.hooks.assetEmitted.callAsync(file, content, callback);
});
}
};

View File

@ -0,0 +1,3 @@
import("./module");
it("should run", () => {});

View File

@ -0,0 +1,21 @@
module.exports = {
output: {
futureEmitAssets: true
},
plugins: [
compiler => {
const files = {};
compiler.hooks.assetEmitted.tap("Test", (file, buffer) => {
files[file] = Buffer.isBuffer(buffer);
});
compiler.hooks.afterEmit.tap("Test", () => {
expect(files).toMatchInlineSnapshot(`
Object {
"1.bundle0.js": true,
"bundle0.js": true,
}
`);
});
}
]
};

View File

@ -0,0 +1,3 @@
import("./module");
it("should run", () => {});

View File

@ -0,0 +1,18 @@
module.exports = {
plugins: [
compiler => {
const files = {};
compiler.hooks.assetEmitted.tap("Test", (file, buffer) => {
files[file] = Buffer.isBuffer(buffer);
});
compiler.hooks.afterEmit.tap("Test", () => {
expect(files).toMatchInlineSnapshot(`
Object {
"1.bundle0.js": true,
"bundle0.js": true,
}
`);
});
}
]
};