diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 9c47a93a..6a3f780d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -131,6 +131,39 @@ jobs: MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }} + publish-npm: + needs: publish + runs-on: ubuntu-latest + permissions: + contents: read + id-token: write # npm trusted-publishing OIDC + steps: + - uses: actions/checkout@v6 + with: + ref: v${{ inputs.version }} + - uses: actions/setup-node@v6 + with: + # Trusted publishing needs npm >=11.5.1; Node 22 LTS ships npm 10.x. + node-version: 24 + cache: npm + cache-dependency-path: bindings/typescript/package-lock.json + - name: Install dependencies + run: npm ci + working-directory: bindings/typescript + - name: Build + run: npm run build + working-directory: bindings/typescript + # LICENSE is a symlink in-tree (matches bindings/{haskell,rust}); npm-pack drops symlinks. + - name: Materialize LICENSE for npm pack + run: | + rm -f bindings/typescript/LICENSE + cp LICENSE bindings/typescript/LICENSE + - uses: JS-DevTools/npm-publish@v4 + with: + package: bindings/typescript + access: public + provenance: true + build-go-binaries: needs: publish permissions: @@ -192,7 +225,7 @@ jobs: gh release upload "$TAG" "$ASSET.tar.gz" "$ASSET.tar.gz.sha256" --clobber finalize-release: - needs: [release-crate, build-go-binaries, publish-jvm-bindings] + needs: [release-crate, build-go-binaries, publish-jvm-bindings, publish-npm] runs-on: ubuntu-latest permissions: contents: write diff --git a/.gitignore b/.gitignore index 8348665d..d501303f 100644 --- a/.gitignore +++ b/.gitignore @@ -29,4 +29,7 @@ dist-newstyle/ # Nix output /result +# TypeScript bindings build output +/bindings/typescript/dist/ + vendor/ diff --git a/bindings/typescript/LICENSE b/bindings/typescript/LICENSE new file mode 120000 index 00000000..30cff740 --- /dev/null +++ b/bindings/typescript/LICENSE @@ -0,0 +1 @@ +../../LICENSE \ No newline at end of file diff --git a/bindings/typescript/README.md b/bindings/typescript/README.md new file mode 100644 index 00000000..cf8016cf --- /dev/null +++ b/bindings/typescript/README.md @@ -0,0 +1,31 @@ +# `@scip-code/scip` + +Generated TypeScript definitions for the [SCIP Code Intelligence Protocol]. + +## Install + +``` sh +npm install @scip-code/scip +``` + +The package is ESM-only and ships with `.d.ts` declarations. Peer-style runtime +dependency on [`@bufbuild/protobuf`], which is installed transitively. + +## Use + +``` ts +import { fromBinary, toBinary } from "@bufbuild/protobuf"; +import { IndexSchema } from "@scip-code/scip"; +import { readFileSync } from "node:fs"; + +const bytes = readFileSync("index.scip"); +const index = fromBinary(IndexSchema, bytes); + +console.log(index.metadata?.projectRoot); +for (const doc of index.documents) { + console.log(doc.relativePath, doc.occurrences.length); +} +``` + + [SCIP Code Intelligence Protocol]: https://github.com/scip-code/scip + [`@bufbuild/protobuf`]: https://www.npmjs.com/package/@bufbuild/protobuf diff --git a/bindings/typescript/package.json b/bindings/typescript/package.json index 546a58e1..bd3f48a9 100644 --- a/bindings/typescript/package.json +++ b/bindings/typescript/package.json @@ -2,11 +2,28 @@ "name": "@scip-code/scip", "version": "0.8.0", "description": "Generated TypeScript definitions for the Semantic Code Intelligence Protocol.", - "repository": "https://github.com/scip-code/scip/bindings/typescript", + "repository": { + "type": "git", + "url": "git+https://github.com/scip-code/scip.git", + "directory": "bindings/typescript" + }, "author": "Sourcegraph", "license": "Apache-2.0", + "type": "module", + "main": "./dist/scip_pb.js", + "types": "./dist/scip_pb.d.ts", + "exports": { + ".": { + "types": "./dist/scip_pb.d.ts", + "import": "./dist/scip_pb.js" + } + }, + "files": ["dist", "LICENSE"], "sideEffects": false, - "private": false, + "scripts": { + "build": "tsc", + "typecheck": "tsc --noEmit" + }, "dependencies": { "@bufbuild/protobuf": "^2.11.0" }, diff --git a/bindings/typescript/tsconfig.json b/bindings/typescript/tsconfig.json index 38262ef0..ca06db1d 100644 --- a/bindings/typescript/tsconfig.json +++ b/bindings/typescript/tsconfig.json @@ -1,9 +1,15 @@ { "compilerOptions": { - "target": "ES2020", - "module": "ES2020", - "moduleResolution": "bundler", + "target": "ES2022", + "module": "NodeNext", + "moduleResolution": "NodeNext", + "outDir": "dist", "rootDir": ".", - "strict": true - } + "declaration": true, + "declarationMap": true, + "sourceMap": true, + "strict": true, + "skipLibCheck": true + }, + "include": ["scip_pb.ts"] } diff --git a/checks.nix b/checks.nix index 5ed23c74..fda571d9 100644 --- a/checks.nix +++ b/checks.nix @@ -146,7 +146,7 @@ npmDepsHash = "sha256-c+UXwcqJVmRvaIwmzjj42gbmu0X/iEUJUiTcqfXNDvg="; buildPhase = '' runHook preBuild - npx tsc --noEmit + npm run build runHook postBuild ''; installPhase = "touch $out";