From 819d5bc856aedac10a775c2898b9711cb6aa2d36 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Wed, 27 Mar 2024 10:22:09 +0100 Subject: [PATCH] chore: automate publishing --- .github/workflows/publish.yml | 23 +++++++++++++++++++++++ deno.json | 2 +- tools/pre_publish.ts | 29 +++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/publish.yml create mode 100644 tools/pre_publish.ts diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000000..65c10d40ce3 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,23 @@ +name: Publish JSR + +on: + push: + branches: + - fresh-2.0 + +jobs: + publish: + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write + + steps: + - uses: actions/checkout@v4 + + - name: Install Deno + uses: denoland/setup-deno@v1 + with: + deno-version: v1.x + - run: deno run --allow-write --allow-read tools/pre_publish.ts + - run: npx jsr publish \ No newline at end of file diff --git a/deno.json b/deno.json index cd400d66b8e..65959103218 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@marvinh-test/fresh", - "version": "2.0.0-prealpha.7", + "version": "2.0.0-prealpha.8", "exports": { ".": "./src/mod.ts", "./runtime": "./src/runtime/client/mod.tsx", diff --git a/tools/pre_publish.ts b/tools/pre_publish.ts new file mode 100644 index 00000000000..22bd0ae583c --- /dev/null +++ b/tools/pre_publish.ts @@ -0,0 +1,29 @@ +import * as path from "@std/path"; +import { DenoConfig } from "../src/dev/dev_app.ts"; + +const denoJsonPath = path.join(import.meta.dirname!, "..", "deno.json"); +const denoJson = JSON.parse( + await Deno.readTextFile(denoJsonPath), +) as DenoConfig; + +const replaceLibs = ["preact", "preact-render-to-string", "@preact/signals"]; + +if (denoJson.imports) { + for (const replace of replaceLibs) { + const value = denoJson.imports[replace]; + if (value === undefined) continue; + + // Remove url expansion imports. They are not neede with + // `npm:` or `jsr:` prefixes. + delete denoJson.imports[replace + "/"]; + + const match = value.match( + /^https:\/\/esm\.sh\/((@\w+\/)?[^@\?]+)(@[^\?]+)?.*$/, + ); + if (match !== null) { + denoJson.imports[replace] = `npm:${match[1]}${match[3]}`; + } + } +} + +await Deno.writeTextFile(denoJsonPath, JSON.stringify(denoJson, null, 2));