Skip to content

Commit 532736a

Browse files
committed
now that the problem with the vscode-textmate import is fixed we can migrate our config typescript
1 parent bb83cbf commit 532736a

File tree

1 file changed

+31
-29
lines changed

1 file changed

+31
-29
lines changed

next.config.mjs renamed to next.config.ts

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ import { withSentryConfig } from '@sentry/nextjs'
33
//import WithBundleAnalyzer from '@next/bundle-analyzer'
44
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants.js'
55
import createMdx from '@next/mdx'
6-
import { remarkTableOfContents } from 'remark-table-of-contents'
7-
import rehypeAutolinkHeadings from 'rehype-autolink-headings'
6+
import { remarkTableOfContents, type IRemarkTableOfContentsOptions as remarkTableOfContentsOptionsType } from 'remark-table-of-contents'
7+
import rehypeAutolinkHeadings, { type Options as rehypeAutolinkHeadingsOptionsType } from 'rehype-autolink-headings'
8+
import { type ElementContent } from 'hast'
89
import { fromHtmlIsomorphic } from 'hast-util-from-html-isomorphic'
910
import { toString as hastToString } from 'mdast-util-to-string'
1011
import rehypeSlug from 'rehype-slug'
11-
import remarkGfm from 'remark-gfm'
12-
import { rehypeGithubAlerts } from 'rehype-github-alerts'
12+
import remarkGfm, { type Options as remarkGfmOptionsType } from 'remark-gfm'
13+
import { rehypeGithubAlerts, type DefaultBuildType as rehypeGithubAlertsDefaultBuildType, type IOptions as rehypeGithubAlertsOptionsType } from 'rehype-github-alerts'
1314
import rehypeMDXImportMedia from 'rehype-mdx-import-media'
1415
import remarkFrontmatter from 'remark-frontmatter'
1516
import remarkMdxFrontmatter from 'remark-mdx-frontmatter'
16-
import { rehypePrettyCode } from 'rehype-pretty-code'
17+
import { rehypePrettyCode, type Options as rehypePrettyCodeOptionsType } from 'rehype-pretty-code'
1718
import { transformerNotationDiff } from '@shikijs/transformers'
19+
import type { ShikiTransformer } from 'shiki'
20+
import { NextConfig } from 'next'
1821

19-
const nextConfig = (phase) => {
22+
const nextConfig = (phase: string) => {
2023

2124
// to use the bundle analyzer uncomment the following lines
2225
// then uncomment the return to use withBundleAnalyzer
@@ -26,27 +29,25 @@ const nextConfig = (phase) => {
2629
})*/
2730

2831
// https://rehype-pretty-code.netlify.app/
29-
/** @type {import('rehype-pretty-code').Options} */
30-
const rehypePrettyCodeOptions = {
32+
const rehypePrettyCodeOptions: rehypePrettyCodeOptionsType = {
3133
// VSCode "SynthWave '84" theme
3234
theme: 'synthwave-84',
3335
// Keep the background or use a custom background color?
3436
keepBackground: true,
3537
tokensMap: {
36-
'function': 'entity.name.function',
37-
'string': 'string',
38-
'key': '.meta.object-literal.key',
38+
function: 'entity.name.function',
39+
string: 'string',
40+
key: '.meta.object-literal.key',
3941
},
4042
defaultLang: {
4143
block: 'tsx',
4244
inline: 'shell',
4345
},
44-
transformers: [transformerNotationDiff()],
46+
transformers: [transformerNotationDiff() as ShikiTransformer],
4547
}
4648

4749
// https://github.com/chrisweb/remark-table-of-contents#options
48-
/** @type {import('remark-table-of-contents').IRemarkTableOfContentsOptions} */
49-
const remarkTableOfContentsOptions = {
50+
const remarkTableOfContentsOptions: remarkTableOfContentsOptionsType = {
5051
containerAttributes: {
5152
id: 'articleToc',
5253
},
@@ -57,32 +58,30 @@ const nextConfig = (phase) => {
5758
}
5859

5960
// https://github.com/rehypejs/rehype-autolink-headings#api
60-
const rehypeAutolinkHeadingsOptions = {
61+
const rehypeAutolinkHeadingsOptions: rehypeAutolinkHeadingsOptionsType = {
6162
behavior: 'append',
6263
properties: (node) => {
6364
//console.log(node)
6465
const headingText = hastToString(node.children[0])
6566
return {
66-
class: 'headingAnchor',
67+
'class': 'headingAnchor',
6768
'aria-label': 'Heading permalink for: ' + headingText,
68-
title: 'Heading permalink for: ' + headingText,
69+
'title': 'Heading permalink for: ' + headingText,
6970
}
7071
},
7172
content: fromHtmlIsomorphic(
7273
'<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24" class="icon iconLink" aria-hidden="true"><path d="M11 17H7q-2.075 0-3.537-1.463Q2 14.075 2 12t1.463-3.538Q4.925 7 7 7h4v2H7q-1.25 0-2.125.875T4 12q0 1.25.875 2.125T7 15h4Zm-3-4v-2h8v2Zm5 4v-2h4q1.25 0 2.125-.875T20 12q0-1.25-.875-2.125T17 9h-4V7h4q2.075 0 3.538 1.462Q22 9.925 22 12q0 2.075-1.462 3.537Q19.075 17 17 17Z"/></svg>',
7374
{ fragment: true }
74-
).children,
75+
).children as ElementContent[],
7576
}
7677

7778
// https://github.com/remarkjs/remark-gfm
78-
/** @type {import('remark-gfm').Options} */
79-
const remarkGfmOptions = {
79+
const remarkGfmOptions: remarkGfmOptionsType = {
8080
singleTilde: false,
8181
}
8282

8383
// https://github.com/chrisweb/rehype-github-alerts
84-
/** @type {import('rehype-github-alerts').DefaultBuildType} */
85-
const myGithubAlertBuild = (alertOptions, originalChildren) => {
84+
const myGithubAlertBuild: rehypeGithubAlertsDefaultBuildType = (alertOptions, originalChildren) => {
8685

8786
const alert = {
8887
type: 'element',
@@ -135,12 +134,12 @@ const nextConfig = (phase) => {
135134
],
136135
}
137136

138-
return alert
137+
return alert as ElementContent
139138

140139
}
141140

142-
/** @type {import('rehype-github-alerts').IOptions} */
143-
const rehypeGithubAlertsOptions = {
141+
// https://github.com/chrisweb/rehype-github-alerts#options
142+
const rehypeGithubAlertsOptions: rehypeGithubAlertsOptionsType = {
144143
supportLegacy: false,
145144
build: myGithubAlertBuild,
146145
alerts: [
@@ -174,8 +173,7 @@ const nextConfig = (phase) => {
174173
},
175174
})
176175

177-
/** @type {import('next').NextConfig} */
178-
const nextConfigOptions = {
176+
const nextConfigOptions: NextConfig = {
179177
reactStrictMode: true,
180178
poweredByHeader: false,
181179
experimental: {
@@ -202,7 +200,7 @@ const nextConfig = (phase) => {
202200
reactCompiler: true,
203201
// experimental partial prerendering
204202
// https://nextjs.org/docs/messages/ppr-preview
205-
ppr: true,
203+
ppr: false,
206204
// experimental typescript "statically typed links"
207205
// https://nextjs.org/docs/app/api-reference/next-config-js/typedRoutes
208206
typedRoutes: true,
@@ -227,6 +225,7 @@ const nextConfig = (phase) => {
227225
eslint: {
228226
ignoreDuringBuilds: true,
229227
},
228+
// eslint-disable-next-line @typescript-eslint/require-await
230229
headers: async () => {
231230
return [
232231
{
@@ -253,6 +252,7 @@ const nextConfig = (phase) => {
253252
},
254253
]
255254
},
255+
// eslint-disable-next-line @typescript-eslint/require-await
256256
redirects: async () => {
257257
return [
258258
{
@@ -269,7 +269,7 @@ const nextConfig = (phase) => {
269269

270270
}
271271

272-
const securityHeadersConfig = (phase) => {
272+
const securityHeadersConfig = (phase: string) => {
273273

274274
const cspReportOnly = false
275275
const reportingUrl = 'https://o4504017992482816.ingest.us.sentry.io/api/4506763918770176/security/?sentry_key=daf0befe66519725bbe2ad707a11bbb3'
@@ -278,6 +278,7 @@ const securityHeadersConfig = (phase) => {
278278

279279
const cspHeader = () => {
280280

281+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
281282
const upgradeInsecure = (!isDev && !cspReportOnly) ? 'upgrade-insecure-requests;' : ''
282283

283284
// report directive to be added at the end
@@ -373,6 +374,7 @@ const securityHeadersConfig = (phase) => {
373374
const headers = [
374375
...extraSecurityHeaders,
375376
{
377+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
376378
key: cspReportOnly ? 'Content-Security-Policy-Report-Only' : 'Content-Security-Policy',
377379
value: cspHeader().replace(/\n/g, ''),
378380
},

0 commit comments

Comments
 (0)