commit
2675771ec1
3
index.js
3
index.js
|
@ -200,7 +200,8 @@ exports.PluginBase = PluginBase;
|
||||||
|
|
||||||
exports.execute = function(app, instructions, done) {
|
exports.execute = function(app, instructions, done) {
|
||||||
var bootstrapper = new Bootstrapper(
|
var bootstrapper = new Bootstrapper(
|
||||||
{phases: ['starting', 'start', 'started']});
|
{phases: ['starting', 'start', 'started']}
|
||||||
|
);
|
||||||
var context = {
|
var context = {
|
||||||
app: app,
|
app: app,
|
||||||
instructions: instructions,
|
instructions: instructions,
|
||||||
|
|
|
@ -104,7 +104,8 @@ function bundleInstructions(context, bundler) {
|
||||||
if (hasMiddleware) {
|
if (hasMiddleware) {
|
||||||
g.warn(
|
g.warn(
|
||||||
'Discarding {{middleware}} instructions,' +
|
'Discarding {{middleware}} instructions,' +
|
||||||
' {{loopback}} client does not support {{middleware}}.');
|
' {{loopback}} client does not support {{middleware}}.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
delete instructions.middleware;
|
delete instructions.middleware;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,8 @@ function assertLoopBackVersion(app) {
|
||||||
'The `app` is powered by an incompatible loopback version %s. ' +
|
'The `app` is powered by an incompatible loopback version %s. ' +
|
||||||
'Supported versions: %s',
|
'Supported versions: %s',
|
||||||
loopback.version || '(unknown)',
|
loopback.version || '(unknown)',
|
||||||
RANGE);
|
RANGE
|
||||||
|
);
|
||||||
throw new Error(msg);
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,8 +102,7 @@ Middleware.prototype.buildInstructions = function(context, rootDir, config) {
|
||||||
if (!resolved.sourceFile) {
|
if (!resolved.sourceFile) {
|
||||||
return g.log('Middleware "%s" not found: %s',
|
return g.log('Middleware "%s" not found: %s',
|
||||||
middleware,
|
middleware,
|
||||||
resolved.optional
|
resolved.optional);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var middlewareConfig = cloneDeep(config);
|
var middlewareConfig = cloneDeep(config);
|
||||||
|
@ -111,7 +110,8 @@ Middleware.prototype.buildInstructions = function(context, rootDir, config) {
|
||||||
|
|
||||||
if (middlewareConfig.params) {
|
if (middlewareConfig.params) {
|
||||||
middlewareConfig.params = resolveMiddlewareParams(
|
middlewareConfig.params = resolveMiddlewareParams(
|
||||||
rootDir, middlewareConfig.params);
|
rootDir, middlewareConfig.params
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var item = {
|
var item = {
|
||||||
|
|
|
@ -37,7 +37,8 @@ Mixin.prototype.buildInstructions = function(context, rootDir, config) {
|
||||||
var scriptExtensions = this.options.scriptExtensions || require.extensions;
|
var scriptExtensions = this.options.scriptExtensions || require.extensions;
|
||||||
|
|
||||||
var mixinInstructions = buildAllMixinInstructions(
|
var mixinInstructions = buildAllMixinInstructions(
|
||||||
rootDir, this.options, mixinSources, scriptExtensions, modelInstructions);
|
rootDir, this.options, mixinSources, scriptExtensions, modelInstructions
|
||||||
|
);
|
||||||
|
|
||||||
return mixinInstructions;
|
return mixinInstructions;
|
||||||
};
|
};
|
||||||
|
@ -72,12 +73,14 @@ function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
||||||
|
|
||||||
// Filter-in only mixins, that are used in models
|
// Filter-in only mixins, that are used in models
|
||||||
instructionsFromMixinSources = filterMixinInstructionsUsingWhitelist(
|
instructionsFromMixinSources = filterMixinInstructionsUsingWhitelist(
|
||||||
instructionsFromMixinSources, modelMixins);
|
instructionsFromMixinSources, modelMixins
|
||||||
|
);
|
||||||
|
|
||||||
var mixins = _.assign(
|
var mixins = _.assign(
|
||||||
instructionsFromMixins,
|
instructionsFromMixins,
|
||||||
instructionsFromMixinDirs,
|
instructionsFromMixinDirs,
|
||||||
instructionsFromMixinSources);
|
instructionsFromMixinSources
|
||||||
|
);
|
||||||
|
|
||||||
return _.values(mixins);
|
return _.values(mixins);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,8 @@ Model.prototype.buildInstructions = function(context, rootDir, modelsConfig) {
|
||||||
['./models'];
|
['./models'];
|
||||||
var modelInstructions = buildAllModelInstructions(
|
var modelInstructions = buildAllModelInstructions(
|
||||||
rootDir, modelsConfig, modelSources, this.options.modelDefinitions,
|
rootDir, modelsConfig, modelSources, this.options.modelDefinitions,
|
||||||
this.options.scriptExtensions);
|
this.options.scriptExtensions
|
||||||
|
);
|
||||||
return modelInstructions;
|
return modelInstructions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,7 +153,8 @@ function verifyModelDefinitions(rootDir, modelDefinitions, scriptExtensions) {
|
||||||
definition.sourceFile = fixFileExtension(
|
definition.sourceFile = fixFileExtension(
|
||||||
fullPath,
|
fullPath,
|
||||||
tryReadDir(path.dirname(fullPath)),
|
tryReadDir(path.dirname(fullPath)),
|
||||||
scriptExtensions);
|
scriptExtensions
|
||||||
|
);
|
||||||
|
|
||||||
if (!definition.sourceFile) {
|
if (!definition.sourceFile) {
|
||||||
debug('Model source code not found: %s - %s', definition.sourceFile);
|
debug('Model source code not found: %s - %s', definition.sourceFile);
|
||||||
|
@ -246,7 +248,8 @@ function assertIsValidModelConfig(config) {
|
||||||
if (unsupported) {
|
if (unsupported) {
|
||||||
throw new Error(g.f(
|
throw new Error(g.f(
|
||||||
'The data in {{model-config.json}} ' +
|
'The data in {{model-config.json}} ' +
|
||||||
'is in the unsupported {{1.x}} format.'));
|
'is in the unsupported {{1.x}} format.'
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -254,7 +257,8 @@ function assertIsValidModelConfig(config) {
|
||||||
// Regular expression to match built-in loopback models
|
// Regular expression to match built-in loopback models
|
||||||
var LOOPBACK_MODEL_REGEXP = new RegExp(
|
var LOOPBACK_MODEL_REGEXP = new RegExp(
|
||||||
['', 'node_modules', 'loopback', '[^\\/\\\\]+', 'models', '[^\\/\\\\]+\\.js$']
|
['', 'node_modules', 'loopback', '[^\\/\\\\]+', 'models', '[^\\/\\\\]+\\.js$']
|
||||||
.join('\\' + path.sep));
|
.join('\\' + path.sep)
|
||||||
|
);
|
||||||
|
|
||||||
function isBuiltinLoopBackModel(app, data) {
|
function isBuiltinLoopBackModel(app, data) {
|
||||||
// 1. Built-in models are exposed on the loopback object
|
// 1. Built-in models are exposed on the loopback object
|
||||||
|
|
10
package.json
10
package.json
|
@ -34,8 +34,8 @@
|
||||||
"debug": "^2.2.0",
|
"debug": "^2.2.0",
|
||||||
"lodash": "^4.13.1",
|
"lodash": "^4.13.1",
|
||||||
"semver": "^5.1.0",
|
"semver": "^5.1.0",
|
||||||
"strong-globalize": "^3.1.0",
|
"strong-globalize": "^4.1.1",
|
||||||
"toposort": "^1.0.0"
|
"toposort": "^2.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"browserify": "^4.2.3",
|
"browserify": "^4.2.3",
|
||||||
|
@ -43,11 +43,11 @@
|
||||||
"coffeescript": "^2.3.1",
|
"coffeescript": "^2.3.1",
|
||||||
"coffeeify": "^2.0.1",
|
"coffeeify": "^2.0.1",
|
||||||
"dirty-chai": "^1.2.2",
|
"dirty-chai": "^1.2.2",
|
||||||
"eslint": "^3.19.0",
|
"eslint": "^5.2.0",
|
||||||
"eslint-config-loopback": "^8.0.0",
|
"eslint-config-loopback": "^11.0.0",
|
||||||
"fs-extra": "^3.0.1",
|
"fs-extra": "^3.0.1",
|
||||||
"loopback": "^3.0.0",
|
"loopback": "^3.0.0",
|
||||||
"mocha": "^3.3.0",
|
"mocha": "^5.2.0",
|
||||||
"supertest": "^3.0.0"
|
"supertest": "^3.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,8 +407,7 @@ describe('executor', function() {
|
||||||
boot.execute(app, context.instructions, done);
|
boot.execute(app, context.instructions, done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
describe('for mixins', function() {
|
describe('for mixins', function() {
|
||||||
var options;
|
var options;
|
||||||
|
@ -598,8 +597,7 @@ describe('executor', function() {
|
||||||
|
|
||||||
it('should parse a simple config variable', function(done) {
|
it('should parse a simple config variable', function(done) {
|
||||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||||
{path: '${restApiRoot}'}
|
{path: '${restApiRoot}'}), function(err) {
|
||||||
), function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
supertest(app).get('/').end(function(err, res) {
|
supertest(app).get('/').end(function(err, res) {
|
||||||
|
@ -613,8 +611,7 @@ describe('executor', function() {
|
||||||
it('should parse simple config variable from env var', function(done) {
|
it('should parse simple config variable from env var', function(done) {
|
||||||
process.env.restApiRoot = '/url-from-env-var';
|
process.env.restApiRoot = '/url-from-env-var';
|
||||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||||
{path: '${restApiRoot}'}
|
{path: '${restApiRoot}'}), function(err) {
|
||||||
), function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
supertest(app).get('/url-from-env-var').end(function(err, res) {
|
supertest(app).get('/url-from-env-var').end(function(err, res) {
|
||||||
|
@ -646,8 +643,7 @@ describe('executor', function() {
|
||||||
|
|
||||||
it('should parse multiple config variables', function(done) {
|
it('should parse multiple config variables', function(done) {
|
||||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||||
{path: '${restApiRoot}', env: '${env}'}
|
{path: '${restApiRoot}', env: '${env}'}), function(err) {
|
||||||
), function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
supertest(app).get('/').end(function(err, res) {
|
supertest(app).get('/').end(function(err, res) {
|
||||||
|
@ -661,8 +657,7 @@ describe('executor', function() {
|
||||||
|
|
||||||
it('should parse config variables in an array', function(done) {
|
it('should parse config variables in an array', function(done) {
|
||||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||||
{paths: ['${restApiRoot}']}
|
{paths: ['${restApiRoot}']}), function(err) {
|
||||||
), function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
supertest(app).get('/').end(function(err, res) {
|
supertest(app).get('/').end(function(err, res) {
|
||||||
|
@ -677,8 +672,7 @@ describe('executor', function() {
|
||||||
|
|
||||||
it('should parse config variables in an object', function(done) {
|
it('should parse config variables in an object', function(done) {
|
||||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||||
{info: {path: '${restApiRoot}'}}
|
{info: {path: '${restApiRoot}'}}), function(err) {
|
||||||
), function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
supertest(app).get('/').end(function(err, res) {
|
supertest(app).get('/').end(function(err, res) {
|
||||||
|
@ -693,8 +687,7 @@ describe('executor', function() {
|
||||||
|
|
||||||
it('should parse config variables in a nested object', function(done) {
|
it('should parse config variables in a nested object', function(done) {
|
||||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||||
{nested: {info: {path: '${restApiRoot}'}}}
|
{nested: {info: {path: '${restApiRoot}'}}}), function(err) {
|
||||||
), function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
supertest(app).get('/').end(function(err, res) {
|
supertest(app).get('/').end(function(err, res) {
|
||||||
|
@ -709,8 +702,7 @@ describe('executor', function() {
|
||||||
|
|
||||||
it('should parse config variables with null values', function(done) {
|
it('should parse config variables with null values', function(done) {
|
||||||
boot.execute(app, simpleMiddlewareConfig('routes',
|
boot.execute(app, simpleMiddlewareConfig('routes',
|
||||||
{nested: {info: {path: '${restApiRoot}', some: null}}}
|
{nested: {info: {path: '${restApiRoot}', some: null}}}), function(err) {
|
||||||
), function(err) {
|
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
supertest(app).get('/').end(function(err, res) {
|
supertest(app).get('/').end(function(err, res) {
|
||||||
|
@ -769,7 +761,8 @@ describe('executor', function() {
|
||||||
'routes',
|
'routes',
|
||||||
// IMPORTANT we need more than one item to trigger the original issue
|
// IMPORTANT we need more than one item to trigger the original issue
|
||||||
[/^\/foobar/, /^\/another/],
|
[/^\/foobar/, /^\/another/],
|
||||||
{});
|
{}
|
||||||
|
);
|
||||||
boot.execute(app, config, function(err) {
|
boot.execute(app, config, function(err) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
|
@ -1036,7 +1029,8 @@ describe('executor', function() {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
expect(Object.keys(require.cache)).to.include(
|
expect(Object.keys(require.cache)).to.include(
|
||||||
appdir.resolve('components/test-component/index.js'));
|
appdir.resolve('components/test-component/index.js')
|
||||||
|
);
|
||||||
|
|
||||||
expect(app.componentOptions).to.eql({option: 'value'});
|
expect(app.componentOptions).to.eql({option: 'value'});
|
||||||
done();
|
done();
|
||||||
|
@ -1056,7 +1050,8 @@ describe('executor', function() {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
expect(Object.keys(require.cache)).to.not.include(
|
expect(Object.keys(require.cache)).to.not.include(
|
||||||
appdir.resolve('components/test-component/index.js'));
|
appdir.resolve('components/test-component/index.js')
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1078,7 +1073,8 @@ describe('executor', function() {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
|
|
||||||
expect(Object.keys(require.cache)).to.not.include(
|
expect(Object.keys(require.cache)).to.not.include(
|
||||||
appdir.resolve('components/test-component/index.js'));
|
appdir.resolve('components/test-component/index.js')
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -1219,7 +1215,8 @@ describe('executor', function() {
|
||||||
boot.execute(app, someInstructions(bootInstructions), function() {
|
boot.execute(app, someInstructions(bootInstructions), function() {
|
||||||
expect(app.get('DYNAMIC_HOST')).to.equal('127.0.0.4');
|
expect(app.get('DYNAMIC_HOST')).to.equal('127.0.0.4');
|
||||||
expect(app.datasources.mydb.settings.host).to.equal(
|
expect(app.datasources.mydb.settings.host).to.equal(
|
||||||
'127.0.0.4');
|
'127.0.0.4'
|
||||||
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue