|
| 1 | +import { createRequire } from 'node:module'; |
| 2 | +import { COMPILED_PATH } from '../constants'; |
| 3 | + |
| 4 | +const require = createRequire(import.meta.url); |
| 5 | + |
| 6 | +type CompiledPackages = { |
| 7 | + ws: typeof import('../../compiled/ws').default; |
| 8 | + cors: typeof import('../../compiled/cors').default; |
| 9 | + sirv: typeof import('../../compiled/sirv'); |
| 10 | + rslog: typeof import('../../compiled/rslog'); |
| 11 | + memfs: typeof import('../../compiled/memfs'); |
| 12 | + mrmime: typeof import('../../compiled/mrmime'); |
| 13 | + connect: typeof import('../../compiled/connect').default; |
| 14 | + chokidar: typeof import('../../compiled/chokidar').default; |
| 15 | + tinyglobby: typeof import('../../compiled/tinyglobby'); |
| 16 | + picocolors: typeof import('../../compiled/picocolors').default; |
| 17 | + 'html-rspack-plugin': typeof import('../../compiled/html-rspack-plugin').default; |
| 18 | + 'http-proxy-middleware': typeof import('../../compiled/http-proxy-middleware'); |
| 19 | + 'webpack-bundle-analyzer': typeof import('../../compiled/webpack-bundle-analyzer'); |
| 20 | + 'rspack-manifest-plugin': typeof import('../../compiled/rspack-manifest-plugin'); |
| 21 | + 'launch-editor-middleware': typeof import('../../compiled/launch-editor-middleware'); |
| 22 | + '@jridgewell/remapping': typeof import('../../compiled/@jridgewell/remapping'); |
| 23 | + '@jridgewell/trace-mapping': typeof import('../../compiled/@jridgewell/trace-mapping'); |
| 24 | +}; |
| 25 | + |
| 26 | +/** |
| 27 | + * Load compiled package from `compiled` folder. |
| 28 | + * use `require()` as compiled packages are CommonJS modules. |
| 29 | + * https://github.com/nodejs/node/issues/59913 |
| 30 | + * @param name |
| 31 | + * @returns |
| 32 | + */ |
| 33 | +export const requireCompiledPackage = <T extends keyof CompiledPackages>( |
| 34 | + name: T, |
| 35 | +): CompiledPackages[T] => require(`${COMPILED_PATH}/${name}/index.js`); |
| 36 | + |
| 37 | +export const color: typeof import('../../compiled/picocolors').default = |
| 38 | + requireCompiledPackage('picocolors'); |
0 commit comments