Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove plugin detective logic #530

Merged
merged 1 commit into from
Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"clean-css": "4.1.3",
"colors": "1.1.2",
"dependency-graph": "0.5.0",
"detective": "4.5.0",
"errorhandler": "^1.5.0",
"express": "4.15.3",
"form-data": "2.1.4",
Expand Down
21 changes: 6 additions & 15 deletions src/cli/facade/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ module.exports = function(dependencies) {
},
error => {
if (error) {
const errorDescription = error instanceof SyntaxError ||
!!error.message
? error.message
: error;
const errorDescription =
error instanceof SyntaxError || !!error.message
? error.message
: error;
logger.err(
format(
strings.errors.cli.PACKAGING_FAIL,
Expand Down Expand Up @@ -136,12 +136,10 @@ module.exports = function(dependencies) {
});
};

const registerPlugins = function(registry) {
const registerPlugins = registry => {
const mockedPlugins = getMockedPlugins(logger, componentsDir);

mockedPlugins.forEach(p => {
registry.register(p);
});
mockedPlugins.forEach(registry.register);

registry.on('request', data => {
if (data.errorCode === 'PLUGIN_MISSING_FROM_REGISTRY') {
Expand All @@ -152,13 +150,6 @@ module.exports = function(dependencies) {
colors.blue(strings.commands.cli.MOCK_PLUGIN)
)
);
} else if (data.errorCode === 'PLUGIN_MISSING_FROM_COMPONENT') {
logger.err(
format(
strings.errors.cli.PLUGIN_MISSING_FROM_COMPONENT,
data.errorDetails
)
);
}
});
};
Expand Down
14 changes: 0 additions & 14 deletions src/registry/domain/plugins-detective.js

This file was deleted.

94 changes: 30 additions & 64 deletions src/registry/routes/helpers/get-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const _ = require('lodash');

const applyDefaultValues = require('./apply-default-values');
const Client = require('../../../../client');
const detective = require('../../domain/plugins-detective');
const eventsHandler = require('../../domain/events-handler');
const GetComponentRetrievingInfo = require('./get-component-retrieving-info');
const getComponentFallback = require('./get-component-fallback');
Expand All @@ -34,13 +33,13 @@ module.exports = function(conf, repository) {
retrievingInfo = new GetComponentRetrievingInfo(options);
let responseHeaders = {};

const getLanguage = function() {
const getLanguage = () => {
const paramOverride =
!!options.parameters && options.parameters['__ocAcceptLanguage'];
return paramOverride || options.headers['accept-language'];
};

const callback = function(result) {
const callback = result => {
if (result.response.error) {
retrievingInfo.extend(result.response);
}
Expand All @@ -55,13 +54,13 @@ module.exports = function(conf, repository) {
};

let componentCallbackDone = false;
const conf = options.conf,
acceptLanguage = getLanguage(),
requestedComponent = {
name: options.name,
version: options.version || '',
parameters: options.parameters
};
const conf = options.conf;
const acceptLanguage = getLanguage();
const requestedComponent = {
name: options.name,
version: options.version || '',
parameters: options.parameters
};

repository.getComponent(
requestedComponent.name,
Expand Down Expand Up @@ -122,9 +121,9 @@ module.exports = function(conf, repository) {

// sanitise and check params
const appliedParams = applyDefaultValues(
requestedComponent.parameters,
component.oc.parameters
),
requestedComponent.parameters,
component.oc.parameters
),
params = sanitiser.sanitiseComponentParameters(
appliedParams,
component.oc.parameters
Expand All @@ -144,11 +143,11 @@ module.exports = function(conf, repository) {
});
}

const filterCustomHeaders = function(
const filterCustomHeaders = (
headers,
requestedVersion,
actualVersion
) {
) => {
const needFiltering =
!_.isEmpty(headers) &&
!_.isEmpty(conf.customHeadersToSkipOnWeakVersion) &&
Expand All @@ -159,7 +158,7 @@ module.exports = function(conf, repository) {
: headers;
};

const returnComponent = function(err, data) {
const returnComponent = (err, data) => {
if (componentCallbackDone) {
return;
}
Expand Down Expand Up @@ -196,7 +195,8 @@ module.exports = function(conf, repository) {
);

const isUnrendered =
options.headers.accept === settings.registry.acceptUnrenderedHeader,
options.headers.accept ===
settings.registry.acceptUnrenderedHeader,
renderMode = isUnrendered ? 'unrendered' : 'rendered';

const response = {
Expand Down Expand Up @@ -241,24 +241,20 @@ module.exports = function(conf, repository) {
})
});
} else {
const cacheKey = format(
'{0}/{1}/template.js',
component.name,
component.version
),
const cacheKey = `${component.name}/${component.version}/template.js`,
cached = cache.get('file-contents', cacheKey),
key = component.oc.files.template.hashKey,
renderOptions = {
href: componentHref,
key: key,
key,
version: component.version,
name: component.name,
templateType: component.oc.files.template.type,
container: component.oc.container,
renderInfo: component.oc.renderInfo
};

const returnResult = function(template) {
const returnResult = template => {
client.renderTemplate(
template,
data,
Expand All @@ -277,7 +273,7 @@ module.exports = function(conf, repository) {
callback({
status: 200,
headers: responseHeaders,
response: _.extend(response, { html: html })
response: _.extend(response, { html })
});
}
);
Expand Down Expand Up @@ -320,26 +316,22 @@ module.exports = function(conf, repository) {
if (!component.oc.files.dataProvider) {
returnComponent(null, {});
} else {
const cacheKey = format(
'{0}/{1}/server.js',
component.name,
component.version
),
const cacheKey = `${component.name}/${component.version}/server.js`,
cached = cache.get('file-contents', cacheKey),
domain = Domain.create(),
contextObj = {
acceptLanguage: acceptLanguageParser.parse(acceptLanguage),
baseUrl: conf.baseUrl,
env: conf.env,
params: params,
params,
plugins: conf.plugins,
renderComponent: nestedRenderer.renderComponent,
renderComponents: nestedRenderer.renderComponents,
requestHeaders: options.headers,
staticPath: repository
.getStaticFilePath(component.name, component.version, '')
.replace('https:', ''),
setHeader: function(header, value) {
setHeader: (header, value) => {
if (
!(typeof header === 'string' && typeof value === 'string')
) {
Expand All @@ -355,15 +347,11 @@ module.exports = function(conf, repository) {
templates: repository.getTemplates()
};

const setCallbackTimeout = function() {
const setCallbackTimeout = () => {
if (conf.executionTimeout) {
setTimeout(() => {
returnComponent({
message: format(
'timeout ({0}ms)',
conf.executionTimeout * 1000
)
});
const message = `timeout (${conf.executionTimeout * 1000}ms)`;
returnComponent({ message });
domain.exit();
}, conf.executionTimeout * 1000);
}
Expand Down Expand Up @@ -401,11 +389,11 @@ module.exports = function(conf, repository) {
require: RequireWrapper(conf.dependencies),
module: { exports: {} },
console: conf.local ? console : { log: _.noop },
setTimeout: setTimeout,
Buffer: Buffer
setTimeout,
Buffer
};

const handleError = function(err) {
const handleError = err => {
if (err.code === 'DEPENDENCY_MISSING_FROM_REGISTRY') {
componentCallbackDone = true;

Expand All @@ -422,28 +410,6 @@ module.exports = function(conf, repository) {
});
}

const usedPlugins = detective.parse(dataProcessorJs),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

unRegisteredPlugins = _.difference(
usedPlugins,
_.keys(conf.plugins)
);

if (!_.isEmpty(unRegisteredPlugins)) {
componentCallbackDone = true;

return callback({
status: 501,
response: {
code: 'PLUGIN_MISSING_FROM_COMPONENT',
error: format(
strings.errors.registry.PLUGIN_NOT_FOUND,
unRegisteredPlugins.join(' ,')
),
missingPlugins: unRegisteredPlugins
}
});
}

returnComponent(err);
};

Expand Down
3 changes: 0 additions & 3 deletions src/resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ module.exports = {
PACKAGING_FAIL: 'an error happened while packaging {0}: {1}',
PLUGIN_MISSING_FROM_REGISTRY:
'Looks like you are trying to use a plugin in the dev mode ({0}).\nYou need to mock it doing {1}',
PLUGIN_MISSING_FROM_COMPONENT:
"Looks like you are trying to use a plugin you haven't registered ({0})." +
"\nYou need to register it editing your component's package.json",
PORT_IS_BUSY:
'The port {0} is already in use. Specify the optional port parameter to use another port.',
PUBLISHING_FAIL: 'An error happened when publishing the component: {0}',
Expand Down
42 changes: 0 additions & 42 deletions test/unit/registry-domain-plugins-detective.js

This file was deleted.

Loading