Use native Promises

Summary: Use native Promises in React Native Packager. Remove all the non-standard `Promise.done()` calls throughout the codebase & replace `Promise.denodeify` with the stand-alone `denodeify` module.

Reviewed By: davidaurelio

Differential Revision: D4146965

fbshipit-source-id: 1730531c914863ac3c52626801d9f91c28eed717
This commit is contained in:
Ovidiu Viorel Iepure 2016-11-08 12:19:36 -08:00 committed by Facebook Github Bot
parent 5c47289e92
commit 5a6d3f99e2
6 changed files with 14 additions and 20 deletions

View File

@ -13,8 +13,6 @@ jest.disableAutomock();
jest.mock('fs'); jest.mock('fs');
const Promise = require('promise');
const AssetServer = require('../'); const AssetServer = require('../');
const crypto = require('crypto'); const crypto = require('crypto');
const {EventEmitter} = require('events'); const {EventEmitter} = require('events');

View File

@ -8,10 +8,9 @@
*/ */
'use strict'; 'use strict';
const Promise = require('promise');
const crypto = require('crypto'); const crypto = require('crypto');
const declareOpts = require('../lib/declareOpts'); const declareOpts = require('../lib/declareOpts');
const denodeify = require('denodeify');
const fs = require('fs'); const fs = require('fs');
const getAssetDataFromName = require('../node-haste').getAssetDataFromName; const getAssetDataFromName = require('../node-haste').getAssetDataFromName;
const path = require('path'); const path = require('path');
@ -23,7 +22,7 @@ function timeoutableDenodeify(fsFunc, timeout) {
return function raceWrapper(...args) { return function raceWrapper(...args) {
return Promise.race([ return Promise.race([
createTimeoutPromise(timeout), createTimeoutPromise(timeout),
Promise.denodeify(fsFunc).apply(this, args) denodeify(fsFunc).apply(this, args)
]); ]);
}; };
} }

View File

@ -12,7 +12,6 @@ jest.disableAutomock();
const Bundle = require('../Bundle'); const Bundle = require('../Bundle');
const ModuleTransport = require('../../lib/ModuleTransport'); const ModuleTransport = require('../../lib/ModuleTransport');
const Promise = require('Promise');
const SourceMapGenerator = require('source-map').SourceMapGenerator; const SourceMapGenerator = require('source-map').SourceMapGenerator;
const crypto = require('crypto'); const crypto = require('crypto');

View File

@ -11,8 +11,6 @@
'use strict'; 'use strict';
const Promise = require('promise');
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');
@ -25,12 +23,13 @@ const ModuleTransport = require('../lib/ModuleTransport');
const declareOpts = require('../lib/declareOpts'); const declareOpts = require('../lib/declareOpts');
const imageSize = require('image-size'); const imageSize = require('image-size');
const version = require('../../../../package.json').version; const version = require('../../../../package.json').version;
const denodeify = require('denodeify');
import AssetServer from '../AssetServer'; import AssetServer from '../AssetServer';
import Module from '../node-haste/Module'; import Module from '../node-haste/Module';
import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
const sizeOf = Promise.denodeify(imageSize); const sizeOf = denodeify(imageSize);
const noop = () => {}; const noop = () => {};

View File

@ -9,9 +9,9 @@
'use strict'; 'use strict';
const Logger = require('../Logger'); const Logger = require('../Logger');
const Promise = require('promise');
const declareOpts = require('../lib/declareOpts'); const declareOpts = require('../lib/declareOpts');
const denodeify = require('denodeify');
const os = require('os'); const os = require('os');
const util = require('util'); const util = require('util');
const workerFarm = require('worker-farm'); const workerFarm = require('worker-farm');
@ -99,8 +99,8 @@ class Transformer {
['minify', 'transformAndExtractDependencies'], ['minify', 'transformAndExtractDependencies'],
opts.transformTimeoutInterval, opts.transformTimeoutInterval,
); );
this._transform = Promise.denodeify(this._workers.transformAndExtractDependencies); this._transform = denodeify(this._workers.transformAndExtractDependencies);
this.minify = Promise.denodeify(this._workers.minify); this.minify = denodeify(this._workers.minify);
} }
} }

View File

@ -14,7 +14,6 @@ const getPlatformExtension = require('../node-haste').getPlatformExtension;
const Bundler = require('../Bundler'); const Bundler = require('../Bundler');
const MultipartResponse = require('./MultipartResponse'); const MultipartResponse = require('./MultipartResponse');
const ProgressBar = require('progress'); const ProgressBar = require('progress');
const Promise = require('promise');
const SourceMapConsumer = require('source-map').SourceMapConsumer; const SourceMapConsumer = require('source-map').SourceMapConsumer;
const declareOpts = require('../lib/declareOpts'); const declareOpts = require('../lib/declareOpts');
@ -505,15 +504,14 @@ class Server {
// This is safe as the asset url contains a hash of the asset. // This is safe as the asset url contains a hash of the asset.
res.setHeader('Cache-Control', 'max-age=31536000'); res.setHeader('Cache-Control', 'max-age=31536000');
res.end(this._rangeRequestMiddleware(req, res, data, assetPath)); res.end(this._rangeRequestMiddleware(req, res, data, assetPath));
print(log(createActionEndEntry(processingAssetRequestLogEntry)), ['asset']);
}, },
error => { error => {
console.error(error.stack); console.error(error.stack);
res.writeHead('404'); res.writeHead('404');
res.end('Asset not found'); res.end('Asset not found');
} }
).done(() => { );
print(log(createActionEndEntry(processingAssetRequestLogEntry)), ['asset']);
});
} }
optionsHash(options) { optionsHash(options) {
@ -776,15 +774,16 @@ class Server {
}); });
}); });
}).then( }).then(
stack => res.end(JSON.stringify({stack: stack})), stack => {
res.end(JSON.stringify({stack: stack}));
print(log(createActionEndEntry(symbolicatingLogEntry)));
},
error => { error => {
console.error(error.stack || error); console.error(error.stack || error);
res.statusCode = 500; res.statusCode = 500;
res.end(JSON.stringify({error: error.message})); res.end(JSON.stringify({error: error.message}));
} }
).done(() => { );
print(log(createActionEndEntry(symbolicatingLogEntry)));
});
} }
_sourceMapForURL(reqUrl) { _sourceMapForURL(reqUrl) {