Publish to JSR registry

This commit is contained in:
Héctor Molinero Fernández
2024-06-03 22:30:39 +02:00
parent b6556d0b54
commit 7137bf6013
4 changed files with 68 additions and 1 deletions
+27
View File
@@ -222,6 +222,33 @@ jobs:
npm publish --provenance --access public
fi
publish-jsr:
name: "Publish JSR package"
if: "startsWith(github.ref, 'refs/tags/v')"
needs: ["test-node", "test-deno", "test-bun", "test-browser"]
runs-on: "ubuntu-latest"
permissions:
contents: "read"
id-token: "write"
steps:
- name: "Checkout"
uses: "actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29"
- name: "Remove dist directory"
shell: "bash"
run: "rm -rf ./dist/"
- name: "Download dist artifact"
uses: "actions/download-artifact@65a9edc5881444af0b9093a5e628f2fe47ea3b2e"
with:
name: "dist"
path: "./dist/"
- name: "Use Node.js lts/*"
uses: "actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8"
with:
node-version: "lts/*"
- name: "Publish"
run: |
npx jsr publish
publish-github-release:
name: "Publish GitHub release"
if: "startsWith(github.ref, 'refs/tags/v')"
+10
View File
@@ -0,0 +1,10 @@
{
"name": "@hectorm/otpauth",
"version": "9.3.0",
"exports": {
".": "./dist/otpauth.esm.js"
},
"publish": {
"include": ["./*.md", "./dist/otpauth.esm.js", "./dist/otpauth.d.ts"]
}
}
+3 -1
View File
@@ -106,7 +106,9 @@
"test:browser:webkit:umd": "run-s test:browser:webkit:umd:*",
"test:browser:webkit:umd:unmin": "node ./test/browser.test.mjs webkit",
"test:browser:webkit:umd:min": "node ./test/browser.test.min.mjs webkit",
"version": "run-s all && git add -A ./types/ ./dist/ ./docs/"
"version": "run-s all version:jsr version:git",
"version:jsr": "node ./scripts/jsr.mjs",
"version:git": "git add -A ./jsr.json ./types/ ./dist/ ./docs/"
},
"dependencies": {
"@noble/hashes": "1.4.0"
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/env node
import fs from "node:fs/promises";
import path from "node:path";
import url from "node:url";
import { format, resolveConfig } from "prettier";
const __dirname = url.fileURLToPath(path.dirname(import.meta.url));
const pkgPath = path.join(__dirname, "../package.json");
const pkgSpec = JSON.parse(await fs.readFile(pkgPath, "utf8"));
const jsrPath = path.join(__dirname, "../jsr.json");
const jsrSpec = {
name: "@hectorm/otpauth",
version: pkgSpec.version,
exports: {
".": pkgSpec.exports["."].default,
},
publish: {
include: ["./*.md", pkgSpec.exports["."].default, pkgSpec.exports["."].types.import],
},
};
const prettierOpts = (await resolveConfig(__dirname)) ?? {};
prettierOpts.parser = "json";
await fs.writeFile(jsrPath, await format(JSON.stringify(jsrSpec, null, 2), prettierOpts));