diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c9408e8ea..560e99d3d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: publish to npm +name: publish to npm and jsr on: release: types: [published] @@ -9,6 +9,9 @@ env: jobs: publish-npm: runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # The OIDC ID token is used for authentication with JSR. steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -21,16 +24,16 @@ jobs: - name: Check tag format run: sh .github/scripts/check-tag-format.sh "${{ github.event.release.prerelease }}" - name: Install dependencies - run: yarn install + run: yarn - name: Build meilisearch-js run: yarn build - name: Publish with latest tag if: '!github.event.release.prerelease' - run: npm publish . + run: npm publish && yarn publish:jsr env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} - name: Publish with beta tag if: 'github.event.release.prerelease' - run: npm publish . --tag beta + run: npm publish --tag beta env: NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}} diff --git a/.gitignore b/.gitignore index 868fe3fb0..201906973 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,9 @@ typings/ # Output of 'npm pack' *.tgz +# JSR generated config +jsr.json + # Generated Docs docs/ diff --git a/package.json b/package.json index 5480ccfec..02c7d1462 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ }, "scripts": { "playground:javascript": "vite serve playgrounds/javascript --open", + "publish:jsr": "node scripts/make-jsr-json.js && npx jsr publish", "build:docs": "typedoc", "build": "vite build && tsc -p tsconfig.build.json && vite --mode production-umd build", "postbuild": "node scripts/build.js", diff --git a/scripts/make-jsr-json.js b/scripts/make-jsr-json.js new file mode 100644 index 000000000..8ae184dfd --- /dev/null +++ b/scripts/make-jsr-json.js @@ -0,0 +1,23 @@ +import { writeFileSync } from "node:fs"; +import pkg from "../package.json" with { type: "json" }; + +const { name, version, exports, files } = pkg; + +writeFileSync( + new URL("../jsr.json", import.meta.url), + JSON.stringify( + { + name: `@meilisearch/${name}`, + version, + exports: Object.fromEntries( + Object.entries(exports).map(([key, val]) => [ + key, + val.import.replace("dist/esm", "src").replace(".js", ".ts"), + ]), + ), + publish: { include: files.filter((v) => v !== "dist") }, + }, + null, + 2, + ), +);