Skip to content

Commit

Permalink
feat: JSR + /x support (#453)
Browse files Browse the repository at this point in the history
* feat: JSR support

* work

* work

* work

* tweak

* fmt

* tweak

* tweak

* tweak

* tweak

* workaround
  • Loading branch information
iuioiua authored Feb 6, 2024
1 parent 52322da commit b78c2a6
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
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

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
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",
"version": "0.17.2",
"exports": "./mod.ts"
}
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/[email protected]/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);
}

1 comment on commit b78c2a6

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No typecheck tests failure

This error was most likely caused by incorrect type stripping from the SWC crate

Please report the following failure to https://github.com/denoland/deno with a reproduction of the current commit

Failure log

Please sign in to comment.