Skip to content

Commit

Permalink
feat!: bump all unified ecosystem dependencies, support mdx v3
Browse files Browse the repository at this point in the history
close #480, close #481
  • Loading branch information
JounQin committed Dec 1, 2023
1 parent 2d17526 commit 80846ee
Show file tree
Hide file tree
Showing 12 changed files with 3,174 additions and 3,145 deletions.
33 changes: 20 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"workspaces": [
"packages/*"
],
"packageManager": "[email protected].19",
"packageManager": "[email protected].21",
"scripts": {
"build": "run-p build:*",
"build:r": "r -f es2015",
Expand All @@ -27,25 +27,32 @@
},
"devDependencies": {
"@1stg/lib-config": "^12.0.0",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@types/eslint": "^8.44.1",
"@types/eslint-plugin-markdown": "^2.0.0",
"@types/jest": "^29.5.3",
"@types/node": "^20.4.6",
"@types/react": "^18.2.18",
"@types/unist": "^2.0.6",
"jest": "^29.6.2",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@types/eslint": "^8.44.8",
"@types/eslint-plugin-markdown": "^2.0.2",
"@types/jest": "^29.5.10",
"@types/node": "^20.10.1",
"@types/react": "^18.2.39",
"@types/unist": "^3.0.2",
"jest": "^29.7.0",
"patch-package": "^8.0.0",
"react": "^18.2.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"type-coverage": "^2.26.0",
"typescript": "^5.1.6",
"type-coverage": "^2.27.0",
"typescript": "^5.3.2",
"yarn-deduplicate": "^6.0.2"
},
"resolutions": {
"prettier": "^2.8.8"
"@types/acorn": "^6.0.0",
"@types/mdast": "^4.0.3",
"acorn": "^8.11.2",
"cliui": "npm:@isaacs/cliui@^8.0.2",
"mdast-util-gfm": "^3.0.0",
"prettier": "^2.8.8",
"unified": "^11.0.4",
"unified-engine": "^11.1.1"
},
"commitlint": {
"extends": [
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-mdx/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const getPositionAtFactory = (text: string) => {
return {
line,
column: offset - currOffset,
offset,
}
}

Expand Down
11 changes: 6 additions & 5 deletions packages/eslint-mdx/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ export class Parser {
ignoreRemarkConfig,
})
} catch (err: unknown) {
const error = err as VFileMessage
throw Object.assign(new SyntaxError(error.message), {
lineNumber: error.line,
column: error.column,
index: /* istanbul ignore next */ error.position?.start.offset,
const { message, line, column, place } = err as VFileMessage
const point = place && ('start' in place ? place.start : place)
throw Object.assign(new SyntaxError(message), {
lineNumber: line,
column,
index: /* istanbul ignore next */ point?.offset,
})
}

Expand Down
5 changes: 4 additions & 1 deletion packages/eslint-mdx/src/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference types="mdast-util-mdx-expression" />

import type { Token, TokenType, tokTypes } from 'acorn'
import type { Root } from 'remark-mdx'
import type { Root } from 'mdast'
import type { visit as visitor } from 'unist-util-visit'
import { ok as assert } from 'uvu/assert'

Expand Down Expand Up @@ -29,6 +31,7 @@ export const restoreTokens = (
value?: string,
): Token => ({
type,
// @ts-expect-error -- FIXME: `value` is not a valid property of `Token`
value,
start,
end,
Expand Down
23 changes: 13 additions & 10 deletions packages/eslint-mdx/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import type {
} from 'estree-jsx'
import type {
BlockContent,
PhrasingContent,
Literal as MdastLiteral,
PhrasingContent,
Root,
} from 'mdast'
import type { Options } from 'micromark-extension-mdx-expression'
import type { Root } from 'remark-mdx'
import { extractProperties, runAsWorker } from 'synckit'
import type { FrozenProcessor } from 'unified'
import type { Config, Configuration } from 'unified-engine/lib/configuration'
import type { Processor } from 'unified'
import type { Configuration, Result } from 'unified-engine'
import type { Node } from 'unist'
import { ok as assert } from 'uvu/assert'
import type { VFileMessage } from 'vfile-message'
Expand Down Expand Up @@ -60,7 +60,10 @@ let tt: Record<string, TokenType> & typeof _tokTypes

let TokenTranslator: typeof import('espree/lib/token-translator')['default']

export const processorCache = new Map<string, FrozenProcessor>()
export const processorCache = new Map<
string,
Processor<Root, undefined, undefined, Root, string>
>()

const getRemarkConfig = async (searchFrom: string) => {
if (!config) {
Expand All @@ -76,10 +79,10 @@ const getRemarkConfig = async (searchFrom: string) => {
})
}

return new Promise<Config>((resolve, reject) =>
config.load(searchFrom, (error, result) =>
error ? reject(error) : resolve(result),
),
return new Promise<Result>((resolve, reject) =>
config.load(searchFrom, (error, result) => {
error ? reject(error) : resolve(result)
}),
)
}

Expand Down Expand Up @@ -270,7 +273,7 @@ runAsWorker(
const text = fileOptions.value as string
const tokenTranslator = new TokenTranslator(tt, text)

const root = processor.parse(fileOptions) as Root
const root = processor.parse(fileOptions)

const body: Program['body'] = []
const comments: Comment[] = []
Expand Down
1 change: 0 additions & 1 deletion packages/eslint-plugin-mdx/src/processors/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { processorOptions as defaultProcessorOptions } from './options'
export const createRemarkProcessor = (
processorOptions = defaultProcessorOptions,
): Linter.Processor => ({
// @ts-expect-error -- FIXME: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65826
meta: {
name: 'mdx/remark',
version: meta.version,
Expand Down
30 changes: 16 additions & 14 deletions packages/eslint-plugin-mdx/src/rules/remark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const remark: Rule.RuleModule = {
fatal,
line,
column,
position: { start, end },
place,
} of messages) {
// https://github.com/remarkjs/remark-lint/issues/65#issuecomment-220800231
/* istanbul ignore next */
Expand All @@ -89,22 +89,24 @@ export const remark: Rule.RuleModule = {
ruleId,
severity,
}

const point = {
line,
// ! eslint ast column is 0-indexed, but unified is 1-indexed
column: column - 1,
}

context.report({
// related to https://github.com/eslint/eslint/issues/14198
message: JSON.stringify(message),
loc: {
line,
// ! eslint ast column is 0-indexed, but unified is 1-indexed
column: column - 1,
start: {
...start,
column: start.column - 1,
},
end: {
...end,
column: end.column - 1,
},
},
loc:
'start' in place
? {
...point,
start: { ...place.start, column: place.start.column - 1 },
end: { ...place.end, column: place.end.column - 1 },
}
: point,
node,
fix:
fixedText === sourceText
Expand Down
11 changes: 11 additions & 0 deletions patches/string-width-cjs+4.2.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/node_modules/string-width-cjs/index.js b/node_modules/string-width-cjs/index.js
index f4d261a..7ea642a 100644
--- a/node_modules/string-width-cjs/index.js
+++ b/node_modules/string-width-cjs/index.js
@@ -1,5 +1,5 @@
'use strict';
-const stripAnsi = require('strip-ansi');
+const stripAnsi = require('strip-ansi-cjs');
const isFullwidthCodePoint = require('is-fullwidth-code-point');
const emojiRegex = require('emoji-regex');

10 changes: 10 additions & 0 deletions patches/unified-engine+11.1.1.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/node_modules/unified-engine/index.d.ts b/node_modules/unified-engine/index.d.ts
index 0e25d67..503f1ab 100644
--- a/node_modules/unified-engine/index.d.ts
+++ b/node_modules/unified-engine/index.d.ts
@@ -1,4 +1,4 @@
-export { Configuration } from "./lib/configuration.js";
+export { Configuration, Result } from "./lib/configuration.js";
export { engine } from "./lib/index.js";
export type Completer = import('./lib/file-set.js').Completer;
export type Callback = import('./lib/index.js').Callback;
13 changes: 13 additions & 0 deletions patches/wrap-ansi-cjs+7.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/wrap-ansi-cjs/index.js b/node_modules/wrap-ansi-cjs/index.js
index d502255..c33a23a 100755
--- a/node_modules/wrap-ansi-cjs/index.js
+++ b/node_modules/wrap-ansi-cjs/index.js
@@ -1,6 +1,6 @@
'use strict';
-const stringWidth = require('string-width');
-const stripAnsi = require('strip-ansi');
+const stringWidth = require('string-width-cjs');
+const stripAnsi = require('strip-ansi-cjs');
const ansiStyles = require('ansi-styles');

const ESCAPES = new Set([
7 changes: 7 additions & 0 deletions patches/yargs+17.7.2.patch

Large diffs are not rendered by default.

Loading

0 comments on commit 80846ee

Please sign in to comment.