Skip to content

Commit

Permalink
refactor: Replace _.assign and _.extend with Object.assign (#7766)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyễn Việt Đức committed May 26, 2020
1 parent d1721cb commit 85e9cd4
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 35 deletions.
2 changes: 1 addition & 1 deletion lib/classes/PluginManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class PluginManager {
}
this.createCommandAlias(alias, key);
});
return _.assign({}, details, { key, pluginName, commands });
return Object.assign({}, details, { key, pluginName, commands });
}

loadCommands(pluginInstance) {
Expand Down
8 changes: 4 additions & 4 deletions lib/classes/Variables.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class Variables {
const provider = this.serverless.getProvider('aws');
if (provider) {
const requiredConfigs = [
_.assign({ name: 'region' }, provider.getRegionSourceValue()),
_.assign({ name: 'stage' }, provider.getStageSourceValue()),
Object.assign({ name: 'region' }, provider.getRegionSourceValue()),
Object.assign({ name: 'stage' }, provider.getStageSourceValue()),
{
name: 'profile',
value: this.service.provider.profile,
Expand Down Expand Up @@ -177,7 +177,7 @@ class Variables {
return this.disableDepedentServices(() => {
const prepopulations = requiredConfigs.map(config =>
this.populateValue(config.value, true) // populate
.then(populated => _.assign(config, { populated }))
.then(populated => Object.assign(config, { populated }))
);
return this.assignProperties(provider, prepopulations);
});
Expand Down Expand Up @@ -293,7 +293,7 @@ class Variables {
);
return _.map(variables, variable =>
this.populateValue(variable.value, false).then(populated =>
_.assign({}, variable, { populated })
Object.assign({}, variable, { populated })
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/deploy/lib/createStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = {

// Merge additional stack tags
if (typeof this.serverless.service.provider.stackTags === 'object') {
stackTags = _.extend(stackTags, this.serverless.service.provider.stackTags);
stackTags = Object.assign(stackTags, this.serverless.service.provider.stackTags);
}

const params = {
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/deploy/lib/extendedValidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
const selfReferences = findReferences(state.service, '${self:}');
_.forEach(selfReferences, ref => _.set(state.service, ref, this.serverless.service));

_.assign(this.serverless.service, state.service);
Object.assign(this.serverless.service, state.service);

this.serverless.service.package.artifactDirectoryName = state.package.artifactDirectoryName;
// only restore the default artifact path if the user is not using a custom path
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/lib/updateStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {

// Merge additional stack tags
if (typeof this.serverless.service.provider.stackTags === 'object') {
stackTags = _.extend(stackTags, this.serverless.service.provider.stackTags);
stackTags = Object.assign(stackTags, this.serverless.service.provider.stackTags);
}

const params = {
Expand Down Expand Up @@ -66,7 +66,7 @@ module.exports = {

// Merge additional stack tags
if (typeof this.serverless.service.provider.stackTags === 'object') {
stackTags = _.extend(stackTags, this.serverless.service.provider.stackTags);
stackTags = Object.assign(stackTags, this.serverless.service.provider.stackTags);
}

const params = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
};

if (typeof authorizer.identityValidationExpression === 'string') {
_.assign(authorizerProperties, {
Object.assign(authorizerProperties, {
IdentityValidationExpression: authorizer.identityValidationExpression,
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ module.exports = {
// * `HTTP_PROXY` for integrating with the HTTP proxy integration, or
// * `AWS_PROXY` for integrating with the Lambda proxy integration type (the default)
if (type === 'AWS' || type === 'AWS_PROXY') {
_.assign(integration, {
Object.assign(integration, {
Uri: {
'Fn::Join': [
'',
Expand All @@ -82,12 +82,12 @@ module.exports = {
},
});
} else if (type === 'HTTP' || type === 'HTTP_PROXY') {
_.assign(integration, {
Object.assign(integration, {
Uri: http.request && http.request.uri,
IntegrationHttpMethod: _.toUpper((http.request && http.request.method) || http.method),
});
if (http.connectionType) {
_.assign(integration, {
Object.assign(integration, {
ConnectionType: http.connectionType,
ConnectionId: http.connectionId,
});
Expand All @@ -97,7 +97,7 @@ module.exports = {
}

if (type === 'AWS' || type === 'HTTP' || type === 'MOCK') {
_.assign(integration, {
Object.assign(integration, {
PassthroughBehavior: http.request && http.request.passThrough,
ContentHandling: http.request && http.request.contentHandling,
RequestTemplates: this.getIntegrationRequestTemplates(http, type === 'AWS'),
Expand All @@ -110,7 +110,7 @@ module.exports = {
!_.isEmpty(http.request.parameters)) ||
http.async
) {
_.assign(integration, {
Object.assign(integration, {
RequestParameters: this.getIntegrationRequestParameters(http),
});
}
Expand Down Expand Up @@ -199,15 +199,15 @@ module.exports = {

// Only set defaults for AWS (lambda) integration
if (useDefaults) {
_.assign(integrationRequestTemplates, {
Object.assign(integrationRequestTemplates, {
'application/json': this.DEFAULT_JSON_REQUEST_TEMPLATE,
'application/x-www-form-urlencoded': this.DEFAULT_FORM_URL_ENCODED_REQUEST_TEMPLATE,
});
}

// set custom request templates if provided
if (http.request && typeof http.request.template === 'object') {
_.assign(integrationRequestTemplates, http.request.template);
Object.assign(integrationRequestTemplates, http.request.template);
}

return !_.isEmpty(integrationRequestTemplates) ? integrationRequestTemplates : undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ module.exports = {
}

if (response.statusCodes) {
response.statusCodes = _.assign({}, response.statusCodes);
response.statusCodes = Object.assign({}, response.statusCodes);

if (!_.some(response.statusCodes, code => code.pattern === '')) {
response.statusCodes['200'] = DEFAULT_STATUS_CODES['200'];
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/aws/package/compile/events/s3/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class AwsCompileS3Events {
};

// Assign 'filter' if not empty
newLambdaConfiguration = _.assign(newLambdaConfiguration, filter);
newLambdaConfiguration = Object.assign(newLambdaConfiguration, filter);
bucketsLambdaConfigurations[bucketName].push(newLambdaConfiguration);
} else {
bucketsLambdaConfigurations[bucketName] = [
Expand All @@ -151,7 +151,7 @@ class AwsCompileS3Events {
},
];
// Assign 'filter' if not empty
bucketsLambdaConfigurations[bucketName][0] = _.assign(
bucketsLambdaConfigurations[bucketName][0] = Object.assign(
bucketsLambdaConfigurations[bucketName][0],
filter
);
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/package/lib/generateCoreTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const validateS3BucketName = require('../../lib/validateS3BucketName');

module.exports = {
generateCoreTemplate() {
_.assign(this, validateS3BucketName);
Object.assign(this, validateS3BucketName);

this.serverless.service.provider.compiledCloudFormationTemplate = this.serverless.utils.readFileSync(
path.join(
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/package/lib/saveServiceState.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = {
_.split(_.get(this.serverless.service, 'package.artifact', ''), path.sep)
);

const strippedService = _.assign(
const strippedService = Object.assign(
{},
_.omit(this.serverless.service, ['serverless', 'package'])
);
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/aws/provider/awsProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class AwsProvider {
// We do not want to trigger the retry mechanism for credential errors
return BbPromise.reject(
Object.assign(new this.serverless.classes.Error(errorMessage), {
providerError: _.assign({}, err, { retryable: false }),
providerError: Object.assign({}, err, { retryable: false }),
})
);
}
Expand Down
17 changes: 8 additions & 9 deletions lib/plugins/plugin/install/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const fse = require('fs-extra');
const PluginInstall = require('./install');
const Serverless = require('../../../Serverless');
const CLI = require('../../../classes/CLI');
const _ = require('lodash');
const userStats = require('../../../utils/userStats');
const { expect } = require('chai');
const { getTmpDirPath } = require('../../../../tests/utils/fs');
Expand Down Expand Up @@ -334,7 +333,7 @@ describe('PluginInstall', () => {

return expect(pluginInstall.addPluginToServerlessFile()).to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessYmlFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessYml, {
Object.assign({}, serverlessYml, {
plugins: ['serverless-plugin-1'],
})
);
Expand All @@ -354,7 +353,7 @@ describe('PluginInstall', () => {

return expect(pluginInstall.addPluginToServerlessFile()).to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessYmlFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessYml, {
Object.assign({}, serverlessYml, {
plugins: ['serverless-existing-plugin', 'serverless-plugin-1'],
})
);
Expand All @@ -371,7 +370,7 @@ describe('PluginInstall', () => {
pluginInstall.options.pluginName = 'serverless-plugin-1';
return expect(pluginInstall.addPluginToServerlessFile()).to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessYamlFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessYml, { plugins: ['serverless-plugin-1'] })
Object.assign({}, serverlessYml, { plugins: ['serverless-plugin-1'] })
);
});
});
Expand All @@ -387,14 +386,14 @@ describe('PluginInstall', () => {
return expect(pluginInstall.addPluginToServerlessFile())
.to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessJsonFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessJson, { plugins: ['serverless-plugin-1'] })
Object.assign({}, serverlessJson, { plugins: ['serverless-plugin-1'] })
);
})
.then(() => {
pluginInstall.options.pluginName = 'serverless-plugin-2';
return expect(pluginInstall.addPluginToServerlessFile()).to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessJsonFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessJson, {
Object.assign({}, serverlessJson, {
plugins: ['serverless-plugin-1', 'serverless-plugin-2'],
})
);
Expand Down Expand Up @@ -438,7 +437,7 @@ describe('PluginInstall', () => {

return expect(pluginInstall.addPluginToServerlessFile()).to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessYmlFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessYml, {
Object.assign({}, serverlessYml, {
plugins: {
localPath: 'test',
modules: [pluginInstall.options.pluginName],
Expand All @@ -463,7 +462,7 @@ describe('PluginInstall', () => {
return expect(pluginInstall.addPluginToServerlessFile())
.to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessJsonFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessJson, {
Object.assign({}, serverlessJson, {
plugins: {
localPath: 'test',
modules: [pluginInstall.options.pluginName],
Expand All @@ -475,7 +474,7 @@ describe('PluginInstall', () => {
pluginInstall.options.pluginName = 'serverless-plugin-2';
return expect(pluginInstall.addPluginToServerlessFile()).to.be.fulfilled.then(() => {
expect(serverless.utils.readFileSync(serverlessJsonFilePath, 'utf8')).to.deep.equal(
_.assign({}, serverlessJson, {
Object.assign({}, serverlessJson, {
plugins: {
localPath: 'test',
modules: ['serverless-plugin-1', 'serverless-plugin-2'],
Expand Down
5 changes: 2 additions & 3 deletions lib/utils/yamlAstParser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const chai = require('chai');
const writeFileSync = require('./fs/writeFileSync');
const readFileSync = require('./fs/readFileSync');
const yamlAstParser = require('./yamlAstParser');
const _ = require('lodash');
const chaiAsPromised = require('chai-as-promised');
const { getTmpDirPath } = require('../../tests/utils/fs');

Expand Down Expand Up @@ -33,7 +32,7 @@ describe('#yamlAstParser', () => {

it('should add a top level object and item into the yaml file', () => {
const yamlContent = { service: 'test-service' };
const expectedResult = _.assign({}, yamlContent, {
const expectedResult = Object.assign({}, yamlContent, {
toplevel: ['foo'],
});
return addNewArrayItemAndVerifyResult(yamlContent, 'toplevel', 'foo', expectedResult);
Expand All @@ -47,7 +46,7 @@ describe('#yamlAstParser', () => {

it('should add a multiple level object and item into the yaml file', () => {
const yamlContent = { service: 'test-service' };
const expectedResult = _.assign({}, yamlContent, {
const expectedResult = Object.assign({}, yamlContent, {
toplevel: {
second: {
third: ['foo'],
Expand Down

0 comments on commit 85e9cd4

Please sign in to comment.