Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to jsr.io #22

Merged
merged 7 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

Expand All @@ -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
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,7 +49,7 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: build
path: npm/
path: pkg/

- uses: actions/setup-node@v4
with:
Expand All @@ -65,7 +65,7 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: build
path: npm/
path: pkg/

- uses: denoland/setup-deno@v1
with:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@
*.app

.DS_Store
npm
pkg
node_modules
build
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.tgz
*.tgz
jsr.jsonc
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 8 additions & 6 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
25 changes: 25 additions & 0 deletions scripts/package.mjs
Original file line number Diff line number Diff line change
@@ -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));
2 changes: 1 addition & 1 deletion test_bun/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
2 changes: 1 addition & 1 deletion test_deno/deno.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion test_node/test-node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down