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('crypto')
.mock('fs'); .mock('fs');
var Promise = require('bluebird'); var Promise = require('promise');
describe('AssetServer', function() { describe('AssetServer', function() {
var AssetServer; var AssetServer;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -10,7 +10,7 @@
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
var sane = require('sane'); var sane = require('sane');
var Promise = require('bluebird'); var Promise = require('promise');
var util = require('util'); var util = require('util');
var exec = require('child_process').exec; var exec = require('child_process').exec;
@ -57,7 +57,7 @@ util.inherits(FileWatcher, EventEmitter);
FileWatcher.prototype.end = function() { FileWatcher.prototype.end = function() {
return this._loading.then(function(watchers) { return this._loading.then(function(watchers) {
watchers.forEach(function(watcher) { 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 fs = require('fs');
var isAbsolutePath = require('absolute-path'); var isAbsolutePath = require('absolute-path');
var path = require('path'); var path = require('path');
var Promise = require('bluebird'); var Promise = require('promise');
var tmpdir = require('os').tmpDir(); var tmpdir = require('os').tmpDir();
var version = require('../../../../package.json').version; var version = require('../../../../package.json').version;
@ -74,11 +74,13 @@ Cache.prototype.get = function(filepath, loaderCb) {
Cache.prototype._set = function(filepath, loaderPromise) { Cache.prototype._set = function(filepath, loaderPromise) {
this._data[filepath] = loaderPromise.then(function(data) { this._data[filepath] = loaderPromise.then(function(data) {
return [ return Promise.all([
data, data,
Promise.promisify(fs.stat)(filepath) Promise.denodeify(fs.stat)(filepath)
]; ]);
}).spread(function(data, stat) { }).then(function(ref) {
var data = ref[0];
var stat = ref[1];
this._persistEventually(); this._persistEventually();
return { return {
data: data, data: data,
@ -113,7 +115,7 @@ Cache.prototype._persistCache = function() {
Object.keys(data).forEach(function(key, i) { Object.keys(data).forEach(function(key, i) {
json[key] = values[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() { .then(function() {
this._persisting = null; this._persisting = null;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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