From bba7d73e2c3a9eeb07f6e804754d9c1349b20e8c Mon Sep 17 00:00:00 2001 From: JasonShin Date: Wed, 25 Feb 2026 00:26:36 +1100 Subject: [PATCH 1/4] support bun and deno --- .github/workflows/alternative-runtimes.yaml | 107 ++++++++++++++++++++ .github/workflows/e2e.yaml | 14 ++- node/cli.js | 38 +++++++ node/package-lock.json | 2 +- node/package.json | 9 +- 5 files changed, 160 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/alternative-runtimes.yaml create mode 100644 node/cli.js diff --git a/.github/workflows/alternative-runtimes.yaml b/.github/workflows/alternative-runtimes.yaml new file mode 100644 index 00000000..db978987 --- /dev/null +++ b/.github/workflows/alternative-runtimes.yaml @@ -0,0 +1,107 @@ +name: Alternative Runtimes (Bun & Deno) + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + bun-test: + name: Bun ${{ matrix.bun-version }} on ${{ matrix.os }} + # Skip this job for version bump commits (binary won't exist yet) + if: "!contains(github.event.head_commit.message, 'Release')" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + bun-version: [ '1.0.0', 'latest' ] + defaults: + run: + working-directory: ./node + + steps: + - uses: actions/checkout@v3 + + - name: Setup Bun ${{ matrix.bun-version }} + uses: oven-sh/setup-bun@v1 + with: + bun-version: ${{ matrix.bun-version }} + + - name: Verify Bun installation + run: bun --version + + - name: Install dependencies (npm install via postinstall) + run: bun install + + - name: Test CLI wrapper with Bun (--version) + run: bun run cli.js --version + + - name: Test CLI wrapper with Bun (--help) + run: bun run cli.js --help + + - name: Verify CLI wrapper is JavaScript (not binary) + shell: bash + run: | + if file cli.js | grep -q "script\|text\|ASCII"; then + echo "✅ cli.js is a JavaScript file" + else + echo "❌ cli.js is not a text file!" + file cli.js + exit 1 + fi + + deno-test: + name: Deno ${{ matrix.deno-version }} on ${{ matrix.os }} + # Skip this job for version bump commits (binary won't exist yet) + if: "!contains(github.event.head_commit.message, 'Release')" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + deno-version: [ 'v1.x', 'v2.x' ] + defaults: + run: + working-directory: ./node + + steps: + - uses: actions/checkout@v3 + + - name: Setup Deno ${{ matrix.deno-version }} + uses: denoland/setup-deno@v1 + with: + deno-version: ${{ matrix.deno-version }} + + - name: Verify Deno installation + run: deno --version + + - name: Setup Node.js (for npm install to download binary) + uses: actions/setup-node@v3 + with: + node-version: 20 + + - name: Install dependencies and download binary + run: npm install + + - name: Test CLI wrapper with Deno (--version) + run: deno run --allow-read --allow-run cli.js --version + + - name: Test CLI wrapper with Deno (--help) + run: deno run --allow-read --allow-run cli.js --help + + - name: Verify CLI wrapper is JavaScript (not binary) + shell: bash + run: | + if file cli.js | grep -q "script\|text\|ASCII"; then + echo "✅ cli.js is a JavaScript file" + else + echo "❌ cli.js is not a text file!" + file cli.js + exit 1 + fi diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 5f2cefa9..90a11fe6 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -36,20 +36,18 @@ jobs: - name: Install dependencies (npm install) run: npm install - - name: Verify sqlx-ts binary from npm install + - name: Verify sqlx-ts CLI wrapper from npm install run: | - chmod +x ./sqlx-ts || true - ./sqlx-ts --version - ./sqlx-ts --help + node cli.js --version + node cli.js --help - name: Install using local install.sh run: node postinstall.js - - name: Verify sqlx-ts binary from local install + - name: Verify sqlx-ts CLI wrapper from local install run: | - chmod +x ./sqlx-ts || true - ./sqlx-ts --version - ./sqlx-ts --help + node cli.js --version + node cli.js --help linux-distro-static-binary-test: name: linux distro ${{ matrix.distro }} diff --git a/node/cli.js b/node/cli.js new file mode 100644 index 00000000..e2a2dc79 --- /dev/null +++ b/node/cli.js @@ -0,0 +1,38 @@ +#!/usr/bin/env node + +const { spawn } = require('child_process'); +const path = require('path'); +const fs = require('fs'); + +// Determine the binary name based on platform +const platform = process.platform; +const binaryName = platform === 'win32' ? 'sqlx-ts.exe' : 'sqlx-ts'; +const binaryPath = path.join(__dirname, binaryName); + +// Check if binary exists +if (!fs.existsSync(binaryPath)) { + console.error(`ERROR: sqlx-ts binary not found at ${binaryPath}`); + console.error('Please ensure the package was installed correctly (postinstall script should have downloaded it).'); + process.exit(1); +} + +// Spawn the binary with all arguments passed through +const child = spawn(binaryPath, process.argv.slice(2), { + stdio: 'inherit', + windowsHide: true +}); + +// Handle exit +child.on('exit', (code, signal) => { + if (signal) { + process.kill(process.pid, signal); + } else { + process.exit(code || 0); + } +}); + +// Handle errors +child.on('error', (err) => { + console.error(`ERROR: Failed to execute sqlx-ts binary: ${err.message}`); + process.exit(1); +}); diff --git a/node/package-lock.json b/node/package-lock.json index 6378565b..7d6b555c 100644 --- a/node/package-lock.json +++ b/node/package-lock.json @@ -13,7 +13,7 @@ "adm-zip": "^0.5.16" }, "bin": { - "sqlx-ts": "sqlx-ts" + "sqlx-ts": "cli.js" }, "devDependencies": { "@types/jest": "^27.4.1", diff --git a/node/package.json b/node/package.json index 9a50ac62..8f8d197b 100644 --- a/node/package.json +++ b/node/package.json @@ -3,12 +3,19 @@ "version": "0.40.0", "description": "sqlx-ts ensures your raw SQLs are compile-time checked", "main": "dist/index.js", + "types": "dist/index.d.ts", + "exports": { + ".": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + } + }, "maintainers": [ "visualbbasic@gmail.com" ], "author": "Jason Shin ", "license": "MIT", - "bin": "./sqlx-ts", + "bin": "./cli.js", "scripts": { "postinstall": "node postinstall.js", "compile": "npx tsc -p tsconfig.json", From b3b1bf6098c32a46a842ba8f29f09b8fe002f80a Mon Sep 17 00:00:00 2001 From: JasonShin Date: Wed, 25 Feb 2026 00:34:08 +1100 Subject: [PATCH 2/4] fix --- .github/workflows/alternative-runtimes.yaml | 73 +++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/.github/workflows/alternative-runtimes.yaml b/.github/workflows/alternative-runtimes.yaml index db978987..6ad93615 100644 --- a/.github/workflows/alternative-runtimes.yaml +++ b/.github/workflows/alternative-runtimes.yaml @@ -36,6 +36,21 @@ jobs: - name: Verify Bun installation run: bun --version + - name: Build docker-compose services for integration tests + run: docker compose -f docker-compose.yml up -d + env: + MYSQL_VERSION: 8 + PG_VERSION: 16 + MYSQL_MIGRATION_FILE: 'mysql_migration.sql' + + - name: Wait for databases to be ready + uses: GuillaumeFalourd/wait-sleep-action@v1 + with: + time: '10' + + - name: Check docker-compose services + run: docker ps -a + - name: Install dependencies (npm install via postinstall) run: bun install @@ -45,6 +60,23 @@ jobs: - name: Test CLI wrapper with Bun (--help) run: bun run cli.js --help + - name: Add happy.ts test file + shell: bash + run: | + cat << 'EOF' > tests/staging/happy.ts + import { sql } from 'sqlx-ts' + + const selectSql4 = sql` + SELECT items.* + FROM items; + ` + EOF + + - name: Run happy test + working-directory: ./node + shell: bash + run: bun run cli.js --config=../.sqlxrc.sample.json ../tests/staging + - name: Verify CLI wrapper is JavaScript (not binary) shell: bash run: | @@ -86,6 +118,47 @@ jobs: with: node-version: 20 + - name: Build docker-compose services for integration tests + run: docker compose -f docker-compose.yml up -d + env: + MYSQL_VERSION: 8 + PG_VERSION: 16 + MYSQL_MIGRATION_FILE: 'mysql_migration.sql' + + - name: Wait for databases to be ready + uses: GuillaumeFalourd/wait-sleep-action@v1 + with: + time: '10' + + - name: Check docker-compose services + run: docker ps -a + + - name: Install dependencies (npm install via postinstall) + run: bun install + + - name: Test CLI wrapper with Bun (--version) + run: bun run cli.js --version + + - name: Test CLI wrapper with Bun (--help) + run: bun run cli.js --help + + - name: Add happy.ts test file + shell: bash + run: | + cat << 'EOF' > tests/staging/happy.ts + import { sql } from 'sqlx-ts' + + const selectSql4 = sql` + SELECT items.* + FROM items; + ` + EOF + + - name: Run happy test + working-directory: ./node + shell: bash + run: deno run --allow-read --allow-run cli.js --config=../.sqlxrc.sample.json ../tests/staging + - name: Install dependencies and download binary run: npm install From 90c429e0a680b821629380835dd64053080df50b Mon Sep 17 00:00:00 2001 From: JasonShin Date: Wed, 25 Feb 2026 00:38:24 +1100 Subject: [PATCH 3/4] fix --- .github/workflows/alternative-runtimes.yaml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.github/workflows/alternative-runtimes.yaml b/.github/workflows/alternative-runtimes.yaml index 6ad93615..9983cdf4 100644 --- a/.github/workflows/alternative-runtimes.yaml +++ b/.github/workflows/alternative-runtimes.yaml @@ -21,9 +21,6 @@ jobs: matrix: os: [ ubuntu-latest, macos-latest, windows-latest ] bun-version: [ '1.0.0', 'latest' ] - defaults: - run: - working-directory: ./node steps: - uses: actions/checkout@v3 @@ -55,9 +52,11 @@ jobs: run: bun install - name: Test CLI wrapper with Bun (--version) + working-directory: ./node run: bun run cli.js --version - name: Test CLI wrapper with Bun (--help) + working-directory: ./node run: bun run cli.js --help - name: Add happy.ts test file @@ -78,6 +77,7 @@ jobs: run: bun run cli.js --config=../.sqlxrc.sample.json ../tests/staging - name: Verify CLI wrapper is JavaScript (not binary) + working-directory: ./node shell: bash run: | if file cli.js | grep -q "script\|text\|ASCII"; then @@ -98,9 +98,6 @@ jobs: matrix: os: [ ubuntu-latest, macos-latest, windows-latest ] deno-version: [ 'v1.x', 'v2.x' ] - defaults: - run: - working-directory: ./node steps: - uses: actions/checkout@v3 @@ -160,15 +157,19 @@ jobs: run: deno run --allow-read --allow-run cli.js --config=../.sqlxrc.sample.json ../tests/staging - name: Install dependencies and download binary + working-directory: ./node run: npm install - name: Test CLI wrapper with Deno (--version) + working-directory: ./node run: deno run --allow-read --allow-run cli.js --version - name: Test CLI wrapper with Deno (--help) + working-directory: ./node run: deno run --allow-read --allow-run cli.js --help - name: Verify CLI wrapper is JavaScript (not binary) + working-directory: ./node shell: bash run: | if file cli.js | grep -q "script\|text\|ASCII"; then From 854da234b0c2750e89f4fef7394462ad64da815d Mon Sep 17 00:00:00 2001 From: JasonShin Date: Wed, 25 Feb 2026 00:40:40 +1100 Subject: [PATCH 4/4] fix --- .github/workflows/alternative-runtimes.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/alternative-runtimes.yaml b/.github/workflows/alternative-runtimes.yaml index 9983cdf4..98c6e9ed 100644 --- a/.github/workflows/alternative-runtimes.yaml +++ b/.github/workflows/alternative-runtimes.yaml @@ -49,6 +49,7 @@ jobs: run: docker ps -a - name: Install dependencies (npm install via postinstall) + working-directory: ./node run: bun install - name: Test CLI wrapper with Bun (--version) @@ -131,12 +132,15 @@ jobs: run: docker ps -a - name: Install dependencies (npm install via postinstall) + working-directory: ./node run: bun install - name: Test CLI wrapper with Bun (--version) + working-directory: ./node run: bun run cli.js --version - name: Test CLI wrapper with Bun (--help) + working-directory: ./node run: bun run cli.js --help - name: Add happy.ts test file