Skip to content

Commit

Permalink
Add promises support
Browse files Browse the repository at this point in the history
  • Loading branch information
NekR committed Nov 3, 2016
1 parent 066e5b5 commit 5de0176
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions index.js
Expand Up @@ -8,18 +8,6 @@
var loaderUtils = require('loader-utils');
var path = require('path');

function asyncModule() {
module.exports = function(callback, errback) {
require.ensure([], function(error) {
if (error) {
errback();
} else {
callback(require(__module__))
}
});
};
};

module.exports = function() {};
module.exports.pitch = function(remainingRequest) {
this.cacheable && this.cacheable();
Expand All @@ -46,17 +34,21 @@ module.exports.pitch = function(remainingRequest) {
callback = 'callback(require(' + request + '))';
}

var result = [
'require(' + loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'patch.js')) + ')',
'module.exports = function(callback, errback) {',
var executor = [
'function(callback, errback) {',
' require.ensure([], function(_, error) {',
' if (error) {',
' errback();',
' } else {',
' ' + callback,
' }',
' }' + chunkName + ');',
'};',
'}'
].join('\n');

var result = [
'require(' + loaderUtils.stringifyRequest(this, '!' + path.join(__dirname, 'patch.js')) + ');',
'module.exports = ' + (query.promise ? 'new Promise(' + executor + ')' : executor),
];

return result.join('\n');
Expand Down

0 comments on commit 5de0176

Please sign in to comment.