Skip to content

Commit 7217009

Browse files
Merge pull request #73 from technote-space/release/next-v2.4.23
release: v2.5.0
2 parents 466a46c + 8fdcb23 commit 7217009

26 files changed

+1430
-2451
lines changed

.eslintrc.json renamed to .eslintrc

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"plugin:@typescript-eslint/eslint-recommended"
66
],
77
"plugins": [
8-
"@typescript-eslint"
8+
"@typescript-eslint",
9+
"import"
910
],
1011
"parser": "@typescript-eslint/parser",
1112
"parserOptions": {
@@ -15,7 +16,8 @@
1516
"env": {
1617
"node": true,
1718
"jest": true,
18-
"es6": true
19+
"es6": true,
20+
"browser": true
1921
},
2022
"settings": {
2123
"react": {
@@ -47,12 +49,6 @@
4749
}
4850
}
4951
],
50-
"no-magic-numbers": [
51-
"error",
52-
{
53-
"ignoreArrayIndexes": true
54-
}
55-
],
5652
"eqeqeq": "error",
5753
"block-scoped-var": "error",
5854
"complexity": [
@@ -61,7 +57,6 @@
6157
"maximum": 20
6258
}
6359
],
64-
"curly": "error",
6560
"default-case": "error",
6661
"dot-location": [
6762
"error",
@@ -78,16 +73,6 @@
7873
"after": true
7974
}
8075
],
81-
"id-length": [
82-
"error",
83-
{
84-
"min": 2,
85-
"properties": "never",
86-
"exceptions": [
87-
"$"
88-
]
89-
}
90-
],
9176
"indent": [
9277
"error",
9378
2,
@@ -119,19 +104,13 @@
119104
}
120105
],
121106
"semi": [
122-
"error",
123-
"always"
107+
"error"
124108
],
125-
"@typescript-eslint/naming-convention": [
126-
"error",
127-
{
128-
"selector": "interface",
129-
"format": ["PascalCase"],
130-
"custom": {
131-
"regex": "^I[A-Z]",
132-
"match": true
133-
}
134-
}
135-
]
109+
"sort-imports": 0,
110+
"import/order": [2, {
111+
"groups": ["type", "builtin", "external", "internal", "parent", "sibling", "index", "object"],
112+
"alphabetize": { "order": "asc", "caseInsensitive": true }
113+
}],
114+
"@typescript-eslint/no-non-null-assertion": "off"
136115
}
137116
}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/.idea
22
/node_modules
33
/coverage
4-
/build
4+
/dist
55
.eslintcache

__tests__/file.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {findMarkdownFiles} from '../src';
2+
import { resolve } from 'path';
3+
import { describe, expect, it, vi } from 'vitest';
4+
import { findMarkdownFiles } from '../src';
45

56
describe('findMarkdownFiles', () => {
67
it('should find markdown files', () => {
7-
const mockLog = jest.spyOn(console, 'log').mockImplementation(() => ({}));
8+
const mockLog = vi.spyOn(console, 'log').mockImplementation(() => ({}));
89
expect(findMarkdownFiles(resolve(__dirname, 'fixtures')).map(info => ({
910
name: info.name,
1011
path: info.path,

__tests__/params.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-magic-numbers */
2-
import {extractParams, getStartSection, getParamsSection} from '../src/lib/params';
3-
import {CLOSING_COMMENT, OPENING_COMMENT} from '../src';
2+
import { describe, expect, it } from 'vitest';
3+
import { CLOSING_COMMENT, OPENING_COMMENT } from '../src';
4+
import { extractParams, getStartSection, getParamsSection } from '../src/lib/params';
45

56
describe('extractParams', () => {
67
const opening = OPENING_COMMENT.replace('\n', ' ');

__tests__/transform-custom-mode.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('run in html mode', () => {
89
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-html.md'), 'utf8');
9-
const headers = transform(content, {mode: 'github.com', isCustomMode: true});
10+
const headers = transform(content, { mode: 'github.com', isCustomMode: true });
1011

1112
expect(headers.toc.split('\n')).toEqual(
1213
['**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',

__tests__/transform-footer.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('add footer', () => {
89
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-custom-title.md'), 'utf8');
9-
const headers = transform(content, {title: '## Table of Contents', footer: '*generated with [TOC Generator](https://github.com/technote-space/toc-generator)*'});
10+
const headers = transform(content, { title: '## Table of Contents', footer: '*generated with [TOC Generator](https://github.com/technote-space/toc-generator)*' });
1011

1112
expect(headers.toc.split('\n')).toEqual(
1213
['## Table of Contents',

__tests__/transform-html.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('given a file that includes html with header tags and maxHeaderLevel 8', () => {
89
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-html.md'), 'utf8');
9-
const headers = transform(content, {mode: 'github.com', maxHeaderLevel: 8});
10+
const headers = transform(content, { mode: 'github.com', maxHeaderLevel: 8 });
1011

1112
expect(headers.toc.split('\n')).toEqual(
1213
['**Table of Contents** *generated with [DocToc](https://github.com/technote-space/doctoc)*',

__tests__/transform-nested-markdown.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('\nhandle inline links and images', () => {

__tests__/transform-not-transformed.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('update only', () => {
89
const content = readFileSync(resolve(__dirname, 'fixtures/readme-update-only.md'), 'utf8');
9-
const headers = transform(content, {updateOnly: true});
10+
const headers = transform(content, { updateOnly: true });
1011

1112
expect(headers.transformed).toBe(false);
1213
expect(headers.reason).toBe('update only');

__tests__/transform-override-params.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('override params (empty toc)', () => {
89
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params1.md'), 'utf8');
9-
const headers = transform(content, {isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*'});
10+
const headers = transform(content, { isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*' });
1011

1112
expect(headers.wrappedToc.split('\n')).toEqual(
1213
[
@@ -36,7 +37,7 @@ describe('transform', () => {
3637

3738
it('override params (not empty toc)', () => {
3839
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params2.md'), 'utf8');
39-
const headers = transform(content, {isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*', footer: 'footer'});
40+
const headers = transform(content, { isNotitle: true, isFolding: false, maxHeaderLevel: 1, entryPrefix: '*', footer: 'footer' });
4041

4142
expect(headers.wrappedToc.split('\n')).toEqual(
4243
[
@@ -69,7 +70,7 @@ describe('transform', () => {
6970

7071
it('not override params', () => {
7172
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-params1.md'), 'utf8');
72-
const headers = transform(content, {isFolding: true, title: 'Test title'});
73+
const headers = transform(content, { isFolding: true, title: 'Test title' });
7374

7475
expect(headers.wrappedToc.split('\n')).toEqual(
7576
[

__tests__/transform-title.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('overwrite existing title', () => {
89
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-custom-title.md'), 'utf8');
9-
const headers = transform(content, {title: '## Table of Contents'});
10+
const headers = transform(content, { title: '## Table of Contents' });
1011

1112
expect(headers.toc.split('\n')).toEqual(
1213
['## Table of Contents',
@@ -34,7 +35,7 @@ describe('transform', () => {
3435

3536
it('clobber existing title', () => {
3637
const content = readFileSync(resolve(__dirname, 'fixtures/readme-with-custom-title.md'), 'utf8');
37-
const headers = transform(content, {isNotitle: true});
38+
const headers = transform(content, { isNotitle: true });
3839

3940
expect(headers.toc.split('\n')).toEqual(
4041
['',

__tests__/transform-weird-headers.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable no-magic-numbers */
2-
import {resolve} from 'path';
3-
import {readFileSync} from 'fs';
4-
import {transform} from '../src';
2+
import { readFileSync } from 'fs';
3+
import { resolve } from 'path';
4+
import { describe, expect, it } from 'vitest';
5+
import { transform } from '../src';
56

67
describe('transform', () => {
78
it('given a file with edge-case header names', () => {

__tests__/transform.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable no-magic-numbers */
2-
import {transform} from '../src';
3-
import {getLinesToToc, matchesStart, matchesEnd} from '../src/lib/transform';
4-
import {OPENING_COMMENT, CLOSING_COMMENT} from '../src';
2+
import { describe, expect, it } from 'vitest';
3+
import { transform } from '../src';
4+
import { OPENING_COMMENT, CLOSING_COMMENT } from '../src';
5+
import { getLinesToToc, matchesStart, matchesEnd } from '../src/lib/transform';
56

67
const check = (
78
name: string,
@@ -499,7 +500,7 @@ describe('transform', () => {
499500
'',
500501
].join('\n');
501502

502-
const res = transform(md, {processAll: true});
503+
const res = transform(md, { processAll: true });
503504

504505
expect(res.transformed).toBe(true);
505506
expect(res.toc.split('\n')).toEqual(

__tests__/utils.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
/* eslint-disable no-magic-numbers */
2-
import {replaceVariables} from '../src/lib/utils';
2+
import { describe, expect, it } from 'vitest';
3+
import { replaceVariables } from '../src/lib/utils';
34

45
describe('replaceVariables', () => {
56
it('should replace variables', () => {
67
expect(replaceVariables('', [])).toBe('');
78
expect(replaceVariables('abc/${test1}/${test2}/${test1}/xyz', [
8-
{key: 'test1', replace: '1'},
9-
{key: 'test3', replace: '3'},
9+
{ key: 'test1', replace: '1' },
10+
{ key: 'test3', replace: '3' },
1011
])).toBe('abc/1/${test2}/1/xyz');
1112
});
1213
});

jest.config.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

package.json

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/doctoc",
3-
"version": "2.4.23",
3+
"version": "2.5.0",
44
"description": "Generates TOC for markdown files of local git repo.",
55
"keywords": [
66
"github",
@@ -29,40 +29,44 @@
2929
"url": "https://technote.space"
3030
}
3131
],
32-
"main": "build/index.js",
33-
"types": "build/index.d.ts",
32+
"type": "module",
33+
"exports": "./dist/index.mjs",
34+
"main": "dist/index.mjs",
3435
"files": [
3536
"build"
3637
],
3738
"scripts": {
38-
"build": "rm -rf ./build && tsc",
39-
"cover": "jest --coverage",
39+
"build": "tsc --emitDeclarationOnly && rollup -c",
40+
"cover": "vitest run --coverage",
4041
"lint": "eslint 'src/**/*.ts' '__tests__/**/*.ts' --cache",
4142
"lint:fix": "eslint --fix 'src/**/*.ts' '__tests__/**/*.ts'",
42-
"test": "yarn lint && yarn cover",
43-
"update": "npx npm-check-updates -u && yarn install && yarn upgrade && yarn audit"
43+
"test": "yarn lint && yarn typecheck && yarn cover",
44+
"typecheck": "tsc --noEmit",
45+
"update": "npm_config_yes=true npx npm-check-updates -u --timeout 100000 && yarn install && yarn upgrade && yarn audit"
4446
},
4547
"dependencies": {
4648
"@technote-space/anchor-markdown-header": "^1.1.36",
4749
"@textlint/markdown-to-ast": "^12.1.1",
48-
"htmlparser2": "^7.2.0",
50+
"htmlparser2": "^8.0.1",
4951
"update-section": "^0.3.3"
5052
},
5153
"devDependencies": {
52-
"@commitlint/cli": "^16.2.3",
53-
"@commitlint/config-conventional": "^16.2.1",
54+
"@commitlint/cli": "^17.0.2",
55+
"@commitlint/config-conventional": "^17.0.2",
56+
"@rollup/plugin-typescript": "^8.3.3",
57+
"@sindresorhus/tsconfig": "^3.0.1",
5458
"@textlint/ast-node-types": "^12.1.1",
55-
"@types/jest": "^27.4.1",
56-
"@types/node": "^17.0.23",
57-
"@typescript-eslint/eslint-plugin": "^5.16.0",
58-
"@typescript-eslint/parser": "^5.16.0",
59-
"eslint": "^8.12.0",
60-
"husky": "^7.0.4",
61-
"jest": "^27.5.1",
62-
"jest-circus": "^27.5.1",
63-
"lint-staged": "^12.3.7",
64-
"ts-jest": "^27.1.4",
65-
"typescript": "^4.6.3"
59+
"@types/node": "^18.0.0",
60+
"@typescript-eslint/eslint-plugin": "^5.29.0",
61+
"@typescript-eslint/parser": "^5.29.0",
62+
"c8": "^7.11.3",
63+
"eslint": "^8.18.0",
64+
"eslint-plugin-import": "^2.26.0",
65+
"husky": "^8.0.1",
66+
"lint-staged": "^13.0.2",
67+
"rollup": "^2.75.7",
68+
"typescript": "^4.7.4",
69+
"vitest": "^0.15.2"
6670
},
6771
"publishConfig": {
6872
"access": "public"

0 commit comments

Comments
 (0)