Skip to content

Commit 1dfbc06

Browse files
committed
Update unified, vfile, etc
1 parent 791abf3 commit 1dfbc06

File tree

4 files changed

+53
-23
lines changed

4 files changed

+53
-23
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import process from 'node:process'
22
import path from 'node:path'
33
// @ts-expect-error: hush
44
import gitDiffTree from 'git-diff-tree'
5-
import {findUpOne} from 'vfile-find-up'
5+
import {findUp} from 'vfile-find-up'
66

77
const own = {}.hasOwnProperty
88

@@ -61,7 +61,7 @@ export default function diff() {
6161
if (own.call(cache, base)) {
6262
tick(cache[base])
6363
} else {
64-
findUpOne('.git', file.dirname, (error, git) => {
64+
findUp('.git', file.dirname, (error, git) => {
6565
// Never happens.
6666
/* c8 ignore next */
6767
if (error) return next(error)

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@
3535
],
3636
"dependencies": {
3737
"git-diff-tree": "^1.0.0",
38-
"vfile-find-up": "^6.0.0"
38+
"vfile-find-up": "^7.0.0"
3939
},
4040
"devDependencies": {
41+
"@types/nlcst": "^2.0.0",
4142
"@types/rimraf": "^3.0.0",
4243
"@types/tape": "^5.0.0",
4344
"c8": "^8.0.0",
44-
"nlcst-to-string": "^3.0.0",
45+
"nlcst-to-string": "^4.0.0",
46+
"parse-english": "^7.0.0",
4547
"prettier": "^3.0.0",
4648
"remark-cli": "^11.0.0",
4749
"remark-preset-wooorm": "^9.0.0",
48-
"retext-english": "^4.0.0",
49-
"retext-stringify": "^3.0.0",
5050
"rimraf": "^3.0.0",
5151
"tape": "^5.0.0",
52-
"to-vfile": "^7.0.0",
52+
"to-vfile": "^8.0.0",
5353
"type-coverage": "^2.0.0",
5454
"typescript": "^5.0.0",
55-
"unified": "^10.0.0",
56-
"unist-util-visit": "^4.0.0",
55+
"unified": "^11.0.0",
56+
"unist-util-visit": "^5.0.0",
5757
"xo": "^0.56.0"
5858
},
5959
"scripts": {

test/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import fs from 'node:fs'
44
import path from 'node:path'
55
import {promisify} from 'node:util'
66
import test from 'tape'
7-
import {toVFile} from 'to-vfile'
7+
import {toVFile, write} from 'to-vfile'
88
import rimraf from 'rimraf'
99
import {processor} from './processor.js'
1010

@@ -69,15 +69,15 @@ test('diff() (travis)', async (t) => {
6969
'should set messages'
7070
)
7171

72-
await toVFile.write(fileOne)
72+
await write(fileOne)
7373

7474
await exec('git add example.txt')
7575
await exec('git commit -m one')
7676
const resultInitial = await exec('git rev-parse HEAD')
7777
const initial = resultInitial.stdout.trim()
7878

7979
// Change files.
80-
await toVFile.write({path: 'example.txt', value: stepTwo})
80+
await write({path: 'example.txt', value: stepTwo})
8181
await exec('git add example.txt')
8282
await exec('git commit -m two')
8383
const resultFinal = await exec('git rev-parse HEAD')
@@ -117,8 +117,8 @@ test('diff() (travis)', async (t) => {
117117
)
118118

119119
// New file.
120-
await toVFile.write({path: 'example.txt', value: stepThree})
121-
await toVFile.write({path: 'new.txt', value: other})
120+
await write({path: 'example.txt', value: stepThree})
121+
await write({path: 'new.txt', value: other})
122122
await exec('git add example.txt new.txt')
123123
await exec('git commit -m three')
124124
const resultNew = await exec('git rev-parse HEAD')
@@ -168,12 +168,12 @@ test('diff() (GitHub Actions)', async (t) => {
168168

169169
await exec('git init')
170170
// Add initial file.
171-
await toVFile.write({path: 'example.txt', value: stepOne})
171+
await write({path: 'example.txt', value: stepOne})
172172
await exec('git add example.txt')
173173
await exec('git commit -m one')
174174

175175
// Change file.
176-
await toVFile.write({path: 'example.txt', value: stepTwo})
176+
await write({path: 'example.txt', value: stepTwo})
177177
await exec('git add example.txt')
178178
await exec('git commit -m two')
179179
const resultInitial = await exec('git rev-parse HEAD')
@@ -197,10 +197,10 @@ test('diff() (GitHub Actions)', async (t) => {
197197
await exec('git checkout -b other-branch')
198198

199199
// Change file.
200-
await toVFile.write({path: 'example.txt', value: stepThree})
200+
await write({path: 'example.txt', value: stepThree})
201201
await exec('git add example.txt')
202202
await exec('git commit -m three')
203-
await toVFile.write({path: 'example.txt', value: stepFour})
203+
await write({path: 'example.txt', value: stepFour})
204204
await exec('git add example.txt')
205205
await exec('git commit -m four')
206206
const final = await exec('git rev-parse HEAD')

test/processor.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,43 @@
1+
/**
2+
* @typedef {import('nlcst').Root} Root
3+
*/
4+
15
import {unified} from 'unified'
2-
import retextEnglish from 'retext-english'
3-
import retextStringify from 'retext-stringify'
4-
import {visit} from 'unist-util-visit'
56
import {toString} from 'nlcst-to-string'
7+
import {ParseEnglish} from 'parse-english'
8+
import {visit} from 'unist-util-visit'
69
import unifiedDiff from '../index.js'
710

11+
// To do: use `retext-english`, `retext-stringify` when they are released.
12+
// import retextEnglish from 'retext-english'
13+
// import retextStringify from 'retext-stringify'
14+
815
export const processor = unified()
9-
.use(retextEnglish)
10-
.use(retextStringify)
16+
.use(
17+
/** @type {import('unified').Plugin<[], string, Root>} */
18+
// @ts-expect-error: TS doesn’t understand `this`.
19+
function () {
20+
this.parser = parser
21+
/** @type {import('unified').Parser<Root>} */
22+
function parser(value) {
23+
const parser = new ParseEnglish()
24+
const node = parser.parse(value)
25+
return node
26+
}
27+
}
28+
)
29+
.use(
30+
/** @type {import('unified').Plugin<[], Root, string>} */
31+
// @ts-expect-error: TS doesn’t understand `this`.
32+
function () {
33+
// @ts-expect-error: TS doesn’t understand `this`.
34+
this.compiler = compiler
35+
/** @type {import('unified').Compiler<Root, string>} */
36+
function compiler(node) {
37+
return toString(node)
38+
}
39+
}
40+
)
1141
.use(() => (tree, file) => {
1242
visit(tree, 'WordNode', (node) => {
1343
if (/lorem/i.test(toString(node))) {

0 commit comments

Comments
 (0)