Skip to content

Commit 29fe669

Browse files
authored
feat: call creatSyncFn lazily for performance (#324)
1 parent b31723d commit 29fe669

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"build:ts": "tsc -b",
1616
"clean": "rimraf packages/*/{lib,*.tsbuildinfo} node_modules/@1stg/eslint-config/node_modules",
1717
"lint": "run-p lint:*",
18-
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache --ext js,md,ts -f friendly",
18+
"lint:es": "eslint . --cache -f friendly",
1919
"lint:ts": "tslint -p . -t stylish",
2020
"postinstall": "simple-git-hooks && yarn-deduplicate --strategy fewer || exit 0",
2121
"prelint": "yarn build",
@@ -30,15 +30,15 @@
3030
"@types/eslint": "^7.2.14",
3131
"@types/eslint-plugin-markdown": "^2.0.0",
3232
"@types/jest": "^26.0.24",
33-
"@types/node": "^16.3.0",
33+
"@types/node": "^16.3.1",
3434
"@types/react": "^17.0.14",
3535
"@types/unist": "^2.0.5",
3636
"lerna": "^4.0.0",
3737
"npm-run-all": "^4.1.5",
3838
"react": "^17.0.2",
3939
"remark-validate-links": "^10.0.4",
4040
"ts-jest": "^27.0.3",
41-
"ts-node": "^10.0.0",
41+
"ts-node": "^10.1.0",
4242
"tslint": "^6.1.3",
4343
"type-coverage": "^2.18.0",
4444
"typescript": "^4.3.5",

packages/eslint-plugin-mdx/src/rules/remark.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ import vfile from 'vfile'
1111
import { getPhysicalFilename, getRemarkProcessor } from './helpers'
1212
import type { RemarkLintMessage } from './types'
1313

14-
const processSync = createSyncFn(require.resolve('../worker')) as (
15-
fileOptions: VFileOptions,
16-
physicalFilename: string,
17-
isFile: boolean,
18-
) => {
19-
messages: VFile['messages']
20-
content: string
14+
// call `creatSyncFn` lazily for performance, it is already cached inside, related #323
15+
const lazyRemark = {
16+
get processSync() {
17+
return createSyncFn(require.resolve('../worker')) as (
18+
fileOptions: VFileOptions,
19+
physicalFilename: string,
20+
isMdx: boolean,
21+
) => {
22+
messages: VFile['messages']
23+
content: string
24+
}
25+
},
2126
}
2227

2328
const brokenCache = new WeakMap<FrozenProcessor, true>()
@@ -67,7 +72,7 @@ export const remark: Rule.RuleModule = {
6772
let broken = brokenCache.get(remarkProcessor)
6873

6974
if (broken) {
70-
const { messages, content } = processSync(
75+
const { messages, content } = lazyRemark.processSync(
7176
fileOptions,
7277
physicalFilename,
7378
isMdx,
@@ -84,7 +89,7 @@ export const remark: Rule.RuleModule = {
8489
'`processSync` finished async. Use `process` instead'
8590
) {
8691
brokenCache.set(remarkProcessor, (broken = true))
87-
const { messages, content } = processSync(
92+
const { messages, content } = lazyRemark.processSync(
8893
fileOptions,
8994
physicalFilename,
9095
isMdx,

yarn.lock

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3076,10 +3076,10 @@
30763076
resolved "https://registry.yarnpkg.com/@types/minimist/-/minimist-1.2.1.tgz#283f669ff76d7b8260df8ab7a4262cc83d988256"
30773077
integrity sha512-fZQQafSREFyuZcdWFAExYjBiCL7AUCdgsk80iO0q4yihYYdcIiH28CcuPTGFgLOCC8RlW49GSQxdHwZP+I7CNg==
30783078

3079-
"@types/node@*", "@types/node@^16.3.0":
3080-
version "16.3.0"
3081-
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.0.tgz#1836664e4fad13b51b07eb6e882a53925e6543c4"
3082-
integrity sha512-OydMCocGMGqw/1BnWbhtK+AtwyWTOigtrQlRe57OQmTNcI3HKlVI5FGlh+c4mSqInMPLynFrTlYjfajPu9O/eQ==
3079+
"@types/node@*", "@types/node@^16.3.1":
3080+
version "16.3.1"
3081+
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.3.1.tgz#24691fa2b0c3ec8c0d34bfcfd495edac5593ebb4"
3082+
integrity sha512-N87VuQi7HEeRJkhzovao/JviiqKjDKMVKxKMfUvSKw+MbkbW8R0nA3fi/MQhhlxV2fQ+2ReM+/Nt4efdrJx3zA==
30833083

30843084
"@types/normalize-package-data@^2.4.0":
30853085
version "2.4.0"
@@ -11749,10 +11749,10 @@ ts-jest@^27.0.3:
1174911749
semver "7.x"
1175011750
yargs-parser "20.x"
1175111751

11752-
ts-node@^10.0.0:
11753-
version "10.0.0"
11754-
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.0.0.tgz#05f10b9a716b0b624129ad44f0ea05dac84ba3be"
11755-
integrity sha512-ROWeOIUvfFbPZkoDis0L/55Fk+6gFQNZwwKPLinacRl6tsxstTF1DbAcLKkovwnpKMVvOMHP1TIbnwXwtLg1gg==
11752+
ts-node@^10.1.0:
11753+
version "10.1.0"
11754+
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.1.0.tgz#e656d8ad3b61106938a867f69c39a8ba6efc966e"
11755+
integrity sha512-6szn3+J9WyG2hE+5W8e0ruZrzyk1uFLYye6IGMBadnOzDh8aP7t8CbFpsfCiEx2+wMixAhjFt7lOZC4+l+WbEA==
1175611756
dependencies:
1175711757
"@tsconfig/node10" "^1.0.7"
1175811758
"@tsconfig/node12" "^1.0.7"

0 commit comments

Comments
 (0)