Skip to content

Conversation

@grypez
Copy link
Contributor

@grypez grypez commented Jan 22, 2026

Summary

Replace @endo/bundle-source with vite for vat bundling and remove @endo/import-bundle for bundle loading.

Changes

  • Bundle vats using vite's build() API with IIFE output format
  • Load bundles via Compartment.evaluate() instead of importBundle()
  • Remove @endo/import-bundle dependency from all packages.
  • Remove @endo/bundle-source dependency from all packages except kernel-shims.

Bundle Format

New bundles use vite-iife format:

{
  "moduleFormat": "vite-iife",
  "code": "var __vatExports__ = ...",
  "exports": ["buildRootObject"],
  "modules": { ... }
}

Closes: #742


Note

Replaces Endo bundle tooling with a Vite-based bundling pipeline and a new runtime loader.

  • Add Vite bundler (bundleVat) producing IIFE bundles; include Rollup plugins export-metadata and strip-comments
  • Update CLI to use Vite bundler for bundle, watch, and server tests; adjust mocks and types
  • Replace kernel bundle loading: remove importBundle, fetch bundle as text, and load via loadBundle using Compartment.evaluate()
  • Introduce VatBundle type and isVatBundle guard in @metamask/kernel-utils; update tests and fixtures to IIFE format
  • Dependencies: add vite/rollup; remove @endo/bundle-source and @endo/import-bundle; update README accordingly

Written by Cursor Bugbot for commit b9cfdcc. This will update automatically on new commits. Configure here.

@socket-security
Copy link

socket-security bot commented Jan 22, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedrollup@​4.46.3 ⏵ 4.55.38810010099 +2100

View full report

@grypez grypez force-pushed the grypez/bundle-with-vite branch 3 times, most recently from 504110d to 1a13965 Compare January 22, 2026 15:17
@github-actions
Copy link
Contributor

github-actions bot commented Jan 22, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 88.12%
⬇️ -0.25%
5564 / 6314
🔵 Statements 88%
⬇️ -0.24%
5654 / 6425
🔵 Functions 87.19%
⬇️ -0.31%
1437 / 1648
🔵 Branches 84.07%
⬇️ -0.36%
2027 / 2411
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/cli/src/app.ts 0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
0%
🟰 ±0%
15-155
packages/cli/src/commands/bundle.ts 92.3%
🟰 ±0%
50%
🟰 ±0%
100%
🟰 ±0%
92.3%
🟰 ±0%
79
packages/cli/src/commands/watch.ts 100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
100%
🟰 ±0%
packages/cli/src/vite/export-metadata-plugin.ts 0% 0% 0% 0% 23-46
packages/cli/src/vite/vat-bundler.ts 0% 0% 0% 0% 22-62
packages/ocap-kernel/src/vats/VatSupervisor.ts 74.64%
🟰 ±0%
44.82%
🟰 ±0%
58.33%
🟰 ±0%
74.64%
🟰 ±0%
122, 133, 141, 179, 217-221, 232, 241-242, 263-265, 268, 272-274, 309, 326-334
packages/ocap-kernel/src/vats/bundle-loader.ts 87.5% 80% 100% 87.5% 31
Generated in workflow #3285 for commit b8e02c0 by the Vitest Coverage Report Action

@github-actions
Copy link
Contributor

@grypez grypez marked this pull request as ready for review January 22, 2026 18:29
@grypez grypez requested a review from a team as a code owner January 22, 2026 18:29
grypez and others added 4 commits January 22, 2026 13:45
Drop support for the legacy endoZipBase64 bundle format and remove
the @endo/import-bundle dependency. All vat bundles now use the
vite-iife format loaded via Compartment.evaluate().

- Remove @endo/import-bundle from ocap-kernel dependencies
- Simplify bundle-loader.ts to only support vite-iife format
- Update VatSupervisor to use synchronous loadBundle
- Update CLI tests to mock bundleVat instead of @endo/bundle-source
- Update serve integration test to check vite-iife format

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@grypez grypez force-pushed the grypez/bundle-with-vite branch from 1a13965 to b8e02c0 Compare January 22, 2026 18:45
Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice!

Comment on lines 13 to 20
type ViteBundle = {
moduleFormat: 'vite-iife';
code: string;
exports: string[];
modules: Record<string, unknown>;
};

const isViteBundle = (value: unknown): value is ViteBundle =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should import the renamed VatBundle type here, ideally. The type may need to be relocated to kernel-utils to resolve dependency circularity issues. That would also make a nice home for isVatBundle.

Comment on lines 54 to 56
// SES rejects code containing `import(` patterns, even in comments.
// Replace them with a safe alternative that won't trigger detection.
const sanitizedCode = chunk.code.replace(/\bimport\s*\(/gu, 'IMPORT(');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment ought to say something about "we solemnly swear that the string import only occurs in comments".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative approach that might be more convincing is to filter comments from the AST using a rollup plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommend punting to #770

import type { BundleMetadata } from './export-metadata-plugin.ts';

export type VatBundle = BundleMetadata & {
moduleFormat: 'vite-iife';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing to harp on this topic: the number of times we declare this property is a code smell.

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 4 potential issues.

// Skip until end of line
while (i < code.length && code[i] !== '\n') {
i += 1;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment stripper incorrectly handles regex literals

High Severity

The comment stripping logic treats any // sequence as a single-line comment, even when it appears inside regex literals. Code containing regex patterns like /https:\/\// or /\w+\/\// would be incorrectly parsed, with content after the escaped slashes stripped away. The plugin only detects string literals but not regex literals, causing valid JavaScript to be corrupted when regex patterns contain comment-like sequences.

Fix in Cursor Fix in Web

result += strChar;
i += 1;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template literal expressions with comments not handled

Medium Severity

The comment stripper treats backticks as regular string delimiters, copying everything between them without recognizing ${...} template expressions. Comments within these expressions like `${foo /* comment */}` won't be stripped. Since SES rejects code with import( in comments, and this plugin's purpose is preventing that rejection, unstripped comments in template expressions could cause bundle evaluation to fail.

Fix in Cursor Fix in Web

i += 1;
}
i += 1; // Skip the closing /
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stripped multi-line comments create syntax errors

High Severity

Multi-line comments are removed without replacing them with whitespace, causing adjacent tokens to merge. Code like foo/*comment*/instanceof bar becomes fooinstanceof bar, creating a syntax error. The bundled code will fail to parse when loaded by the compartment, causing vat initialization to fail with confusing parse errors rather than executing correctly.

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: Bundle vats with vite

3 participants