-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v4] compile
nextra/components
, nextra/hooks
and `nextra-theme-bl…
…og` source code with react-compiler (#3742) * improve * aa * aa * aa * aa * more * more * more * more * react compiler * react compiler * react compiler * react com * react com * react compiler * react com * react com * react compiler * react com * more * react com * react com * react com * react com * react com * aa * aa * aa * aa * better name * fix build * fix xx * moreee * moreee * Update packages/nextra/src/client/mdx-components/pre/copy-to-clipboard.tsx * should log on windows now * missed this * check with use 'use no memo' comments either files were optimized or not * more * more * more * more * more * more * more * more * more * more * more * more * more * more * more * more * yoyo * pnpm dedupe * aa * `react-compiler-runtime` should be direct dependency for nextra/nextra-theme-docs/nextra-theme-blog
- Loading branch information
1 parent
f065137
commit 386b620
Showing
91 changed files
with
1,002 additions
and
688 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'nextra': minor | ||
--- | ||
|
||
compile `nextra/components`, `nextra/hooks`, `nextra-theme-docs` and `nextra-theme-blog` source code with react-compiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "esbuild-react-compiler-plugin", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"description": "", | ||
"author": "Dimitri POSTOLOV", | ||
"license": "ISC", | ||
"private": true, | ||
"exports": { | ||
".": { | ||
"types": "./dist/index.d.ts", | ||
"import": "./dist/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"scripts": { | ||
"build": "tsup", | ||
"dev": "tsup --watch" | ||
}, | ||
"dependencies": { | ||
"react-compiler-webpack": "0.1.2" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^22.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
declare module 'react-compiler-webpack/dist/react-compiler-loader.js' { | ||
export default function reactCompilerLoader( | ||
source: string | Buffer | ||
): Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import fs from 'node:fs/promises' | ||
import path from 'node:path' | ||
import reactCompilerLoader from 'react-compiler-webpack/dist/react-compiler-loader.js' | ||
import type { Options } from 'tsup' | ||
|
||
const reactCompilerConfig = { | ||
sources(_filename: string) { | ||
return true | ||
}, | ||
target: '18' | ||
} | ||
|
||
export const reactCompilerPlugin = ( | ||
filter: RegExp | ||
): NonNullable<Options['esbuildPlugins']>[number] => ({ | ||
name: 'react-compiler', | ||
setup(build) { | ||
build.onLoad({ filter }, async args => { | ||
// Read the file content | ||
const code = await fs.readFile(args.path) | ||
return new Promise<{ | ||
contents: string | ||
loader: 'ts' | 'tsx' | ||
}>((resolve, reject) => { | ||
function callback(error: Error | null, result?: string) { | ||
if (!result) { | ||
reject(error) | ||
return | ||
} | ||
// Mark the file as a ts/tsx file | ||
const loader = path.extname(args.path).slice(1) as 'ts' | 'tsx' | ||
const relativePath = path.relative(process.cwd(), args.path) | ||
|
||
if ( | ||
/^import \{ c as _c } from "react-compiler-runtime";/m.test(result) | ||
) { | ||
console.info( | ||
'🚀 File', | ||
relativePath, | ||
'was optimized with react-compiler' | ||
) | ||
} else if (!/^'use no memo'/m.test(result)) { | ||
console.error( | ||
'❌ File', | ||
relativePath, | ||
'was not optimized with react-compiler' | ||
) | ||
} | ||
|
||
resolve({ contents: result, loader }) | ||
} | ||
|
||
reactCompilerLoader.call( | ||
{ | ||
async: () => callback, | ||
getOptions: () => reactCompilerConfig, | ||
resourcePath: args.path | ||
}, | ||
code | ||
) | ||
}) | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2022", | ||
"module": "ESNext", | ||
"declaration": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"strict": true, | ||
"skipLibCheck": true, | ||
"strictNullChecks": true, | ||
"lib": ["esnext", "dom"], | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true | ||
}, | ||
"exclude": ["dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { defineConfig } from 'tsup' | ||
import packageJson from './package.json' | ||
|
||
export default defineConfig({ | ||
name: packageJson.name, | ||
entry: ['src/**/*.ts'], | ||
format: 'esm', | ||
dts: true, | ||
splitting: process.env.NODE_ENV === 'production', | ||
bundle: false | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use no memo' | ||
|
||
export { useMDXComponents } from './mdx-components' | ||
export { | ||
Comments, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// should be used on server | ||
'use no memo' | ||
|
||
/* eslint sort-keys: error */ | ||
import { | ||
Callout, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use no memo' | ||
|
||
/* eslint typescript-sort-keys/interface: error */ | ||
import type { ReadingTime } from 'nextra' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.