diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 68df492..371292c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -61,6 +61,19 @@ jobs: - run: npm install --ignore-scripts - run: npm run build-debug - run: npm test + - run: npm run build-release + - name: Test shell wrapper (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + shell: powershell + run: | + echo "SELECT 'wrapper test';" | node shell.js + node shell.js --version + - name: Test shell wrapper (Unix) + if: ${{ !startsWith(matrix.os, 'windows') }} + shell: bash + run: | + echo "SELECT 'wrapper test';" | node shell.js + node shell.js --version test-bun: strategy: @@ -90,6 +103,19 @@ jobs: - run: bun install --ignore-scripts - run: bun run build-debug - run: bun run test + - run: bun run build-release + - name: Test shell wrapper (Windows) + if: ${{ startsWith(matrix.os, 'windows') }} + shell: powershell + run: | + echo "SELECT 'wrapper test';" | bun shell.js + bun shell.js --version + - name: Test shell wrapper (Unix) + if: ${{ !startsWith(matrix.os, 'windows') }} + shell: bash + run: | + echo "SELECT 'wrapper test';" | bun shell.js + bun shell.js --version publish: if: ${{ github.event_name == 'release' }} diff --git a/package.json b/package.json index 8326f29..c77bb33 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rocicorp/zero-sqlite3", - "version": "1.0.14", + "version": "1.0.15", "description": "better-sqlite3 on bedrock", "homepage": "https://github.com/rocicorp/zero-sqlite3", "author": "Rocicorp", @@ -10,14 +10,14 @@ }, "main": "lib/index.js", "bin": { - "zero-sqlite3": "./shell.ps1" + "zero-sqlite3": "./shell.js" }, "files": [ "binding.gyp", "src/**/*.[ch]pp", "lib/**", "deps/**", - "shell.sh" + "shell.js" ], "engines": { "node": "20.x || 22.x || 23.x || 24.x", diff --git a/shell.js b/shell.js new file mode 100755 index 0000000..c9632c3 --- /dev/null +++ b/shell.js @@ -0,0 +1,25 @@ +#!/usr/bin/env node +const { spawnSync } = require('child_process'); +const path = require('path'); +const fs = require('fs'); + +const binaryName = process.platform === 'win32' ? 'zero_sqlite3.exe' : 'zero_sqlite3'; +const binary = path.join(__dirname, 'build', 'Release', binaryName); + +if (!fs.existsSync(binary)) { + console.error(`Error: Binary not found at ${binary}`); + console.error('Please run: npm run build-release'); + process.exit(1); +} + +const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' }); + +if (result.error) { + console.error(`Error executing binary: ${result.error.message}`); + if (result.error.code === 'ENOEXEC') { + console.error('The binary may be built for a different platform. Please rebuild with: npm run build-release'); + } + process.exit(1); +} + +process.exit(result.status ?? 1); diff --git a/shell.ps1 b/shell.ps1 deleted file mode 100755 index a335951..0000000 --- a/shell.ps1 +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env sh -echo --% >/dev/null;: ' | out-null -<#' - - -# -# sh part -# -"$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")/build/Release/zero_sqlite3" "$@" -# end bash part - -exit #> - - -# -# powershell part -# -$scriptDir = (Get-Item -Path $MyInvocation.MyCommand.Definition).DirectoryName -& (Join-Path $scriptDir "build" "Release" "zero_sqlite3.exe") @args -