Skip to content

Commit 2126b82

Browse files
committed
command + skill
1 parent 1117b46 commit 2126b82

3 files changed

Lines changed: 325 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
name: add-cdn-bundle
3+
description: Create a new CDN bundle for the browser package with specified features
4+
argument-hint: <feature-combo> (e.g., replay.logs.metrics, tracing.logs, tracing.replay.feedback.logs.metrics)
5+
---
6+
7+
# Add CDN Bundle Skill
8+
9+
This skill creates a new CDN bundle for the browser package that includes a specific combination of features.
10+
11+
## Input
12+
13+
The user provides a feature combination using dot notation:
14+
15+
- `logs.metrics` - Bundle with logs and metrics
16+
- `replay.logs.metrics` - Bundle with replay, logs, and metrics
17+
- `tracing.replay.logs` - Bundle with tracing, replay, and logs
18+
- `tracing.replay.feedback.logs.metrics` - Full featured bundle
19+
20+
**Feature order in bundle names:** `tracing``replay``feedback``logs``metrics`
21+
22+
## Instructions
23+
24+
Follow the detailed guide at [docs/adding-cdn-bundle.md](../../../docs/adding-cdn-bundle.md) to create the bundle.
25+
26+
### Quick Reference - Naming Conventions
27+
28+
Given a feature combination, derive these variants:
29+
30+
| Placeholder | Example (`replay.logs.metrics`) |
31+
| ------------------------------- | --------------------------------- |
32+
| `{FEATURE_COMBO}` | `replay.logs.metrics` |
33+
| `{feature_combo}` | `replay_logs_metrics` |
34+
| `{featureCombo}` | `replayLogsMetrics` |
35+
| `{Human Readable Features}` | `Replay, Logs, Metrics` |
36+
| `{Human Readable Feature List}` | `Replay, Logs, and Metrics` |
37+
38+
### Quick Reference - Files to Create/Modify
39+
40+
1. **Create** `packages/browser/src/index.bundle.{FEATURE_COMBO}.ts`
41+
2. **Create** `packages/browser/test/index.bundle.{FEATURE_COMBO}.test.ts`
42+
3. **Modify** `packages/browser/rollup.bundle.config.mjs`
43+
4. **Modify** `.size-limit.js`
44+
5. **Modify** `dev-packages/browser-integration-tests/package.json`
45+
6. **Modify** `dev-packages/browser-integration-tests/utils/generatePlugin.ts`
46+
7. **Modify** `.github/workflows/build.yml`
47+
48+
### Verification Steps
49+
50+
After making changes:
51+
52+
```bash
53+
yarn lint
54+
cd packages/browser && yarn build:dev
55+
cd packages/browser && yarn test
56+
```

.cursor/commands/add_cdn_bundle.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Add CDN Bundle for `{FEATURE_COMBO}`
2+
3+
Create a new CDN bundle for the browser package that includes `{FEATURE_COMBO}` (e.g., `replay.logs.metrics`, `tracing.logs`, etc.).
4+
5+
## Instructions
6+
7+
Follow the detailed guide at [docs/adding-cdn-bundle.md](../../docs/adding-cdn-bundle.md) to create the bundle.
8+
9+
## Quick Reference - Naming Conventions
10+
11+
| Placeholder | Example (`replay.logs.metrics`) |
12+
| ------------------------------- | --------------------------------- |
13+
| `{FEATURE_COMBO}` | `replay.logs.metrics` |
14+
| `{feature_combo}` | `replay_logs_metrics` |
15+
| `{featureCombo}` | `replayLogsMetrics` |
16+
| `{Human Readable Features}` | `Replay, Logs, Metrics` |
17+
| `{Human Readable Feature List}` | `Replay, Logs, and Metrics` |
18+
19+
## Quick Reference - Files to Create/Modify
20+
21+
1. **Create** `packages/browser/src/index.bundle.{FEATURE_COMBO}.ts`
22+
2. **Create** `packages/browser/test/index.bundle.{FEATURE_COMBO}.test.ts`
23+
3. **Modify** `packages/browser/rollup.bundle.config.mjs`
24+
4. **Modify** `.size-limit.js`
25+
5. **Modify** `dev-packages/browser-integration-tests/package.json`
26+
6. **Modify** `dev-packages/browser-integration-tests/utils/generatePlugin.ts`
27+
7. **Modify** `.github/workflows/build.yml`
28+
29+
## Verification Steps
30+
31+
After making changes:
32+
33+
1. Run `yarn lint` to check for linting issues
34+
2. Run `cd packages/browser && yarn build:dev` to verify TypeScript compilation
35+
3. Run `cd packages/browser && yarn test` to run the unit tests

docs/adding-cdn-bundle.md

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
# Adding a New CDN Bundle
2+
3+
This guide explains how to create a new CDN bundle for the browser package that includes a specific combination of features.
4+
5+
## Feature Combinations
6+
7+
Feature combinations use dot notation:
8+
9+
- `logs.metrics` - Bundle with logs and metrics
10+
- `replay.logs.metrics` - Bundle with replay, logs, and metrics
11+
- `tracing.replay.logs` - Bundle with tracing, replay, and logs
12+
- `tracing.replay.feedback.logs.metrics` - Full featured bundle
13+
14+
**Feature order in bundle names:** `tracing``replay``feedback``logs``metrics`
15+
16+
## Naming Conventions
17+
18+
Given a feature combination, derive these variants:
19+
20+
| Placeholder | Example (`replay.logs.metrics`) |
21+
| ------------------------------- | --------------------------------- |
22+
| `{FEATURE_COMBO}` | `replay.logs.metrics` |
23+
| `{feature_combo}` | `replay_logs_metrics` |
24+
| `{featureCombo}` | `replayLogsMetrics` |
25+
| `{Human Readable Features}` | `Replay, Logs, Metrics` |
26+
| `{Human Readable Feature List}` | `Replay, Logs, and Metrics` |
27+
28+
## Files to Create
29+
30+
### 1. Entry Point: `packages/browser/src/index.bundle.{FEATURE_COMBO}.ts`
31+
32+
**Base structure:**
33+
34+
```typescript
35+
// If bundle includes TRACING, add this at the top:
36+
import { registerSpanErrorInstrumentation } from '@sentry/core';
37+
registerSpanErrorInstrumentation();
38+
39+
// Always export base bundle
40+
export * from './index.bundle.base';
41+
```
42+
43+
**For LOGS (without tracing):**
44+
45+
```typescript
46+
export { logger, consoleLoggingIntegration } from '@sentry/core';
47+
```
48+
49+
**For TRACING:**
50+
51+
```typescript
52+
export {
53+
getActiveSpan,
54+
getRootSpan,
55+
getSpanDescendants,
56+
setMeasurement,
57+
startInactiveSpan,
58+
startNewTrace,
59+
startSpan,
60+
startSpanManual,
61+
withActiveSpan,
62+
} from '@sentry/core';
63+
64+
export {
65+
browserTracingIntegration,
66+
startBrowserTracingNavigationSpan,
67+
startBrowserTracingPageLoadSpan,
68+
} from './tracing/browserTracingIntegration';
69+
export { reportPageLoaded } from './tracing/reportPageLoaded';
70+
export { setActiveSpanInBrowser } from './tracing/setActiveSpan';
71+
```
72+
73+
**For REPLAY:**
74+
75+
```typescript
76+
export { replayIntegration, getReplay } from '@sentry-internal/replay';
77+
```
78+
79+
**For FEEDBACK:**
80+
81+
```typescript
82+
import { feedbackAsyncIntegration } from './feedbackAsync';
83+
export { getFeedback, sendFeedback } from '@sentry-internal/feedback';
84+
export { feedbackAsyncIntegration as feedbackAsyncIntegration, feedbackAsyncIntegration as feedbackIntegration };
85+
```
86+
87+
**For features NOT included, export shims:**
88+
89+
```typescript
90+
import {
91+
browserTracingIntegrationShim, // if NO tracing
92+
feedbackIntegrationShim, // if NO feedback
93+
replayIntegrationShim, // if NO replay
94+
consoleLoggingIntegrationShim, // if NO logs
95+
loggerShim, // if NO logs
96+
} from '@sentry-internal/integration-shims';
97+
98+
// Then export them with proper names:
99+
export { browserTracingIntegrationShim as browserTracingIntegration };
100+
export { feedbackIntegrationShim as feedbackAsyncIntegration, feedbackIntegrationShim as feedbackIntegration };
101+
export { replayIntegrationShim as replayIntegration };
102+
export { consoleLoggingIntegrationShim as consoleLoggingIntegration, loggerShim as logger };
103+
```
104+
105+
### 2. Test File: `packages/browser/test/index.bundle.{FEATURE_COMBO}.test.ts`
106+
107+
```typescript
108+
import { logger as coreLogger, metrics as coreMetrics } from '@sentry/core';
109+
import { describe, expect, it } from 'vitest';
110+
// Import real integrations for features included in the bundle
111+
import { browserTracingIntegration, feedbackAsyncIntegration, replayIntegration } from '../src';
112+
import * as Bundle from '../src/index.bundle.{FEATURE_COMBO}';
113+
114+
describe('index.bundle.{FEATURE_COMBO}', () => {
115+
it('has correct exports', () => {
116+
// Test real exports match core implementations
117+
expect(Bundle.browserTracingIntegration).toBe(browserTracingIntegration); // if tracing included
118+
expect(Bundle.feedbackAsyncIntegration).toBe(feedbackAsyncIntegration); // if feedback included
119+
expect(Bundle.replayIntegration).toBe(replayIntegration); // if replay included
120+
expect(Bundle.logger).toBe(coreLogger); // if logs included
121+
expect(Bundle.metrics).toBe(coreMetrics); // always (in base bundle)
122+
});
123+
});
124+
```
125+
126+
## Files to Modify
127+
128+
### 3. `packages/browser/rollup.bundle.config.mjs`
129+
130+
Add bundle config before `builds.push(...)`:
131+
132+
```javascript
133+
const {featureCombo}BaseBundleConfig = makeBaseBundleConfig({
134+
bundleType: 'standalone',
135+
entrypoints: ['src/index.bundle.{FEATURE_COMBO}.ts'],
136+
licenseTitle: '@sentry/browser ({Human Readable Feature List})',
137+
outputFileBase: () => 'bundles/bundle.{FEATURE_COMBO}',
138+
});
139+
```
140+
141+
Add to `builds.push(...)`:
142+
143+
```javascript
144+
...makeBundleConfigVariants({featureCombo}BaseBundleConfig),
145+
```
146+
147+
### 4. `.size-limit.js`
148+
149+
Add two entries in the "Browser CDN bundles" section:
150+
151+
```javascript
152+
// Gzipped (add after similar bundles)
153+
{
154+
name: 'CDN Bundle (incl. {Human Readable Features})',
155+
path: createCDNPath('bundle.{FEATURE_COMBO}.min.js'),
156+
gzip: true,
157+
limit: '{SIZE} KB', // Estimate based on features
158+
},
159+
160+
// Uncompressed (add in the non-gzipped section)
161+
{
162+
name: 'CDN Bundle (incl. {Human Readable Features}) - uncompressed',
163+
path: createCDNPath('bundle.{FEATURE_COMBO}.min.js'),
164+
gzip: false,
165+
brotli: false,
166+
limit: '{SIZE} KB', // ~3x the gzipped size
167+
},
168+
```
169+
170+
### 5. `dev-packages/browser-integration-tests/package.json`
171+
172+
Add test scripts in the `scripts` section:
173+
174+
```json
175+
"test:bundle:{feature_combo}": "PW_BUNDLE=bundle_{feature_combo} yarn test",
176+
"test:bundle:{feature_combo}:min": "PW_BUNDLE=bundle_{feature_combo}_min yarn test",
177+
"test:bundle:{feature_combo}:debug_min": "PW_BUNDLE=bundle_{feature_combo}_debug_min yarn test",
178+
```
179+
180+
### 6. `dev-packages/browser-integration-tests/utils/generatePlugin.ts`
181+
182+
Add entries to `BUNDLE_PATHS.browser`:
183+
184+
```javascript
185+
bundle_{feature_combo}: 'build/bundles/bundle.{FEATURE_COMBO}.js',
186+
bundle_{feature_combo}_min: 'build/bundles/bundle.{FEATURE_COMBO}.min.js',
187+
bundle_{feature_combo}_debug_min: 'build/bundles/bundle.{FEATURE_COMBO}.debug.min.js',
188+
```
189+
190+
### 7. `.github/workflows/build.yml`
191+
192+
Add to the bundle matrix (in the `job_browser_playwright_tests` job):
193+
194+
```yaml
195+
- bundle_{feature_combo}
196+
```
197+
198+
## Size Estimation Guide
199+
200+
Use these approximate sizes when setting limits in `.size-limit.js`:
201+
202+
| Feature | Gzipped Size |
203+
| ----------- | ------------ |
204+
| Base bundle | ~28 KB |
205+
| + Tracing | +15 KB |
206+
| + Replay | +37 KB |
207+
| + Feedback | +12 KB |
208+
| + Logs | +1 KB |
209+
210+
Uncompressed size is approximately 3x the gzipped size.
211+
212+
## Verification Steps
213+
214+
After making changes:
215+
216+
1. Run `yarn lint` to check for linting issues
217+
2. Run `cd packages/browser && yarn build:dev` to verify TypeScript compilation
218+
3. Run `cd packages/browser && yarn test` to run the unit tests
219+
220+
## Reference: Existing Bundle Examples
221+
222+
Look at these existing bundles for reference:
223+
224+
- `packages/browser/src/index.bundle.tracing.ts` - Tracing only
225+
- `packages/browser/src/index.bundle.replay.ts` - Replay only
226+
- `packages/browser/src/index.bundle.tracing.replay.ts` - Tracing + Replay
227+
- `packages/browser/src/index.bundle.logs.metrics.ts` - Logs + Metrics
228+
229+
## Error Handling
230+
231+
- **Invalid feature combination**: Validate feature names are valid (tracing, replay, feedback, logs, metrics)
232+
- **Build failures**: Fix TypeScript errors before proceeding
233+
- **Lint errors**: Run `yarn fix` to auto-fix common issues
234+
- **Test failures**: Update test expectations to match the bundle's actual exports

0 commit comments

Comments
 (0)