- This is a monorepo containing multiple JavaScript SDK packages
- Packages are organized into categories:
- Shared packages (common code)
- SDK packages (platform-specific implementations)
- Store packages (persistent storage)
- Telemetry packages (monitoring)
- Tooling packages (development tools)
- Node environment version 16 required (minimum)
- yarn required
- Some projects may have specific environment prerequisites
- Use
yarnto install dependencies from project root - Use
yarn buildto build all projects - For single project builds:
yarn workspaces foreach -pR --topological-dev --from '@launchdarkly/js-client-sdk' run build - Replace package name as needed
- Running
yarn buildin individual packages won't rebuild dependencies
- Always create pull requests as Draft Pull Requests unless explicitly instructed otherwise
- Dependencies should be avoided unless absolutely necessary
- Consider these factors when evaluating a dependency:
- Size: Impact on final bundle size (especially important for browser SDK)
- Maintenance: Risk of becoming unmaintained or deprecated
- Security: Potential security vulnerabilities
- Compatibility: Support across all target platforms
- Conflicts: Potential conflicts with application dependencies
- Most important to avoid dependencies in: common, sdk-client, and sdk-server packages
- Individual SDK packages may have platform-specific dependencies
- Edge SDKs must use their provider's edge store and may require specific dependencies
- Only use dependencies for functionality with highly-specified behavior, wide usage, active maintenance, and large community support
- Aim for compiled JavaScript to not be substantially different than if written as JavaScript
- Consider JavaScript consumers when making TypeScript decisions
- Avoid TypeScript enumerations — use unions of strings instead:
- Bad:
enum ValueType { Bool = 'bool', Int = 'int' } - Good:
type ValueType = 'bool' | 'int'
- Bad:
- Prefer interfaces over classes when reasonable, especially for public APIs
- Remember that
privateandreadonlyonly affect TypeScript — JavaScript can still access and mutate - For private members that need to be minified, prefix with underscore
- Unit tests go in a
__tests__folder at the root of each package - Directory structure inside
__tests__should mirror the source directory - Run tests only for single projects at a time:
yarn workspace <package name> test - Use
itfor test cases (should read as a sentence includingit):- Good:
it('does not load flags prior to start', async () => { ... })
- Good:
- Use
describeblocks only for shared setup across a series of tests:- Good:
describe('given a mock filesystem and memory feature store', () => { ... }) - If there is no shared configuration, do not use a describe block
- Good:
- Run unit tests for any package you've modified
- Run lint checks with:
yarn workspace <package name> lint - Auto-fix many issues with:
yarn workspace <package name> lint --fix - Package names are in each package's
package.json - Run lint on any package you've modified
- When working with mocks in tests,
@ts-ignoreor ESLint ignore comments are acceptable for typing issues (test code only, not implementation)