mirror of
https://github.com/serverless/serverless.git
synced 2026-01-18 14:58:43 +00:00
Merge pull request #5791 from danielcondemarin/aws-deploy-checkForChanges-TODO
Replace blocking fs.readFileSync with non blocking fs.readFile in checkForChanges.js
This commit is contained in:
commit
bc9cb08bad
@ -109,23 +109,24 @@ module.exports = {
|
||||
// create hashes for all the zip files
|
||||
const zipFiles = globby.sync(['**.zip'], { cwd: serverlessDirPath, dot: true, silent: true });
|
||||
const zipFilePaths = zipFiles.map((zipFile) => path.join(serverlessDirPath, zipFile));
|
||||
const zipFileHashes = zipFilePaths.map((zipFilePath) => {
|
||||
// TODO refactor to be async (use util function to compute checksum async)
|
||||
const zipFile = fs.readFileSync(zipFilePath);
|
||||
return crypto.createHash('sha256').update(zipFile).digest('base64');
|
||||
|
||||
const readFile = BbPromise.promisify(fs.readFile);
|
||||
const zipFileHashesPromises = zipFilePaths.map(zipFilePath => readFile(zipFilePath)
|
||||
.then(zipFile => crypto.createHash('sha256').update(zipFile).digest('base64')));
|
||||
|
||||
return BbPromise.all(zipFileHashesPromises).then(zipFileHashes => {
|
||||
const localHashes = zipFileHashes;
|
||||
localHashes.push(localCfHash);
|
||||
|
||||
if (_.isEqual(remoteHashes.sort(), localHashes.sort())) {
|
||||
this.serverless.service.provider.shouldNotDeploy = true;
|
||||
|
||||
const message = [
|
||||
'Service files not changed. Skipping deployment...',
|
||||
].join('');
|
||||
this.serverless.cli.log(message);
|
||||
}
|
||||
});
|
||||
|
||||
const localHashes = zipFileHashes;
|
||||
localHashes.push(localCfHash);
|
||||
|
||||
if (_.isEqual(remoteHashes.sort(), localHashes.sort())) {
|
||||
this.serverless.service.provider.shouldNotDeploy = true;
|
||||
|
||||
const message = [
|
||||
'Service files not changed. Skipping deployment...',
|
||||
].join('');
|
||||
this.serverless.cli.log(message);
|
||||
}
|
||||
}
|
||||
|
||||
return BbPromise.resolve();
|
||||
|
||||
@ -278,7 +278,7 @@ describe('checkForChanges', () => {
|
||||
describe('#checkIfDeploymentIsNecessary()', () => {
|
||||
let normalizeCloudFormationTemplateStub;
|
||||
let globbySyncStub;
|
||||
let readFileSyncStub;
|
||||
let readFileStub;
|
||||
|
||||
beforeEach(() => {
|
||||
normalizeCloudFormationTemplateStub = sinon
|
||||
@ -286,22 +286,22 @@ describe('checkForChanges', () => {
|
||||
.returns();
|
||||
globbySyncStub = sinon
|
||||
.stub(globby, 'sync');
|
||||
readFileSyncStub = sinon
|
||||
.stub(fs, 'readFileSync')
|
||||
.returns();
|
||||
readFileStub = sinon
|
||||
.stub(fs, 'readFile')
|
||||
.yields(null, undefined);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
normalizeFiles.normalizeCloudFormationTemplate.restore();
|
||||
globby.sync.restore();
|
||||
fs.readFileSync.restore();
|
||||
fs.readFile.restore();
|
||||
});
|
||||
|
||||
it('should resolve if no input is provided', () => expect(awsDeploy
|
||||
.checkIfDeploymentIsNecessary()).to.be.fulfilled.then(() => {
|
||||
expect(normalizeCloudFormationTemplateStub).to.not.have.been.called;
|
||||
expect(globbySyncStub).to.not.have.been.called;
|
||||
expect(readFileSyncStub).to.not.have.been.called;
|
||||
expect(readFileStub).to.not.have.been.called;
|
||||
expect(awsDeploy.serverless.cli.log).to.not.have.been.called;
|
||||
})
|
||||
);
|
||||
@ -313,7 +313,7 @@ describe('checkForChanges', () => {
|
||||
.to.be.fulfilled.then(() => {
|
||||
expect(normalizeCloudFormationTemplateStub).to.not.have.been.called;
|
||||
expect(globbySyncStub).to.not.have.been.called;
|
||||
expect(readFileSyncStub).to.not.have.been.called;
|
||||
expect(readFileStub).to.not.have.been.called;
|
||||
expect(awsDeploy.serverless.cli.log).to.not.have.been.called;
|
||||
});
|
||||
});
|
||||
@ -333,7 +333,7 @@ describe('checkForChanges', () => {
|
||||
.to.be.fulfilled.then(() => {
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledOnce;
|
||||
expect(globbySyncStub).to.have.been.calledOnce;
|
||||
expect(readFileSyncStub).to.have.been.calledOnce;
|
||||
expect(readFileStub).to.have.been.calledOnce;
|
||||
expect(awsDeploy.serverless.cli.log).to.not.have.been.called;
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledWithExactly(
|
||||
awsDeploy.serverless.service.provider.compiledCloudFormationTemplate
|
||||
@ -346,7 +346,7 @@ describe('checkForChanges', () => {
|
||||
silent: true,
|
||||
}
|
||||
);
|
||||
expect(readFileSyncStub).to.have.been.calledWithExactly(
|
||||
expect(readFileStub).to.have.been.calledWith(
|
||||
path.join('my-service/.serverless/my-service.zip')
|
||||
);
|
||||
expect(awsDeploy.serverless.service.provider.shouldNotDeploy).to.equal(undefined);
|
||||
@ -367,7 +367,7 @@ describe('checkForChanges', () => {
|
||||
.to.be.fulfilled.then(() => {
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledOnce;
|
||||
expect(globbySyncStub).to.have.been.calledOnce;
|
||||
expect(readFileSyncStub).to.have.been.calledOnce;
|
||||
expect(readFileStub).to.have.been.calledOnce;
|
||||
expect(awsDeploy.serverless.cli.log).to.not.have.been.called;
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledWithExactly(
|
||||
awsDeploy.serverless.service.provider.compiledCloudFormationTemplate
|
||||
@ -380,7 +380,7 @@ describe('checkForChanges', () => {
|
||||
silent: true,
|
||||
}
|
||||
);
|
||||
expect(readFileSyncStub).to.have.been.calledWithExactly(
|
||||
expect(readFileStub).to.have.been.calledWith(
|
||||
path.join('my-service/.serverless/my-service.zip')
|
||||
);
|
||||
expect(awsDeploy.serverless.service.provider.shouldNotDeploy).to.equal(undefined);
|
||||
@ -403,7 +403,7 @@ describe('checkForChanges', () => {
|
||||
.to.be.fulfilled.then(() => {
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledOnce;
|
||||
expect(globbySyncStub).to.have.been.calledOnce;
|
||||
expect(readFileSyncStub).to.have.been.calledTwice;
|
||||
expect(readFileStub).to.have.been.calledTwice;
|
||||
expect(awsDeploy.serverless.cli.log).to.not.have.been.called;
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledWithExactly(
|
||||
awsDeploy.serverless.service.provider.compiledCloudFormationTemplate
|
||||
@ -416,10 +416,10 @@ describe('checkForChanges', () => {
|
||||
silent: true,
|
||||
}
|
||||
);
|
||||
expect(readFileSyncStub).to.have.been.calledWithExactly(
|
||||
expect(readFileStub).to.have.been.calledWith(
|
||||
path.join('my-service/.serverless/func1.zip')
|
||||
);
|
||||
expect(readFileSyncStub).to.have.been.calledWithExactly(
|
||||
expect(readFileStub).to.have.been.calledWith(
|
||||
path.join('my-service/.serverless/func2.zip')
|
||||
);
|
||||
expect(awsDeploy.serverless.service.provider.shouldNotDeploy).to.equal(undefined);
|
||||
@ -440,7 +440,7 @@ describe('checkForChanges', () => {
|
||||
.to.be.fulfilled.then(() => {
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledOnce;
|
||||
expect(globbySyncStub).to.have.been.calledOnce;
|
||||
expect(readFileSyncStub).to.have.been.calledOnce;
|
||||
expect(readFileStub).to.have.been.calledOnce;
|
||||
expect(awsDeploy.serverless.cli.log).to.have.been.calledOnce;
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledWithExactly(
|
||||
awsDeploy.serverless.service.provider.compiledCloudFormationTemplate
|
||||
@ -453,7 +453,7 @@ describe('checkForChanges', () => {
|
||||
silent: true,
|
||||
}
|
||||
);
|
||||
expect(readFileSyncStub).to.have.been.calledWithExactly(
|
||||
expect(readFileStub).to.have.been.calledWith(
|
||||
path.join('my-service/.serverless/my-service.zip')
|
||||
);
|
||||
expect(awsDeploy.serverless.service.provider.shouldNotDeploy).to.equal(true);
|
||||
@ -477,7 +477,7 @@ describe('checkForChanges', () => {
|
||||
.to.be.fulfilled.then(() => {
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledOnce;
|
||||
expect(globbySyncStub).to.have.been.calledOnce;
|
||||
expect(readFileSyncStub).to.have.been.calledTwice;
|
||||
expect(readFileStub).to.have.been.calledTwice;
|
||||
expect(awsDeploy.serverless.cli.log).to.have.been.calledOnce;
|
||||
expect(normalizeCloudFormationTemplateStub).to.have.been.calledWithExactly(
|
||||
awsDeploy.serverless.service.provider.compiledCloudFormationTemplate
|
||||
@ -490,10 +490,10 @@ describe('checkForChanges', () => {
|
||||
silent: true,
|
||||
}
|
||||
);
|
||||
expect(readFileSyncStub).to.have.been.calledWithExactly(
|
||||
expect(readFileStub).to.have.been.calledWith(
|
||||
path.join('my-service/.serverless/func1.zip')
|
||||
);
|
||||
expect(readFileSyncStub).to.have.been.calledWithExactly(
|
||||
expect(readFileStub).to.have.been.calledWith(
|
||||
path.join('my-service/.serverless/func2.zip')
|
||||
);
|
||||
expect(awsDeploy.serverless.service.provider.shouldNotDeploy).to.equal(true);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user