Skip to content

Commit

Permalink
refactor($shared-utils): migrate to typescript (vuejs#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz authored Dec 8, 2018
1 parent e963731 commit e599c05
Show file tree
Hide file tree
Showing 60 changed files with 729 additions and 462 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages/@vuepress/shared-utils/lib
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ node_modules
.temp
TODOs.md
vuepress
packages/@vuepress/shared-utils/lib/
types
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
"scripts": {
"bootstrap": "lerna bootstrap",
"boot": "node scripts/bootstrap.js",
"dev": "yarn workspace docs dev",
"build": "yarn workspace docs build",
"dev": "yarn tsc && yarn workspace docs dev",
"build": "yarn tsc && yarn workspace docs build",
"show-help": "yarn workspace docs show-help",
"dev:blog": "yarn workspace blog dev",
"build:blog": "yarn workspace blog build",
"register-vuepress": "lerna exec --scope vuepress -- yarn link",
"lint": "eslint --fix packages/**/*.js packages/**/*.vue packages/**/bin/*",
"release": "yarn --pure-lockfile && node scripts/release.js",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"test": "node scripts/test.js"
"test": "node scripts/test.js",
"tsc": "lerna run tsc"
},
"gitHooks": {
"pre-commit": "lint-staged"
Expand All @@ -39,6 +40,14 @@
"lint-staged": "^7.0.4",
"minimist": "^1.2.0",
"yorkie": "^1.0.3",
"inquirer": "^6.2.0"
"inquirer": "^6.2.0",
"typescript": "^3.2.2",
"@types/node": "^10.12.12",
"@types/lru-cache": "^4.1.1",
"@types/fs-extra": "^5.0.4",
"@types/semver": "^5.5.0",
"@types/hash-sum": "^1.0.0",
"@types/globby": "^8.0.0",
"@types/escape-html": "^0.0.20"
}
}
2 changes: 1 addition & 1 deletion packages/@vuepress/core/lib/prepare/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const {
getPermalink,
extractHeaders,
parseFrontmatter,
parseVueFrontmatter
parseVueFrontmatter: { parse: parseVueFrontmatter }
} = require('@vuepress/shared-utils')

/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import deeplyParseHeaders from '../src/deeplyParseHeaders'

test('deeplyParseHeaders', () => {
const asserts: Record<string, string> = {
// Remove tail html
'# `H1` <Comp></Comp>': '# H1',
'# *H1* <Comp/>': '# H1',

// Reserve code-wrapped tail html
'# `H1` `<Comp></Comp>`': '# H1 <Comp></Comp>',
'# *H1* `<Comp/>`': '# H1 <Comp/>',

// Remove leading html
'# <Comp></Comp> `H1`': '# H1',
'# <Comp/> *H1*': '# H1',

// Reserve code-wrapped leading html
'# `<Comp></Comp>` `H1`': '# <Comp></Comp> H1',
'# `<Comp/>` *H1*': '# <Comp/> H1',

// Remove middle html
'# `H1` <Comp></Comp> `H2`': '# H1 H2',
'# `H1` <Comp/> `H2`': '# H1 H2',

// Reserve middle html
'# `H1` `<Comp></Comp>` `H2`': '# H1 <Comp></Comp> H2',
'# `H1` `<Comp/>` `H2`': '# H1 <Comp/> H2'
}

Object.keys(asserts).forEach(input => {
expect(deeplyParseHeaders(input)).toBe(asserts[input])
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fileToPath from '../lib/fileToPath'
import fileToPath from '../src/fileToPath'

test('fileToPath', () => {
const asserts = {
const asserts: Record<string, string> = {
'README.md': '/',
'foo/README.md': '/foo/',
'foo.md': '/foo.html',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isIndexFile from '../lib/isIndexFile'
import { isIndexFile } from '../src/isIndexFile'

test('isIndexFile', () => {
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import {
getThemeResolver,
getPluginResolver,
resolveScopePackage
} from '../lib/moduleResolver'
} from '../src/moduleResolver'
import hash from 'hash-sum'

const MOCK_RELATIVE = '../../../../__mocks__'

function loadMockModule (name) {
function loadMockModule (name: string) {
return require(`${MOCK_RELATIVE}/${name}`)
}

function resolveMockModule (name) {
function resolveMockModule (name: string) {
return path.resolve(__dirname, `${MOCK_RELATIVE}/${name}`)
}

Expand All @@ -46,14 +46,14 @@ describe('resolveScopePackage', () => {

test('incorrect format', () => {
const pkg2 = resolveScopePackage('vuepress/plugin-a')
expect(pkg2).toBe(null)
expect(pkg2).toEqual({ "name": "", "org": "" })

const pkg3 = resolveScopePackage('vuepress-plugin-a')
expect(pkg3).toBe(null)
expect(pkg3).toEqual({ "name": "", "org": "" })
})
})

const getBaseAsserts = (type) => [
const getBaseAsserts = (type: string) => [
{ input: 'a', output: ['a', `vuepress-${type}-a`] },
{ input: `vuepress-${type}-a`, output: ['a', `vuepress-${type}-a`] },
{ input: '@vuepress/a', output: ['@vuepress/a', `@vuepress/${type}-a`] },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import parseHeaders from '../lib/parseHeaders'
import parseHeaders from '../src/parseHeaders'

describe('parseHeaders', () => {
test('should unescape html', () => {
Expand All @@ -7,7 +7,7 @@ describe('parseHeaders', () => {
})

test('should remove markdown tokens correctly', () => {
const asserts = {
const asserts: Record<string, string> = {
// #238
'[vue](vuejs.org)': 'vue',
'`vue`': 'vue',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import removeNonCodeWrappedHTML from '../src/removeNonCodeWrappedHTML'

test('removeNonCodeWrappedHTML', () => {
const asserts: Record<string, string> = {
// Remove tail html
'# H1 <Comp></Comp>': '# H1 ',
'# H1<Comp></Comp>': '# H1',
'# H1 <Comp a="b"></Comp>': '# H1 ',
'# H1<Comp a="b"></Comp>': '# H1',
'# H1 <Comp/>': '# H1 ',
'# H1<Comp/>': '# H1',
'# H1 <Comp a="b"/>': '# H1 ',
'# H1<Comp a="b"/>': '# H1',

// Reserve code-wrapped tail html
'# H1 `<Comp></Comp>`': '# H1 `<Comp></Comp>`',
'# H1 `<Comp a="b"></Comp>`': '# H1 `<Comp a="b"></Comp>`',
'# H1 `<Comp/>`': '# H1 `<Comp/>`',
'# H1 `<Comp a="b"/>`': '# H1 `<Comp a="b"/>`',

// Remove leading html
'# <Comp></Comp> H1': '# H1',
'# <Comp></Comp>H1': '# H1',
'# <Comp a="b"></Comp> H1': '# H1',
'# <Comp a="b"></Comp>H1': '# H1',
'# <Comp/> H1': '# H1',
'# <Comp/>H1': '# H1',
'# <Comp a="b"/> H1': '# H1',
'# <Comp a="b"/>H1': '# H1',

// Reserve code-wrapped leading html
'# `<Comp></Comp>` H1': '# `<Comp></Comp>` H1',
'# `<Comp a="b"></Comp>` H1': '# `<Comp a="b"></Comp>` H1',
'# `<Comp/>` H1': '# `<Comp/>` H1',
'# `<Comp a="b"/>` H1': '# `<Comp a="b"/>` H1',

// Remove middle html
'# H1 <Comp></Comp> H2': '# H1 H2',
'# H1 <Comp a="b"></Comp> H2': '# H1 H2',
'# H1 <Comp/> H2': '# H1 H2',
'# H1 <Comp a="b"/> H2': '# H1 H2',

// Reserve code-wrapped middle html
'# H1 `<Comp></Comp>` H2': '# H1 `<Comp></Comp>` H2',
'# H1 `<Comp a="b"></Comp>` H2': '# H1 `<Comp a="b"></Comp>` H2',
'# H1 `<Comp/>` H2': '# H1 `<Comp/>` H2',
'# H1 `<Comp a="b"/>` H2': '# H1 `<Comp a="b"/>` H2'
}

Object.keys(asserts).forEach(input => {
expect(removeNonCodeWrappedHTML(input)).toBe(asserts[input])
})
})
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import unescapeHtml from '../lib/unescapeHtml'
import unescapeHtml from '../src/unescapeHtml'

test('should unescape html', () => {
const input = '&lt;div&gt;'
Expand Down
39 changes: 0 additions & 39 deletions packages/@vuepress/shared-utils/index.js

This file was deleted.

10 changes: 0 additions & 10 deletions packages/@vuepress/shared-utils/lib/compose.js

This file was deleted.

Loading

0 comments on commit e599c05

Please sign in to comment.