|
| 1 | +# GitHub Copilot Instructions for AlaSQL |
| 2 | + |
| 3 | +## About This Project |
| 4 | + |
| 5 | +AlaSQL is an open source SQL database for JavaScript with a focus on query speed and data source flexibility for both relational data and schemaless data. It works in web browsers, Node.js, and mobile apps. |
| 6 | + |
| 7 | +## Technology Stack |
| 8 | + |
| 9 | +- **Language**: JavaScript (ES5/ES6) |
| 10 | +- **Build System**: Shell script (`build.sh`) that concatenates source files from `src/` into `dist/` |
| 11 | +- **Package Manager**: Yarn (preferred) or npm |
| 12 | +- **Testing**: Mocha test framework |
| 13 | +- **Code Formatting**: Prettier with specific settings (tabs, single quotes, no bracket spacing) |
| 14 | +- **Parser**: Jison for SQL parsing (generates `src/alasqlparser.js`) |
| 15 | +- **Minification**: esbuild for minifying distribution files |
| 16 | + |
| 17 | +## Project Structure |
| 18 | + |
| 19 | +- `src/` - Source files numbered sequentially (e.g., `05copyright.js`, `10start.js`, etc.) |
| 20 | +- `dist/` - Built distribution files (generated, not committed) |
| 21 | +- `test/` - Test files following `test###.js` naming pattern where ### is typically the issue number |
| 22 | +- `types/` - TypeScript type definitions |
| 23 | +- `docs/` - Documentation |
| 24 | +- `examples/` - Example usage code |
| 25 | + |
| 26 | +## Development Workflow |
| 27 | + |
| 28 | +### Building |
| 29 | + |
| 30 | +```bash |
| 31 | +# Full build (includes formatting) |
| 32 | +yarn build |
| 33 | + |
| 34 | +# Build only (no formatting) |
| 35 | +yarn build-only |
| 36 | + |
| 37 | +# Or use the shell script directly |
| 38 | +sh build.sh |
| 39 | +``` |
| 40 | + |
| 41 | +The build process: |
| 42 | +1. Concatenates all source files from `src/` in a specific order |
| 43 | +2. Removes comments and performs text replacements |
| 44 | +3. Creates browser (`alasql.js`, `alasql.min.js`) and Node.js (`alasql.fs.js`) versions |
| 45 | +4. Injects version numbers from package.json |
| 46 | + |
| 47 | +### Testing |
| 48 | + |
| 49 | +```bash |
| 50 | +# Run all tests (includes build) |
| 51 | +yarn test |
| 52 | + |
| 53 | +# Run tests only (without build) |
| 54 | +yarn test-only |
| 55 | + |
| 56 | +# Run browser tests |
| 57 | +yarn test-browser |
| 58 | +``` |
| 59 | + |
| 60 | +### Code Formatting |
| 61 | + |
| 62 | +```bash |
| 63 | +# Format changed files since develop branch |
| 64 | +yarn format |
| 65 | + |
| 66 | +# Format all files |
| 67 | +yarn format-all |
| 68 | + |
| 69 | +# Check formatting |
| 70 | +yarn test-format |
| 71 | +``` |
| 72 | + |
| 73 | +**Important**: Always run `yarn format` before committing. The pre-push hook checks formatting. |
| 74 | + |
| 75 | +## Code Style Guidelines |
| 76 | + |
| 77 | +### Formatting Rules |
| 78 | +- Use **tabs** for indentation (not spaces) |
| 79 | +- Use **single quotes** for strings |
| 80 | +- No spaces inside brackets: `{foo: 'bar'}` not `{ foo: 'bar' }` |
| 81 | +- Print width: 100 characters |
| 82 | +- Arrow functions: avoid parens when possible (`x => x` not `(x) => x`) |
| 83 | +- Trailing commas: ES5 style |
| 84 | + |
| 85 | +### File Organization |
| 86 | +- Source files in `src/` are numbered to control concatenation order |
| 87 | +- Each file typically handles a specific SQL statement or feature |
| 88 | +- The concatenation order in `build.sh` determines the final build output |
| 89 | + |
| 90 | +### Comments |
| 91 | +- Avoid multiline comments starting with `/*/*` (they are removed during build) |
| 92 | +- Avoid comments with `console.log()` in them (removed during build) |
| 93 | +- Use `//` for single-line comments when they contain meaningful information |
| 94 | + |
| 95 | +## Testing Guidelines |
| 96 | + |
| 97 | +### Creating Tests |
| 98 | +1. Copy `test/test000.js` as a template |
| 99 | +2. Name new test files as `test/test###.js` where `###` is the GitHub issue number if applicable |
| 100 | +3. Tests should be self-contained and clear about what they're testing |
| 101 | +4. Use the Mocha test framework with standard assertions |
| 102 | + |
| 103 | +### Test Structure |
| 104 | +- Tests are run with `--bail` flag (stops on first failure) |
| 105 | +- Tests use dot reporter in CI for concise output |
| 106 | +- Browser tests can be run separately with `yarn test-browser` |
| 107 | + |
| 108 | +## SQL Parser Modifications |
| 109 | + |
| 110 | +If modifying the SQL parser: |
| 111 | + |
| 112 | +```bash |
| 113 | +# Regenerate parser from Jison grammar |
| 114 | +yarn jison |
| 115 | +``` |
| 116 | + |
| 117 | +This generates `src/alasqlparser.js` from `src/alasqlparser.jison`. The generated file is committed to the repository. |
| 118 | + |
| 119 | +## Branch Strategy |
| 120 | + |
| 121 | +- **develop** - Main development branch (work from this branch) |
| 122 | +- **master** - Production/release branch |
| 123 | +- Always base your work on the `develop` branch |
| 124 | + |
| 125 | +## Common Commands |
| 126 | + |
| 127 | +```bash |
| 128 | +# Install dependencies |
| 129 | +yarn |
| 130 | + |
| 131 | +# Run tests |
| 132 | +yarn test |
| 133 | + |
| 134 | +# Format code |
| 135 | +yarn format |
| 136 | + |
| 137 | +# Build project |
| 138 | +yarn build |
| 139 | + |
| 140 | +# Install globally for testing CLI |
| 141 | +yarn install-g |
| 142 | +``` |
| 143 | + |
| 144 | +## Important Notes |
| 145 | + |
| 146 | +### Files to Avoid Modifying |
| 147 | +- `dist/` - Generated files, will be overwritten on build |
| 148 | +- `src/alasqlparser.js` - Generated from Jison grammar (modify the `.jison` file instead) |
| 149 | +- `.min.js` files - Generated during build |
| 150 | + |
| 151 | +### Node.js Version |
| 152 | +- Requires Node.js >= 15 |
| 153 | + |
| 154 | +### Code Generation |
| 155 | +- The build process heavily uses `rexreplace` for text transformations |
| 156 | +- Version strings `PACKAGE_VERSION` and `BUILD_VERSION` are injected during build |
| 157 | +- Browser and Node.js builds have different code paths (marked with `not-for-browser` and `only-for-browser`) |
| 158 | + |
| 159 | +## When Implementing Features |
| 160 | + |
| 161 | +1. **Understand the issue thoroughly** - Read related test cases and existing code |
| 162 | +2. **Write a test first** - Create `test/test###.js` for the issue |
| 163 | +3. **Verify test fails** - Run `yarn test` to confirm the test catches the issue |
| 164 | +4. **Implement the fix** - Modify appropriate file(s) in `src/` |
| 165 | +5. **Verify test passes** - Run `yarn test` again |
| 166 | +6. **Format code** - Run `yarn format` before committing |
| 167 | +7. **Build succeeds** - Ensure `yarn build` completes without errors |
| 168 | + |
| 169 | +## When Reviewing Code |
| 170 | + |
| 171 | +- Check that formatting matches Prettier config (tabs, single quotes, etc.) |
| 172 | +- Verify tests exist for new functionality |
| 173 | +- Ensure the build script includes any new source files in the correct order |
| 174 | +- Confirm browser and Node.js compatibility if applicable |
| 175 | +- Check that documentation is updated if API changes |
| 176 | + |
| 177 | +## Resources |
| 178 | + |
| 179 | +- [AlaSQL Documentation](https://github.com/alasql/alasql/wiki) |
| 180 | +- [Contributing Guide](CONTRIBUTING.md) |
| 181 | +- [Stack Overflow Tag](http://stackoverflow.com/questions/ask?tags=AlaSQL) |
| 182 | +- [Issue Tracker](https://github.com/AlaSQL/alasql/issues) |
0 commit comments