From 044a4df07a8c076ec0c72e98261fdb44631f7acd Mon Sep 17 00:00:00 2001 From: Bryan Clark Date: Fri, 10 Apr 2015 04:38:06 -0700 Subject: [PATCH] Upgrade lodash and drop underscore.string MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update to the latest version of "lodash" to use the string functions included and drop the usage of "underscore.string". Existing tests run checks for `flying-car` definitions to be named `FlyingCar` so there doesn’t seem to be a need to add more checks. `isFinite` changed from the older version of lodash to no longer coerce strings into numbers, this commit adds a call of `parseInt` before checking whether the value is a finite number. `parseInt` on an undefined returns NaN which isFinite does not identify as a number. While changing this part, the code was reworked to use `Number.isFinite` and thus the executor no longer depends on lodash. This should reduce the size of the browser bundle. --- lib/compiler.js | 3 +-- lib/executor.js | 11 ++++++++--- package.json | 5 ++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/compiler.js b/lib/compiler.js index e2dea15..c148da2 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -7,7 +7,6 @@ var ConfigLoader = require('./config-loader'); var debug = require('debug')('loopback:boot:compiler'); var Module = require('module'); var _ = require('lodash'); -var _s = require('underscore.string'); var FILE_EXTENSION_JSON = '.json'; @@ -384,7 +383,7 @@ function tryResolveAppPath(rootDir, relativePath, resolveOptions) { function loadModelDefinition(rootDir, jsonFile, allFiles) { var definition = require(jsonFile); var basename = path.basename(jsonFile, path.extname(jsonFile)); - definition.name = definition.name || _s.capitalize(_s.camelize(basename)); + definition.name = definition.name || _.capitalize(_.camelCase(basename)); // find a matching file with a supported extension like `.js` or `.coffee` var sourceFile = fixFileExtension(jsonFile, allFiles, true); diff --git a/lib/executor.js b/lib/executor.js index 43b2fca..609579d 100644 --- a/lib/executor.js +++ b/lib/executor.js @@ -1,5 +1,4 @@ var assert = require('assert'); -var _ = require('lodash'); var semver = require('semver'); var debug = require('debug')('loopback:boot:executor'); var async = require('async'); @@ -107,7 +106,7 @@ function setHost(app, instructions) { function setPort(app, instructions) { // jscs:disable requireCamelCaseOrUpperCaseIdentifiers - var port = _.find([ + var port = find([ process.env.npm_config_port, process.env.OPENSHIFT_SLS_PORT, process.env.OPENSHIFT_NODEJS_PORT, @@ -116,7 +115,9 @@ function setPort(app, instructions) { process.env.npm_package_config_port, app.get('port'), 3000 - ], _.isFinite); + ], function isNumberLike(v) { + return Number.isFinite(parseInt(v, 10)); + }); if (port !== undefined) { var portType = typeof port; @@ -126,6 +127,10 @@ function setPort(app, instructions) { } } +function find(array, predicate) { + return array.filter(predicate)[0]; +} + function setApiRoot(app, instructions) { var restApiRoot = instructions.config.restApiRoot || diff --git a/package.json b/package.json index c2df7b5..0f5c4eb 100644 --- a/package.json +++ b/package.json @@ -26,10 +26,9 @@ "async": "~0.9.0", "commondir": "0.0.1", "debug": "^2.0.0", - "lodash": "^2.4.1", + "lodash": "^3.6.0", "semver": "^4.1.0", - "toposort": "^0.2.10", - "underscore.string": "^3.0.3" + "toposort": "^0.2.10" }, "devDependencies": { "browserify": "^4.1.8",