diff --git a/.github/workflows/alternative-runtimes.yaml b/.github/workflows/alternative-runtimes.yaml new file mode 100644 index 00000000..98c6e9ed --- /dev/null +++ b/.github/workflows/alternative-runtimes.yaml @@ -0,0 +1,185 @@ +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' ] + + 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: 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) + 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 + 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) + working-directory: ./node + 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' ] + + 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: 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) + 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 + 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 + 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 + 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",