diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 667640fb7..1231e0d5b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 \ diff --git a/package.json b/package.json index 4ce415bd8..cd3b3e2de 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/framework-debug-gui/package.json b/packages/framework-debug-gui/package.json index bab4bbb92..efcb4dd5b 100644 --- a/packages/framework-debug-gui/package.json +++ b/packages/framework-debug-gui/package.json @@ -18,6 +18,7 @@ "files": [ "dist" ], + "preferUnplugged": true, "devDependencies": { "@angular-devkit/build-angular": "^17.1.0", "@angular/animations": "^17.1.0", diff --git a/packages/framework/package.json b/packages/framework/package.json index 02e7f1622..dfd99a7aa 100644 --- a/packages/framework/package.json +++ b/packages/framework/package.json @@ -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": { diff --git a/packages/framework/src/debug/http-debug.controller.ts b/packages/framework/src/debug/http-debug.controller.ts index 2207252b3..a39f2cf83 100644 --- a/packages/framework/src/debug/http-debug.controller.ts +++ b/packages/framework/src/debug/http-debug.controller.ts @@ -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, 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' }); } diff --git a/packages/framework/src/debug/resolve.cts b/packages/framework/src/debug/resolve.cts new file mode 100644 index 000000000..18eb8c7bd --- /dev/null +++ b/packages/framework/src/debug/resolve.cts @@ -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)) +} diff --git a/packages/framework/src/debug/resolve.d.ts b/packages/framework/src/debug/resolve.d.ts new file mode 100644 index 000000000..3938c97a8 --- /dev/null +++ b/packages/framework/src/debug/resolve.d.ts @@ -0,0 +1 @@ +export function resolve(assetName: string): string; diff --git a/packages/framework/src/debug/resolve.mts b/packages/framework/src/debug/resolve.mts new file mode 100644 index 000000000..29af40554 --- /dev/null +++ b/packages/framework/src/debug/resolve.mts @@ -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)) +} diff --git a/packages/framework/tsconfig.esm.json b/packages/framework/tsconfig.esm.json index 9687ac83e..40d877b9d 100644 --- a/packages/framework/tsconfig.esm.json +++ b/packages/framework/tsconfig.esm.json @@ -4,6 +4,10 @@ "outDir": "./dist/esm", "module": "ES2020" }, + "exclude": [ + "tests", + "src/debug/resolve.cts" + ], "references": [ { "path": "../api-console-module/tsconfig.esm.json" diff --git a/packages/framework/tsconfig.json b/packages/framework/tsconfig.json index a14075981..b00e1f786 100644 --- a/packages/framework/tsconfig.json +++ b/packages/framework/tsconfig.json @@ -37,7 +37,8 @@ "loader.ts" ], "exclude": [ - "tests" + "tests", + "src/debug/resolve.mts" ], "references": [ {