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;
|
||||||
|
|
||||||
|
|
|
@ -287,7 +287,7 @@ function getConfigVariable(app, param, useEnvVars) {
|
||||||
configVariable = undefined;
|
configVariable = undefined;
|
||||||
g.warn('%s does not resolve to a valid value, returned as %s. ' +
|
g.warn('%s does not resolve to a valid value, returned as %s. ' +
|
||||||
'"%s" must be resolvable in Environment variable or by {{app.get()}}.',
|
'"%s" must be resolvable in Environment variable or by {{app.get()}}.',
|
||||||
param, configVariable, varName);
|
param, configVariable, varName);
|
||||||
debug('Dynamic Configuration: Cannot resolve variable for `%s`, ' +
|
debug('Dynamic Configuration: Cannot resolve variable for `%s`, ' +
|
||||||
'returned as %s', varName, configVariable);
|
'returned as %s', varName, configVariable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ function Component(options) {
|
||||||
|
|
||||||
util.inherits(Component, PluginBase);
|
util.inherits(Component, PluginBase);
|
||||||
|
|
||||||
Component.prototype.getRootDir = function() {
|
Component.prototype.getRootDir = function() {
|
||||||
return this.options.componentRootDir || this.options.rootDir;
|
return this.options.componentRootDir || this.options.rootDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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,13 +37,14 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
||||||
scriptExtensions, modelInstructions) {
|
scriptExtensions, modelInstructions) {
|
||||||
// load mixins from `options.mixins`
|
// load mixins from `options.mixins`
|
||||||
var sourceFiles = options.mixins || [];
|
var sourceFiles = options.mixins || [];
|
||||||
var mixinDirs = options.mixinDirs || [];
|
var mixinDirs = options.mixinDirs || [];
|
||||||
|
@ -53,7 +54,7 @@ function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
||||||
sourceFiles = findMixinDefinitions(appRootDir, mixinDirs, scriptExtensions);
|
sourceFiles = findMixinDefinitions(appRootDir, mixinDirs, scriptExtensions);
|
||||||
if (sourceFiles === undefined) return;
|
if (sourceFiles === undefined) return;
|
||||||
var instructionsFromMixinDirs = loadMixins(sourceFiles,
|
var instructionsFromMixinDirs = loadMixins(sourceFiles,
|
||||||
options.normalization);
|
options.normalization);
|
||||||
|
|
||||||
/* If `mixinDirs` and `mixinSources` have any directories in common,
|
/* If `mixinDirs` and `mixinSources` have any directories in common,
|
||||||
* then remove the common directories from `mixinSources` */
|
* then remove the common directories from `mixinSources` */
|
||||||
|
@ -61,10 +62,10 @@ function buildAllMixinInstructions(appRootDir, options, mixinSources,
|
||||||
|
|
||||||
// load mixins from `options.mixinSources`
|
// load mixins from `options.mixinSources`
|
||||||
sourceFiles = findMixinDefinitions(appRootDir, mixinSources,
|
sourceFiles = findMixinDefinitions(appRootDir, mixinSources,
|
||||||
scriptExtensions);
|
scriptExtensions);
|
||||||
if (sourceFiles === undefined) return;
|
if (sourceFiles === undefined) return;
|
||||||
var instructionsFromMixinSources = loadMixins(sourceFiles,
|
var instructionsFromMixinSources = loadMixins(sourceFiles,
|
||||||
options.normalization);
|
options.normalization);
|
||||||
|
|
||||||
// Fetch unique list of mixin names, used in models
|
// Fetch unique list of mixin names, used in models
|
||||||
var modelMixins = fetchMixinNamesUsedInModelInstructions(modelInstructions);
|
var modelMixins = fetchMixinNamesUsedInModelInstructions(modelInstructions);
|
||||||
|
@ -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,14 +49,15 @@ 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildAllModelInstructions(rootDir, modelsConfig, sources,
|
function buildAllModelInstructions(rootDir, modelsConfig, sources,
|
||||||
modelDefinitions, scriptExtensions) {
|
modelDefinitions, scriptExtensions) {
|
||||||
var registry = verifyModelDefinitions(rootDir, modelDefinitions,
|
var registry = verifyModelDefinitions(rootDir, modelDefinitions,
|
||||||
scriptExtensions);
|
scriptExtensions);
|
||||||
if (!registry) {
|
if (!registry) {
|
||||||
registry = findModelDefinitions(rootDir, sources, scriptExtensions);
|
registry = findModelDefinitions(rootDir, sources, scriptExtensions);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -170,7 +172,7 @@ function verifyModelDefinitions(rootDir, modelDefinitions, scriptExtensions) {
|
||||||
if (!modelName) {
|
if (!modelName) {
|
||||||
debug('Skipping model definition without Model name ' +
|
debug('Skipping model definition without Model name ' +
|
||||||
'(from options.modelDefinitions @ index %s)',
|
'(from options.modelDefinitions @ index %s)',
|
||||||
idx);
|
idx);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
registry[modelName] = definition;
|
registry[modelName] = definition;
|
||||||
|
@ -198,7 +200,7 @@ function findModelDefinitions(rootDir, sources, scriptExtensions) {
|
||||||
.forEach(function(f) {
|
.forEach(function(f) {
|
||||||
var fullPath = path.resolve(srcDir, f);
|
var fullPath = path.resolve(srcDir, f);
|
||||||
var entry = loadModelDefinition(rootDir, fullPath, files,
|
var entry = loadModelDefinition(rootDir, fullPath, files,
|
||||||
scriptExtensions);
|
scriptExtensions);
|
||||||
var modelName = entry.definition.name;
|
var modelName = entry.definition.name;
|
||||||
if (!modelName) {
|
if (!modelName) {
|
||||||
debug('Skipping model definition without Model name: %s',
|
debug('Skipping model definition without Model name: %s',
|
||||||
|
@ -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
|
||||||
|
|
|
@ -102,7 +102,7 @@ function getExcludedExtensions() {
|
||||||
return {
|
return {
|
||||||
'.json': '.json',
|
'.json': '.json',
|
||||||
'.node': 'node',
|
'.node': 'node',
|
||||||
/**
|
/**
|
||||||
* This is a temporary workaround for #246
|
* This is a temporary workaround for #246
|
||||||
* See discussion here for full description of the underlying issue
|
* See discussion here for full description of the underlying issue
|
||||||
* https://github.com/strongloop/loopback-boot/pull/245#issuecomment-311052798
|
* https://github.com/strongloop/loopback-boot/pull/245#issuecomment-311052798
|
||||||
|
|
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,24 +300,24 @@ describe('compiler', function() {
|
||||||
name: 'model-with-definition-with-falsey-source-file',
|
name: 'model-with-definition-with-falsey-source-file',
|
||||||
},
|
},
|
||||||
sourceFile: appdir.resolve(
|
sourceFile: appdir.resolve(
|
||||||
'custom-models',
|
'custom-models',
|
||||||
'file-does-not-exist.js'
|
'file-does-not-exist.js'
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
dataSources: dataSources,
|
dataSources: dataSources,
|
||||||
},
|
},
|
||||||
function(err, context) {
|
function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var instructions = context.instructions;
|
var instructions = context.instructions;
|
||||||
expect(instructions.models[0].name).to.equal(
|
expect(instructions.models[0].name).to.equal(
|
||||||
'model-with-definition-with-falsey-source-file'
|
'model-with-definition-with-falsey-source-file'
|
||||||
);
|
);
|
||||||
expect(instructions.models[0].definition).not.to.equal(undefined);
|
expect(instructions.models[0].definition).not.to.equal(undefined);
|
||||||
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not set source file path if no source file supplied.',
|
it('does not set source file path if no source file supplied.',
|
||||||
|
@ -340,17 +340,17 @@ describe('compiler', function() {
|
||||||
],
|
],
|
||||||
dataSources: dataSources,
|
dataSources: dataSources,
|
||||||
},
|
},
|
||||||
function(err, context) {
|
function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var instructions = context.instructions;
|
var instructions = context.instructions;
|
||||||
expect(instructions.models[0].name).to.equal(
|
expect(instructions.models[0].name).to.equal(
|
||||||
'model-with-definition-without-source-file-property'
|
'model-with-definition-without-source-file-property'
|
||||||
);
|
);
|
||||||
expect(instructions.models[0].definition).not.to.equal(undefined);
|
expect(instructions.models[0].definition).not.to.equal(undefined);
|
||||||
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
expect(instructions.models[0].sourceFile).to.equal(undefined);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('loads models defined in `models` only.', function(done) {
|
it('loads models defined in `models` only.', function(done) {
|
||||||
|
@ -949,13 +949,13 @@ describe('compiler', function() {
|
||||||
appRootDir: appdir.PATH,
|
appRootDir: appdir.PATH,
|
||||||
bootDirs: ['./custom-boot'],
|
bootDirs: ['./custom-boot'],
|
||||||
},
|
},
|
||||||
function(err, context) {
|
function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var instructions = context.instructions;
|
var instructions = context.instructions;
|
||||||
expect(instructions.bootScripts).to.eql([coffee]);
|
expect(instructions.bootScripts).to.eql([coffee]);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prefers coffeescript over json in `bootDir` non-relative path',
|
it('prefers coffeescript over json in `bootDir` non-relative path',
|
||||||
|
@ -969,13 +969,13 @@ describe('compiler', function() {
|
||||||
appRootDir: appdir.PATH,
|
appRootDir: appdir.PATH,
|
||||||
bootDirs: ['custom-boot'],
|
bootDirs: ['custom-boot'],
|
||||||
},
|
},
|
||||||
function(err, context) {
|
function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var instructions = context.instructions;
|
var instructions = context.instructions;
|
||||||
expect(instructions.bootScripts).to.eql([coffee]);
|
expect(instructions.bootScripts).to.eql([coffee]);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports `bootScripts` option', function(done) {
|
it('supports `bootScripts` option', function(done) {
|
||||||
|
@ -1084,13 +1084,13 @@ describe('compiler', function() {
|
||||||
appRootDir: appdir.PATH,
|
appRootDir: appdir.PATH,
|
||||||
bootScripts: ['custom-boot/init'],
|
bootScripts: ['custom-boot/init'],
|
||||||
},
|
},
|
||||||
function(err, context) {
|
function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var instructions = context.instructions;
|
var instructions = context.instructions;
|
||||||
expect(instructions.bootScripts).to.eql([initJs]);
|
expect(instructions.bootScripts).to.eql([initJs]);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resolves module relative path for `bootScripts`', function(done) {
|
it('resolves module relative path for `bootScripts`', function(done) {
|
||||||
|
@ -1146,12 +1146,12 @@ describe('compiler', function() {
|
||||||
it('throws when models-config.json contains 1.x `properties`',
|
it('throws when models-config.json contains 1.x `properties`',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
foo: {properties: {name: 'string'}},
|
foo: {properties: {name: 'string'}},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
expectCompileToThrow(/unsupported 1\.x format/, done);
|
expectCompileToThrow(/unsupported 1\.x format/, done);
|
||||||
});
|
});
|
||||||
|
@ -1159,12 +1159,12 @@ describe('compiler', function() {
|
||||||
it('throws when model-config.json contains 1.x `options.base`',
|
it('throws when model-config.json contains 1.x `options.base`',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
Customer: {options: {base: 'User'}},
|
Customer: {options: {base: 'User'}},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
expectCompileToThrow(/unsupported 1\.x format/, done);
|
expectCompileToThrow(/unsupported 1\.x format/, done);
|
||||||
});
|
});
|
||||||
|
@ -1363,12 +1363,12 @@ describe('compiler', function() {
|
||||||
it('resolves module relative path in `modelSources` option',
|
it('resolves module relative path in `modelSources` option',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
Car: {dataSource: 'db'},
|
Car: {dataSource: 'db'},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appdir.writeConfigFileSync('node_modules/custom-models/car.json', {
|
appdir.writeConfigFileSync('node_modules/custom-models/car.json', {
|
||||||
name: 'Car',
|
name: 'Car',
|
||||||
});
|
});
|
||||||
|
@ -1380,29 +1380,29 @@ describe('compiler', function() {
|
||||||
appRootDir: appdir.PATH,
|
appRootDir: appdir.PATH,
|
||||||
modelSources: ['custom-models'],
|
modelSources: ['custom-models'],
|
||||||
},
|
},
|
||||||
function(err, context) {
|
function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
var instructions = context.instructions;
|
var instructions = context.instructions;
|
||||||
|
|
||||||
expect(instructions.models).to.have.length(1);
|
expect(instructions.models).to.have.length(1);
|
||||||
expect(instructions.models[0].sourceFile).to.equal(appJS);
|
expect(instructions.models[0].sourceFile).to.equal(appJS);
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('resolves relative path in `sources` option in `model-config.json`',
|
it('resolves relative path in `sources` option in `model-config.json`',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
_meta: {
|
_meta: {
|
||||||
sources: ['./custom-models'],
|
sources: ['./custom-models'],
|
||||||
},
|
},
|
||||||
Car: {dataSource: 'db'},
|
Car: {dataSource: 'db'},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appdir.writeConfigFileSync('custom-models/car.json', {name: 'Car'});
|
appdir.writeConfigFileSync('custom-models/car.json', {name: 'Car'});
|
||||||
var appJS = appdir.writeFileSync('custom-models/car.js', '');
|
var appJS = appdir.writeFileSync('custom-models/car.js', '');
|
||||||
|
|
||||||
|
@ -1419,15 +1419,15 @@ describe('compiler', function() {
|
||||||
it('resolves module relative path in `sources` option in model-config.json',
|
it('resolves module relative path in `sources` option in model-config.json',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
_meta: {
|
_meta: {
|
||||||
sources: ['custom-models'],
|
sources: ['custom-models'],
|
||||||
},
|
},
|
||||||
Car: {dataSource: 'db'},
|
Car: {dataSource: 'db'},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appdir.writeConfigFileSync('node_modules/custom-models/car.json', {
|
appdir.writeConfigFileSync('node_modules/custom-models/car.json', {
|
||||||
name: 'Car',
|
name: 'Car',
|
||||||
});
|
});
|
||||||
|
@ -1623,12 +1623,12 @@ describe('compiler', function() {
|
||||||
it('uses `OrderItem` as default model name for file with name `order-item`',
|
it('uses `OrderItem` as default model name for file with name `order-item`',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
OrderItem: {dataSource: 'db'},
|
OrderItem: {dataSource: 'db'},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appdir.writeConfigFileSync('models/order-item.json', {});
|
appdir.writeConfigFileSync('models/order-item.json', {});
|
||||||
|
|
||||||
boot.compile(appdir.PATH, function(err, context) {
|
boot.compile(appdir.PATH, function(err, context) {
|
||||||
|
@ -1644,12 +1644,12 @@ describe('compiler', function() {
|
||||||
it('uses `OrderItem` as default model name for file with name `order_item`',
|
it('uses `OrderItem` as default model name for file with name `order_item`',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
OrderItem: {dataSource: 'db'},
|
OrderItem: {dataSource: 'db'},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appdir.writeConfigFileSync('models/order_item.json', {});
|
appdir.writeConfigFileSync('models/order_item.json', {});
|
||||||
|
|
||||||
boot.compile(appdir.PATH, function(err, context) {
|
boot.compile(appdir.PATH, function(err, context) {
|
||||||
|
@ -1665,12 +1665,12 @@ describe('compiler', function() {
|
||||||
it('uses `OrderItem` as default model name for file with name `order item`',
|
it('uses `OrderItem` as default model name for file with name `order item`',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
OrderItem: {dataSource: 'db'},
|
OrderItem: {dataSource: 'db'},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appdir.writeConfigFileSync('models/order item.json', {});
|
appdir.writeConfigFileSync('models/order item.json', {});
|
||||||
|
|
||||||
boot.compile(appdir.PATH, function(err, context) {
|
boot.compile(appdir.PATH, function(err, context) {
|
||||||
|
@ -1686,12 +1686,12 @@ describe('compiler', function() {
|
||||||
it('overrides `default model name` by `name` in model definition',
|
it('overrides `default model name` by `name` in model definition',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.createConfigFilesSync(
|
appdir.createConfigFilesSync(
|
||||||
{},
|
{},
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
overrideCar: {dataSource: 'db'},
|
overrideCar: {dataSource: 'db'},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
appdir.writeConfigFileSync('models/car.json', {name: 'overrideCar'});
|
appdir.writeConfigFileSync('models/car.json', {name: 'overrideCar'});
|
||||||
|
|
||||||
boot.compile(appdir.PATH, function(err, context) {
|
boot.compile(appdir.PATH, function(err, context) {
|
||||||
|
@ -1853,10 +1853,10 @@ describe('compiler', function() {
|
||||||
it('resolves module relative path in `mixinDirs` option',
|
it('resolves module relative path in `mixinDirs` option',
|
||||||
function(done) {
|
function(done) {
|
||||||
verifyMixinIsFoundViaMixinDirs(
|
verifyMixinIsFoundViaMixinDirs(
|
||||||
'node_modules/custom-mixins/other.js',
|
'node_modules/custom-mixins/other.js',
|
||||||
['custom-mixins'],
|
['custom-mixins'],
|
||||||
done
|
done
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1915,10 +1915,10 @@ describe('compiler', function() {
|
||||||
it('resolves module relative path in `mixinSources` option',
|
it('resolves module relative path in `mixinSources` option',
|
||||||
function(done) {
|
function(done) {
|
||||||
verifyMixinIsFoundViaMixinSources(
|
verifyMixinIsFoundViaMixinSources(
|
||||||
'node_modules/custom-mixins/time-stamps.js',
|
'node_modules/custom-mixins/time-stamps.js',
|
||||||
['custom-mixins'],
|
['custom-mixins'],
|
||||||
done
|
done
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports `mixins` option in `model-config.json`', function(done) {
|
it('supports `mixins` option in `model-config.json`', function(done) {
|
||||||
|
@ -2808,13 +2808,13 @@ describe('compiler', function() {
|
||||||
var instructions = context.instructions;
|
var instructions = context.instructions;
|
||||||
|
|
||||||
expect(instructions.middleware.middleware[0]).have.property(
|
expect(instructions.middleware.middleware[0]).have.property(
|
||||||
'sourceFile',
|
'sourceFile',
|
||||||
pathWithoutIndex(require.resolve('loopback'))
|
pathWithoutIndex(require.resolve('loopback'))
|
||||||
);
|
);
|
||||||
expect(instructions.middleware.middleware[0]).have.property(
|
expect(instructions.middleware.middleware[0]).have.property(
|
||||||
'fragment',
|
'fragment',
|
||||||
'errorHandler'
|
'errorHandler'
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2883,9 +2883,9 @@ describe('compiler', function() {
|
||||||
|
|
||||||
expect(instructions.middleware.middleware).to.have.length(1);
|
expect(instructions.middleware.middleware).to.have.length(1);
|
||||||
expect(instructions.middleware.middleware[0]).have.property(
|
expect(instructions.middleware.middleware[0]).have.property(
|
||||||
'sourceFile',
|
'sourceFile',
|
||||||
moduleJS
|
moduleJS
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2951,9 +2951,9 @@ describe('compiler', function() {
|
||||||
|
|
||||||
expect(instructions.middleware.middleware).to.have.length(1);
|
expect(instructions.middleware.middleware).to.have.length(1);
|
||||||
expect(instructions.middleware.middleware[0]).have.property(
|
expect(instructions.middleware.middleware[0]).have.property(
|
||||||
'sourceFile',
|
'sourceFile',
|
||||||
coffee
|
coffee
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -2961,9 +2961,9 @@ describe('compiler', function() {
|
||||||
it('prefers coffeescript over json for module relative middleware path',
|
it('prefers coffeescript over json for module relative middleware path',
|
||||||
function(done) {
|
function(done) {
|
||||||
var coffee = appdir.writeFileSync(
|
var coffee = appdir.writeFileSync(
|
||||||
'node_modules/my-middleware.coffee',
|
'node_modules/my-middleware.coffee',
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
appdir.writeFileSync('node_modules/my-middleware.json', '');
|
appdir.writeFileSync('node_modules/my-middleware.json', '');
|
||||||
appdir.writeConfigFileSync('middleware.json', {
|
appdir.writeConfigFileSync('middleware.json', {
|
||||||
routes: {
|
routes: {
|
||||||
|
@ -2977,9 +2977,9 @@ describe('compiler', function() {
|
||||||
|
|
||||||
expect(instructions.middleware.middleware).to.have.length(1);
|
expect(instructions.middleware.middleware).to.have.length(1);
|
||||||
expect(instructions.middleware.middleware[0]).have.property(
|
expect(instructions.middleware.middleware[0]).have.property(
|
||||||
'sourceFile',
|
'sourceFile',
|
||||||
coffee
|
coffee
|
||||||
);
|
);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -3209,9 +3209,9 @@ describe('compiler', function() {
|
||||||
appdir.writeConfigFileSync('./my-component/component.js', '');
|
appdir.writeConfigFileSync('./my-component/component.js', '');
|
||||||
|
|
||||||
expectCompileToThrow(
|
expectCompileToThrow(
|
||||||
'Cannot resolve path "my-component/component.js"',
|
'Cannot resolve path "my-component/component.js"',
|
||||||
done
|
done
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prefers coffeescript over json for relative path component',
|
it('prefers coffeescript over json for relative path component',
|
||||||
|
|
|
@ -355,16 +355,16 @@ describe('executor', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('receives rejected promise as callback error',
|
it('receives rejected promise as callback error',
|
||||||
function(done) {
|
function(done) {
|
||||||
simpleAppInstructions(function(err, context) {
|
simpleAppInstructions(function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
boot.execute(app, context.instructions, function(err) {
|
boot.execute(app, context.instructions, function(err) {
|
||||||
expect(err).to.exist.and.be.an.instanceOf(Error)
|
expect(err).to.exist.and.be.an.instanceOf(Error)
|
||||||
.with.property('message', 'reject');
|
.with.property('message', 'reject');
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with boot script throwing an error', function() {
|
describe('with boot script throwing an error', function() {
|
||||||
|
@ -378,16 +378,16 @@ describe('executor', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('receives thrown error as callback errors',
|
it('receives thrown error as callback errors',
|
||||||
function(done) {
|
function(done) {
|
||||||
simpleAppInstructions(function(err, context) {
|
simpleAppInstructions(function(err, context) {
|
||||||
if (err) return done(err);
|
if (err) return done(err);
|
||||||
boot.execute(app, context.instructions, function(err) {
|
boot.execute(app, context.instructions, function(err) {
|
||||||
expect(err).to.exist.and.be.an.instanceOf(Error)
|
expect(err).to.exist.and.be.an.instanceOf(Error)
|
||||||
.with.property('message', 'throw');
|
.with.property('message', 'throw');
|
||||||
done();
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('with boot script returning a promise and calling callback',
|
describe('with boot script returning a promise and calling callback',
|
||||||
|
@ -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,32 +1050,34 @@ 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();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('disables component if overrided by production configuration',
|
it('disables component if overrided by production configuration',
|
||||||
function(done) {
|
function(done) {
|
||||||
appdir.writeConfigFileSync('component-config.json', {
|
appdir.writeConfigFileSync('component-config.json', {
|
||||||
'./components/test-component': {},
|
'./components/test-component': {},
|
||||||
});
|
});
|
||||||
appdir.writeConfigFileSync('component-config.production.json', {
|
appdir.writeConfigFileSync('component-config.production.json', {
|
||||||
'./components/test-component': null,
|
'./components/test-component': null,
|
||||||
});
|
});
|
||||||
|
|
||||||
appdir.writeFileSync('components/test-component/index.js',
|
appdir.writeFileSync('components/test-component/index.js',
|
||||||
'module.exports = ' +
|
'module.exports = ' +
|
||||||
'function(app, options) { app.componentOptions = options; }');
|
'function(app, options) { app.componentOptions = options; }');
|
||||||
|
|
||||||
boot(app, {appRootDir: appdir.PATH, env: 'production'}, function(err) {
|
boot(app, {appRootDir: appdir.PATH, env: 'production'}, function(err) {
|
||||||
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('configures middleware (that requires `this`)', function(done) {
|
it('configures middleware (that requires `this`)', function(done) {
|
||||||
var passportPath = require.resolve('./fixtures/passport');
|
var passportPath = require.resolve('./fixtures/passport');
|
||||||
|
@ -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