Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: JSR + /x support #453

Merged
merged 11 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/publish_jsr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish to JSR

on:
push:
branches:
- main

env:
DENO_UNSTABLE_WORKSPACES: true
iuioiua marked this conversation as resolved.
Show resolved Hide resolved

jobs:
publish:
runs-on: ubuntu-latest
timeout-minutes: 30

permissions:
contents: read
id-token: write

steps:
- name: Clone repository
uses: actions/checkout@v4
with:
submodules: true

- name: Set up Deno
uses: denoland/setup-deno@v1

- name: Convert to JSR package
run: deno run -A tools/convert_to_jsr.ts

- name: Format
run: deno fmt --check

- name: Lint
run: deno lint

- name: Documentation tests
run: deno test --doc client.ts mod.ts pool.ts client/ connection/ query/ utils/

- name: Build tests container
run: docker-compose build tests

- name: Run tests
run: docker-compose run tests

- name: Publish (dry run)
if: startsWith(github.ref, 'refs/tags/') == false
run: deno publish --dry-run

- name: Publish (real)
if: startsWith(github.ref, 'refs/tags/')
run: deno publish
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
![Build Status](https://img.shields.io/github/workflow/status/denodrivers/postgres/ci?label=Build&logo=github&style=flat-square)
[![Discord server](https://img.shields.io/discord/768918486575480863?color=blue&label=Ask%20for%20help%20here&logo=discord&style=flat-square)](https://discord.gg/HEdTCvZUSf)
[![Manual](https://img.shields.io/github/v/release/denodrivers/postgres?color=orange&label=Manual&logo=deno&style=flat-square)](https://deno-postgres.com)
[![Documentation](https://img.shields.io/github/v/release/denodrivers/postgres?color=yellow&label=Documentation&logo=deno&style=flat-square)](https://doc.deno.land/https/deno.land/x/postgres@v0.17.1/mod.ts)
[![Documentation](https://img.shields.io/github/v/release/denodrivers/postgres?color=yellow&label=Documentation&logo=deno&style=flat-square)](https://doc.deno.land/https/deno.land/x/postgres/mod.ts)
[![License](https://img.shields.io/github/license/denodrivers/postgres?color=yellowgreen&label=License&style=flat-square)](LICENSE)

A lightweight PostgreSQL driver for Deno focused on user experience
Expand All @@ -16,7 +16,7 @@ A lightweight PostgreSQL driver for Deno focused on user experience

```ts
// deno run --allow-net --allow-read mod.ts
import { Client } from "https://deno.land/x/postgres@v0.17.1/mod.ts";
import { Client } from "https://deno.land/x/postgres/mod.ts";

const client = new Client({
user: "user",
Expand Down
6 changes: 6 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"lock": false,
"name": "@bartlomieju/postgres",
iuioiua marked this conversation as resolved.
Show resolved Hide resolved
"version": "0.17.2",
"exports": "./mod.ts"
}
6 changes: 3 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
![Build Status](https://img.shields.io/github/workflow/status/denodrivers/postgres/ci?label=Build&logo=github&style=flat-square)
[![Discord server](https://img.shields.io/discord/768918486575480863?color=blue&label=Ask%20for%20help%20here&logo=discord&style=flat-square)](https://discord.gg/HEdTCvZUSf)
![Manual](https://img.shields.io/github/v/release/denodrivers/postgres?color=orange&label=Manual&logo=deno&style=flat-square)
[![Documentation](https://img.shields.io/github/v/release/denodrivers/postgres?color=yellow&label=Documentation&logo=deno&style=flat-square)](https://doc.deno.land/https/deno.land/x/postgres@v0.17.1/mod.ts)
[![Documentation](https://img.shields.io/github/v/release/denodrivers/postgres?color=yellow&label=Documentation&logo=deno&style=flat-square)](https://doc.deno.land/https/deno.land/x/postgres/mod.ts)
![License](https://img.shields.io/github/license/denodrivers/postgres?color=yellowgreen&label=License&style=flat-square)

`deno-postgres` is a lightweight PostgreSQL driver for Deno focused on user
experience. It provides abstractions for most common operations such as typed
queries, prepared statements, connection pools and transactions.

```ts
import { Client } from "https://deno.land/x/postgres@v0.17.1/mod.ts";
import { Client } from "https://deno.land/x/postgres/mod.ts";

const client = new Client({
user: "user",
Expand All @@ -38,7 +38,7 @@ All `deno-postgres` clients provide the following options to authenticate and
manage your connections

```ts
import { Client } from "https://deno.land/x/postgres@v0.17.1/mod.ts";
import { Client } from "https://deno.land/x/postgres/mod.ts";

let config;

Expand Down
38 changes: 38 additions & 0 deletions tools/convert_to_jsr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { walk } from "https://deno.land/std@0.214.0/fs/walk.ts";
import denoConfig from "../deno.json" with { type: "json" };

const STD_SPECIFIER_REGEX =
/https:\/\/deno\.land\/std@(\d+\.\d+\.\d+)\/(\w+)\/(.+)\.ts/g;
const POSTGRES_X_SPECIFIER = "https://deno.land/x/postgres/mod.ts";
const POSTGRES_JSR_SPECIFIER = `jsr:${denoConfig.name}`;

function toStdJsrSpecifier(
_full: string,
_version: string,
module: string,
path: string,
): string {
/**
* @todo(iuioiua) Restore the dynamic use of the `version` argument
* once 0.214.0 is released.
*/
const version = "0.213.1";
return path === "mod"
? `jsr:@std/${module}@${version}`
: `jsr:@std/${module}@${version}/${path}`;
}

for await (
const entry of walk(".", {
includeDirs: false,
exts: [".ts", ".md"],
skip: [/docker/, /.github/, /tools/],
followSymlinks: false,
})
) {
const text = await Deno.readTextFile(entry.path);
const newText = text
.replaceAll(STD_SPECIFIER_REGEX, toStdJsrSpecifier)
.replaceAll(POSTGRES_X_SPECIFIER, POSTGRES_JSR_SPECIFIER);
await Deno.writeTextFile(entry.path, newText);
}