|
| 1 | +# Contributing to pgTyped |
| 2 | + |
| 3 | +pgTyped is an open source project, and we welcome contributions of all kinds, including bug reports, feature requests, and pull requests. |
| 4 | + |
| 5 | +# How to contribute? |
| 6 | + |
| 7 | +Our rules for pull requests and issues are fairly standard and flexible. When submitting a change, please provide a brief and descriptive title, if possible written in the imperative mood. |
| 8 | + |
| 9 | +If you have an idea for a new feature or want to address a bug, it's recommended that you first open an issue. We're available to assist and discuss the process of opening a pull request to ensure your changes are incorporated. |
| 10 | + |
| 11 | +We highly recommend you include a test-case added to the `packages/example` project when you submit a pull request or an issue. |
| 12 | + |
| 13 | +This will help us verify your issue or pull request and prevent regressions in the future. |
| 14 | + |
| 15 | +# Development Setup |
| 16 | + |
| 17 | +To get started, clone the repository and install the dependencies: |
| 18 | + |
| 19 | +```bash |
| 20 | +git clone [email protected]:adelsz/pgtyped.git |
| 21 | +cd pgtyped |
| 22 | +npm install |
| 23 | +``` |
| 24 | + |
| 25 | +We use a mono-repo setup with [Lerna](https://lernajs.io/) and NPM workspaces. |
| 26 | +This means that running `npm install` will install all the dependencies for all the packages in the project. |
| 27 | +It will also link the packages together, so that you can make changes to one package and immediately see the effects in another package. |
| 28 | + |
| 29 | +The `packages` directory contains the source code for the various components of pgTyped: |
| 30 | + |
| 31 | +- `packages/cli` - The CLI tool for generating TypeScript types from SQL files |
| 32 | +- `packages/wire` - The pgTyped PostgreSQL wire protocol implementation |
| 33 | +- `packages/parser` - The pgTyped SQL and TS language parser |
| 34 | +- `packages/runtime` - The pgTyped runtime library that provides the `sql` template tag and the `sql` function for executing queries. |
| 35 | +- `packages/query` - This package contains higher level PostgreSQL protocol utilities for describing query types, SSL support, and more. |
| 36 | +- `packages/example` - This repository contains a simple example of a pgTyped project written as a Jest test suite. We use this project both as a demonstration of pgTyped and as an end-to-end test suite for the project. |
| 37 | + |
| 38 | +To build the project, run: |
| 39 | + |
| 40 | +```bash |
| 41 | +npm run build |
| 42 | +``` |
| 43 | + |
| 44 | +This will build all the packages in the project. To run build in watch mode, run: |
| 45 | + |
| 46 | +```bash |
| 47 | +npm run watch |
| 48 | +``` |
| 49 | + |
| 50 | +To run the tests, run: |
| 51 | + |
| 52 | +```bash |
| 53 | +npm test |
| 54 | +``` |
| 55 | + |
| 56 | +It will run the tests for all the packages in the project, including end-to-end tests for the example project. |
| 57 | + |
| 58 | +# The `packages/example` project |
| 59 | + |
| 60 | +The `packages/example` project is an end-to-end test suite for pgTyped. It contains a simple example of a pgTyped project written as a Jest test suite. |
| 61 | + |
| 62 | +The packages `npm test` runs the following command: |
| 63 | + |
| 64 | +```bash |
| 65 | +docker-compose run build && docker-compose run test && docker-compose run test-cjs |
| 66 | +``` |
| 67 | + |
| 68 | +As you can see it runs the `build` target, then runs the `test` target twice, once with the `esm` module format and once with the `cjs` module format: |
| 69 | +- The `build` target runs pgTyped on the `sql` files in the `packages/example/src` directory generating the query code and type definitions. It also runs `git diff` to verify that the generated code matches the code in the repository. |
| 70 | +- The `test` target runs the queries in `packages/example/src/index.ts` and verifies that the results match the expected results. |
| 71 | +- The `test-cjs` target runs the same tests as the `test` target, but using the `cjs` module format to verify that the generated code works with both module formats. |
| 72 | + |
| 73 | +All the targets are run in a Docker container, with a Postgres database running in a separate container spun up by Docker Compose. |
| 74 | + |
| 75 | +The definitions of each of these targets and the DB service can be found in the `packages/example/docker-compose.yml` file. |
| 76 | + |
| 77 | +The database is initialized with the `sql/schema.sql` file. |
0 commit comments