Skip to content

Commit

Permalink
Fix VSCode Docker container debugging sourcemap
Browse files Browse the repository at this point in the history
Use inline sourcemaps for debug builds (otherwise VSCode kept wanting to load map files from the workspace rather than the container)

Add conditional debug build to Dockerfile

Don't include sourcemaps in normal build

Add "run with tsx" task
  • Loading branch information
longzheng committed Dec 18, 2024
1 parent cdb9a2d commit 01ddce5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"configurations": [
{
"command": "npm run dev",
"name": "Run with tsx",
"request": "launch",
"type": "node-terminal"
},
{
"type": "node",
"request": "attach",
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Build
FROM node:22-alpine AS build

ARG DEBUG=false

WORKDIR /app

# Download dependencies as a separate step to take advantage of Docker's caching.
Expand All @@ -17,7 +19,8 @@ RUN --mount=type=bind,source=package.json,target=package.json \
# Copy the rest of the source files into the image.
COPY . .

RUN npm run build
# Conditional debug build
RUN if [ "$DEBUG" = "true" ]; then npm run build:debug; else npm run build; fi

# Production
FROM node:22-alpine AS production
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.debug.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
services:
open-dynamic-export:
build:
args:
DEBUG: "true"
environment:
NODE_ENV: development
ports:
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"main": "index.js",
"type": "module",
"scripts": {
"prebuild": "tsoa spec-and-routes",
"build": "tsc",
"build": "npm run routes:generate && tsc",
"build:debug": "npm run routes:generate && tsc -p tsconfig.debug.json",
"lint": "tsc --noEmit && npx eslint . && npm run generate:config-json-schema",
"test": "vitest",
"start": "node dist/src/app.js",
"dev": "npm run prebuild && tsx src/app.ts",
"dev": "npm run routes:generate && tsx src/app.ts",
"routes:generate": "tsoa spec-and-routes",
"debug:sunspec-discovery": "tsx scripts/debugSunspecDiscovery.ts",
"cert:device-request": "tsx scripts/certDeviceRequest.ts",
"cert:device-generate": "tsx scripts/certDeviceGenerate.ts",
Expand Down
7 changes: 7 additions & 0 deletions tsconfig.debug.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"inlineSourceMap": true,
"inlineSources": true
}
}
1 change: 0 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"module": "NodeNext",
"moduleResolution": "NodeNext",
"outDir": "dist",
"sourceMap": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
Expand Down

0 comments on commit 01ddce5

Please sign in to comment.