Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 54 additions & 11 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,66 @@ jobs:
with:
node-version: ${{ matrix.node }}

- name: Install dependencies (npm install)
run: npm install
- name: Build npm packages from the current release
shell: bash
run: |
TEMP_DIR="${RUNNER_TEMP//\\//}"
VERSION=$(node -p "require('./package.json').version")
gh release download "v$VERSION" -p '*.zip' -D "$TEMP_DIR/zips"
../scripts/build-npm-platform-packages.sh "v$VERSION" "$TEMP_DIR/zips" "$TEMP_DIR/platform"
git checkout package.json
npm pack --pack-destination "$TEMP_DIR"
(cd "$TEMP_DIR/platform/sqlx-ts-$(node -p 'process.platform + "-" + process.arch')" && npm pack --pack-destination "$TEMP_DIR")
env:
GH_TOKEN: ${{ github.token }}

- name: Install sqlx-ts with its platform package
shell: bash
run: |
TEMP_DIR="${RUNNER_TEMP//\\//}"
mkdir "$TEMP_DIR/project"
cd "$TEMP_DIR/project"
npm init -y
npm install "$TEMP_DIR"/sqlx-ts-*.tgz

- name: Verify sqlx-ts binary from npm install
working-directory: ${{ runner.temp }}/project
run: |
npx sqlx-ts --version
npx sqlx-ts --help

- uses: oven-sh/setup-bun@v2
if: matrix.node == 22

- name: Verify sqlx-ts binary from bun install
if: matrix.node == 22
shell: bash
run: |
chmod +x ./sqlx-ts || true
./sqlx-ts --version
./sqlx-ts --help
TEMP_DIR="${RUNNER_TEMP//\\//}"
mkdir "$TEMP_DIR/bun-project"
cd "$TEMP_DIR/bun-project"
echo '{ "name": "bun-project" }' > package.json
bun add "$TEMP_DIR"/sqlx-ts-*.tgz
bunx sqlx-ts --version

- uses: denoland/setup-deno@v2
if: matrix.node == 22
with:
deno-version: v2.x

- name: Install using local install.sh
run: node postinstall.js
- name: Verify sqlx-ts launcher with deno
if: matrix.node == 22
working-directory: ${{ runner.temp }}/project
run: deno run -A node_modules/sqlx-ts/bin/sqlx-ts.js --version

- name: Verify sqlx-ts binary from local install
- name: Install using install.sh
shell: bash
run: |
chmod +x ./sqlx-ts || true
./sqlx-ts --version
./sqlx-ts --help
OS=$(node -p 'process.platform')
CPU=$(node -p '["arm64", "x64"].includes(process.arch) ? process.arch : "x32"')
TEMP_DIR="${RUNNER_TEMP//\\//}"
sh ../scripts/install.sh --os "$OS" --cpu "$CPU" --to "$TEMP_DIR/bin"
"$TEMP_DIR/bin/sqlx-ts" --version

linux-distro-static-binary-test:
name: linux distro ${{ matrix.distro }}
Expand Down
62 changes: 61 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,31 @@ jobs:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm run compile
- run: cp ../README.md .
- run: npm version "${TAG#v}" --no-git-tag-version
env:
TAG: ${{ github.event.release.tag_name }}
- run: npm publish --access public
- name: Publish platform packages and sqlx-ts
run: |
[[ "$TAG" == *-* ]] && NPM_TAG=next || NPM_TAG=latest
gh release download "$TAG" -p '*.zip' -D "$RUNNER_TEMP/zips"
../scripts/build-npm-platform-packages.sh "$TAG" "$RUNNER_TEMP/zips" "$RUNNER_TEMP/platform"
for dir in "$RUNNER_TEMP"/platform/*; do
if [ -n "$(npm view "$(basename "$dir")@${TAG#v}" version 2> /dev/null)" ]; then
echo "$(basename "$dir")@${TAG#v} is already published"
else
npm publish "$dir" --access public --tag "$NPM_TAG"
fi
done
npm publish --access public --tag "$NPM_TAG" --ignore-scripts
env:
TAG: ${{ github.event.release.tag_name }}
GH_TOKEN: ${{ github.token }}

bump-version:
needs: node
if: ${{ !contains(github.event.release.tag_name, '-') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
Expand All @@ -148,3 +166,45 @@ jobs:
git push origin main
env:
TAG: ${{ github.event.release.tag_name }}

smoke-test:
needs: node
name: smoke test ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/setup-node@v6
with:
node-version: '24'
- uses: oven-sh/setup-bun@v2
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Wait for npm to make the packages available
shell: bash
run: |
VERSION="${TAG#v}"
PLATFORM_PACKAGE="sqlx-ts-$(node -p 'process.platform + "-" + process.arch')"
for i in $(seq 1 30); do
if [ -n "$(npm view "sqlx-ts@$VERSION" version 2> /dev/null)" ] && [ -n "$(npm view "$PLATFORM_PACKAGE@$VERSION" version 2> /dev/null)" ]; then
exit 0
fi
sleep 20
done
echo "sqlx-ts@$VERSION or $PLATFORM_PACKAGE@$VERSION is not available on npm after 10 minutes"
exit 1
env:
TAG: ${{ github.event.release.tag_name }}
- name: Run sqlx-ts with npx, bunx and deno
shell: bash
run: |
VERSION="${TAG#v}"
cd "$(mktemp -d)"
npx -y "sqlx-ts@$VERSION" --version | grep -F "sqlx-ts $VERSION"
bunx "sqlx-ts@$VERSION" --version | grep -F "sqlx-ts $VERSION"
deno run -A "npm:sqlx-ts@$VERSION" --version | grep -F "sqlx-ts $VERSION"
env:
TAG: ${{ github.event.release.tag_name }}
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,32 @@ Verify the installation by running
$ npx sqlx-ts --version
```

##### Bun and Deno

From v0.50.0, the `sqlx-ts` binary comes as an optional dependency for your platform (e.g. `sqlx-ts-darwin-arm64`), so
Bun and Deno install it the same way as npm

```bash
# Bun
$ bun add sqlx-ts
$ bunx sqlx-ts --version
# Deno
$ deno add npm:sqlx-ts
$ deno run -A npm:sqlx-ts --version
```

The binary is not installed with `--omit=optional` or `--no-optional`. In that case, or on a platform without a prebuilt
binary, [install the binary separately](#installing-binary-separately) to a directory on your PATH and `sqlx-ts` will use it.

v0.49.0 and older download the binary in a `postinstall` step, which Bun and Deno do not run. For these versions, install
the binary separately, or with Bun add sqlx-ts to `trustedDependencies` in package.json

```json
{
"trustedDependencies": ["sqlx-ts"]
}
```

And to use sqlx-ts in your code

In TypeScript based projects:
Expand Down Expand Up @@ -119,7 +145,7 @@ If you're a **Windows** user, then you can install sqlx-ts from via install.sh:
# windows & x32
$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os win32 --cpu x32
# windows & x64
$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os win32 --cpu x32
$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os win32 --cpu x64
```

If you're a **Linux** user, then you can install sqlx-ts from via install.sh:
Expand Down
31 changes: 31 additions & 0 deletions book/docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,35 @@ Verify the installation of `sqlx-ts` binary by running
$ npx sqlx-ts --version
```

## Bun and Deno

From v0.50.0, the `sqlx-ts` binary comes as an optional dependency for your platform (e.g. `sqlx-ts-darwin-arm64`), so
Bun and Deno install it the same way as npm

```bash
# Bun
$ bun add --dev sqlx-ts
$ bunx sqlx-ts --version
# Deno
$ deno add --dev npm:sqlx-ts
$ deno run -A npm:sqlx-ts --version
```

The binary is not installed with `--omit=optional` or `--no-optional`. In that case, or on a platform without a prebuilt
binary, install the binary to a directory on your PATH with install.sh and `sqlx-ts` will use it

```bash
# --os: darwin | linux | win32, --cpu: arm64 | x64 | x32
$ curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os darwin --cpu arm64 --to ~/.local/bin
```

v0.49.0 and older download the binary in a `postinstall` step, which Bun and Deno do not run. For these versions, install
the binary with install.sh as above, or with Bun add sqlx-ts to `trustedDependencies` in package.json

```json
{
"trustedDependencies": ["sqlx-ts"]
}
```

🚀 you now have `sqlx-ts` installed 🚀
44 changes: 44 additions & 0 deletions node/bin/sqlx-ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
const { spawnSync } = require('child_process')
const fs = require('fs')
const path = require('path')

const platformPackage = `sqlx-ts-${process.platform}-${process.arch}`
const binaryName = process.platform === 'win32' ? 'sqlx-ts.exe' : 'sqlx-ts'

function findInPlatformPackage() {
try {
return require.resolve(`${platformPackage}/${binaryName}`)
} catch {
return undefined
}
}

function findOnPath() {
for (const dir of (process.env.PATH || '').split(path.delimiter)) {
const candidate = path.join(dir, binaryName)
if (fs.existsSync(candidate) && !fs.realpathSync(candidate).endsWith('.js')) {
return candidate
}
}
}

const binary = findInPlatformPackage() || findOnPath()

if (!binary) {
const cpu = process.arch === 'arm64' || process.arch === 'x64' ? process.arch : 'x32'
console.error(`sqlx-ts binary is not installed. It comes from the optional dependency ${platformPackage}.
If you installed with --omit=optional or --no-optional, or copied node_modules from another OS, reinstall without them.
Otherwise install the binary separately to a directory on your PATH:

curl -LSfs https://jasonshin.github.io/sqlx-ts/install.sh | sh -s -- --os ${process.platform} --cpu ${cpu} --to ~/.local/bin

See https://jasonshin.github.io/sqlx-ts for other installation options.`)
process.exit(1)
}

const result = spawnSync(binary, process.argv.slice(2), { stdio: 'inherit' })
if (result.error) {
throw result.error
}
process.exit(result.status ?? 1)
15 changes: 1 addition & 14 deletions node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"homepage": "https://jasonshin.github.io/sqlx-ts",
"repository": {
"type": "git",
"url": "https://github.com/JasonShin/sqlx-ts"
"url": "git+https://github.com/JasonShin/sqlx-ts.git"
},
"bugs": {
"url": "https://github.com/JasonShin/sqlx-ts/issues"
Expand All @@ -36,19 +36,15 @@
"author": "Jason Shin <visualbbasic@gmail.com>",
"license": "MIT",
"bin": {
"sqlx-ts": "sqlx-ts"
"sqlx-ts": "bin/sqlx-ts.js"
},
"scripts": {
"postinstall": "node postinstall.js",
"compile": "npx tsc -p tsconfig.json",
"lint": "npx eslint --ext .ts src",
"lint:fix": "npx eslint --ext .ts src --fix",
"test": "npx jest",
"prepublishOnly": "cp ../README.md . && npm i && npm run compile"
},
"dependencies": {
"adm-zip": "^0.5.16"
},
"devDependencies": {
"@types/jest": "^27.4.1",
"@types/node": "^20.14.8",
Expand All @@ -61,5 +57,9 @@
},
"engines": {
"node": ">=16"
}
},
"files": [
"dist",
"bin"
]
}
Loading
Loading