Skip to content

Commit

Permalink
chore: reuse lodash memoize
Browse files Browse the repository at this point in the history
  • Loading branch information
topaxi committed Sep 9, 2019
1 parent 3dada81 commit 5e28040
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 86 deletions.
83 changes: 14 additions & 69 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"bs-logger": "0.x",
"buffer-from": "1.x",
"fast-json-stable-stringify": "2.x",
"lodash.memoize": "4.x",
"json5": "2.x",
"make-error": "1.x",
"mkdirp": "0.x",
Expand Down Expand Up @@ -103,7 +104,6 @@
"jest": "24.x",
"js-yaml": "latest",
"lint-staged": "latest",
"lodash.memoize": "4.x",
"lodash.merge": "4.x",
"lodash.set": "4.x",
"npm-run-all": "latest",
Expand Down
17 changes: 1 addition & 16 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { LogContexts, LogLevels, Logger } from 'bs-logger'
import bufferFrom = require('buffer-from')
import stableStringify = require('fast-json-stable-stringify')
import { readFileSync, writeFileSync } from 'fs'
import memoize = require('lodash.memoize')
import mkdirp = require('mkdirp')
import { basename, extname, join, relative } from 'path'

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

type AnyFn = (...args: any[]) => any
function memoize<T extends AnyFn = AnyFn>(fn: T): T {
const cache = new Map()

return ((arg: string) => {
const entry = cache.get(arg)
if (entry !== undefined) {
return entry
}

const res = fn(arg)
cache.set(arg, res)
return res
}) as T
}

/**
* Internal source output.
*/
Expand Down

0 comments on commit 5e28040

Please sign in to comment.