From 2467f974cd67aefcd391aede3f2d2e03de281e41 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 22 Sep 2026 16:32:40 +0000 Subject: [PATCH] Build with tsc alone and publish to npm from tags Emit JS and declarations with tsc so a prepare script can build dist/ on install, which makes installing from GitHub work without Bun. Source imports use .js extensions so the emitted ESM resolves under Node. Add a release workflow that tests, builds and publishes to npm with provenance when a v* tag matching package.json is pushed, via trusted publishing or an NPM_TOKEN secret. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01NTbgsritf5j3MP1V7UsU3p --- .github/workflows/release.yml | 30 ++++++++++++++++++++++++++++++ README.md | 5 +++++ package.json | 9 +++++++-- src/gk.ts | 6 +++--- src/index.ts | 16 ++++++++-------- src/list.ts | 4 ++-- src/map.ts | 4 ++-- src/options.ts | 4 ++-- src/set.ts | 4 ++-- tsconfig.build.json | 1 - 10 files changed, 61 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..a99fbd1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,30 @@ +# Publishes to npm when a tag like v1.2.3 is pushed and matches package.json. +# Uses npm trusted publishing (OIDC) if configured on npmjs.com for this +# repository and workflow; otherwise set an NPM_TOKEN repository secret. +name: release +on: + push: + tags: ["v*"] +permissions: + contents: read + id-token: write +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: oven-sh/setup-bun@v2 + - uses: actions/setup-node@v4 + with: + node-version: 22 + registry-url: https://registry.npmjs.org + - run: npm install -g npm@latest + - run: bun install --frozen-lockfile + - run: bun run typecheck + - run: bun test + - run: bun run smoke + - name: Check that the tag matches package.json + run: test "v$(node -p 'require("./package.json").version')" = "${GITHUB_REF_NAME}" + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/README.md b/README.md index ae05a46..c95d839 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,11 @@ bun run build # dist/ with ESM and type declarations bun run smoke # build, then import dist/ from Node ``` +Installing straight from GitHub also works (`npm install github:carsonfarmer/geometric-tree`): +the `prepare` script builds `dist/` on install. To release, bump `version` in `package.json`, +then push a matching tag (`git tag v0.2.0 && git push --tags`); the release workflow tests, +builds and publishes to npm with provenance. + ## References - Carson Farmer and Aljoscha Meyer. *Geometric Search Trees.* https://g-trees.github.io/g_trees/ diff --git a/package.json b/package.json index 9330df7..368a405 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,8 @@ "scripts": { "test": "bun test", "typecheck": "tsc --noEmit", - "build": "bun build src/index.ts --outdir dist --target node && tsc -p tsconfig.build.json", + "build": "tsc -p tsconfig.build.json", + "prepare": "tsc -p tsconfig.build.json", "smoke": "bun run build && node test/node.mjs", "bench": "bun run bench/bench.ts" }, @@ -37,5 +38,9 @@ "@types/bun": "^1.4.2", "typescript": "^5" }, - "main": "dist/index.js" + "main": "dist/index.js", + "publishConfig": { + "access": "public", + "provenance": true + } } diff --git a/src/gk.ts b/src/gk.ts index ca9c201..a59355f 100644 --- a/src/gk.ts +++ b/src/gk.ts @@ -14,8 +14,8 @@ * conversion happens in both directions at the same threshold, so the * representation remains a function of the stored set alone. */ -import { hashed, type Rank } from "./rank"; -import type { ItemsFactory, Options } from "./options"; +import { hashed, type Rank } from "./rank.js"; +import type { ItemsFactory, Options } from "./options.js"; import { ArrayItems, entries, @@ -29,7 +29,7 @@ import { type Entry, type Items, type Tree, -} from "./tree"; +} from "./tree.js"; /** One dimension of a Gk-tree: how its inner trees rank, weigh and nest. */ export type Dimension = { diff --git a/src/index.ts b/src/index.ts index 9221360..c8284f0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,8 @@ -export * from "./tree"; -export * as binary from "./binary"; -export * from "./rank"; -export { type ItemsFactory, type Options } from "./options"; -export { gk, GkItems, TreeItems } from "./gk"; -export { GMap } from "./map"; -export { GSet } from "./set"; -export { GList, at, splitAt, type Seq } from "./list"; +export * from "./tree.js"; +export * as binary from "./binary.js"; +export * from "./rank.js"; +export { type ItemsFactory, type Options } from "./options.js"; +export { gk, GkItems, TreeItems } from "./gk.js"; +export { GMap } from "./map.js"; +export { GSet } from "./set.js"; +export { GList, at, splitAt, type Seq } from "./list.js"; diff --git a/src/list.ts b/src/list.ts index 5ceb518..ff02702 100644 --- a/src/list.ts +++ b/src/list.ts @@ -1,4 +1,4 @@ -import { random, type Rank } from "./rank"; +import { random, type Rank } from "./rank.js"; import { ArrayItems, entries, @@ -8,7 +8,7 @@ import { zip, type Entry, type Tree, -} from "./tree"; +} from "./tree.js"; /** * A G-tree used as a sequence: positions replace keys, and node sizes guide diff --git a/src/map.ts b/src/map.ts index b0ef4bc..e07bb67 100644 --- a/src/map.ts +++ b/src/map.ts @@ -1,4 +1,4 @@ -import { config, type Config, type Options } from "./options"; +import { config, type Config, type Options } from "./options.js"; import { entries, find, @@ -8,7 +8,7 @@ import { size, type Entry, type Tree, -} from "./tree"; +} from "./tree.js"; /** An immutable, ordered map. Every update returns a new map. */ export class GMap implements Iterable<[K, V]> { diff --git a/src/options.ts b/src/options.ts index 19eaede..090ef2b 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,5 +1,5 @@ -import { hashed, type Rank } from "./rank"; -import { ArrayItems, type Compare, type Items } from "./tree"; +import { hashed, type Rank } from "./rank.js"; +import { ArrayItems, type Compare, type Items } from "./tree.js"; /** Creates the empty inner set for a node of a tree keyed by `K`. */ export type ItemsFactory = () => Items; diff --git a/src/set.ts b/src/set.ts index b7cbf3d..f6af5f6 100644 --- a/src/set.ts +++ b/src/set.ts @@ -1,4 +1,4 @@ -import { config, type Config, type Options } from "./options"; +import { config, type Config, type Options } from "./options.js"; import { entries, find, @@ -8,7 +8,7 @@ import { size, type Entry, type Tree, -} from "./tree"; +} from "./tree.js"; /** An immutable, ordered set. Every update returns a new set. */ export class GSet implements Iterable { diff --git a/tsconfig.build.json b/tsconfig.build.json index cef5624..314c1fa 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -3,7 +3,6 @@ "compilerOptions": { "noEmit": false, "declaration": true, - "emitDeclarationOnly": true, "outDir": "dist" }, "include": ["src"]