Skip to content

Commit 5e28040

Browse files
committed
chore: reuse lodash memoize
1 parent 3dada81 commit 5e28040

File tree

3 files changed

+16
-86
lines changed

3 files changed

+16
-86
lines changed

package-lock.json

Lines changed: 14 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"bs-logger": "0.x",
6060
"buffer-from": "1.x",
6161
"fast-json-stable-stringify": "2.x",
62+
"lodash.memoize": "4.x",
6263
"json5": "2.x",
6364
"make-error": "1.x",
6465
"mkdirp": "0.x",
@@ -103,7 +104,6 @@
103104
"jest": "24.x",
104105
"js-yaml": "latest",
105106
"lint-staged": "latest",
106-
"lodash.memoize": "4.x",
107107
"lodash.merge": "4.x",
108108
"lodash.set": "4.x",
109109
"npm-run-all": "latest",

src/compiler.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { LogContexts, LogLevels, Logger } from 'bs-logger'
3333
import bufferFrom = require('buffer-from')
3434
import stableStringify = require('fast-json-stable-stringify')
3535
import { readFileSync, writeFileSync } from 'fs'
36+
import memoize = require('lodash.memoize')
3637
import mkdirp = require('mkdirp')
3738
import { basename, extname, join, relative } from 'path'
3839

@@ -226,22 +227,6 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
226227
return { cwd, compile, getTypeInfo, extensions, cachedir, ts }
227228
}
228229

229-
type AnyFn = (...args: any[]) => any
230-
function memoize<T extends AnyFn = AnyFn>(fn: T): T {
231-
const cache = new Map()
232-
233-
return ((arg: string) => {
234-
const entry = cache.get(arg)
235-
if (entry !== undefined) {
236-
return entry
237-
}
238-
239-
const res = fn(arg)
240-
cache.set(arg, res)
241-
return res
242-
}) as T
243-
}
244-
245230
/**
246231
* Internal source output.
247232
*/

0 commit comments

Comments
 (0)