-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
355 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
coverage/ | ||
node_modules/ | ||
.DS_Store | ||
*.d.ts | ||
*.log | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
/** | ||
* @typedef {import('./lib/index.js').Options} Options | ||
*/ | ||
|
||
import remarkUsage from './lib/index.js' | ||
|
||
export default remarkUsage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
/** | ||
* @typedef {import('mdast').Root} Root | ||
* @typedef {import('vfile').VFile} VFile | ||
* @typedef {import('type-fest').PackageJson} PackageJson | ||
* @typedef {import('../index.js').Options} Options | ||
*/ | ||
|
||
import url from 'url' | ||
import {resolve} from 'import-meta-resolve' | ||
import {nanoid} from 'nanoid' | ||
import {relativeModule} from '../util/relative-module.js' | ||
|
||
/** @param {{tree: Root, file: VFile, options: Options, pkg: PackageJson|undefined, pkgRoot: string, main?: string|undefined, name?: string|undefined, id?: string}} ctx */ | ||
export async function config(ctx) { | ||
const options = ctx.options | ||
const pkg = ctx.pkg || {} | ||
const cwd = ctx.file.cwd | ||
const mainRoot = url.pathToFileURL(options.main ? cwd : ctx.pkgRoot || cwd) | ||
const mainId = relativeModule(options.main || pkg.main || 'index.js') | ||
/** @type {string|undefined} */ | ||
let main | ||
|
||
try { | ||
main = await resolve(mainId, mainRoot.href + '/') | ||
main = await resolve( | ||
mainId, | ||
url.pathToFileURL(options.main ? cwd : ctx.pkgRoot || cwd).href + '/' | ||
) | ||
} catch {} | ||
|
||
ctx.cwd = cwd | ||
ctx.main = main | ||
ctx.name = options.name || pkg.name || null | ||
ctx.name = options.name || pkg.name || undefined | ||
ctx.id = 'remark-usage-example-' + nanoid().toLowerCase() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.