-
Notifications
You must be signed in to change notification settings - Fork 557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Delete local .iac-data directory after scan is finished [CC-765] #1762
Conversation
dd4aeed
to
7a37a90
Compare
0e37d86
to
e3fa251
Compare
e3fa251
to
9390456
Compare
9390456
to
7a37a90
Compare
90d6dfc
to
e8d37ed
Compare
e8d37ed
to
1848bf4
Compare
d7b3d0d
to
6de51e9
Compare
bae5a78
to
8044917
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Very nice, shall we add a note above the rimraf import/call site that says it can be removed when minimum node version is above 12.x?
Good call, I'll add that now |
75e1732
to
d49c829
Compare
[CC-765] refactor: Move rimraf to prod deps
d49c829
to
b6803e8
Compare
Expected release notes (by @ipapast) features: others (will not be included in Semantic-Release notes):
|
export function cleanLocalCache() { | ||
// path to delete is hardcoded for now | ||
const iacPath: fs.PathLike = path.join(`${process.cwd()}`, '.iac-data'); | ||
if (fs.existsSync(iacPath) && fs.lstatSync(iacPath).isDirectory()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking, but this if
guard shouldn't be needed as rimraf already checks and succeeds if the directory doesn't exist.
If the file doesn't exist, rimraf will return successfully, since your desired outcome is already the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call, I'll merge it right after this. thank you!
What does this PR do?
In a previous task, we introduced the download and extraction of files in a local cache directory, called '.iac-data'.
We do not need the files anymore after the scan/test, so we decided to clean up that local directory after the tests finishes.
We also move the dev dependency
rimraf
from dev deps to prod deps. When we support Node >= v12.10.0 we can switch to the supported rmdirSync with recursive options.https://snyk.slack.com/archives/C0127HWU0E7/p1616688051070900
How should this be manually tested?
npm run build && node iac test file.tf --experimental
ls .iac-data
and see that there is no such directory in the filesystem anymore.Any background context you want to provide?
The package rimraf was used for the deletion of the directory. This was already in our dev dependencies.
Option 2:
In our version of node fs.rmdirSync is not supported, so in order to delete a non empty directory we would need to make our own recursive function, to check for files in the directory, unlink them and then delete them one by one. Rimraf does this in one line. That function would look like this:
What are the relevant tickets?
CC-765