Skip to content

Commit cb1e091

Browse files
Dan Cortelclaygregory
authored andcommitted
Allow pruning all versions if explicitly configured
1 parent 8e1b4bc commit cb1e091

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ custom:
6060
```
6161
6262
To run automatically, the `automatic` property of `prune` must be set to `true` and the `number` of versions to keep must be specified.
63+
It is possible to set `number` to `0`. In this case, the plugin will delete all the function versions (except $LATEST); this is useful when disabling function versioning for an already-deployed stack.
6364

6465
### Layers
6566

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class Prune {
9999
return BbPromise.resolve();
100100
}
101101

102-
if (this.pluginCustom.automatic && this.pluginCustom.number >= 1) {
102+
if (this.pluginCustom.automatic &&
103+
this.pluginCustom.number !== undefined && this.pluginCustom.number >= 0) {
103104
this.serverless.cli.log('Prune: Running post-deployment pruning');
104105

105106
if(this.pluginCustom.includeLayers) {

test/index.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ describe('Prune', function() {
482482

483483
describe('postDeploy', function() {
484484

485-
it('should prune functions if automatic is option is configured', function() {
485+
it('should prune functions if automatic option is configured', function() {
486486

487487
const custom = {
488488
prune: { automatic: true, number: 10 }
@@ -497,6 +497,36 @@ describe('Prune', function() {
497497
});
498498
});
499499

500+
it('should prune all functions if automatic option is configured and number is 0', function() {
501+
502+
const custom = {
503+
prune: { automatic: true, number: 0 }
504+
};
505+
const serverlessStub = createMockServerless([], custom);
506+
507+
const plugin = new PrunePlugin(serverlessStub, {});
508+
sinon.spy(plugin, 'prune');
509+
510+
return plugin.postDeploy().then(() => {
511+
sinon.assert.calledOnce(plugin.prune);
512+
});
513+
});
514+
515+
it('should not prune functions if automatic option is configured without a number', function() {
516+
517+
const custom = {
518+
prune: { automatic: true }
519+
};
520+
const serverlessStub = createMockServerless([], custom);
521+
522+
const plugin = new PrunePlugin(serverlessStub, {});
523+
sinon.spy(plugin, 'prune');
524+
525+
return plugin.postDeploy().then(() => {
526+
sinon.assert.notCalled(plugin.prune);
527+
});
528+
});
529+
500530
it('should not prune functions if noDeploy flag is set', function() {
501531

502532
const serverlessStub = createMockServerless([], null);

0 commit comments

Comments
 (0)