diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 67f1ea7..b643ad1 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -45,7 +45,7 @@ jobs: - run: deno publish working-directory: ${{ matrix.workspace }} npm: - if: fromJSON(needs.generate-matrix.outputs.exists) + if: ${{ fromJSON(needs.generate-matrix.outputs.exists)}} name: Publish ${{ matrix.name }}@${{matrix.version}} to NPM runs-on: ubuntu-latest @@ -71,6 +71,7 @@ jobs: - run: deno run -A www/tasks/build-npm.ts ${{matrix.workspace}} - run: npm publish --access=public --tag=latest + if: ${{ matrix.npmVersionUnpublished }} working-directory: ${{matrix.workspace}}/build/npm env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/www/hooks/use-npm-client.ts b/www/hooks/use-npm-client.ts new file mode 100644 index 0000000..26e99f3 --- /dev/null +++ b/www/hooks/use-npm-client.ts @@ -0,0 +1,19 @@ +import { createContext } from "effection"; +import { Client } from "jsr:@yorganci/npm-registry-api@0.3.0"; +import { call } from "effection"; + +const NPMClientContext = createContext("npm-client", new Client()); + +export function* isVersionPublished(name: string, versionOrTag = "latest") { + const client = yield* NPMClientContext; + + try { + yield* call(() => client.getPackageManifest(name, versionOrTag)); + return true; + } catch (error) { + if (error instanceof Deno.errors.NotFound) { + return false; + } + throw error; + } +} diff --git a/www/tasks/publish-matrix.ts b/www/tasks/publish-matrix.ts index ccebccc..b0019d3 100644 --- a/www/tasks/publish-matrix.ts +++ b/www/tasks/publish-matrix.ts @@ -2,6 +2,7 @@ import { call, each, main } from "effection"; import { usePackages } from "../hooks/use-packages.ts"; import { DenoJson } from "../hooks/use-package.tsx"; import { x } from "../../tinyexec/mod.ts"; +import { isVersionPublished } from "../hooks/use-npm-client.ts"; await main(function* () { let packages = yield* usePackages(); @@ -33,6 +34,8 @@ await main(function* () { tagname, name: pkg.name, version: pkg.version, + npmVersionUnpublished: + !(yield* isVersionPublished(pkg.name, pkg.version)), }); } }