Skip to content

Commit

Permalink
Use @types/nlcst
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 27, 2021
1 parent e0e1fe8 commit 95fd8db
Show file tree
Hide file tree
Showing 24 changed files with 136 additions and 81 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
node_modules/
coverage/
packages/*/*.d.ts
packages/retext/*.d.ts
packages/retext-dutch/lib/*.d.ts
packages/retext-english/lib/*.d.ts
packages/retext-latin/lib/*.d.ts
packages/retext-stringify/lib/*.d.ts
/*.d.ts
.DS_Store
*.log
*.d.ts
yarn.lock
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
},
"type": "module",
"workspaces": [
"packages/retext-latin",
"packages/retext-english",
"packages/retext-dutch",
"packages/retext-stringify",
"packages/retext"
],
"packages/retext-latin",
"packages/retext-english",
"packages/retext-dutch",
"packages/retext-stringify",
"packages/retext"
],
"devDependencies": {
"@types/tape": "^4.0.0",
"c8": "^7.0.0",
Expand All @@ -33,7 +33,6 @@
"xo": "^0.44.0"
},
"scripts": {
"postinstall": "lerna bootstrap --no-ci",
"build": "npm run build --workspaces && rimraf \"*.d.ts\" && tsc && type-coverage",
"todo": "remark -qfo && ",
"format": "prettier . -w --loglevel warn && xo --fix",
Expand Down
8 changes: 8 additions & 0 deletions packages/retext-dutch/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This wrapper exists because JS in TS can’t export a `@type` of a function.
import type {Root} from 'nlcst'
import type {Plugin, ParserClass} from 'unified'

export const Parser: ParserClass<Root>

declare const retextDutch: Plugin<void[], string, Root>
export default retextDutch
16 changes: 2 additions & 14 deletions packages/retext-dutch/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
*/
import retextDutch, {Parser} from './lib/index.js'

import {unherit} from 'unherit'
// @ts-expect-error: untyped.
import {ParseDutch as Parser} from 'parse-dutch'

// Untyped.
// type-coverage:ignore-next-line
export {Parser}

/** @type {Plugin} */
export default function retextDutch() {
Object.assign(this, {Parser: unherit(Parser)})
}
export default retextDutch
15 changes: 15 additions & 0 deletions packages/retext-dutch/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @typedef {import('nlcst').Root} Root
*/

import {unherit} from 'unherit'
// @ts-expect-error: untyped.
import {ParseDutch} from 'parse-dutch'

/** @type {import('unified').ParserClass<Root>} */
export const Parser = ParseDutch

/** @type {import('unified').Plugin<void[], string, Root>} */
export default function retextDutch() {
Object.assign(this, {Parser: unherit(ParseDutch)})
}
4 changes: 3 additions & 1 deletion packages/retext-dutch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/nlcst": "^1.0.0",
"parse-dutch": "^5.0.0",
"unherit": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
"build": "rimraf \"lib/**/*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
Expand Down
2 changes: 1 addition & 1 deletion packages/retext-dutch/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
"include": ["lib/**/*.js"]
}
8 changes: 8 additions & 0 deletions packages/retext-english/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This wrapper exists because JS in TS can’t export a `@type` of a function.
import type {Root} from 'nlcst'
import type {Plugin, ParserClass} from 'unified'

export const Parser: ParserClass<Root>

declare const retextEnglish: Plugin<void[], string, Root>
export default retextEnglish
16 changes: 2 additions & 14 deletions packages/retext-english/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
*/
import retextEnglish, {Parser} from './lib/index.js'

import {unherit} from 'unherit'
// @ts-expect-error: untyped.
import {ParseEnglish as Parser} from 'parse-english'

// Untyped.
// type-coverage:ignore-next-line
export {Parser}

/** @type {Plugin} */
export default function retextEnglish() {
Object.assign(this, {Parser: unherit(Parser)})
}
export default retextEnglish
15 changes: 15 additions & 0 deletions packages/retext-english/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @typedef {import('nlcst').Root} Root
*/

import {unherit} from 'unherit'
// @ts-expect-error: untyped.
import {ParseEnglish} from 'parse-english'

/** @type {import('unified').ParserClass<Root>} */
export const Parser = ParseEnglish

/** @type {import('unified').Plugin<void[], string, Root>} */
export default function retextEnglish() {
Object.assign(this, {Parser: unherit(ParseEnglish)})
}
4 changes: 3 additions & 1 deletion packages/retext-english/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/nlcst": "^1.0.0",
"parse-english": "^5.0.0",
"unherit": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
"build": "rimraf \"lib/**/*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
Expand Down
2 changes: 1 addition & 1 deletion packages/retext-english/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
"include": ["lib/**/*.js"]
}
8 changes: 8 additions & 0 deletions packages/retext-latin/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This wrapper exists because JS in TS can’t export a `@type` of a function.
import type {Root} from 'nlcst'
import type {Plugin, ParserClass} from 'unified'

export const Parser: ParserClass<Root>

declare const retextLatin: Plugin<void[], string, Root>
export default retextLatin
16 changes: 2 additions & 14 deletions packages/retext-latin/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
*/
import retextLatin, {Parser} from './lib/index.js'

import {unherit} from 'unherit'
// @ts-expect-error: untyped.
import {ParseLatin as Parser} from 'parse-latin'

// Untyped.
// type-coverage:ignore-next-line
export {Parser}

/** @type {Plugin} */
export default function retextLatin() {
Object.assign(this, {Parser: unherit(Parser)})
}
export default retextLatin
15 changes: 15 additions & 0 deletions packages/retext-latin/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @typedef {import('nlcst').Root} Root
*/

import {unherit} from 'unherit'
// @ts-expect-error: untyped.
import {ParseLatin} from 'parse-latin'

/** @type {import('unified').ParserClass<Root>} */
export const Parser = ParseLatin

/** @type {import('unified').Plugin<void[], string, Root>} */
export default function retextLatin() {
Object.assign(this, {Parser: unherit(ParseLatin)})
}
4 changes: 3 additions & 1 deletion packages/retext-latin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/nlcst": "^1.0.0",
"parse-latin": "^5.0.0",
"unherit": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
"build": "rimraf \"lib/**/*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
Expand Down
2 changes: 1 addition & 1 deletion packages/retext-latin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
"include": ["lib/**/*.js"]
}
6 changes: 6 additions & 0 deletions packages/retext-stringify/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// This wrapper exists because JS in TS can’t export a `@type` of a function.
import type {Root} from 'nlcst'
import type {Plugin} from 'unified'

declare const retextStringify: Plugin<void[], Root, string>
export default retextStringify
20 changes: 2 additions & 18 deletions packages/retext-stringify/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
/**
* @typedef {import('unified').Plugin<[]>} Plugin
* @typedef {import('unist').Node} Node
*/
import retextStringify from './lib/index.js'

import {toString} from 'nlcst-to-string'

/** @type {Plugin} */
export default function retextStringify() {
Object.assign(this, {Compiler})
}

/**
* @param {Node} tree
* @returns {string}
*/
function Compiler(tree) {
return toString(tree)
}
export default retextStringify
15 changes: 15 additions & 0 deletions packages/retext-stringify/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* @typedef {import('nlcst').Root} Root
*/

import {toString} from 'nlcst-to-string'

/** @type {import('unified').Plugin<void[], Root, string>} */
export default function retextStringify() {
Object.assign(this, {Compiler})
}

/** @type {import('unified').CompilerFunction<Root, string>} */
function Compiler(tree) {
return toString(tree)
}
5 changes: 3 additions & 2 deletions packages/retext-stringify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/unist": "^2.0.0",
"@types/nlcst": "^1.0.0",
"nlcst-to-string": "^3.0.0",
"unified": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
"build": "rimraf \"lib/**/*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
Expand Down
2 changes: 1 addition & 1 deletion packages/retext-stringify/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
"include": ["lib/**/*.js"]
}
1 change: 1 addition & 0 deletions packages/retext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"index.js"
],
"dependencies": {
"@types/nlcst": "^1.0.0",
"retext-latin": "^3.0.0",
"retext-stringify": "^3.0.0",
"unified": "^10.0.0"
Expand Down
12 changes: 9 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
/**
* @typedef {import('nlcst').Root} Root
* @typedef {import('nlcst').Content} Content
* @typedef {Root|Content} Node
*/

import test from 'tape'
import {removePosition} from 'unist-util-remove-position'
import {assert} from 'nlcst-test'
import {u} from 'unist-builder'
import {unified} from './packages/retext/node_modules/unified/index.js'
import {retext} from './packages/retext/index.js'
import {unified} from 'unified'
import {retext} from 'retext'

const parsers = ['latin', 'english', 'dutch']

Expand Down Expand Up @@ -39,7 +45,7 @@ function eachParser(name) {

const fp = './packages/retext-' + name + '/index.js'

/** @type {import('./packages/retext/node_modules/unified').Plugin<[]>} */
/** @type {import('unified').Plugin<void[], string, Root>} */
// type-coverage:ignore-next-line
const plugin = (await import(fp)).default

Expand Down

0 comments on commit 95fd8db

Please sign in to comment.