Replace bluebird with promise

This commit is contained in:
Forbes Lindesay 2015-06-22 08:42:02 -07:00
parent 23ac061d83
commit bc1f94b7b2
18 changed files with 57 additions and 53 deletions

View File

@ -1,5 +0,0 @@
'use strict';
jest.autoMockOff();
module.exports = require.requireActual('bluebird');
jest.autoMockOn();

View File

@ -8,7 +8,7 @@ jest
.mock('crypto')
.mock('fs');
var Promise = require('bluebird');
var Promise = require('promise');
describe('AssetServer', function() {
var AssetServer;

View File

@ -11,13 +11,13 @@
var declareOpts = require('../lib/declareOpts');
var getAssetDataFromName = require('../lib/getAssetDataFromName');
var path = require('path');
var Promise = require('bluebird');
var Promise = require('promise');
var fs = require('fs');
var crypto = require('crypto');
var stat = Promise.promisify(fs.stat);
var readDir = Promise.promisify(fs.readdir);
var readFile = Promise.promisify(fs.readFile);
var stat = Promise.denodeify(fs.stat);
var readDir = Promise.denodeify(fs.readdir);
var readFile = Promise.denodeify(fs.readFile);
module.exports = AssetServer;
@ -56,12 +56,15 @@ AssetServer.prototype._getAssetRecord = function(assetPath) {
this._roots,
path.dirname(assetPath)
).then(function(dir) {
return [
return Promise.all([
dir,
readDir(dir),
];
}).spread(function(dir, files) {
]);
}).then(function(res) {
var dir = res[0];
var files = res[1];
var assetData = getAssetDataFromName(filename);
var map = buildAssetMap(dir, files);
var record = map[assetData.assetName];
@ -114,21 +117,23 @@ AssetServer.prototype.getAssetData = function(assetPath) {
};
function findRoot(roots, dir) {
return Promise.some(
return Promise.all(
roots.map(function(root) {
var absPath = path.join(root, dir);
return stat(absPath).then(function(fstat) {
if (!fstat.isDirectory()) {
throw new Error('Looking for dirs');
}
fstat._path = absPath;
return fstat;
return {path: absPath, isDirectory: fstat.isDirectory()};
}, function (err) {
return {path: absPath, isDirectory: false};
});
}),
1
).spread(
function(fstat) {
return fstat._path;
})
).then(
function(stats) {
for (var i = 0; i < stats.length; i++) {
if (stats[i].isDirectory) {
return stats[i].path;
}
}
throw new Error('Could not find any directories');
}
);
}

View File

@ -1,7 +1,7 @@
'use strict';
const Module = require('./Module');
const Promise = require('bluebird');
const Promise = require('promise');
const getAssetDataFromName = require('../lib/getAssetDataFromName');
class AssetModule extends Module {

View File

@ -1,7 +1,7 @@
'use strict';
const Module = require('./Module');
const Promise = require('bluebird');
const Promise = require('promise');
const getAssetDataFromName = require('../lib/getAssetDataFromName');
class AssetModule_DEPRECATED extends Module {

View File

@ -17,7 +17,7 @@ const isAbsolutePath = require('absolute-path');
const debug = require('debug')('DependencyGraph');
const getAssetDataFromName = require('../../lib/getAssetDataFromName');
const util = require('util');
const Promise = require('bluebird');
const Promise = require('promise');
const _ = require('underscore');
const validateOpts = declareOpts({

View File

@ -1,6 +1,6 @@
'use strict';
const Promise = require('bluebird');
const Promise = require('promise');
const docblock = require('./DependencyGraph/docblock');
const isAbsolutePath = require('absolute-path');
const path = require('path');

View File

@ -14,7 +14,7 @@ jest.dontMock('../')
jest.mock('path');
var Promise = require('bluebird');
var Promise = require('promise');
describe('HasteDependencyResolver', function() {
var HasteDependencyResolver;

View File

@ -1,6 +1,6 @@
'use strict';
const Promise = require('bluebird');
const Promise = require('promise');
const {EventEmitter} = require('events');
const _ = require('underscore');
@ -8,9 +8,9 @@ const debug = require('debug')('DependencyGraph');
const fs = require('fs');
const path = require('path');
const readDir = Promise.promisify(fs.readdir);
const readFile = Promise.promisify(fs.readFile);
const stat = Promise.promisify(fs.stat);
const readDir = Promise.denodeify(fs.readdir);
const readFile = Promise.denodeify(fs.readFile);
const stat = Promise.denodeify(fs.stat);
const hasOwn = Object.prototype.hasOwnProperty;
class Fastfs extends EventEmitter {

View File

@ -12,7 +12,7 @@ var path = require('path');
var DependencyGraph = require('./DependencyGraph');
var replacePatterns = require('./replacePatterns');
var declareOpts = require('../lib/declareOpts');
var Promise = require('bluebird');
var Promise = require('promise');
var validateOpts = declareOpts({
projectRoots: {

View File

@ -10,7 +10,7 @@
var EventEmitter = require('events').EventEmitter;
var sane = require('sane');
var Promise = require('bluebird');
var Promise = require('promise');
var util = require('util');
var exec = require('child_process').exec;
@ -57,7 +57,7 @@ util.inherits(FileWatcher, EventEmitter);
FileWatcher.prototype.end = function() {
return this._loading.then(function(watchers) {
watchers.forEach(function(watcher) {
return Promise.promisify(watcher.close, watcher)();
return Promise.denodeify(watcher.close).call(watcher);
});
});
};

View File

@ -14,7 +14,7 @@ var declareOpts = require('../lib/declareOpts');
var fs = require('fs');
var isAbsolutePath = require('absolute-path');
var path = require('path');
var Promise = require('bluebird');
var Promise = require('promise');
var tmpdir = require('os').tmpDir();
var version = require('../../../../package.json').version;
@ -74,11 +74,13 @@ Cache.prototype.get = function(filepath, loaderCb) {
Cache.prototype._set = function(filepath, loaderPromise) {
this._data[filepath] = loaderPromise.then(function(data) {
return [
return Promise.all([
data,
Promise.promisify(fs.stat)(filepath)
];
}).spread(function(data, stat) {
Promise.denodeify(fs.stat)(filepath)
]);
}).then(function(ref) {
var data = ref[0];
var stat = ref[1];
this._persistEventually();
return {
data: data,
@ -113,7 +115,7 @@ Cache.prototype._persistCache = function() {
Object.keys(data).forEach(function(key, i) {
json[key] = values[i];
});
return Promise.promisify(fs.writeFile)(cacheFilepath, JSON.stringify(json));
return Promise.denodeify(fs.writeFile)(cacheFilepath, JSON.stringify(json));
})
.then(function() {
this._persisting = null;

View File

@ -17,7 +17,7 @@ jest
.mock('os')
.mock('fs');
var Promise = require('bluebird');
var Promise = require('promise');
describe('JSTransformer Cache', function() {
var Cache;

View File

@ -9,14 +9,14 @@
'use strict';
var fs = require('fs');
var Promise = require('bluebird');
var Promise = require('promise');
var Cache = require('./Cache');
var workerFarm = require('worker-farm');
var declareOpts = require('../lib/declareOpts');
var util = require('util');
var ModuleTransport = require('../lib/ModuleTransport');
var readFile = Promise.promisify(fs.readFile);
var readFile = Promise.denodeify(fs.readFile);
module.exports = Transformer;
Transformer.TransformError = TransformError;
@ -69,7 +69,7 @@ function Transformer(options) {
options.transformModulePath
);
this._transform = Promise.promisify(this._workers);
this._transform = Promise.denodeify(this._workers);
}
}

View File

@ -17,7 +17,7 @@ jest
jest.mock('fs');
var Promise = require('bluebird');
var Promise = require('promise');
describe('Packager', function() {
var getDependencies;

View File

@ -11,7 +11,7 @@
var assert = require('assert');
var fs = require('fs');
var path = require('path');
var Promise = require('bluebird');
var Promise = require('promise');
var Transformer = require('../JSTransformer');
var DependencyResolver = require('../DependencyResolver');
var Package = require('./Package');
@ -20,8 +20,8 @@ var ModuleTransport = require('../lib/ModuleTransport');
var declareOpts = require('../lib/declareOpts');
var imageSize = require('image-size');
var sizeOf = Promise.promisify(imageSize);
var readFile = Promise.promisify(fs.readFile);
var sizeOf = Promise.denodeify(imageSize);
var readFile = Promise.denodeify(fs.readFile);
var validateOpts = declareOpts({
projectRoots: {
@ -207,7 +207,9 @@ Packager.prototype.generateAssetModule = function(ppackage, module) {
return Promise.all([
sizeOf(module.path),
this._assetServer.getAssetData(relPath),
]).spread(function(dimensions, assetData) {
]).then(function(res) {
var dimensions = res[0];
var assetData = res[1];
var img = {
__packager_asset: true,
fileSystemLocation: path.dirname(module.path),

View File

@ -20,7 +20,7 @@ jest.setMock('worker-farm', function() { return function() {}; })
.setMock('uglify-js')
.dontMock('../');
var Promise = require('bluebird');
var Promise = require('promise');
describe('processRequest', function() {
var server;

View File

@ -15,7 +15,7 @@ var FileWatcher = require('../FileWatcher');
var Packager = require('../Packager');
var Activity = require('../Activity');
var AssetServer = require('../AssetServer');
var Promise = require('bluebird');
var Promise = require('promise');
var _ = require('underscore');
var exec = require('child_process').exec;
var fs = require('fs');