File tree Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Expand file tree Collapse file tree 3 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " netlify-plugin-ttl-cache" ,
3- "version" : " 1.0.1 " ,
3+ "version" : " 1.0.2 " ,
44 "description" : " A Netlify plugin for persisting immutable build assets across releases." ,
55 "keywords" : [
66 " netlify" ,
Original file line number Diff line number Diff line change 1- const { stat, unlink } = require ( "fs" ) . promises ;
1+ const { stat, unlink, rmdir } = require ( "fs" ) . promises ;
22const { getDaysApart, getDirFilenames, addTrailingSlash } = require ( "./utils" ) ;
33
44const TMP_CACHE_DIR = ".netlify-plugin-ttl-cache" ;
@@ -38,6 +38,7 @@ const onPostBuild = async ({ utils, inputs }) => {
3838 addTrailingSlash ( TMP_CACHE_DIR ) ,
3939 addTrailingSlash ( inputs . path ) ,
4040 ] ) ;
41+ await rmdir ( TMP_CACHE_DIR , { recursive : true } ) ;
4142 }
4243
4344 // Save new cache
Original file line number Diff line number Diff line change @@ -2,13 +2,14 @@ jest.mock("fs", () => ({
22 promises : {
33 stat : jest . fn ( ) ,
44 unlink : jest . fn ( ) ,
5+ rmdir : jest . fn ( ) ,
56 } ,
67} ) ) ;
78jest . mock ( "./utils" , ( ) => ( {
89 ...jest . requireActual ( "./utils" ) ,
910 getDirFilenames : jest . fn ( ) ,
1011} ) ) ;
11- const { stat, unlink } = require ( "fs" ) . promises ;
12+ const { stat, unlink, rmdir } = require ( "fs" ) . promises ;
1213const { onPreBuild, onPostBuild } = require ( "./index" ) ;
1314const { getDirFilenames } = require ( "./utils" ) ;
1415
@@ -144,5 +145,18 @@ describe("on onPostBuild", () => {
144145 expect ( utils . cache . save ) . toBeCalledTimes ( 1 ) ;
145146 expect ( utils . cache . save ) . toBeCalledWith ( inputs . path ) ;
146147 } ) ;
148+
149+ it ( "removes old cache directory" , async ( ) => {
150+ await onPostBuild ( { inputs, utils } ) ;
151+ expect ( rmdir ) . toBeCalledTimes ( 1 ) ;
152+ expect ( rmdir . mock . calls [ 0 ] ) . toMatchInlineSnapshot ( `
153+ Array [
154+ ".netlify-plugin-ttl-cache",
155+ Object {
156+ "recursive": true,
157+ },
158+ ]
159+ ` ) ;
160+ } ) ;
147161 } ) ;
148162} ) ;
You can’t perform that action at this time.
0 commit comments