Skip to content

Commit

Permalink
feat: export module types (#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Jun 12, 2024
1 parent 6425fec commit b123744
Show file tree
Hide file tree
Showing 32 changed files with 1,557 additions and 163 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Install pnpm
id: pnpm-install
with:
version: 9
version: 9.3.0
- run: pnpm install
- run: pnpm dev:prepare
- run: pnpm lint
Expand All @@ -48,7 +48,7 @@ jobs:
name: Install pnpm
id: pnpm-install
with:
version: 9
version: 9.3.0
- name: Install dependencies
run: pnpm install

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ Now import the `useMarkdownParser` composable we just created along with an expo
import { onBeforeMount, ref, watch } from 'vue'
// Import package exports
import MDCRenderer from '@nuxtjs/mdc/runtime/components/MDCRenderer.vue'
import type { MDCParserResult } from '@nuxtjs/mdc/runtime/types/index'
import type { MDCParserResult } from '@nuxtjs/mdc'
import useMarkdownParser from './composables/useMarkdownParser';
const md = ref(`
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
"test:watch": "vitest watch"
},
"dependencies": {
"@nuxt/kit": "^3.11.2",
"@shikijs/transformers": "^1.6.3",
"@nuxt/kit": "^3.12.1",
"@shikijs/transformers": "^1.6.4",
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.4",
"@vue/compiler-core": "^3.4.27",
Expand Down Expand Up @@ -100,7 +100,7 @@
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.0",
"scule": "^1.3.0",
"shiki": "^1.6.3",
"shiki": "^1.6.4",
"ufo": "^1.5.3",
"unified": "^11.0.4",
"unist-builder": "^4.0.0",
Expand All @@ -111,19 +111,20 @@
"@nuxt/devtools": "latest",
"@nuxt/eslint-config": "^0.3.13",
"@nuxt/module-builder": "^0.7.1",
"@nuxt/schema": "^3.11.2",
"@nuxt/schema": "^3.12.1",
"@nuxt/test-utils": "^3.13.1",
"@nuxt/ui": "^2.16.0",
"@types/node": "^20.14.2",
"changelogen": "^0.5.5",
"eslint": "^9.4.0",
"nuxt": "^3.11.2",
"nuxt": "^3.12.1",
"rehype": "^13.0.1",
"release-it": "^17.3.0",
"typescript": "^5.4.5",
"vitest": "^1.6.0",
"vue-tsc": "^2.0.19"
},
"packageManager": "pnpm@9.3.0",
"release-it": {
"git": {
"commitMessage": "chore(release): release v${version}"
Expand Down
1,646 changes: 1,518 additions & 128 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MdcConfig } from './runtime/types/config'
import type { MdcConfig } from './types/config'

export function defineConfig(config: MdcConfig) {
return config
Expand Down
4 changes: 3 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { defineNuxtModule, extendViteConfig, addComponent, addComponentsDir, cre
import { defu } from 'defu'
import { resolve } from 'pathe'
import type { BundledLanguage } from 'shiki'
import type { ModuleOptions } from './types'
import type { ModuleOptions } from './types/module'
import { registerMDCSlotTransformer } from './utils/vue-mdc-slot'
import * as templates from './templates'
import { addWasmSupport } from './utils'

export * from './types/module'

export const DefaultHighlightLangs: BundledLanguage[] = [
'js',
'jsx',
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/MDC.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { hash } from 'ohash'
import { useAsyncData } from 'nuxt/app'
import { watch, computed, type PropType } from 'vue'
import { parseMarkdown } from '../parser'
import type { MDCParseOptions } from '../types'
import type { MDCParseOptions } from '../../types'
const props = defineProps({
tag: {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/components/MDCRenderer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { kebabCase, pascalCase } from 'scule'
import { find, html } from 'property-information'
import type { VNode, ConcreteComponent, PropType, DefineComponent } from 'vue'
import htmlTags from '../parser/utils/html-tags-list'
import type { MDCElement, MDCNode, MDCRoot, MDCData } from '../types'
import type { MDCElement, MDCNode, MDCRoot, MDCData } from '../../types'
import { flatUnwrap } from '../utils/node'
type CreateElement = typeof h
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/highlighter/rehype-nuxt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { HighlightResult } from '../../types/highlighter'
import { rehypeHighlight as rehypeHighlightUniversal, type RehypeHighlightOption } from './rehype'
import type { HighlightResult } from './types'

const defaults: RehypeHighlightOption = {
theme: {},
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/highlighter/rehype.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Root, Element } from 'hast'
import { visit } from 'unist-util-visit'
import { toString } from 'hast-util-to-string'
import type { Highlighter, MdcThemeOptions } from './types'
import type { Highlighter, MdcThemeOptions } from '../../types/highlighter'

export interface RehypeHighlightOption {
theme?: MdcThemeOptions
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/highlighter/shiki.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
transformerNotationFocus,
transformerNotationHighlight
} from '@shikijs/transformers'
import type { MdcConfig } from '../types/config'
import type { Highlighter } from './types'
import type { MdcConfig } from '../../types/config'
import type { Highlighter } from '../../types/highlighter'

export interface CreateShikiHighlighterOptions {
/* An array of themes to be loaded initially */
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/parser/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { toString } from 'hast-util-to-string'
import Slugger from 'github-slugger'
import type { RootContent, Root } from '../types/hast'
import type { MDCNode, MDCParseOptions, MDCRoot } from '../types'
import type { RootContent, Root } from '../../types/hast'
import type { MDCNode, MDCParseOptions, MDCRoot } from '../../types'
import { validateProps } from './utils/props'

export function compileHast(this: any, options: MDCParseOptions = {}) {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/parser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import remarkParse from 'remark-parse'
import remark2rehype from 'remark-rehype'
import { parseFrontMatter } from 'remark-mdc'
import { defu } from 'defu'
import type { MDCData, MDCElement, MDCParseOptions, MDCParserResult, MDCRoot, Toc } from '../types'
import type { MDCData, MDCElement, MDCParseOptions, MDCParserResult, MDCRoot, Toc } from '../../types'
import { nodeTextContent } from '../utils/node'
import type { MdcConfig } from '../types/config'
import type { MdcConfig } from '../../types/config'
import { useProcessorPlugins } from './utils/plugins'
import { defaults } from './options'
import { generateToc } from './toc'
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/parser/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import rehypeExternalLinks from 'rehype-external-links'
import rehypeSortAttributeValues from 'rehype-sort-attribute-values'
import rehypeSortAttributes from 'rehype-sort-attributes'
import rehypeRaw from 'rehype-raw'
import type { MDCParseOptions } from '../types'
import type { MDCParseOptions } from '../../types'
import handlers from './handlers'

export const defaults: MDCParseOptions = {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/parser/toc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MDCNode, Toc, TocLink, MDCElement, MDCRoot } from '../types'
import type { MDCNode, Toc, TocLink, MDCElement, MDCRoot } from '../../types'
import { flattenNode, flattenNodeText } from '../utils/ast'

const TOC_TAGS = ['h2', 'h3', 'h4', 'h5', 'h6']
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/parser/utils/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-expect-error missing types
import type { Processor } from 'remark-rehype/lib'
import type { MDCParseOptions, RehypePlugin, RemarkPlugin } from '../../types'
import type { MDCParseOptions, RehypePlugin, RemarkPlugin } from '../../../types'

export const useProcessorPlugins = async (
processor: Processor,
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/utils/ast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MDCElement, MDCNode } from '../types'
import type { MDCElement, MDCNode } from '../../types'

export function flattenNodeText(node: MDCNode): string {
if (node.type === 'comment') {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/utils/node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { VNode } from 'vue'
import type { MDCElement, MDCNode, MDCText } from '../types'
import type { MDCElement, MDCNode, MDCText } from '../../types'

/**
* List of text nodes
Expand Down
6 changes: 3 additions & 3 deletions src/shims.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
declare module '#mdc-configs' {
import type { MdcConfig } from './runtime/types/config'
import type { MdcConfig } from './types/config'

function getMdcConfigs(): Promise<MdcConfig[]>
export { getMdcConfigs }
}

declare module '#mdc-imports' {
import type { RehypePlugin, RemarkPlugin } from './runtime/types'
import type { RehypePlugin, RemarkPlugin } from './types'
import type { RehypeHighlightOption } from './runtime/highlighter/rehype'

const remarkPlugins: Record<string, false | RemarkPlugin>
Expand All @@ -16,7 +16,7 @@ declare module '#mdc-imports' {
}

declare module '#mdc-highlighter' {
import type { Highlighter } from '../runtime/highlighter/types'
import type { Highlighter } from './types/highlighter'

const highlighter: Highlighter
export default highlighter
Expand Down
2 changes: 1 addition & 1 deletion src/templates/mdc-highlighter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'node:fs/promises'
import { existsSync } from 'node:fs'
import type { LanguageRegistration, ThemeRegistration } from 'shiki/core'
import type { ModuleOptions } from '../types'
import type { ModuleOptions } from '../types/module'

export async function mdcHighlighter({
options: {
Expand Down
2 changes: 1 addition & 1 deletion src/templates/mdc-imports.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pascalCase } from 'scule'
import type { UnistPlugin } from '../types'
import type { UnistPlugin } from '../types/module'

export async function mdcImports({ options }: any) {
const imports: string[] = []
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types/config.ts → src/types/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Highlighter, HighlighterCore, ShikiTransformer } from 'shiki'
import type { Processor } from 'unified'
import type { MdcThemeOptions, HighlighterOptions } from '../highlighter/types'
import type { MdcThemeOptions, HighlighterOptions } from './highlighter'

export type Awaitable<T> = T | Promise<T>

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions src/runtime/types/index.ts → src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './tree'
export * from './parser'
export * from './toc'
export * from './module'
2 changes: 1 addition & 1 deletion src/types.ts → src/types/module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BundledLanguage, BundledTheme, LanguageRegistration, ThemeRegistrationAny } from 'shiki'
import type { MdcThemeOptions } from './runtime/highlighter/types'
import type { MdcThemeOptions } from './highlighter'

export interface UnistPlugin {
src?: string
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/types/parser.ts → src/types/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Options as RehypeOption } from 'remark-rehype'
import type { RehypeHighlightOption } from '../highlighter/rehype'
import type { RehypeHighlightOption } from '../runtime/highlighter/rehype'
import type { MdcConfig } from './config'
import type { MDCData, MDCRoot } from './tree'
import type { Toc } from './toc'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/markdown/xss.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect, it } from 'vitest'
import { parseMarkdown } from '../utils/parser'
import type { MDCElement } from '../../src/runtime/types'
import type { MDCElement } from '../../src/types'
import { validateProp } from '../../src/runtime/parser/utils/props'

const md = `\
Expand Down
2 changes: 1 addition & 1 deletion test/utils/parser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { vi } from 'vitest'
import { parseMarkdown as _parseMarkDown } from '../../src/runtime/parser'
import type { MDCParseOptions } from '../../src/runtime/types'
import type { MDCParseOptions } from '../../src/types'
import { rehypeHighlight } from '../../src/runtime/highlighter/rehype-nuxt'
import { createShikiHighlighter } from '../../src/runtime/highlighter/shiki'

Expand Down

0 comments on commit b123744

Please sign in to comment.