Skip to content

Commit

Permalink
Merge pull request #809 from regseb/clear-content
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpl committed Jul 17, 2023
2 parents 83e9f54 + d6eae4e commit 2d1fdbd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
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();
}

0 comments on commit 2d1fdbd

Please sign in to comment.