diff --git a/lint-staged.config.js b/lint-staged.config.js index 372e7ff..3010843 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,4 +1,7 @@ module.exports = { - "*": ["prettier --write --ignore-unknown", "cspell --no-must-find-files"], + "*": [ + "prettier --cache --write --ignore-unknown", + "cspell --cache --no-must-find-files", + ], "*.js": ["eslint --cache --fix"], }; diff --git a/package.json b/package.json index 1f1ddd1..3ca058b 100644 --- a/package.json +++ b/package.json @@ -25,9 +25,9 @@ "build": "npm-run-all -p \"build:**\"", "commitlint": "commitlint --from=master", "security": "npm audit --production", - "lint:prettier": "prettier --list-different .", + "lint:prettier": "prettier --cache --list-different .", "lint:js": "eslint --cache .", - "lint:spelling": "cspell --cache --quiet \"**/*.*\"", + "lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"", "lint:types": "tsc --pretty --noEmit", "lint": "npm-run-all -l -p \"lint:**\"", "fix:js": "npm run lint:js -- --fix", diff --git a/src/index.js b/src/index.js index 1c30ef4..bdaea74 100644 --- a/src/index.js +++ b/src/index.js @@ -6,13 +6,7 @@ const { validate } = require("schema-utils"); const { version } = require("../package.json"); const schema = require("./options.json"); -const { - readFile, - stat, - throttleAll, - memoize, - asyncMemoize, -} = require("./utils"); +const { readFile, stat, throttleAll, memoize } = require("./utils"); const template = /\[\\*([\w:]+)\\*\]/i; @@ -36,7 +30,7 @@ const getFastGlob = memoize(() => require("fast-glob"), ); -const getGlobby = asyncMemoize(async () => { +const getGlobby = memoize(async () => { // @ts-ignore const { globby } = await import("globby"); diff --git a/src/utils.js b/src/utils.js index 790a105..156c75b 100644 --- a/src/utils.js +++ b/src/utils.js @@ -145,31 +145,4 @@ function memoize(fn) { }; } -/** - * @template T - * @param fn {(function(): any) | undefined} - * @returns {function(): Promise} - */ -function asyncMemoize(fn) { - let cache = false; - /** @type {T} */ - let result; - - return async () => { - if (cache) { - return result; - } - - result = await /** @type {function(): any} */ (fn)(); - cache = true; - - // Allow to clean up memory for fn - // and all dependent resources - // eslint-disable-next-line no-undefined, no-param-reassign - fn = undefined; - - return result; - }; -} - -module.exports = { stat, readFile, throttleAll, memoize, asyncMemoize }; +module.exports = { stat, readFile, throttleAll, memoize }; diff --git a/types/utils.d.ts b/types/utils.d.ts index 4a6752a..bdba07e 100644 --- a/types/utils.d.ts +++ b/types/utils.d.ts @@ -39,9 +39,3 @@ export function throttleAll(limit: number, tasks: Task[]): Promise; * @returns {function(): T} */ export function memoize(fn: (() => any) | undefined): () => T; -/** - * @template T - * @param fn {(function(): any) | undefined} - * @returns {function(): Promise} - */ -export function asyncMemoize(fn: (() => any) | undefined): () => Promise;