Replace underscore by lodash

Summary:As far as we agreed to merge `rnpm` into react-native core, we need to align our dependencies to exclude duplications. One of the steps forward would be to use the same utilities library. According to the thread on fb, everybody is fine with replacing underscore by lodash (which we use internally for rnpm).

So, here we go!

cc mkonicek davidaurelio grabbou

**Test plan**
```
$ npm test
```
![image](https://cloud.githubusercontent.com/assets/2273613/13173972/ee34c922-d700-11e5-971b-68ff7322b6d6.png)

**Code formatting**

Changes are aligned with the current [style guide](https://github.com/facebook/react-native/blob/master/CONTRIBUTING.md#style-guide).
Closes https://github.com/facebook/react-native/pull/6030

Differential Revision: D3016271

Pulled By: davidaurelio

fb-gh-sync-id: c4f6776a7de7470283d3ca5a8b56e423247f5e45
shipit-source-id: c4f6776a7de7470283d3ca5a8b56e423247f5e45
This commit is contained in:
Kureev Alexey 2016-03-09 03:08:25 -08:00 committed by Facebook Github Bot 3
parent faaafd771e
commit 4a5cbbbec8
11 changed files with 23 additions and 21 deletions

View File

@ -14,7 +14,6 @@ require('fast-path').replace();
useGracefulFs();
var debug = require('debug');
var omit = require('underscore').omit;
var Activity = require('./src/Activity');
exports.createServer = createServer;
@ -118,6 +117,16 @@ function createNonPersistentServer(options) {
return createServer(options);
}
function omit(obj, blacklistedKeys) {
return Object.keys(obj).reduce((clone, key) => {
if (blacklistedKeys.indexOf(key) === -1) {
clone[key] = obj[key];
}
return clone;
}, {});
}
// we need to listen on a socket as soon as a server is created, but only once.
// This file also serves as entry point when spawning a socket server; in that
// case we need to start the server immediately.

View File

@ -8,7 +8,7 @@
*/
'use strict';
const _ = require('underscore');
const _ = require('lodash');
const base64VLQ = require('./base64-vlq');
const BundleBase = require('./BundleBase');
const ModuleTransport = require('../lib/ModuleTransport');
@ -143,7 +143,7 @@ class Bundle extends BundleBase {
if (options.excludeSource) {
if (map.sourcesContent && map.sourcesContent.length) {
map = _.extend({}, map, {sourcesContent: []});
map = Object.assign({}, map, {sourcesContent: []});
}
}

View File

@ -8,7 +8,6 @@
*/
'use strict';
const _ = require('underscore');
const ModuleTransport = require('../lib/ModuleTransport');
class BundleBase {
@ -66,7 +65,7 @@ class BundleBase {
return this._source;
}
this._source = _.pluck(this._modules, 'code').join('\n');
this._source = this._modules.map((module) => module.code).join('\n');
return this._source;
}

View File

@ -8,7 +8,6 @@
*/
'use strict';
const _ = require('underscore');
const BundleBase = require('./BundleBase');
const ModuleTransport = require('../lib/ModuleTransport');

View File

@ -11,7 +11,7 @@
jest
.setMock('worker-farm', () => () => undefined)
.dontMock('node-haste/node_modules/throat')
.dontMock('underscore')
.dontMock('lodash')
.dontMock('../../lib/ModuleTransport')
.setMock('uglify-js')
.dontMock('../');

View File

@ -10,4 +10,4 @@
// Bug with Jest because we're going to the node_modules that is a sibling
// of what jest thinks our root (the dir with the package.json) should be.
module.exports = require.requireActual('underscore');
module.exports = require.requireActual('lodash');

View File

@ -8,16 +8,13 @@
*/
'use strict';
jest.dontMock('../')
.dontMock('underscore');
jest.dontMock('../');
jest.mock('path');
const Promise = require('promise');
const Resolver = require('../');
const path = require('path');
const _ = require('underscore');
let DependencyGraph = jest.genMockFn();
jest.setMock('node-haste', DependencyGraph);
@ -126,9 +123,9 @@ describe('Resolver', function() {
.then(function(result) {
expect(result.mainModuleId).toEqual('index');
expect(result.dependencies[result.dependencies.length - 1]).toBe(module);
expect(_.pluck(DependencyGraph.prototype.createPolyfill.mock.calls, 0)).toEqual([
{ file: 'polyfills/polyfills.js',
id: 'polyfills/polyfills.js',
expect(DependencyGraph.prototype.createPolyfill.mock.calls.map((call) => call[0])).toEqual([
{ id: 'polyfills/polyfills.js',
file: 'polyfills/polyfills.js',
dependencies: []
},
{ id: 'polyfills/console.js',

View File

@ -11,7 +11,7 @@
jest.setMock('worker-farm', function() { return () => {}; })
.dontMock('node-haste/node_modules/throat')
.dontMock('os')
.dontMock('underscore')
.dontMock('lodash')
.dontMock('path')
.dontMock('url')
.setMock('timers', { setImmediate: (fn) => setTimeout(fn, 0) })

View File

@ -15,7 +15,7 @@ const getPlatformExtension = require('node-haste').getPlatformExtension;
const Bundler = require('../Bundler');
const Promise = require('promise');
const _ = require('underscore');
const _ = require('lodash');
const declareOpts = require('../lib/declareOpts');
const path = require('path');
const url = require('url');
@ -492,7 +492,7 @@ class Server {
return true;
}).join('.') + '.js';
const sourceMapUrlObj = _.clone(urlObj);
const sourceMapUrlObj = Object.assign({}, urlObj);
sourceMapUrlObj.pathname = pathname.replace(/\.bundle$/, '.map');
// try to get the platform from the url

View File

@ -10,7 +10,6 @@
jest.setMock('uglify-js')
.mock('child_process')
.dontMock('underscore')
.dontMock('../');
var SocketInterface = require('../');

View File

@ -11,7 +11,6 @@
const Promise = require('promise');
const SocketClient = require('./SocketClient');
const SocketServer = require('./SocketServer');
const _ = require('underscore');
const crypto = require('crypto');
const debug = require('debug')('ReactNativePackager:SocketInterface');
const fs = require('fs');
@ -99,7 +98,7 @@ function createServer(resolve, reject, options, sockPath) {
const log = fs.openSync(logPath, 'a');
// Enable server debugging by default since it's going to a log file.
const env = _.clone(process.env);
const env = Object.assign({}, process.env);
env.DEBUG = 'ReactNativePackager:SocketServer';
// We have to go through the main entry point to make sure