You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB

var asyncToGen = require('async-to-gen');
var fs = require('fs');
var os = require('os');
var path = require('path');
var createFilter = require('rollup-pluginutils').createFilter;
module.exports = function(options) {
options = options || {};
var filter = createFilter(options.include, options.exclude);
Squashed commit of the following: Closes #2 commit c925a4d4a49798f6a03c13deca3cd10626619ec8 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 15:04:24 2016 -0600 update tests commit 6b45037a1088cb55a7be11dcf2b25a443cc0ef37 Merge: daf7811 afe66ec Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 15:03:57 2016 -0600 Merge branch 'master' of https://github.com/NicolasParada/rollup-plugin-async into NicolasParada-master commit afe66ecc7ea5704cd64b7c805d5d8858f53a52f9 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 15:02:43 2016 -0600 Add comments commit b2f775f32eaf0562be693ef82c73652b46da7fe5 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:58:14 2016 -0600 nl commit c07cbe790cbcf2ab35a6e4565d3bc8153123cf8c Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:57:47 2016 -0600 merge commit 39143c17b4a177e7e04be4806a9df1718c389c54 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:56:48 2016 -0600 unrelated commit c1adab7cbd05e4b1af44413e4ce13cd01d0b5695 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:55:59 2016 -0600 sp commit 37d3a528818b7859192b476102b926f82363cb18 Author: NicolasParada <parada.nicolas@outlook.com> Date: Sat Nov 5 07:46:47 2016 -0300 semicolon commit 8e6797cce34c0e731dac4b2166ae796d079fe760 Author: NicolasParada <parada.nicolas@outlook.com> Date: Sat Nov 5 07:40:09 2016 -0300 apply backslash replace only on win32 commit ac5094023385bc9bed6c90cca894664e91851616 Author: NicolasParada <parada.nicolas@outlook.com> Date: Tue Oct 18 16:32:36 2016 -0300 update test commit 250cf9fe1d5b8a5423eabcf7c9d5c43371fdd973 Author: NicolasParada <parada.nicolas@outlook.com> Date: Tue Oct 18 16:17:36 2016 -0300 replaced const by var and added semicolons commit 52feb9fa04f43f1690cf3463268fee1f60139054 Author: NicolasParada <parada.nicolas@outlook.com> Date: Tue Oct 18 16:12:42 2016 -0300 path: replace backslashes by forward slashes
8 years ago
var sourceMap = options.sourceMap !== false;
return {
name: 'async-to-gen',
transform: function(code, id) {
if (filter(id)) {
var result = asyncToGen(code, {
sourceMap: sourceMap,
includeHelper: false
});
if (result.isEdited) {
result.prepend('import { __async, __asyncGen, __asyncIterator } from "' + getAsyncHelperFile() + '"\n');
}
return {
code: result.toString(),
map: sourceMap ? result.generateMap() : { mappings: '' }
};
}
}
};
}
var _asyncHelperFile;
function getAsyncHelperFile() {
if (!_asyncHelperFile) {
_asyncHelperFile = path.join(os.tmpdir(), 'asyncHelper.' + Date.now() + '.js');
fs.writeFileSync(
_asyncHelperFile,
'export ' + asyncToGen.asyncHelper + '\n' +
'export ' + asyncToGen.asyncGenHelper + '\n' +
'export ' + asyncToGen.asyncIteratorHelper
);
process.on('exit', function () {
fs.unlinkSync(_asyncHelperFile)
})
}
Squashed commit of the following: Closes #2 commit c925a4d4a49798f6a03c13deca3cd10626619ec8 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 15:04:24 2016 -0600 update tests commit 6b45037a1088cb55a7be11dcf2b25a443cc0ef37 Merge: daf7811 afe66ec Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 15:03:57 2016 -0600 Merge branch 'master' of https://github.com/NicolasParada/rollup-plugin-async into NicolasParada-master commit afe66ecc7ea5704cd64b7c805d5d8858f53a52f9 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 15:02:43 2016 -0600 Add comments commit b2f775f32eaf0562be693ef82c73652b46da7fe5 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:58:14 2016 -0600 nl commit c07cbe790cbcf2ab35a6e4565d3bc8153123cf8c Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:57:47 2016 -0600 merge commit 39143c17b4a177e7e04be4806a9df1718c389c54 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:56:48 2016 -0600 unrelated commit c1adab7cbd05e4b1af44413e4ce13cd01d0b5695 Author: Lee Byron <lee@leebyron.com> Date: Sun Nov 20 14:55:59 2016 -0600 sp commit 37d3a528818b7859192b476102b926f82363cb18 Author: NicolasParada <parada.nicolas@outlook.com> Date: Sat Nov 5 07:46:47 2016 -0300 semicolon commit 8e6797cce34c0e731dac4b2166ae796d079fe760 Author: NicolasParada <parada.nicolas@outlook.com> Date: Sat Nov 5 07:40:09 2016 -0300 apply backslash replace only on win32 commit ac5094023385bc9bed6c90cca894664e91851616 Author: NicolasParada <parada.nicolas@outlook.com> Date: Tue Oct 18 16:32:36 2016 -0300 update test commit 250cf9fe1d5b8a5423eabcf7c9d5c43371fdd973 Author: NicolasParada <parada.nicolas@outlook.com> Date: Tue Oct 18 16:17:36 2016 -0300 replaced const by var and added semicolons commit 52feb9fa04f43f1690cf3463268fee1f60139054 Author: NicolasParada <parada.nicolas@outlook.com> Date: Tue Oct 18 16:12:42 2016 -0300 path: replace backslashes by forward slashes
8 years ago
// Note that while win32 uses \ as path separator, Node require() may rely on /.
return os.platform() === 'win32' ?
_asyncHelperFile.replace(/\\/g, '/') :
_asyncHelperFile;
}