From 4d735a95e9e9fbd993e64d4d8bc49c66b062c8f9 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Tue, 28 Jan 2025 10:48:46 +0200 Subject: [PATCH 1/6] Add script that creates jsr.json from package.json --- scripts/make-jsr-json.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 scripts/make-jsr-json.js diff --git a/scripts/make-jsr-json.js b/scripts/make-jsr-json.js new file mode 100644 index 000000000..e23c82d84 --- /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, + 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, + ), +); From 706b8adc19b02df4bb3ebc9e2316b96e33999c41 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:29:28 +0200 Subject: [PATCH 2/6] Modify publishing workflow and more --- .github/workflows/publish.yml | 11 +++++++---- package.json | 1 + scripts/make-jsr-json.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a7ebb7491..aa55184d5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -6,11 +6,14 @@ on: 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 with: - node-version: 20 + node-version: 22 registry-url: https://registry.npmjs.org/ cache: 'yarn' - name: Check release validity @@ -18,16 +21,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/package.json b/package.json index 2d0388437..e1bc0853b 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ }, "scripts": { "playground:javascript": "yarn --cwd ./playgrounds/javascript && yarn --cwd ./playgrounds/javascript dev", + "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 index e23c82d84..8ae184dfd 100644 --- a/scripts/make-jsr-json.js +++ b/scripts/make-jsr-json.js @@ -7,7 +7,7 @@ writeFileSync( new URL("../jsr.json", import.meta.url), JSON.stringify( { - name, + name: `@meilisearch/${name}`, version, exports: Object.fromEntries( Object.entries(exports).map(([key, val]) => [ From 3a1df74f3679263d706626d3b0dd3cadd3aaff17 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:34:05 +0200 Subject: [PATCH 3/6] Revert unimportant change --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index aa55184d5..38fe7869d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 with: - node-version: 22 + node-version: 20 registry-url: https://registry.npmjs.org/ cache: 'yarn' - name: Check release validity From 3823f48a1bb54a571381c177189448cd463d1eea Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:43:56 +0200 Subject: [PATCH 4/6] Add some explicit types that JSR complains about --- src/errors/version-hint-message.ts | 5 ++++- src/http-requests.ts | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/errors/version-hint-message.ts b/src/errors/version-hint-message.ts index 889b24a86..f4e71532e 100644 --- a/src/errors/version-hint-message.ts +++ b/src/errors/version-hint-message.ts @@ -1,3 +1,6 @@ -export function versionErrorHintMessage(message: string, method: string) { +export function versionErrorHintMessage( + message: string, + method: string, +): string { return `${message}\nHint: It might not be working because maybe you're not up to date with the Meilisearch version that ${method} call requires.`; } diff --git a/src/http-requests.ts b/src/http-requests.ts index 19e466323..e21422399 100644 --- a/src/http-requests.ts +++ b/src/http-requests.ts @@ -122,7 +122,7 @@ class HttpRequests { params?: { [key: string]: any }; body?: any; config?: Record; - }) { + }): Promise { const constructURL = new URL(url, this.url); if (params) { const queryParams = new URLSearchParams(); From 1c1b63dec95182fd95511f7036c0c5ce0601cb00 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Tue, 28 Jan 2025 11:46:52 +0200 Subject: [PATCH 5/6] Add jsr.json to gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 2814bdb2b..285aa8344 100644 --- a/.gitignore +++ b/.gitignore @@ -65,6 +65,9 @@ typings/ # Output of 'npm pack' *.tgz +# JSR generated config +jsr.json + # Generated Docs docs/ From 3e82c42e4ab9851c3cbb7e8721894569ed82f4b5 Mon Sep 17 00:00:00 2001 From: "F. Levi" <55688616+flevi29@users.noreply.github.com> Date: Tue, 28 Jan 2025 14:31:36 +0200 Subject: [PATCH 6/6] Adjust workflow name --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index aa55184d5..b78670c8e 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]