Skip to content

Commit a4d0b82

Browse files
Copilotnaorpeled
andauthored
chore: add Copilot instructions for repository (#574)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: naorpeled <[email protected]>
1 parent 5bfd3e9 commit a4d0b82

File tree

1 file changed

+129
-0
lines changed

1 file changed

+129
-0
lines changed

.github/copilot-instructions.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# Copilot Instructions for Bowser
2+
3+
## Project Overview
4+
5+
Bowser is a small, fast, and rich-API browser/platform/engine detector for both browser and Node.js environments. It's designed to parse User-Agent strings and provide detailed information about browsers, operating systems, platforms, and rendering engines.
6+
7+
## Architecture
8+
9+
### Core Components
10+
11+
- **`src/bowser.js`**: Main entry point and public API. Provides static methods `getParser()` and `parse()`.
12+
- **`src/parser.js`**: Core parsing engine that orchestrates all parsers and returns structured results.
13+
- **`src/parser-browsers.js`**: Browser detection logic using regex patterns.
14+
- **`src/parser-os.js`**: Operating system detection logic.
15+
- **`src/parser-platforms.js`**: Platform type detection (desktop, tablet, mobile).
16+
- **`src/parser-engines.js`**: Rendering engine detection (WebKit, Blink, Gecko, etc.).
17+
- **`src/constants.js`**: Centralized constants including browser aliases and mappings.
18+
- **`src/utils.js`**: Utility functions for string matching and manipulation.
19+
20+
### Build Output
21+
22+
- **`es5.js`**: ES5 transpiled version (default export).
23+
- **`bundled.js`**: ES5 version with babel-polyfill included.
24+
25+
## Development Workflow
26+
27+
### Setup
28+
29+
```bash
30+
npm install
31+
```
32+
33+
### Key Commands
34+
35+
- **Build**: `npm run build` - Compiles source files using Webpack and Babel.
36+
- **Test**: `npm test` - Runs unit and acceptance tests using AVA.
37+
- **Lint**: `npm run lint:check` - Checks code style using ESLint.
38+
- **Lint Fix**: `npm run lint:fix` - Auto-fixes linting issues.
39+
- **Watch Mode**: `npm run watch` - Builds on file changes.
40+
- **Test Watch**: `npm run test:watch` - Runs tests on file changes.
41+
42+
### Testing
43+
44+
- Tests are located in `test/acceptance/` and `test/unit/`.
45+
- Acceptance tests use real User-Agent strings from `test/acceptance/useragentstrings.yml`.
46+
- Always update `useragentstrings.yml` when adding browser support.
47+
- Test framework: AVA with Babel integration.
48+
49+
## Coding Standards
50+
51+
### Style Guide
52+
53+
- **ESLint Config**: Based on Airbnb Base style guide.
54+
- **Parser**: Uses `babel-eslint`.
55+
- **Exceptions**:
56+
- Underscore-dangle allowed for private properties.
57+
- `no-void` disabled.
58+
- ES6 imports must include `.js` extension.
59+
60+
### Naming Conventions
61+
62+
- **Browser Aliases**: Use lowercase letters, replace spaces/dashes with underscores, drop "browser" suffix.
63+
- Examples: `Opera Coast``opera_coast`, `UC Browser``uc`, `SeaMonkey``seamonkey`.
64+
- **Private Properties**: Prefix with underscore (e.g., `_ua`).
65+
- **Constants**: Use `UPPER_SNAKE_CASE` for constant maps and aliases.
66+
67+
### Code Patterns
68+
69+
- Use ES6 modules with explicit `.js` extensions.
70+
- Prefer static methods in Bowser class.
71+
- Use class-based structure for Parser.
72+
- Regex patterns should be well-documented and tested.
73+
- Keep parsers modular and focused on single responsibility.
74+
75+
## Adding Browser Support
76+
77+
When adding support for a new browser:
78+
79+
1. Add regex pattern to `src/parser-browsers.js`.
80+
2. Add browser name to `BROWSER_ALIASES_MAP` in `src/constants.js`.
81+
3. Add corresponding entry to `BROWSER_MAP`.
82+
4. Add test cases to `test/acceptance/useragentstrings.yml`.
83+
5. Run tests to verify: `npm test`.
84+
6. Check for duplicates before adding aliases.
85+
86+
## Branching Strategy
87+
88+
- **`master`**: Development branch.
89+
- **`production`**: Production branch.
90+
- **New Features**: Branch from `master`, PR back to `master`.
91+
- **Hot-fixes/Browser Support**: Branch from `production`, PR back to `production`.
92+
93+
## Important Files
94+
95+
- **`index.d.ts`**: TypeScript definitions.
96+
- **`.babelrc`**: Babel configuration for ES5 transpilation.
97+
- **`webpack.config.js`**: Build configuration.
98+
- **`.eslintrc.yml`**: Linting rules.
99+
- **`package.json`**: Dependencies and scripts.
100+
101+
## API Design Principles
102+
103+
- Keep the API simple and intuitive.
104+
- Bowser class should be stateless and provide factory methods.
105+
- Parser class handles instance-specific logic.
106+
- Results should be structured and predictable.
107+
- Support both immediate parsing and lazy parsing.
108+
109+
## Performance Considerations
110+
111+
- Parsers use lazy evaluation where possible.
112+
- Regex patterns are optimized for common browsers first.
113+
- Optional `skipParsing` parameter for delayed parsing.
114+
- Minimal bundle size is a priority (~4.8kB gzipped).
115+
116+
## Documentation
117+
118+
- Use JSDoc comments for all public APIs.
119+
- Document parameters, return types, and provide examples.
120+
- Update README.md for API changes.
121+
- Generate docs with: `npm run generate-docs`.
122+
123+
## Common Pitfalls
124+
125+
- Always check `BROWSER_ALIASES_MAP` for existing aliases before adding new ones.
126+
- User-Agent strings can be complex; test edge cases thoroughly.
127+
- Remember to update both the alias map and the reverse map in constants.
128+
- Browser versions should be treated as strings, not numbers.
129+
- Keep regex patterns readable with comments explaining their purpose.

0 commit comments

Comments
 (0)