Skip to content

Commit

Permalink
fix: resolve circular imports in worker (#412)
Browse files Browse the repository at this point in the history
Co-authored-by: Zhenggang Su <zgsu@alauda.io>
Co-authored-by: JounQin <admin@1stg.me>
  • Loading branch information
3 people authored Jul 22, 2022
1 parent 89a83a6 commit e697910
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/sharp-carpets-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fake-scope/fake-pkg": patch
---

fix: resolve circular imports in worker
15 changes: 1 addition & 14 deletions packages/eslint-mdx/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,9 @@ import path from 'node:path'
import { pathToFileURL } from 'node:url'

import type { Position } from 'acorn'
import { createSyncFn } from 'synckit'
import type { Point } from 'unist'

import type {
NormalPosition,
WorkerOptions,
WorkerParseResult,
WorkerProcessResult,
} from './types'
import type { NormalPosition } from './types'

export const last = <T>(items: T[] | readonly T[]) =>
items && items[items.length - 1]
Expand Down Expand Up @@ -221,10 +215,3 @@ export const nextCharOffsetFactory = (text: string) => {
}
}
}

const workerPath = require.resolve('./worker')

export const performSyncWork = createSyncFn(workerPath) as ((
options: Omit<WorkerOptions, 'process'>,
) => WorkerParseResult) &
((options: WorkerOptions & { process: true }) => WorkerProcessResult)
1 change: 1 addition & 0 deletions packages/eslint-mdx/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './helpers'
export * from './parser'
export * from './sync'
export * from './types'
8 changes: 2 additions & 6 deletions packages/eslint-mdx/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ import path from 'node:path'
import type { Linter } from 'eslint'
import type { VFileMessage } from 'vfile-message'

import {
arrayify,
normalizePosition,
performSyncWork,
getPhysicalFilename,
} from './helpers'
import { arrayify, normalizePosition, getPhysicalFilename } from './helpers'
import { performSyncWork } from './sync'
import type { ParserOptions, WorkerParseResult } from './types'

export const DEFAULT_EXTENSIONS: readonly string[] = ['.mdx']
Expand Down
14 changes: 14 additions & 0 deletions packages/eslint-mdx/src/sync.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createSyncFn } from 'synckit'

import type {
WorkerOptions,
WorkerParseResult,
WorkerProcessResult,
} from './types'

const workerPath = require.resolve('./worker')

export const performSyncWork = createSyncFn(workerPath) as ((
options: Omit<WorkerOptions, 'process'>,
) => WorkerParseResult) &
((options: WorkerOptions & { process: true }) => WorkerProcessResult)

0 comments on commit e697910

Please sign in to comment.