// import { join } from 'node:path'; // import { Worker } from 'node:worker_threads'; // import type { TransformOptions } from '@moneko/eslint/babel-core'; // import type { PluginOptions } from '@moneko/eslint/react-compiler'; // import type { LoaderContext } from 'webpack'; // import { isBuild } from '../process-env.mjs'; // export interface ReactCompilerOption extends Partial { // /** // * 指定 React 的主要版本 // * @description // * ReactCompiler 与 React 19+ 配合使用效果最佳; // * // * 将 ReactCompiler 与 React 17、18 一起使用需要安装额外的 `react-compiler-runtime` 依赖项; // */ // target: '17' | '18' | '19'; // /** 编译模式 // * @description annotation 注释模式: 通过 "use memo"、"use no memo" 手动指定启用优化 // * @example // * export default function Home() { // * 'use memo'; // * // ... // * } // * export default function About() { // * 'use no memo'; // * // ... // * } // */ // compilationMode: 'annotation' | 'infer' | 'syntax' | 'all'; // } // const worker = new Worker(join(__dirname, '../worker/react-compiler.mjs')); // worker.setMaxListeners(0); // function reactCompilerLoader( // this: LoaderContext, // sourceCode: string, // inputSourceMap?: TransformOptions['inputSourceMap'], // ): string | Buffer | void { // const isDev = this._compiler?.options.mode === 'development'; // if (!isDev || isBuild) { // this._compiler?.hooks.done.tap('react-compiler-loader', () => { // worker.terminate(); // }); // } // const filename = this.resourcePath; // const options = this.getOptions(); // let needRC: boolean; // if (filename.endsWith('.d.ts') || filename.endsWith('.json')) { // return sourceCode; // } // if (options.compilationMode === 'annotation') { // needRC = sourceCode.includes('use memo') || sourceCode.includes('use forget'); // } else { // needRC = sourceCode.includes('react') || filename.endsWith('.tsx') || filename.endsWith('.jsx'); // } // if (!needRC) { // return sourceCode; // } // const call = this.async(); // if (this.cacheable) { // this.cacheable(); // } // worker.postMessage({ // sourceCode, // filename, // inputSourceMap, // options: options, // }); // function callback(out: [filename: string, err: Error | null, code: string, map: string]) { // if (filename === out[0]) { // call(out[1], out[2], out[3]); // worker.removeListener('message', callback); // } // } // worker.addListener('message', callback); // } // export function custom( // this: LoaderContext, // sourceCode: string, // inputSourceMap?: TransformOptions['inputSourceMap'], // ): typeof reactCompilerLoader { // return reactCompilerLoader.bind(this, sourceCode, inputSourceMap); // } // export default reactCompilerLoader; export { };