Upgrade lodash and drop underscore.string
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.
This commit is contained in:
parent
80831cdaaf
commit
044a4df07a
|
@ -7,7 +7,6 @@ var ConfigLoader = require('./config-loader');
|
||||||
var debug = require('debug')('loopback:boot:compiler');
|
var debug = require('debug')('loopback:boot:compiler');
|
||||||
var Module = require('module');
|
var Module = require('module');
|
||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var _s = require('underscore.string');
|
|
||||||
|
|
||||||
var FILE_EXTENSION_JSON = '.json';
|
var FILE_EXTENSION_JSON = '.json';
|
||||||
|
|
||||||
|
@ -384,7 +383,7 @@ function tryResolveAppPath(rootDir, relativePath, resolveOptions) {
|
||||||
function loadModelDefinition(rootDir, jsonFile, allFiles) {
|
function loadModelDefinition(rootDir, jsonFile, allFiles) {
|
||||||
var definition = require(jsonFile);
|
var definition = require(jsonFile);
|
||||||
var basename = path.basename(jsonFile, path.extname(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`
|
// find a matching file with a supported extension like `.js` or `.coffee`
|
||||||
var sourceFile = fixFileExtension(jsonFile, allFiles, true);
|
var sourceFile = fixFileExtension(jsonFile, allFiles, true);
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
var assert = require('assert');
|
var assert = require('assert');
|
||||||
var _ = require('lodash');
|
|
||||||
var semver = require('semver');
|
var semver = require('semver');
|
||||||
var debug = require('debug')('loopback:boot:executor');
|
var debug = require('debug')('loopback:boot:executor');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
@ -107,7 +106,7 @@ function setHost(app, instructions) {
|
||||||
|
|
||||||
function setPort(app, instructions) {
|
function setPort(app, instructions) {
|
||||||
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
// jscs:disable requireCamelCaseOrUpperCaseIdentifiers
|
||||||
var port = _.find([
|
var port = find([
|
||||||
process.env.npm_config_port,
|
process.env.npm_config_port,
|
||||||
process.env.OPENSHIFT_SLS_PORT,
|
process.env.OPENSHIFT_SLS_PORT,
|
||||||
process.env.OPENSHIFT_NODEJS_PORT,
|
process.env.OPENSHIFT_NODEJS_PORT,
|
||||||
|
@ -116,7 +115,9 @@ function setPort(app, instructions) {
|
||||||
process.env.npm_package_config_port,
|
process.env.npm_package_config_port,
|
||||||
app.get('port'),
|
app.get('port'),
|
||||||
3000
|
3000
|
||||||
], _.isFinite);
|
], function isNumberLike(v) {
|
||||||
|
return Number.isFinite(parseInt(v, 10));
|
||||||
|
});
|
||||||
|
|
||||||
if (port !== undefined) {
|
if (port !== undefined) {
|
||||||
var portType = typeof port;
|
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) {
|
function setApiRoot(app, instructions) {
|
||||||
var restApiRoot =
|
var restApiRoot =
|
||||||
instructions.config.restApiRoot ||
|
instructions.config.restApiRoot ||
|
||||||
|
|
|
@ -26,10 +26,9 @@
|
||||||
"async": "~0.9.0",
|
"async": "~0.9.0",
|
||||||
"commondir": "0.0.1",
|
"commondir": "0.0.1",
|
||||||
"debug": "^2.0.0",
|
"debug": "^2.0.0",
|
||||||
"lodash": "^2.4.1",
|
"lodash": "^3.6.0",
|
||||||
"semver": "^4.1.0",
|
"semver": "^4.1.0",
|
||||||
"toposort": "^0.2.10",
|
"toposort": "^0.2.10"
|
||||||
"underscore.string": "^3.0.3"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^4.1.8",
|
"browserify": "^4.1.8",
|
||||||
|
|
Loading…
Reference in New Issue