From 9b78877c0cd2087f1d3bffcea68249de7e1f7b96 Mon Sep 17 00:00:00 2001 From: keito <131662659+mst-mkt@users.noreply.github.com> Date: Tue, 14 May 2024 19:13:45 +0900 Subject: [PATCH] chore: Publish to jsr.io (#22) * add: script of package for jsr * add: workflow of publish to jsr * fix: change directory name to include packages other than npm (`npm` -> `pkg`) * chore: add installation command from jsr.io * fix: package name of jsr.io (`clang-fmt` -> `clang-format`) * chore: Add jsr.jsonc to .npmignore * fix: Update import paths to use the "pkg" directory instead of "npm" --------- Co-authored-by: magic-akari --- .github/workflows/publish.yml | 13 ++++++++----- .github/workflows/test.yml | 10 +++++----- .gitignore | 2 +- .npmignore | 3 ++- README.md | 9 ++++++++- scripts/build.sh | 14 ++++++++------ scripts/package.mjs | 25 +++++++++++++++++++++++++ test_bun/bun.spec.ts | 2 +- test_deno/deno.test.ts | 2 +- test_node/test-node.mjs | 2 +- 10 files changed, 60 insertions(+), 22 deletions(-) create mode 100755 scripts/package.mjs diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 15dfeb4..13dc9c2 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -43,7 +43,7 @@ jobs: WASM_OPT: 1 - name: Publish to npm - run: cd npm && npm publish --provenance + run: cd pkg && npm publish --provenance env: NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} @@ -53,16 +53,19 @@ jobs: registry-url: "https://npm.pkg.github.com" - name: Publish to GitHub Packages - run: cd npm && npm publish + run: cd pkg && npm publish env: NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Publish to jsr.io + run: cd pkg && npx jsr publish + - name: Pack - run: cd npm && npm pack + run: cd pkg && npm pack - name: Publish to Github Releases uses: softprops/action-gh-release@9d7c94cfd0a1f3ed45544c887983e9fa900f0564 with: files: | - npm/*.tgz - npm/*.wasm + pkg/*.tgz + pkg/*.wasm diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 58df9c0..a4c8a22 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,13 +33,13 @@ jobs: run: ./scripts/build.sh - name: Pack - run: cd npm && npm pack + run: cd pkg && npm pack - name: Upload uses: actions/upload-artifact@v4 with: name: build - path: npm + path: pkg node-test: runs-on: ubuntu-latest @@ -49,7 +49,7 @@ jobs: - uses: actions/download-artifact@v4 with: name: build - path: npm/ + path: pkg/ - uses: actions/setup-node@v4 with: @@ -65,7 +65,7 @@ jobs: - uses: actions/download-artifact@v4 with: name: build - path: npm/ + path: pkg/ - uses: denoland/setup-deno@v1 with: @@ -81,7 +81,7 @@ jobs: - uses: actions/download-artifact@v4 with: name: build - path: npm/ + path: pkg/ - uses: oven-sh/setup-bun@v1 name: Install bun diff --git a/.gitignore b/.gitignore index 459aeec..7dfb032 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,6 @@ *.app .DS_Store -npm +pkg node_modules build \ No newline at end of file diff --git a/.npmignore b/.npmignore index 9e30eb9..a93ee7a 100644 --- a/.npmignore +++ b/.npmignore @@ -1 +1,2 @@ -*.tgz \ No newline at end of file +*.tgz +jsr.jsonc diff --git a/README.md b/README.md index a00ed64..3295d52 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,19 @@ [![Test](https://github.com/wasm-fmt/clang-format/actions/workflows/test.yml/badge.svg)](https://github.com/wasm-fmt/clang-format/actions/workflows/test.yml) -[![npm](https://img.shields.io/npm/v/@wasm-fmt/clang-format)](https://www.npmjs.com/package/@wasm-fmt/clang-format) # Install +[![npm](https://img.shields.io/npm/v/@wasm-fmt/clang-format)](https://www.npmjs.com/package/@wasm-fmt/clang-format) + ```bash npm install @wasm-fmt/clang-format ``` +[![jsr.io](https://jsr.io/badges/@fmt/clang-format?color=3572A5)](https://jsr.io/@fmt/clang-format) + +```bash +npx jsr add @fmt/clang-format +``` + # Usage ```JavaScript diff --git a/scripts/build.sh b/scripts/build.sh index 985e21f..ec14564 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -3,8 +3,8 @@ set -Eeo pipefail cd $(dirname $0)/.. project_root=$(pwd) -rm -rf npm -mkdir -p npm build +rm -rf pkg +mkdir -p pkg build cd build export CC=$(which clang) @@ -22,8 +22,10 @@ fi SMALLEST_WASM=$(ls -Sr build/*.wasm | head -1) -cp $SMALLEST_WASM npm/clang-format.wasm -npm exec terser -- src/template.js build/clang-format-wasm.js --config-file .terser.json --output npm/clang-format.js +cp $SMALLEST_WASM pkg/clang-format.wasm +npm exec terser -- src/template.js build/clang-format-wasm.js --config-file .terser.json --output pkg/clang-format.js -cp src/clang-format.d.ts src/clang-format-*.js npm -cp package.json LICENSE README.md .npmignore npm +cp src/clang-format.d.ts src/clang-format-*.js pkg +cp package.json LICENSE README.md .npmignore pkg + +./scripts/package.mjs ./package.json diff --git a/scripts/package.mjs b/scripts/package.mjs new file mode 100755 index 0000000..855715f --- /dev/null +++ b/scripts/package.mjs @@ -0,0 +1,25 @@ +#!/usr/bin/env node +import process from "node:process"; +import path from "node:path"; +import fs from "node:fs"; + +const pkg_path = path.resolve(process.cwd(), process.argv[2]); +const pkg_text = fs.readFileSync(pkg_path, { encoding: "utf-8" }); +const pkg_json = JSON.parse(pkg_text); + +// JSR + +const jsr_path = path.resolve(pkg_path, "..", "pkg", "jsr.jsonc"); +pkg_json.name = "@fmt/clang-format"; +pkg_json.exports = "./clang-format.js"; +pkg_json.publish = { + include: [ + "clang-format.js", + "clang-format.d.ts", + "clang-format.wasm", + "jsr.jsonc", + "LICENSE", + "README.md", + ], +}; +fs.writeFileSync(jsr_path, JSON.stringify(pkg_json, null, 4)); diff --git a/test_bun/bun.spec.ts b/test_bun/bun.spec.ts index 85d6527..08c24f1 100644 --- a/test_bun/bun.spec.ts +++ b/test_bun/bun.spec.ts @@ -1,7 +1,7 @@ import { expect, test } from "bun:test"; import fs from "node:fs/promises"; import path from "node:path"; -import init, { format } from "../npm"; +import init, { format } from "../pkg"; await init(); diff --git a/test_deno/deno.test.ts b/test_deno/deno.test.ts index 8795784..969ffe3 100644 --- a/test_deno/deno.test.ts +++ b/test_deno/deno.test.ts @@ -2,7 +2,7 @@ import { assertEquals } from "https://deno.land/std@0.201.0/assert/mod.ts"; import { walk } from "https://deno.land/std@0.201.0/fs/walk.ts"; import { relative } from "https://deno.land/std@0.201.0/path/mod.ts"; -import init, { format } from "../npm/clang-format.js"; +import init, { format } from "../pkg/clang-format.js"; await init(); diff --git a/test_node/test-node.mjs b/test_node/test-node.mjs index da04c6e..a23d4a0 100644 --- a/test_node/test-node.mjs +++ b/test_node/test-node.mjs @@ -3,7 +3,7 @@ import fs from "node:fs/promises"; import path from "node:path"; import { test } from "node:test"; import { fileURLToPath } from "node:url"; -import init, { format } from "../npm/clang-format-node.js"; +import init, { format } from "../pkg/clang-format-node.js"; await init();