Skip to content

Commit

Permalink
feat: call creatSyncFn lazily for performance (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Jul 10, 2021
1 parent c7e7bd8 commit 7d5dfce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-jars-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-markup": minor
---

feat: call `creatSyncFn` lazily for performance
11 changes: 8 additions & 3 deletions packages/markup/src/rules/markup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { createSyncFn } from 'synckit'

import { getPhysicalFilename, resolveConfig } from '../helpers'

const execSync = createSyncFn<typeof execAsync>(require.resolve('../worker'))
// call `creatSyncFn` lazily for performance, it is already cached inside, related #31
const _ = {
get execSync() {
return createSyncFn<typeof execAsync>(require.resolve('../worker'))
},
}

const brokenCache = new Map<string, true>()

Expand Down Expand Up @@ -45,7 +50,7 @@ export const markup: Rule.RuleModule = {
}

if (broken) {
return execSync(options)
return _.execSync(options)
}

try {
Expand All @@ -54,7 +59,7 @@ export const markup: Rule.RuleModule = {
/* istanbul ignore else */
if (BROKEN_ERROR_PATTERN.test((err as Error).message)) {
brokenCache.set(config, (broken = true))
return execSync(options)
return _.execSync(options)
}
// eslint-disable-next-line no-else-return -- https://github.com/istanbuljs/istanbuljs/issues/605
else {
Expand Down

0 comments on commit 7d5dfce

Please sign in to comment.