Skip to content

Commit 84001ce

Browse files
authored
Merge pull request #1244 from SahilKalra98/fixRemarkToc
Updates remark-toc, remark-gfm, and rehype-autolink-headings libraries
2 parents d80c03d + ddfe3cc commit 84001ce

File tree

7 files changed

+598
-133
lines changed

7 files changed

+598
-133
lines changed

__mocks__/rehype-autolink-headings.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Manual Mocking the rehype-autolink-headings library because our jest and typscript
2+
* configuration doesn't use esm modules yet. After the package update,
3+
* rehype-autolink-headings is a fully ESM module now and the reason this is being
4+
* manual mocked is because it is being mocked as a CommonJS module.
5+
* Here is the link: https://jestjs.io/docs/manual-mocks#mocking-node-modules
6+
*/
7+
const autolink = () => {
8+
console.log('Manual Mocking of rehype-autolink-headings module')
9+
}
10+
11+
module.exports = {
12+
autolink
13+
}

__mocks__/remark-gfm.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Manual Mocking the remark-gfm library because our jest and typscript
2+
* configuration doesn't use esm modules yet. After the package update,
3+
* remark-gfm is a fully ESM module now and the reason this is being
4+
* manual mocked is because it is being mocked as a CommonJS module.
5+
* Here is the link: https://jestjs.io/docs/manual-mocks#mocking-node-modules
6+
*/
7+
const gfm = () => {
8+
console.log('Manual Mocking remark-gfm module')
9+
}
10+
11+
module.exports = {
12+
gfm
13+
}

__mocks__/remark-toc.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Manual Mocking the remark-toc library because our jest and typscript
2+
* configuration doesn't use esm modules yet. After the package update,
3+
* remark-toc is a fully ESM module now and the reason this is being
4+
* manual mocked is because it is being mocked as a CommonJS module.
5+
* Here is the link: https://jestjs.io/docs/manual-mocks#mocking-node-modules
6+
*/
7+
const toc = () => {
8+
console.log('Manual Mocking of remark-toc module')
9+
}
10+
11+
module.exports = {
12+
toc
13+
}

helpers/static/parseMDX.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { serialize } from 'next-mdx-remote/serialize'
22
import { MDXRemoteSerializeResult } from 'next-mdx-remote'
33
import matter from 'gray-matter'
4+
import toc from 'remark-toc'
5+
import gfm from 'remark-gfm'
6+
import autolink from 'rehype-autolink-headings'
47

5-
const autolink = require('rehype-autolink-headings')
68
const slug = require('remark-slug')
7-
const toc = require('remark-toc')
8-
const gfm = require('remark-gfm')
99

1010
type ParsedMDX = {
1111
(fileContents: Buffer, onlyFront?: boolean): Promise<{

jest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const config: Config.InitialOptions = {
3131
setupFilesAfterEnv: ['<rootDir>/jest.env.js'],
3232
testEnvironment: 'jsdom',
3333
testPathIgnorePatterns: ['__tests__/utils/', 'node_modules/', '.next/'],
34-
transformIgnorePatterns: ['node_modules/']
34+
transformIgnorePatterns: ['node_modules/(?!(remark-toc)/)']
3535
}
3636

3737
export default config

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
"react-bootstrap": "^1.6.1",
6464
"react-dom": "^17.0.2",
6565
"react-feather": "^2.0.9",
66-
"rehype-autolink-headings": "^5.1.0",
6766
"sass": "^1.49.0",
67+
"rehype-autolink-headings": "^6.1.0",
6868
"use-undo": "^1.0.5",
6969
"winston": "^3.4.0",
7070
"yup": "^0.32.11"
@@ -116,10 +116,10 @@
116116
"prettier": "^2.5.1",
117117
"prisma": "^2.29.1",
118118
"react-test-renderer": "^17.0.1",
119-
"remark-gfm": "^1.0.0",
119+
"remark-gfm": "^3.0.1",
120120
"remark-slug": "^6.1.0",
121-
"remark-toc": "^7.2.0",
122121
"sass-loader": "^10.2.1",
122+
"remark-toc": "^8.0.1",
123123
"svgo": "^2.8.0",
124124
"ts-node": "^10.4.0",
125125
"typescript": "^4.5.5"

0 commit comments

Comments
 (0)