Skip to content

Commit a7379a9

Browse files
fix: improve perf (#764)
1 parent 7ee03c9 commit a7379a9

File tree

5 files changed

+9
-45
lines changed

5 files changed

+9
-45
lines changed

lint-staged.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
module.exports = {
2-
"*": ["prettier --write --ignore-unknown", "cspell --no-must-find-files"],
2+
"*": [
3+
"prettier --cache --write --ignore-unknown",
4+
"cspell --cache --no-must-find-files",
5+
],
36
"*.js": ["eslint --cache --fix"],
47
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
"build": "npm-run-all -p \"build:**\"",
2626
"commitlint": "commitlint --from=master",
2727
"security": "npm audit --production",
28-
"lint:prettier": "prettier --list-different .",
28+
"lint:prettier": "prettier --cache --list-different .",
2929
"lint:js": "eslint --cache .",
30-
"lint:spelling": "cspell --cache --quiet \"**/*.*\"",
30+
"lint:spelling": "cspell --cache --no-must-find-files --quiet \"**/*.*\"",
3131
"lint:types": "tsc --pretty --noEmit",
3232
"lint": "npm-run-all -l -p \"lint:**\"",
3333
"fix:js": "npm run lint:js -- --fix",

src/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,7 @@ const { validate } = require("schema-utils");
66
const { version } = require("../package.json");
77

88
const schema = require("./options.json");
9-
const {
10-
readFile,
11-
stat,
12-
throttleAll,
13-
memoize,
14-
asyncMemoize,
15-
} = require("./utils");
9+
const { readFile, stat, throttleAll, memoize } = require("./utils");
1610

1711
const template = /\[\\*([\w:]+)\\*\]/i;
1812

@@ -36,7 +30,7 @@ const getFastGlob = memoize(() =>
3630
require("fast-glob"),
3731
);
3832

39-
const getGlobby = asyncMemoize(async () => {
33+
const getGlobby = memoize(async () => {
4034
// @ts-ignore
4135
const { globby } = await import("globby");
4236

src/utils.js

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -145,31 +145,4 @@ function memoize(fn) {
145145
};
146146
}
147147

148-
/**
149-
* @template T
150-
* @param fn {(function(): any) | undefined}
151-
* @returns {function(): Promise<T>}
152-
*/
153-
function asyncMemoize(fn) {
154-
let cache = false;
155-
/** @type {T} */
156-
let result;
157-
158-
return async () => {
159-
if (cache) {
160-
return result;
161-
}
162-
163-
result = await /** @type {function(): any} */ (fn)();
164-
cache = true;
165-
166-
// Allow to clean up memory for fn
167-
// and all dependent resources
168-
// eslint-disable-next-line no-undefined, no-param-reassign
169-
fn = undefined;
170-
171-
return result;
172-
};
173-
}
174-
175-
module.exports = { stat, readFile, throttleAll, memoize, asyncMemoize };
148+
module.exports = { stat, readFile, throttleAll, memoize };

types/utils.d.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,3 @@ export function throttleAll<T>(limit: number, tasks: Task<T>[]): Promise<T[]>;
3939
* @returns {function(): T}
4040
*/
4141
export function memoize<T>(fn: (() => any) | undefined): () => T;
42-
/**
43-
* @template T
44-
* @param fn {(function(): any) | undefined}
45-
* @returns {function(): Promise<T>}
46-
*/
47-
export function asyncMemoize<T>(fn: (() => any) | undefined): () => Promise<T>;

0 commit comments

Comments
 (0)