From 04cc411d4d5e5e2caee739e2da9fd8d884d74db0 Mon Sep 17 00:00:00 2001 From: Gyusun Yeom Date: Sun, 22 Jan 2017 21:28:35 +0900 Subject: [PATCH] Allow async transform with promise --- src/writeFile.js | 2 ++ tests/index.js | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/writeFile.js b/src/writeFile.js index 43c86d6b..3abff673 100644 --- a/src/writeFile.js +++ b/src/writeFile.js @@ -26,6 +26,8 @@ export default function writeFile(globalRef, pattern, file) { content = pattern.transform(content, file.absoluteFrom); } + return content; + }).then((content) => { var hash = loaderUtils.getHashDigest(content); if (pattern.toType === 'template') { diff --git a/tests/index.js b/tests/index.js index 22810fed..0fa0c75a 100644 --- a/tests/index.js +++ b/tests/index.js @@ -799,6 +799,27 @@ describe('apply function', () => { .then(done) .catch(done); }); + + it('transform with promise', (done) => { + runEmit({ + expectedAssetKeys: [ + 'file.txt' + ], + expectedAssetContent: { + 'file.txt': 'newchanged!' + }, + patterns: [{ + from: 'file.txt', + transform: function(content) { + return new Promise((resolve) => { + resolve(content + 'changed!'); + }); + } + }] + }) + .then(done) + .catch(done); + }); }); describe('with directory in from', () => {