agentleFS
bubblelabaibubblelabai/BubbleLab/.cursor/rules/bundling.mdc

BubbleLab / rules

Cursor rule1.1k starsChanged 10 months agoApache-2.0View on GitHub

The project uses a custom type bundling system to provide full TypeScript IntelliSense support in the Monaco editor for @bubblelab/bubble-core and its dependencies. This is necessary because Monaco cannot directly resolve workspace packages or external dependencies. The Monaco editor (in apps/bubble-studio/src/components/MonacoEditor.tsx) loads the bundle: This makes all types available when users write: Problem: Using relative paths as cache keys caused collisions: - bubble-core/dist/index.d.ts → cached as "index.d.ts" - shared-schemas/dist/index.d.ts → same key "index.d.ts" - Second file would return the first…

Trending

Quiet this year.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 0 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the bubblelabai/BubbleLab repository that our weekly crawl found: only 1 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about bubblelabai/BubbleLab

The biggest 1 of 1 mention linking to the repository that our crawl found. Each line is their own headline.

The file

We split this bundling.mdc into the rules it gives an agent

10 rules. About 0 are common, 10 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    All bubble-core types and classes

    line 24
  2. Distinctive:

    Solution: Use absolute file paths as cache keys:

    line 112
  3. Distinctive:

    All external imports are removed from the bundle:

    line 122
  4. Distinctive:

    Check browser console for fetch errors

    line 169
  5. Distinctive:

    Look for "ServiceBubble declarations found" log

    line 170
  6. Distinctive:

    If types are missing after changes:

    line 174
  7. Distinctive:

    Import from shared-schemas instead

    line 187
  8. Distinctive:

    When adding new types to shared-schemas:

    line 204
  9. Distinctive:

    No changes needed! The bundler automatically includes them

    line 205
  10. Distinctive:

    When adding new files to bubble-core:

    line 209

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
bundling.mdc
---
alwaysApply: true
---

# Type Bundling for Monaco Editor

## Overview

The project uses a custom type bundling system to provide full TypeScript IntelliSense support in the Monaco editor for `@bubblelab/bubble-core` and its dependencies. This is necessary because Monaco cannot directly resolve workspace packages or external dependencies.

## Architecture

### Key Files

- **Bundler Script**: `packages/bubble-core/scripts/bubble-bundler.ts`
  - Processes TypeScript declaration files (`.d.ts`)
  - Inlines all dependencies into a single self-contained bundle
  - Runs as part of the build process: `tsc && tsx scripts/bubble-bundler.ts`

- **Bundle Output**: `packages/bubble-core/dist/bubble-bundle.d.ts`
  - Self-contained TypeScript declarations
  - Includes Zod type stubs for type inference
  - Contains inlined types from `@bubblelab/shared-schemas`
  - All bubble-core types and classes

- **Monaco Integration**: `apps/bubble-studio/public/bubble-types.txt`
  - Copy of the bundle served to the Monaco editor
  - Loaded in `apps/bubble-studio/src/components/MonacoEditor.tsx`

### Bundling Process

1. **Compile TypeScript**
   ```bash
   tsc  # Generates .d.ts files in dist/
   ```

2. **Bundle Types**
   - Start from `packages/bubble-core/dist/index.d.ts`
   - Recursively process all imports:
     - Relative imports (`./types/bubble.js`) → inline the file content
     - External imports (`@bubblelab/shared-schemas`) → bundle separately then inline
     - Zod imports → remove (custom stubs provided)

3. **Shared Schemas Handling**
   - `@bubblelab/shared-schemas` is bundled separately via `bundleSharedSchemas()`
   - Prevents cache key collisions (both packages have `index.d.ts`)
   - Uses **absolute file paths** as cache keys to avoid conflicts
   - Inlined content includes all shared types like:
     - `BubbleOperationResult`
     - `BubbleResult<T>`
     - `BubbleTriggerEventRegistry`
     - API schemas, credential types, etc.

4. **Bundle Structure**
   ```typescript
   // Header comment

   // Zod type stubs (for z.infer, z.ZodObject, etc.)
   declare namespace z { ... }

   // Inlined shared-schemas types
   export interface BubbleOperationResult { ... }
   export interface BubbleResult<T> { ... }

   // Bubble-core types and classes
   export class BubbleFlow { ... }
   export class ServiceBubble { ... }
   ```

5. **Minification**
   - Removes comments (except header)
   - Compresses whitespace
   - Reduces bundle size by ~30%

### Monaco Editor Integration

The Monaco editor (in `apps/bubble-studio/src/components/MonacoEditor.tsx`) loads the bundle:

```typescript
// 1. Fetch the bundle
const response = await fetch('/bubble-types.txt');
const bundledTypes = await response.text();

// 2. Wrap in module declaration
const moduleDeclaration = `
declare module '@bubblelab/bubble-core' {
  ${cleanedTypes.replace(/^/gm, '  ')}
}
`;

// 3. Add to Monaco's type system
monaco.languages.typescript.typescriptDefaults.addExtraLib(
  moduleDeclaration,
  'file:///node_modules/@types/nodex__bubble-core/index.d.ts'
);
```

This makes all types available when users write:
```typescript
import { BubbleFlow, ServiceBubble } from '@bubblelab/bubble-core';
```

## Important Implementation Details

### Cache Key Strategy

**Problem**: Using relative paths as cache keys caused collisions:
- `bubble-core/dist/index.d.ts` → cached as `"index.d.ts"`
- `shared-schemas/dist/index.d.ts` → same key `"index.d.ts"`
- Second file would return the first file's cached content!

**Solution**: Use absolute file paths as cache keys:
```typescript
const cacheKey = filePath; // Full absolute path
if (this.processedFiles.has(cacheKey)) {
  return this.typeDefinitions.get(cacheKey) || '';
}
```

### External Import Handling

All external imports are removed from the bundle:
```typescript
if (!importPath.startsWith('.')) {
  // Remove all external imports (zod, shared-schemas, etc)
  processedContent = processedContent.replace(importStatement, '');
  continue;
}
```

Why?
- **Zod**: Custom type stubs are provided (Monaco-friendly simplified versions)
- **@bubblelab/shared-schemas**: Bundled separately and inlined to avoid circular processing

### Type Re-exports

When `bubble-core/src/index.ts` does:
```typescript
export * from '@bubblelab/shared-schemas';
```

The bundler:
1. Compiles to `dist/index.d.ts` with the export statement
2. Detects the external import during bundling
3. Calls `bundleSharedSchemas()` to process shared-schemas separately
4. Inlines the shared-schemas content before bubble-core content
5. Removes the `export *` statement

Result: All types are available directly in the bundle without external dependencies.

## Troubleshooting

### Types Missing in Monaco

**Symptom**: `Cannot find name 'BubbleOperationResult'` or similar errors

**Check**:
1. Is the type defined in the bundle?
   ```bash
   grep "interface BubbleOperationResult" packages/bubble-core/dist/bubble-bundle.d.ts
   ```

2. Was the bundle copied to bubble-studio?
   ```bash
   diff packages/bubble-core/dist/bubble-bundle.d.ts apps/bubble-studio/public/bubble-types.txt
   ```

3. Is Monaco loading the bundle?
   - Check browser console for fetch errors
   - Look for "ServiceBubble declarations found" log

### Cache Issues

If types are missing after changes:
1. Delete `dist/` folder
2. Rebuild: `pnpm run build`
3. Restart dev server

### Duplicate Type Declarations

**Symptom**: `Module has already exported a member named 'X'`

**Cause**: Type defined in both shared-schemas and bubble-core

**Solution**:
- Remove from bubble-core
- Import from shared-schemas instead
- Bundler will inline it automatically

## Build Process

```bash
# In packages/bubble-core
pnpm run build

# This runs:
# 1. tsc (generates .d.ts files)
# 2. tsx scripts/bubble-bundler.ts (creates bundle)
# 3. tsx scripts/bubble-metadata-bundler.ts (creates bubbles.json)
```

## Maintenance

When adding new types to shared-schemas:
1. No changes needed! The bundler automatically includes them
2. Just rebuild bubble-core: `pnpm run build`
3. The bundle will include the new types

When adding new files to bubble-core:
1. Export from `src/index.ts`
2. Rebuild to update the bundle
3. Types automatically available in Monaco

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.