Skip to content

Commit

Permalink
feat(types): extract types from shared package
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Jul 11, 2022
1 parent 4f27884 commit 5fc56ce
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 46 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-frontmatter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"test": "vitest"
},
"dependencies": {
"@mdit-vue/shared": "workspace:*",
"@mdit-vue/types": "workspace:*",
"@types/markdown-it": "^12.2.3",
"gray-matter": "^4.0.3",
"markdown-it": "^13.0.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-frontmatter/src/frontmatter-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MarkdownItEnv } from '@mdit-vue/shared';
import type { MarkdownItEnv } from '@mdit-vue/types';
import grayMatter from 'gray-matter';
import type { PluginWithOptions } from 'markdown-it';
import type { FrontmatterPluginOptions } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-frontmatter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface FrontmatterPluginOptions {
renderExcerpt?: boolean;
}

declare module '@mdit-vue/shared' {
declare module '@mdit-vue/types' {
interface MarkdownItEnv {
excerpt?: string;
frontmatter?: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MarkdownItEnv } from '@mdit-vue/shared';
import type { MarkdownItEnv } from '@mdit-vue/types';
import MarkdownIt from 'markdown-it';
import { describe, expect, it } from 'vitest';
import { frontmatterPlugin } from '../src';
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-headers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"@mdit-vue/shared": "workspace:*",
"@mdit-vue/types": "workspace:*",
"@types/markdown-it": "^12.2.3",
"markdown-it": "^13.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-headers/src/headers-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
slugify as defaultSlugify,
resolveHeadersFromTokens,
} from '@mdit-vue/shared';
import type { MarkdownItEnv, MarkdownItHeader } from '@mdit-vue/shared';
import type { MarkdownItEnv, MarkdownItHeader } from '@mdit-vue/types';
import type { PluginWithOptions } from 'markdown-it';
import type { HeadersPluginOptions } from './types';

Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-headers/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MarkdownItHeader } from '@mdit-vue/shared';
import type { MarkdownItHeader } from '@mdit-vue/types';

export type { MarkdownItHeader };

Expand Down Expand Up @@ -30,7 +30,7 @@ export interface HeadersPluginOptions {
level?: number[];
}

declare module '@mdit-vue/shared' {
declare module '@mdit-vue/types' {
interface MarkdownItEnv {
headers?: MarkdownItHeader[];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-sfc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"test": "vitest"
},
"dependencies": {
"@mdit-vue/shared": "workspace:*",
"@mdit-vue/types": "workspace:*",
"@types/markdown-it": "^12.2.3",
"markdown-it": "^13.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-sfc/src/sfc-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MarkdownItEnv } from '@mdit-vue/shared';
import type { MarkdownItEnv } from '@mdit-vue/types';
import type { PluginWithOptions } from 'markdown-it';
import type { SfcPluginOptions } from './types';

Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-sfc/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface SfcPluginOptions {
customBlocks?: string[];
}

declare module '@mdit-vue/shared' {
declare module '@mdit-vue/types' {
interface MarkdownItEnv {
sfcBlocks?: string[];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-sfc/tests/sfc-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MarkdownItEnv } from '@mdit-vue/shared';
import type { MarkdownItEnv } from '@mdit-vue/types';
import MarkdownIt from 'markdown-it';
import { describe, expect, it } from 'vitest';
import { sfcPlugin } from '../src';
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-title/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"@mdit-vue/shared": "workspace:*",
"@mdit-vue/types": "workspace:*",
"@types/markdown-it": "^12.2.3",
"markdown-it": "^13.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-title/src/title-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { resolveTitleFromToken } from '@mdit-vue/shared';
import type { MarkdownItEnv } from '@mdit-vue/shared';
import type { MarkdownItEnv } from '@mdit-vue/types';
import type { PluginSimple } from 'markdown-it';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-title/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export {};

declare module '@mdit-vue/shared' {
declare module '@mdit-vue/types' {
interface MarkdownItEnv {
title?: string;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-title/tests/title-plugin.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { MarkdownItEnv } from '@mdit-vue/shared';
import type { MarkdownItEnv } from '@mdit-vue/types';
import MarkdownIt from 'markdown-it';
import emojiPlugin from 'markdown-it-emoji';
import { describe, expect, it } from 'vitest';
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-toc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"@mdit-vue/shared": "workspace:*",
"@mdit-vue/types": "workspace:*",
"@types/markdown-it": "^12.2.3",
"markdown-it": "^13.0.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-toc/src/create-render-headers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { htmlEscape } from '@mdit-vue/shared';
import type { MarkdownItHeader } from '@mdit-vue/shared';
import type { MarkdownItHeader } from '@mdit-vue/types';
import type { TocPluginOptions } from './types';

type RenderHeadersFn = (headers: MarkdownItHeader[]) => string;
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-toc/src/toc-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
slugify as defaultSlugify,
resolveHeadersFromTokens,
} from '@mdit-vue/shared';
import type { MarkdownItHeader } from '@mdit-vue/shared';
import type { MarkdownItHeader } from '@mdit-vue/types';
import type { PluginWithOptions } from 'markdown-it';
import { createRenderHeaders } from './create-render-headers';
import { createTocBlockRule } from './create-toc-block-rule';
Expand Down
25 changes: 2 additions & 23 deletions packages/shared/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
# @mdit-vue/shared

[![npm](https://badgen.net/npm/v/@mdit-vue/shared)](https://www.npmjs.com/package/@mdit-vue/plugin-sfc)
[![npm](https://badgen.net/npm/v/@mdit-vue/shared)](https://www.npmjs.com/package/@mdit-vue/shared)

Shared utils and types of mdit-vue.
Shared utils of mdit-vue.

## Install

```sh
npm i @mdit-vue/shared
```

## Usage

Add more properties to `env` via [TypeScript module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation):

```ts
declare module '@mdit-vue/shared' {
interface MarkdownItEnv {
foo?: string[];
}
}
```

```ts
import MarkdownIt from 'markdown-it';
import type { MarkdownItEnv } from '@mdit-vue/shared';

const md = MarkdownIt({ html: true });
const env: MarkdownItEnv = {};
const rendered = md.render('raw markdown text', env);
```
4 changes: 3 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Shared utils and types of mdit-vue",
"keywords": [
"markdown-it",
"vue"
"vue",
"utils"
],
"homepage": "https://github.com/mdit-vue",
"bugs": {
Expand All @@ -31,6 +32,7 @@
"test": "vitest"
},
"dependencies": {
"@mdit-vue/types": "workspace:*",
"@types/markdown-it": "^12.2.3",
"markdown-it": "^13.0.1"
},
Expand Down
1 change: 0 additions & 1 deletion packages/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ export * from './html-unescape';
export * from './resolve-headers-from-tokens';
export * from './resolve-title-from-token';
export * from './slugify';
export * from './types';
2 changes: 1 addition & 1 deletion packages/shared/src/resolve-headers-from-tokens.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { MarkdownItHeader } from '@mdit-vue/types';
import type Token from 'markdown-it/lib/token';
import { resolveTitleFromToken } from './resolve-title-from-token';
import type { MarkdownItHeader } from './types';

/**
* Resolve headers from markdown-it tokens
Expand Down
32 changes: 32 additions & 0 deletions packages/types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# @mdit-vue/types

[![npm](https://badgen.net/npm/v/@mdit-vue/types)](https://www.npmjs.com/package/@mdit-vue/types)

Shared types definition of mdit-vue.

## Install

```sh
npm i @mdit-vue/types
```

## Usage

Add more properties to `env` via [TypeScript module augmentation](https://www.typescriptlang.org/docs/handbook/declaration-merging.html#module-augmentation):

```ts
declare module '@mdit-vue/types' {
interface MarkdownItEnv {
foo?: string[];
}
}
```

```ts
import MarkdownIt from 'markdown-it';
import type { MarkdownItEnv } from '@mdit-vue/types';

const md = MarkdownIt({ html: true });
const env: MarkdownItEnv = {};
const rendered = md.render('raw markdown text', env);
```
11 changes: 11 additions & 0 deletions packages/types/build.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineBuildConfig } from 'unbuild';

export default defineBuildConfig({
clean: true,
declaration: true,
entries: ['src/index'],
rollup: {
emitCJS: true,
inlineDependencies: false,
},
});
39 changes: 39 additions & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@mdit-vue/types",
"version": "0.0.0",
"description": "Shared types definition of mdit-vue",
"keywords": [
"markdown-it",
"vue",
"types"
],
"homepage": "https://github.com/mdit-vue",
"bugs": {
"url": "https://github.com/mdit-vue/mdit-vue/issues"
},
"repository": {
"type": "git",
"url": "git+https://github.com/mdit-vue/mdit-vue.git"
},
"license": "MIT",
"author": "meteorlxy <meteor.lxy@foxmail.com>",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"scripts": {
"build": "unbuild"
},
"devDependencies": {
"unbuild": "^0.7.4"
},
"publishConfig": {
"access": "public"
}
}
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './types';
File renamed without changes.

0 comments on commit 5fc56ce

Please sign in to comment.