mirror of https://github.com/status-im/metro.git
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:
parent
5c47289e92
commit
5a6d3f99e2
|
@ -13,8 +13,6 @@ jest.disableAutomock();
|
|||
|
||||
jest.mock('fs');
|
||||
|
||||
const Promise = require('promise');
|
||||
|
||||
const AssetServer = require('../');
|
||||
const crypto = require('crypto');
|
||||
const {EventEmitter} = require('events');
|
||||
|
|
|
@ -8,10 +8,9 @@
|
|||
*/
|
||||
'use strict';
|
||||
|
||||
const Promise = require('promise');
|
||||
|
||||
const crypto = require('crypto');
|
||||
const declareOpts = require('../lib/declareOpts');
|
||||
const denodeify = require('denodeify');
|
||||
const fs = require('fs');
|
||||
const getAssetDataFromName = require('../node-haste').getAssetDataFromName;
|
||||
const path = require('path');
|
||||
|
@ -23,7 +22,7 @@ function timeoutableDenodeify(fsFunc, timeout) {
|
|||
return function raceWrapper(...args) {
|
||||
return Promise.race([
|
||||
createTimeoutPromise(timeout),
|
||||
Promise.denodeify(fsFunc).apply(this, args)
|
||||
denodeify(fsFunc).apply(this, args)
|
||||
]);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ jest.disableAutomock();
|
|||
|
||||
const Bundle = require('../Bundle');
|
||||
const ModuleTransport = require('../../lib/ModuleTransport');
|
||||
const Promise = require('Promise');
|
||||
const SourceMapGenerator = require('source-map').SourceMapGenerator;
|
||||
const crypto = require('crypto');
|
||||
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const Promise = require('promise');
|
||||
|
||||
const assert = require('assert');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
@ -25,12 +23,13 @@ const ModuleTransport = require('../lib/ModuleTransport');
|
|||
const declareOpts = require('../lib/declareOpts');
|
||||
const imageSize = require('image-size');
|
||||
const version = require('../../../../package.json').version;
|
||||
const denodeify = require('denodeify');
|
||||
|
||||
import AssetServer from '../AssetServer';
|
||||
import Module from '../node-haste/Module';
|
||||
import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
|
||||
|
||||
const sizeOf = Promise.denodeify(imageSize);
|
||||
const sizeOf = denodeify(imageSize);
|
||||
|
||||
const noop = () => {};
|
||||
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
'use strict';
|
||||
|
||||
const Logger = require('../Logger');
|
||||
const Promise = require('promise');
|
||||
|
||||
const declareOpts = require('../lib/declareOpts');
|
||||
const denodeify = require('denodeify');
|
||||
const os = require('os');
|
||||
const util = require('util');
|
||||
const workerFarm = require('worker-farm');
|
||||
|
@ -99,8 +99,8 @@ class Transformer {
|
|||
['minify', 'transformAndExtractDependencies'],
|
||||
opts.transformTimeoutInterval,
|
||||
);
|
||||
this._transform = Promise.denodeify(this._workers.transformAndExtractDependencies);
|
||||
this.minify = Promise.denodeify(this._workers.minify);
|
||||
this._transform = denodeify(this._workers.transformAndExtractDependencies);
|
||||
this.minify = denodeify(this._workers.minify);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ const getPlatformExtension = require('../node-haste').getPlatformExtension;
|
|||
const Bundler = require('../Bundler');
|
||||
const MultipartResponse = require('./MultipartResponse');
|
||||
const ProgressBar = require('progress');
|
||||
const Promise = require('promise');
|
||||
const SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||
|
||||
const declareOpts = require('../lib/declareOpts');
|
||||
|
@ -505,15 +504,14 @@ class Server {
|
|||
// This is safe as the asset url contains a hash of the asset.
|
||||
res.setHeader('Cache-Control', 'max-age=31536000');
|
||||
res.end(this._rangeRequestMiddleware(req, res, data, assetPath));
|
||||
print(log(createActionEndEntry(processingAssetRequestLogEntry)), ['asset']);
|
||||
},
|
||||
error => {
|
||||
console.error(error.stack);
|
||||
res.writeHead('404');
|
||||
res.end('Asset not found');
|
||||
}
|
||||
).done(() => {
|
||||
print(log(createActionEndEntry(processingAssetRequestLogEntry)), ['asset']);
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
optionsHash(options) {
|
||||
|
@ -776,15 +774,16 @@ class Server {
|
|||
});
|
||||
});
|
||||
}).then(
|
||||
stack => res.end(JSON.stringify({stack: stack})),
|
||||
stack => {
|
||||
res.end(JSON.stringify({stack: stack}));
|
||||
print(log(createActionEndEntry(symbolicatingLogEntry)));
|
||||
},
|
||||
error => {
|
||||
console.error(error.stack || error);
|
||||
res.statusCode = 500;
|
||||
res.end(JSON.stringify({error: error.message}));
|
||||
}
|
||||
).done(() => {
|
||||
print(log(createActionEndEntry(symbolicatingLogEntry)));
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
_sourceMapForURL(reqUrl) {
|
||||
|
|
Loading…
Reference in New Issue