Unverified Commit c9aa2ea2 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Tweak styled-jsx type declarations (#39474)

* Tweak styled-jsx type declarations

* fix lint
parent f5cab2f5
......@@ -57,18 +57,31 @@ export async function copy_styled_jsx_assets(task, opts) {
// dev dep `styled-jsx` and `next/dist/styled-jsx` for duplicated declare modules
const typesDir = join(outputDir, 'types')
let typeReferences = ''
let globalTypesContent = ''
await fs.ensureDir(outputDir)
await fs.ensureDir(typesDir)
for (const file of typeFiles) {
const fileNoExt = file.replace(/\.d\.ts/, '')
const content = await fs.readFile(join(styledJsxPath, file), 'utf8')
let content = await fs.readFile(join(styledJsxPath, file), 'utf8')
if (file === 'index.d.ts') {
const styledJsxIdx = content.indexOf(`declare module 'styled-jsx' {`)
globalTypesContent = content.substring(0, styledJsxIdx)
content = content
.substring(styledJsxIdx)
.replace('React.', `import('react').`)
}
await fs.writeFile(join(typesDir, file), content)
typeReferences += `/// <reference types="./${fileNoExt}" />\n`
}
await fs.writeFile(join(typesDir, 'global.d.ts'), typeReferences)
await fs.writeFile(
join(typesDir, 'global.d.ts'),
`${typeReferences}\n${globalTypesContent}`
)
for (const file of jsFiles) {
const content = await fs.readFile(join(styledJsxPath, file), 'utf8')
......
import { useRouter } from 'next/router'
import Link from 'next/link'
import { type PageConfig } from 'next'
// eslint-disable-next-line @typescript-eslint/no-unused-vars
import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
export const config: PageConfig = {}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment