Skip to content

Commit

Permalink
refactor: Improve var name
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Jun 11, 2021
1 parent c86a76c commit 2d3bfac
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions lib/classes/Service.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,16 @@ class Service {
}

loadServiceFileParam() {
const serverlessFileParam = this.serverless.configurationInput;
// Not used internally, left set to not break plugins which depend on it
// TOOD: Remove with next major
this.serviceFilename = this.serverless.configurationFilename;

const serverlessFile = serverlessFileParam;
const configurationInput = this.serverless.configurationInput;
// basic service level validation
const version = this.serverless.utils.getVersion();
let ymlVersion = serverlessFile.frameworkVersion;
let ymlVersion = configurationInput.frameworkVersion;
if (ymlVersion && !semver.validRange(ymlVersion)) {
if (serverlessFile.configValidationMode === 'error') {
if (configurationInput.configValidationMode === 'error') {
throw new ServerlessError(
'Configured "frameworkVersion" does not represent a valid semver version range.',
'INVALID_FRAMEWORK_VERSION'
Expand Down Expand Up @@ -90,20 +89,20 @@ class Service {
].join('');
throw new ServerlessError(errorMessage, 'FRAMEWORK_VERSION_MISMATCH');
}
if (!serverlessFile.service) {
if (!configurationInput.service) {
throw new ServerlessError(
`"service" property is missing in ${this.serverless.configurationFilename}`,
'SERVICE_NAME_MISSING'
);
}
if (!serverlessFile.provider) {
if (!configurationInput.provider) {
throw new ServerlessError(
`"provider" property is missing in ${this.serverless.configurationFilename}`,
'PROVIDER_NAME_MISSING'
);
}

this.initialServerlessConfig = serverlessFile;
this.initialServerlessConfig = configurationInput;

// TODO: Ideally below approach should be replaced at some point with:
// 1. In "initialization" phase: Minimize reliance on service configuration
Expand All @@ -119,54 +118,55 @@ class Service {
//
// `provider` (`provder.name` by many plugin constructs, and few other core properties as
// `provider.stage` are read by dashboard plugin)
if (!_.isObject(serverlessFile.provider)) {
const providerName = serverlessFile.provider;
serverlessFile.provider = {
if (!_.isObject(configurationInput.provider)) {
const providerName = configurationInput.provider;
configurationInput.provider = {
name: providerName,
};
}
if (serverlessFile.provider.stage == null) {
serverlessFile.provider.stage = 'dev';
if (configurationInput.provider.stage == null) {
configurationInput.provider.stage = 'dev';
}
this.provider = serverlessFile.provider;
this.provider = configurationInput.provider;

// `service` (read by dashboard plugin)
if (_.isObject(serverlessFile.service)) {
if (_.isObject(configurationInput.service)) {
this.serverless._logDeprecation(
'SERVICE_OBJECT_NOTATION',
'Starting from next major object notation for "service" property will no longer be ' +
'recognized. Set "service" property directly with service name.'
);
this.serviceObject = serverlessFile.service;
this.service = serverlessFile.service.name;
this.serviceObject = configurationInput.service;
this.service = configurationInput.service.name;
} else {
this.serviceObject = { name: serverlessFile.service };
this.service = serverlessFile.service;
this.serviceObject = { name: configurationInput.service };
this.service = configurationInput.service;
}

// (dashboard plugin)
this.app = serverlessFile.app;
this.tenant = serverlessFile.tenant;
this.org = serverlessFile.org;
this.app = configurationInput.app;
this.tenant = configurationInput.tenant;
this.org = configurationInput.org;

this.plugins = serverlessFile.plugins;
this.disabledDeprecations = serverlessFile.disabledDeprecations;
this.plugins = configurationInput.plugins;
this.disabledDeprecations = configurationInput.disabledDeprecations;

// `package.path` is read by few core plugins at initialization
if (serverlessFile.package) {
this.package = serverlessFile.package;
if (configurationInput.package) {
this.package = configurationInput.package;
}

// ## Properties accessed at "run" phase
this.custom = serverlessFile.custom; // (dashboard plugin)
this.resources = serverlessFile.resources;
this.functions = serverlessFile.functions || {};
this.configValidationMode = serverlessFile.configValidationMode || 'warn';
this.unresolvedVariablesNotificationMode = serverlessFile.unresolvedVariablesNotificationMode;
this.custom = configurationInput.custom; // (dashboard plugin)
this.resources = configurationInput.resources;
this.functions = configurationInput.functions || {};
this.configValidationMode = configurationInput.configValidationMode || 'warn';
this.unresolvedVariablesNotificationMode =
configurationInput.unresolvedVariablesNotificationMode;
if (this.provider.name === 'aws') {
this.layers = serverlessFile.layers || {};
this.layers = configurationInput.layers || {};
}
this.outputs = serverlessFile.outputs;
this.outputs = configurationInput.outputs;

return this;
}
Expand Down

0 comments on commit 2d3bfac

Please sign in to comment.