Skip to content

Commit 91f4327

Browse files
authored
Clean the tmp dir during _archivePrebuilt to match _buildAndArchive behavior (#518)
1 parent 55e8e7c commit 91f4327

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

lib/main.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,13 @@ Emulate only the body of the API Gateway event.
657657
_archivePrebuilt (program) {
658658
const codeDirectory = this._codeDirectory()
659659

660-
return this._fileCopy(program, program.prebuiltDirectory, codeDirectory, false).then(() => {
661-
console.log('=> Zipping deployment package')
662-
return this._zip(program, codeDirectory)
660+
return Promise.resolve().then(() => {
661+
return this._cleanDirectory(codeDirectory, program.keepNodeModules)
662+
}).then(() => {
663+
return this._fileCopy(program, program.prebuiltDirectory, codeDirectory, false).then(() => {
664+
console.log('=> Zipping deployment package')
665+
return this._zip(program, codeDirectory)
666+
})
663667
})
664668
}
665669

test/main.js

+18
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,24 @@ describe('lib/main', function () {
865865
})
866866
})
867867
})
868+
869+
it('cleans the temporary directory before running `_archivePrebuilt`', function () {
870+
_timeout({ this: this, sec: 30 }) // give it time to zip
871+
const buildDir = '.build_' + Date.now()
872+
const codeDir = lambda._codeDirectory()
873+
const tmpFile = path.join(codeDir, 'deleteme')
874+
after(() => fs.removeSync(buildDir))
875+
876+
fs.mkdirSync(codeDir, { recursive: true })
877+
fs.writeFileSync(tmpFile, '...')
878+
fs.mkdirSync(buildDir)
879+
fs.writeFileSync(path.join(buildDir, 'test'), '...')
880+
881+
program.prebuiltDirectory = buildDir
882+
return lambda._archive(program).then((_data) => {
883+
assert.isNotTrue(fs.existsSync(tmpFile))
884+
})
885+
})
868886
})
869887

870888
describe('_readArchive', () => {

0 commit comments

Comments
 (0)