Skip to content

Commit 6d20729

Browse files
committed
chore: migrate from Deno to Node.js
- Replace Deno runtime APIs with Node.js equivalents (process.env, process.exit, fs, child_process) - Replace bare HTTP server with Fastify (with @fastify/cors, @fastify/websocket, @fastify/rate-limit) - Migrate tests from Deno.test + @std/assert to Vitest - Replace postgres.js with node-postgres (pg) + pg-cursor - Add serializeParams for JSONB compatibility and toPgTextArray for PG array params - Add transaction savepoint wrapping and exec serialization to match postgres.js behavior - Delete deno.json, deno.lock, postgresjs.ts, rate-limit.ts - Add package.json, tsconfig.json, vitest.config.ts
1 parent 633d097 commit 6d20729

39 files changed

+6666
-3336
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
.git
4+
.idea
5+
coverage

.github/workflows/build-action.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ jobs:
1414
with:
1515
fetch-depth: 0
1616
fetch-tags: true
17-
- name: Install Deno
18-
uses: denoland/setup-deno@v2
17+
- name: Install Node.js
18+
uses: actions/setup-node@v4
1919
with:
20-
cache-hash: ${{ hashFiles('**/deno.lock') }}
21-
deno-version: v2.x
20+
node-version: 24
21+
cache: npm
22+
- name: Install dependencies
23+
run: npm ci
2224
- name: Export version
2325
run: |
24-
echo "DENO_VERSION=$(jq -r '.version' deno.json)" >> $GITHUB_ENV
26+
echo "VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV
2527
- name: Typecheck
26-
run: deno check
28+
run: npx tsc --noEmit
2729

2830
- name: Install PostgreSQL 17 client
2931
run: |
@@ -33,7 +35,7 @@ jobs:
3335
sudo apt install -y postgresql-client-17
3436
3537
- name: Run tests
36-
run: deno run test
38+
run: npx vitest run
3739
env:
3840
PG_DUMP_BINARY: /usr/lib/postgresql/17/bin/pg_dump
3941
PG_RESTORE_BINARY: /usr/lib/postgresql/17/bin/pg_restore
@@ -42,6 +44,6 @@ jobs:
4244
uses: softprops/action-gh-release@v2
4345
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
4446
with:
45-
tag_name: v${{ env.DENO_VERSION }}
47+
tag_name: v${{ env.VERSION }}
4648
env:
4749
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/publish.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ jobs:
4040
key: ${{ runner.os }}-buildx-${{ github.sha }}
4141
restore-keys: |
4242
${{ runner.os }}-buildx-
43-
- name: Set sync_version from deno.json
43+
- name: Set sync_version from package.json
4444
run: |
45-
sync_version=$(jq -r '.version' deno.json)
45+
sync_version=$(jq -r '.version' package.json)
4646
echo "sync_version=${sync_version}" >> $GITHUB_ENV
4747
- name: Build and push @query-doctor/analyzer
4848
id: build

Dockerfile

Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
ARG ALPINE_VERSION=3.22
2-
ARG DENO_VERSION=2.4.5
32
FROM alpine:${ALPINE_VERSION} AS pg-builder
43

54
# Install build dependencies
@@ -48,54 +47,32 @@ RUN ./bootstrap -DREGRESS_CHECKS=OFF -DPG_CONFIG=/usr/local/pgsql/bin/pg_config
4847
RUN cd build && make -j$(nproc)
4948
RUN cd build && make install
5049

51-
# Adapted from https://github.com/dojyorin/deno_docker_image/blob/master/src/alpine.dockerfile
52-
FROM denoland/deno:alpine-${DENO_VERSION} AS deno
50+
# Build pgBadger
51+
FROM alpine:${ALPINE_VERSION} AS pgbadger-builder
5352

54-
RUN apk add --no-cache \
55-
perl \
56-
curl \
57-
make \
58-
git \
59-
postgresql-client
53+
RUN apk add --no-cache perl curl make
6054

61-
# Download, build, and install pgBadger
6255
ARG PGBADGER_VERSION=13.2
6356
WORKDIR /tmp
64-
6557
RUN curl -L https://github.com/darold/pgbadger/archive/v${PGBADGER_VERSION}.tar.gz | tar -xzf - && \
6658
cd pgbadger-${PGBADGER_VERSION} && \
6759
perl Makefile.PL && \
6860
make && \
6961
make install && \
7062
rm -rf /tmp/pgbadger*
7163

72-
FROM gcr.io/distroless/cc-debian12:latest AS cc
73-
74-
FROM alpine:${ALPINE_VERSION} AS sym
75-
76-
COPY --from=cc --chmod=755 --chown=root:root /lib/*-linux-gnu/ld-linux-* /usr/local/lib/
77-
RUN mkdir -p -m 755 /tmp/lib
78-
RUN ln -s /usr/local/lib/ld-linux-* /tmp/lib/
79-
80-
FROM denoland/deno:alpine-${DENO_VERSION} AS build
81-
82-
COPY deno.json deno.lock* ./
83-
RUN deno install --frozen-lockfile
64+
# Build the application
65+
FROM node:24-alpine AS build
8466

67+
WORKDIR /app
68+
COPY package.json package-lock.json ./
69+
RUN npm ci
8570
COPY . .
71+
RUN npx esbuild src/main.ts --bundle --platform=node --format=esm --outfile=dist/main.mjs --packages=external
72+
RUN npm ci --omit=dev
8673

87-
RUN deno compile \
88-
--allow-run \
89-
--allow-read \
90-
--allow-write \
91-
--allow-env \
92-
--allow-net \
93-
--allow-sys \
94-
-o /app/analyzer \
95-
src/main.ts
96-
97-
FROM alpine:${ALPINE_VERSION}
98-
ENV LD_LIBRARY_PATH="/usr/local/lib"
74+
# Final image
75+
FROM node:24-alpine
9976

10077
RUN apk add -uU --no-cache \
10178
postgresql-client \
@@ -104,17 +81,19 @@ RUN apk add -uU --no-cache \
10481
bash \
10582
su-exec \
10683
openssl \
107-
krb5
84+
krb5 \
85+
perl
10886

109-
COPY --from=deno --chmod=755 --chown=root:root /usr/bin/pg_dump /usr/bin/pg_dump
110-
COPY --from=build --chmod=755 --chown=root:root /app/analyzer /app/analyzer
111-
COPY --from=cc --chmod=755 --chown=root:root /lib/*-linux-gnu/* /usr/local/lib/
112-
COPY --from=sym --chmod=755 --chown=root:root /tmp/lib /lib
113-
COPY --from=sym --chmod=755 --chown=root:root /tmp/lib /lib64
87+
# Copy pgBadger
88+
COPY --from=pgbadger-builder /usr/local/bin/pgbadger /usr/local/bin/pgbadger
11489

11590
# Copy PostgreSQL installation from builder
11691
COPY --from=pg-builder /usr/local/pgsql /usr/local/pgsql
11792

93+
# Copy application
94+
COPY --from=build /app/dist /app/dist
95+
COPY --from=build /app/node_modules /app/node_modules
96+
11897
# Setup postgres user and directories
11998
RUN mkdir -p /var/lib/postgresql/data \
12099
&& chown -R postgres:postgres /var/lib/postgresql \
@@ -142,4 +121,4 @@ CMD ["/bin/bash", "-c", "\
142121
echo \"unix_socket_directories = '/tmp'\" >> $PGDATA/postgresql.conf && \
143122
su-exec postgres pg_ctl -D $PGDATA -l $PGDATA/logfile start || (cat $PGDATA/logfile && exit 1) && \
144123
until su-exec postgres pg_isready -h /tmp; do sleep 0.5; done && \
145-
/app/analyzer"]
124+
node /app/dist/main.mjs"]

Dockerfile.dev

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM denoland/deno:alpine
1+
FROM node:24-alpine
22

33
# Install pgbadger dependencies
44
RUN apk add --no-cache \
@@ -18,14 +18,12 @@ RUN wget https://github.com/darold/pgbadger/archive/v${PGBADGER_VERSION}.tar.gz
1818
make install && \
1919
rm -rf /tmp/pgbadger*
2020

21-
# RUN curl -L https://github.com/supabase-community/postgres-language-server/releases/download/<version>/postgrestools_aarch64-apple-darwin -o postgrestools
22-
# RUN chmod +x postgrestools
23-
2421
WORKDIR /app
2522

2623
# Copy dependency files
27-
COPY deno.json deno.lock* ./
24+
COPY package.json package-lock.json ./
25+
26+
RUN npm ci
2827

29-
RUN deno install --frozen-lockfile
3028
# Development command
31-
CMD ["deno", "run", "dev"]
29+
CMD ["npm", "run", "start:dev"]

action.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ branding:
1111
runs:
1212
using: "composite"
1313
steps:
14-
# Setup Deno environment
15-
- name: Install Deno
16-
uses: denoland/setup-deno@v2
14+
- name: Install Node.js
15+
uses: actions/setup-node@v4
1716
with:
18-
cache: true
19-
deno-version: v2.x
17+
node-version: 24
18+
cache: npm
19+
20+
- name: Install dependencies
21+
shell: bash
22+
run: npm ci
2023

2124
# Cache pgBadger build
2225
- name: Cache pgBadger
@@ -48,10 +51,10 @@ runs:
4851
sudo make install # Use sudo to install globally
4952
cd ${{ github.action_path }} # Return to action directory
5053
51-
# Run the compiled application
54+
# Run the application
5255
- name: Run Analyzer
5356
shell: bash
54-
run: deno run start
57+
run: npm run start
5558
env:
5659
PG_DUMP_BINARY: /usr/bin/pg_dump
5760
CI: "true"

deno.json

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)