|
1 | | -## Setting up the environment |
| 1 | +# Contributing |
2 | 2 |
|
3 | | -This repository uses Bazel 9.2, Node 26, and [`pnpm`](https://pnpm.io/installation). |
| 3 | +## Setup |
4 | 4 |
|
5 | | -To set up the repository, run: |
| 5 | +Install Node 26 and [Bazelisk](https://github.com/bazelbuild/bazelisk), then |
| 6 | +enable the repository's pinned `pnpm`: |
6 | 7 |
|
7 | 8 | ```sh |
8 | | -$ corepack enable pnpm |
9 | | -$ pnpm install |
10 | | -$ pnpm lefthook install |
11 | | -$ bazel build //:pkg |
| 9 | +npm install --global corepack@latest |
| 10 | +corepack enable pnpm |
| 11 | +pnpm install --frozen-lockfile |
| 12 | +pnpm lefthook install |
| 13 | +bazel build //:pkg |
12 | 14 | ``` |
13 | 15 |
|
14 | | -This installs dependencies and builds the publishable package at `bazel-bin/package/`. |
| 16 | +The publishable package is written to `bazel-bin/package/`. |
15 | 17 |
|
16 | | -## Modifying/Adding code |
| 18 | +## Make changes |
17 | 19 |
|
18 | | -API resources are generated from the OpenAPI specification. Keep manual helpers in `src/lib/`. |
| 20 | +Handwritten client, transport, and helper code lives in `src/client.ts`, |
| 21 | +`src/core/`, `src/internal/`, and `src/lib/`. Do not edit `src/generated/`, |
| 22 | +`src/resources.ts`, or `src/resources/`; the code is produced by a private SDK |
| 23 | +codegen pipeline. |
19 | 24 |
|
20 | | -Run Gazelle after adding, removing, or changing TypeScript imports. Gazelle owns |
21 | | -TypeScript sources and dependencies in `BUILD.bazel` files. |
| 25 | +Tests live beside handwritten code under `src/test/`. Compatibility and live |
| 26 | +API tests live under `e2e/`. |
| 27 | + |
| 28 | +After changing TypeScript imports or adding files, update BUILD files: |
22 | 29 |
|
23 | 30 | ```sh |
24 | | -$ bazel run //:gazelle |
| 31 | +bazel run //:gazelle |
25 | 32 | ``` |
26 | 33 |
|
27 | | -## Adding and running examples |
| 34 | +For a dependency change, update `package.json`, run |
| 35 | +`pnpm install --frozen-lockfile=false`, then run Gazelle. Commit |
| 36 | +`pnpm-lock.yaml` and generated `BUILD.bazel` changes. |
28 | 37 |
|
29 | | -Examples can be added under `examples/`. |
| 38 | +Use [Conventional Commits](https://www.conventionalcommits.org/), such as |
| 39 | +`fix: handle empty responses` or `feat: add a resource`. Release Please uses |
| 40 | +these commits to choose the next version and build the changelog. |
30 | 41 |
|
31 | | -```ts |
32 | | -// add an example to examples/<your-example>.mts |
| 42 | +## Test |
33 | 43 |
|
34 | | -#!/usr/bin/env -S node --experimental-transform-types |
35 | | -… |
36 | | -``` |
| 44 | +Run the same main test suite as CI: |
37 | 45 |
|
38 | 46 | ```sh |
39 | | -$ chmod +x examples/<your-example>.mts |
40 | | -# run the example against your api |
41 | | -$ node --experimental-transform-types examples/<your-example>.mts |
| 47 | +bazel test //... |
42 | 48 | ``` |
43 | 49 |
|
44 | | -## Using the repository from source |
45 | | - |
46 | | -To link a local build: |
| 50 | +Run core, package, and published-SDK compatibility gates explicitly: |
47 | 51 |
|
48 | 52 | ```sh |
49 | | -$ bazel build //:pkg |
50 | | -$ pnpm --dir bazel-bin/package link --global |
51 | | -$ cd ../my-package |
52 | | -$ pnpm link --global @perplexity-ai/perplexity_ai |
| 53 | +bazel test //:test //:package_checks //e2e:sdk_parity |
53 | 54 | ``` |
54 | 55 |
|
55 | | -## Running tests |
| 56 | +Validate formatting, lint, and generated BUILD files: |
56 | 57 |
|
57 | 58 | ```sh |
58 | | -$ bazel test //... |
| 59 | +pnpm lefthook run pre-commit --all-files --force --fail-on-changes |
59 | 60 | ``` |
60 | 61 |
|
61 | | -## Linting and formatting |
62 | | - |
63 | | -This repository uses [Oxfmt](https://www.npmjs.com/package/oxfmt) and |
64 | | -[Oxlint](https://www.npmjs.com/package/oxlint) to format and lint the code. |
65 | | - |
66 | | -To lint: |
| 62 | +Apply formatting and lint fixes: |
67 | 63 |
|
68 | 64 | ```sh |
69 | | -$ pnpm lefthook run pre-commit --all-files --force --fail-on-changes |
| 65 | +pnpm lefthook run pre-commit --all-files |
70 | 66 | ``` |
71 | 67 |
|
72 | | -To format and fix all lint issues automatically: |
| 68 | +Live tests call the production API and require a token. Run only the relevant |
| 69 | +shard: |
73 | 70 |
|
74 | 71 | ```sh |
75 | | -$ pnpm lefthook run pre-commit --all-files |
| 72 | +PPLX_API_TOKEN=... bazel test //e2e/live:search --test_env=PPLX_API_TOKEN |
76 | 73 | ``` |
77 | 74 |
|
78 | | -## Publishing and releases |
| 75 | +Build the publishable package: |
79 | 76 |
|
80 | | -Changes made to this repository via the automated release PR pipeline should publish to npm automatically. If |
81 | | -the changes aren't made through the automated pipeline, you may want to make releases manually. |
| 77 | +```sh |
| 78 | +bazel build //:pkg |
| 79 | +``` |
82 | 80 |
|
83 | | -### Publish with a GitHub workflow |
| 81 | +## Release |
84 | 82 |
|
85 | | -You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/perplexityai/perplexity-node/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up. |
| 83 | +Do not bump versions or publish from a development branch. |
86 | 84 |
|
87 | | -### Publish manually |
| 85 | +1. Merge normal PRs into `main`. |
| 86 | +2. Release Please creates or updates a `release: <version>` PR from Conventional |
| 87 | + Commits. |
| 88 | +3. Review and merge that PR. It updates the changelog and version files, then |
| 89 | + creates the `v<version>` tag and GitHub release. |
| 90 | +4. The published GitHub release triggers `Publish NPM`, which builds `//:pkg` |
| 91 | + and publishes it with npm provenance. |
88 | 92 |
|
89 | | -If needed, build the package with `bazel build //:pkg` and publish `bazel-bin/package` with npm. |
| 93 | +Stable versions use the `latest` npm tag. Prerelease versions use their |
| 94 | +prerelease identifier as the npm tag. Release automation requires |
| 95 | +`RELEASE_TOKEN`; npm publishing uses GitHub Actions OIDC and an npm trusted |
| 96 | +publisher for `publish-npm.yml`. For a failed upload, rerun `Publish NPM` |
| 97 | +against the existing release tag; do not create a new version. |
0 commit comments