deepkit / deepkit-framework

A new full-featured and high-performance TypeScript framework
https://deepkit.io/
MIT License
3.24k stars 123 forks source link

fix(http): make the debug panel compatible with Yarn PnP installs #608

Open LEW21 opened 3 months ago

LEW21 commented 3 months ago

I'm trying to get deepkit running with Yarn PnP (using deepkit-node - I might send a pull request with that later, when I figure out if it'll actually be usable).

Summary of changes

Right now, running an app (yarn node --import deepkit-node ./app.ts server:start) with FrameworkModule({ debug: true }) in a Yarn PnP environment produces a warning:

Warning: node_modules/@deepkit/framework-debug-gui no build found in /home/linus/dev/my-deepkit-app/.yarn/unplugged/@deepkit-framework-virtual-9069fc273b/node_modules/@deepkit/framework/dist/esm/src/debug

As a result, the debug panel doesn't work. This is because the node_modules path is hardcoded, and there is no node_modules on Yarn PnP.

With this change, it works. I'm using import.meta.resolve to resolve a path to index.html, and I'm forcing yarn to actually unzip ("unplug") the static files, so that it's possible to access them in a traditional way.

As import.meta is accessible only in the ESM mode, I'm doing some hack to do the resolution with require.resolve in CJS mode - I don't really like this solution, but I don't have any idea for a better one. Theoretically, this should be transparently handled by the ESM->CJS transpiler, but TypeScript doesn't support it.

Relinquishment of Rights

Please mark following checkbox to confirm that you relinquish all rights of your changes: