Skip to content
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: Clear content at end. #809

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ignore from 'ignore';
import debug from 'debug';
import check from './check';
import { loadModuleData, readJSON, tryRequire } from './utils';
import { clearContent } from './utils/file';

import {
defaultOptions,
Expand Down Expand Up @@ -163,7 +164,8 @@ export default function depcheck(rootDir, options, callback) {
),
}),
)
.then(callback);
.then(callback)
.finally(clearContent);
}

depcheck.parser = availableParsers;
Expand Down
14 changes: 9 additions & 5 deletions src/utils/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,20 @@ import util from 'util';
// TODO: this can later be refactored once support for node 10 is dropped
const readFileAsync = util.promisify(fs.readFile);

const promises = {};
const promises = new Map();

// eslint-disable-next-line import/prefer-default-export
export function getContent(filename) {
if (!promises[filename]) {
promises[filename] = readFileAsync(filename, 'utf8');
if (!promises.has(filename)) {
promises.set(filename, readFileAsync(filename, 'utf8'));
}
return promises[filename];
return promises.get(filename);
}

export function setContent(filename, content) {
promises[filename] = Promise.resolve(content);
promises.set(filename, Promise.resolve(content));
}

export function clearContent() {
promises.clear();
}