Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ jobs:
packages/sqlite/tsconfig.json \
packages/topsort/tsconfig.json \
packages/type/tsconfig.json \
packages/type-spec/tsconfig.json
packages/type-spec/tsconfig.json \
&& mv packages/framework/dist/cjs/src/debug/resolve.cjs packages/framework/dist/cjs/src/debug/resolve.js
- name: Test
run: |
npm run test:coverage \
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"scripts": {
"test": "node --max_old_space_size=3048 node_modules/jest/bin/jest.js --forceExit --no-cache",
"test:coverage": "node --max_old_space_size=3048 node_modules/jest/bin/jest.js --coverage --forceExit --no-cache",
"build": "tsc --build tsconfig.json && tsc --build tsconfig.esm.json && lerna run build",
"build:esm": "tsc --build tsconfig.esm.json",
"build": "tsc --build tsconfig.json && mv packages/framework/dist/cjs/src/debug/resolve.cjs packages/framework/dist/cjs/src/debug/resolve.js && tsc --build tsconfig.esm.json && mv packages/framework/dist/esm/src/debug/resolve.mjs packages/framework/dist/esm/src/debug/resolve.js && lerna run build",
"build:esm": "tsc --build tsconfig.esm.json && tsc --build tsconfig.esm.json",
"tsc": "tsc --build",
"postinstall": "lefthook install && sh install-compiler.sh",
"tsc-watch": "tsc --build --watch",
Expand Down
1 change: 1 addition & 0 deletions packages/framework-debug-gui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"files": [
"dist"
],
"preferUnplugged": true,
"devDependencies": {
"@angular-devkit/build-angular": "^17.1.0",
"@angular/animations": "^17.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/framework/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
},
"scripts": {
"test": "jest --coverage",
"tsc": "rm -rf dist && ../../node_modules/.bin/tsc",
"tsc": "rm -rf dist && ../../node_modules/.bin/tsc && mv dist/cjs/src/debug/resolve.cjs dist/cjs/src/debug/resolve.js",
"tsc-watch": "rm -rf dist && tsc --watch"
},
"peerDependencies": {
Expand Down
23 changes: 13 additions & 10 deletions packages/framework/src/debug/http-debug.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
*/

import { registerStaticHttpController } from '@deepkit/http';
import { AppModule, findParentPath } from '@deepkit/app';
import { dirname } from 'path';
import { getCurrentFileName } from '@deepkit/core';
import { AppModule } from '@deepkit/app';
import { resolve } from './resolve.js';

export function registerDebugHttpController(module: AppModule<any>, path: string): void {
const currentDir = dirname(getCurrentFileName());
const localPath = findParentPath('node_modules/@deepkit/framework-debug-gui/dist/framework-debug-gui', currentDir);
if (localPath) {
registerStaticHttpController(module, { path, localPath, groups: ['app-static'], controllerName: 'FrameworkDebuggerController' });
} else {
console.log('Warning: node_modules/@deepkit/framework-debug-gui no build found in ' + currentDir);
}
const localPath = (() => {
try {
return resolve('@deepkit/framework-debug-gui/dist/framework-debug-gui/index.html')
} catch (e) {
console.log('Warning: @deepkit/framework-debug-gui assets location not resolved.')
return null
}
})()
if (!localPath) return

registerStaticHttpController(module, { path, localPath, groups: ['app-static'], controllerName: 'FrameworkDebuggerController' });
}
8 changes: 8 additions & 0 deletions packages/framework/src/debug/resolve.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createRequire } from "module";
import { dirname } from "path"
import { pathToFileURL } from "url";

export function resolve(assetName: string): string {
const require = createRequire(pathToFileURL(__filename).toString());
return dirname(require.resolve(assetName))
}
1 change: 1 addition & 0 deletions packages/framework/src/debug/resolve.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export function resolve(assetName: string): string;
12 changes: 12 additions & 0 deletions packages/framework/src/debug/resolve.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { dirname } from "path"

export function resolve(assetName: string): string {
// @ts-ignore
const assetUrl = import.meta.resolve(assetName)

if (!assetUrl.startsWith('file://')) {
throw new Error('Invalid local URL')
}

return dirname(assetUrl.substring('file://'.length))
}
4 changes: 4 additions & 0 deletions packages/framework/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"outDir": "./dist/esm",
"module": "ES2020"
},
"exclude": [
"tests",
"src/debug/resolve.cts"
],
"references": [
{
"path": "../api-console-module/tsconfig.esm.json"
Expand Down
3 changes: 2 additions & 1 deletion packages/framework/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"loader.ts"
],
"exclude": [
"tests"
"tests",
"src/debug/resolve.mts"
],
"references": [
{
Expand Down