Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: bump all unified ecosystem dependencies, support mdx v3 #486

Merged
merged 14 commits into from
Dec 5, 2023
Merged
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,15 @@ jobs:
- ubuntu-latest
- windows-latest
node:
- 16
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are free to choose 18, as 16 is EOL.
But, Node 16 should work for all other unified projects. Everything is tested and works on Node 16.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 16 still works, I disable testing because the expected errors thrown are different with other versions.

- 18
- 20
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js ${{ matrix.node }}
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: yarn
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/pkg-size.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:

steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v3
- name: Setup Node.js LTS
uses: actions/setup-node@v4
with:
node-version: 16
node-version: --lts
cache: yarn

- name: Package Size Report
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
# This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits
fetch-depth: 0

- name: Setup Node.js 16
uses: actions/setup-node@v3
- name: Setup Node.js LTS
uses: actions/setup-node@v4
with:
node-version: 16
node-version: --lts
cache: yarn

- name: Install Dependencies
Expand Down
34 changes: 21 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"workspaces": [
"packages/*"
],
"packageManager": "yarn@1.22.19",
"packageManager": "yarn@1.22.21",
"scripts": {
"build": "run-p build:*",
"build:r": "r -f es2015",
Expand All @@ -27,25 +27,33 @@
},
"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-frontmatter": "^2.0.1",
"mdast-util-gfm": "^3.0.0",
"prettier": "^2.8.8",
"unified": "^11.0.4",
"unified-engine": "^11.1.1"
},
"commitlint": {
"extends": [
Expand Down
22 changes: 11 additions & 11 deletions packages/eslint-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"license": "MIT",
"engines": {
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
"node": ">=18.0.0"
},
"main": "lib/index.js",
"module": "lib/index.es2015.mjs",
Expand All @@ -30,19 +30,19 @@
"eslint": ">=8.0.0"
},
"dependencies": {
"acorn": "^8.10.0",
"acorn": "^8.11.2",
"acorn-jsx": "^5.3.2",
"espree": "^9.6.1",
"estree-util-visit": "^1.2.1",
"remark-mdx": "^2.3.0",
"remark-parse": "^10.0.2",
"remark-stringify": "^10.0.3",
"estree-util-visit": "^2.0.0",
"remark-mdx": "^3.0.0",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"synckit": "^0.8.5",
"tslib": "^2.6.1",
"unified": "^10.1.2",
"unified-engine": "^10.1.0",
"unist-util-visit": "^4.1.2",
"tslib": "^2.6.2",
"unified": "^11.0.4",
"unified-engine": "^11.1.1",
"unist-util-visit": "^5.0.0",
"uvu": "^0.5.6",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using the latest release of node there's an option to drop uvu in favor of node:test https://nodejs.org/api/test.html
Which is even faster, a stable part of node core, and works well with ESM

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a new PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are actually using uvu/assert only, maybe it can be replaced by devlop. For testing, we're using jest now, and will migrate to vitest later.

"vfile": "^5.3.7"
"vfile": "^6.0.1"
}
}
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" />
JounQin marked this conversation as resolved.
Show resolved Hide resolved

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`
JounQin marked this conversation as resolved.
Show resolved Hide resolved
value,
start,
end,
Expand Down
27 changes: 15 additions & 12 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,13 +60,16 @@ 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) {
const { Configuration } = await loadEsmModule<
typeof import('unified-engine/lib/configuration')
>('unified-engine/lib/configuration.js')
typeof import('unified-engine')
>('unified-engine')
config = new Configuration({
cwd: process.cwd(),
packageField: 'remarkConfig',
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
14 changes: 7 additions & 7 deletions packages/eslint-plugin-mdx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"license": "MIT",
"engines": {
"node": "^12.20.0 || ^14.18.0 || >=16.0.0"
"node": ">=18.0.0"
},
"main": "lib/index.js",
"module": "lib/index.es2015.mjs",
Expand All @@ -33,11 +33,11 @@
"dependencies": {
"eslint-mdx": "^2.2.0",
"eslint-plugin-markdown": "^3.0.1",
"remark-mdx": "^2.3.0",
"remark-parse": "^10.0.2",
"remark-stringify": "^10.0.3",
"tslib": "^2.6.1",
"unified": "^10.1.2",
"vfile": "^5.3.7"
"remark-mdx": "^3.0.0",
"remark-parse": "^11.0.0",
"remark-stringify": "^11.0.0",
"tslib": "^2.6.2",
"unified": "^11.0.4",
"vfile": "^6.0.1"
}
}
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:
/* istanbul ignore next */ '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
13 changes: 13 additions & 0 deletions patches/eslint+8.54.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/eslint/lib/cli-engine/formatters/stylish.js b/node_modules/eslint/lib/cli-engine/formatters/stylish.js
index a808448..1d4b79e 100644
--- a/node_modules/eslint/lib/cli-engine/formatters/stylish.js
+++ b/node_modules/eslint/lib/cli-engine/formatters/stylish.js
@@ -5,7 +5,7 @@
"use strict";

const chalk = require("chalk"),
- stripAnsi = require("strip-ansi"),
+ stripAnsi = require("strip-ansi-cjs"),
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
table = require("text-table");

//------------------------------------------------------------------------------
11 changes: 11 additions & 0 deletions patches/string-length+4.0.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
diff --git a/node_modules/string-length/index.js b/node_modules/string-length/index.js
index c2589a2..3040f0a 100644
--- a/node_modules/string-length/index.js
+++ b/node_modules/string-length/index.js
@@ -1,5 +1,5 @@
'use strict';
-const stripAnsi = require('strip-ansi');
+const stripAnsi = require('strip-ansi-cjs');
ChristianMurphy marked this conversation as resolved.
Show resolved Hide resolved
const charRegex = require('char-regex');

const stringLength = string => {
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";
JounQin marked this conversation as resolved.
Show resolved Hide resolved
export { engine } from "./lib/index.js";
export type Completer = import('./lib/file-set.js').Completer;
export type Callback = import('./lib/index.js').Callback;
Loading
Loading