Skip to content

Commit

Permalink
Update @types/mdast, utilities, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Sep 25, 2023
1 parent 8019890 commit 9ca9d6d
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 30 deletions.
2 changes: 1 addition & 1 deletion lib/generate/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export async function config(ctx) {
let main

try {
main = await resolve(
main = resolve(
mainId,
url.pathToFileURL(options.main ? cwd : ctx.pkgRoot || cwd).href + '/'
)
Expand Down
15 changes: 10 additions & 5 deletions lib/generate/find-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function findExplicitExample(cwd, example) {
*/
async function findImplicitExample(cwd) {
const from = pathToFileURL(cwd).href + '/'
const promises = [
const examples = [
'./example.js',
'./example/index.js',
'./examples.js',
Expand All @@ -50,16 +50,21 @@ async function findImplicitExample(cwd) {
'./doc/example/index.js',
'./docs/example.js',
'./docs/example/index.js'
].map((d) => resolve(d, from))
].map((d) => {
try {
return resolve(d, from)
} catch {
return undefined
}
})

const examples = await Promise.allSettled(promises)
let index = -1

while (++index < examples.length) {
const example = examples[index]

if (example.status === 'fulfilled') {
return example.value
if (example) {
return example
}
}
}
4 changes: 2 additions & 2 deletions lib/generate/find-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

import path from 'node:path'
import {findUpOne} from 'vfile-find-up'
import {findUp} from 'vfile-find-up'
import {read} from 'to-vfile'

/** @param {{tree: Root, file: VFile, options: Options, pkg?: PackageJson, pkgRoot?: string | undefined}} ctx */
export async function findPackage(ctx) {
const file = ctx.file
const pkgFile = await findUpOne(
const pkgFile = await findUp(
'package.json',
file.path ? path.dirname(path.resolve(file.cwd, file.path)) : file.cwd
)
Expand Down
3 changes: 2 additions & 1 deletion lib/generate/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export function generate(ctx) {
* @returns {BlockContent[]}
*/
function comment(token) {
const tree = removePosition(processor.parse(token.values.join('')))
const tree = processor.parse(token.values.join(''))
removePosition(tree)
// @ts-expect-error: Assume block content in `root`.
return tree.children
}
Expand Down
2 changes: 1 addition & 1 deletion lib/generate/instrument.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function instrument(ctx) {

const promises = nodes.map(async (node) => {
try {
const resolved = await resolve(node.value, ctx.exampleFileUrl)
const resolved = resolve(node.value, ctx.exampleFileUrl)

if (resolved === ctx.main) {
// Babel always adds raw, but just to be sure.
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function remarkUsage(options = {}) {
])
}

return next(error)
return next(error || undefined)
}
)
}
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,28 @@
],
"dependencies": {
"@babel/core": "^7.0.0",
"@types/mdast": "^3.0.0",
"import-meta-resolve": "^2.0.0",
"mdast-util-heading-range": "^3.0.0",
"nanoid": "^3.0.0",
"remark-parse": "^10.0.0",
"to-vfile": "^7.0.0",
"@types/mdast": "^4.0.0",
"import-meta-resolve": "^3.0.0",
"mdast-util-heading-range": "^4.0.0",
"nanoid": "^5.0.0",
"remark-parse": "^11.0.0",
"to-vfile": "^8.0.0",
"trough": "^2.0.0",
"unified": "^10.0.0",
"unist-util-remove-position": "^4.0.0",
"vfile": "^5.0.2",
"vfile-find-up": "^6.0.0"
"unified": "^11.0.0",
"unist-util-remove-position": "^5.0.0",
"vfile": "^6.0.0",
"vfile-find-up": "^7.0.0"
},
"devDependencies": {
"@types/babel__core": "^7.0.0",
"@types/node": "^20.0.0",
"c8": "^8.0.0",
"prettier": "^3.0.0",
"remark": "^14.0.0",
"remark": "^15.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"type-fest": "^2.0.0",
"type-fest": "^4.0.0",
"typescript": "^5.0.0",
"xo": "^0.56.0"
},
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/log-handling/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ var pi = require('pi')

Log an object:

{}
```
{}
```

Log nothing, *twice*:

Expand Down
10 changes: 6 additions & 4 deletions test/fixtures/multiple-calls/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ while (++i < 5) {
Print `Number(pi) + i`:
4.141500000000001
5.141500000000001
6.141500000000001
7.141500000000001
```
4.141500000000001
5.141500000000001
6.141500000000001
7.141500000000001
```
```javascript
}
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/no-main/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ var result = a + b

Yields:

3
```
3
```
4 changes: 3 additions & 1 deletion test/fixtures/stdout/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
process.stdout.write('foo')
```

bar
```
bar
```

```javascript
process.stdout.write('baz')
Expand Down

0 comments on commit 9ca9d6d

Please sign in to comment.