ci: test plugin across Vite 3, 6, 7, and 8-beta versions with IIFE support#1105
Open
Toumash wants to merge 15 commits into
Open
ci: test plugin across Vite 3, 6, 7, and 8-beta versions with IIFE support#1105Toumash wants to merge 15 commits into
Toumash wants to merge 15 commits into
Conversation
Enable IIFE bundling for main-world content scripts and add output/e2e coverage for dynamic script injection.
Allow ?iife imports to resolve to content script file names for registerContentScripts use, and align fixtures with the new alias.
- Simplify test fixture to demonstrate the primary use case for IIFE imports - Update background.ts to use chrome.scripting.registerContentScripts - Fix IIFE path format (no leading slash) for registerContentScripts compatibility - Remove unused files (options.ts, content1.ts, content2.ts, redirect.html) - Handle document_start timing in main-world.ts (wait for body)
- Detect IIFE script changes in handleHotUpdate using raw file path since IIFE scripts are not in Vite's module graph - Trigger runtime reload after IIFE rebuild completes so Chrome picks up the updated file (Chrome caches content scripts registered via registerContentScripts) - Update E2E test to verify IIFE rebuild on file change: - Use src1/src2 fixture pattern for testing file updates - Verify that page reload after file change shows updated content
Vite 6+ tracks plugins internally using WeakMaps, causing errors when reusing plugins in a separate Rollup build. This rewrites bundleIife() to use viteBuild() with direct rollupOptions instead of raw Rollup. Key changes: - Use configFile: false to avoid loading user's config with incompatible settings - Use direct rollupOptions with format: 'iife' instead of lib mode - Copy resolve settings (alias, extensions, conditions) from dev server - Filter out manifest.json and .vite/ assets from output Works with Vite 3, 5, 6, and 7.
Merged vite-compat tests into the main test suite under tests/compat/ and updated the CI workflow to run all unit, output, and e2e tests with a Vite version matrix. This ensures the plugin is properly tested against all supported Vite versions as declared in peerDependencies. Changes: - Move tests/vite-compat/* to packages/vite-plugin/tests/compat/ - Add vite-version matrix to unit-output and e2e jobs - Remove separate compat job (now redundant) - Update test imports to use 'src' alias
- Add explicit name property to CrxPlugin interface for Vite 7+ - Use intersection type for ResolvedConfigWithHMRToken - Add isCrxPlugin type guard for cross-version plugin filtering - Improve IIFE bundling with proper Vite build API usage - Add test:run:compat script for version-specific testing - Update CI workflow to test with matrix of Vite versions
Pass entryFileNames, chunkFileNames, and assetFileNames from the parent config to viteBuild() so IIFE-bundled scripts follow the same naming convention as the rest of the build output.
The Vite 6+ manifest plugin expects assets to have 'names' (plural array), 'originalFileNames', and 'needsCodeReference' properties. Assets created via emitAssetToBundle() were missing these, causing the manifest plugin to crash with 'Cannot read properties of undefined (reading length)'. This adds the required properties to emitAssetToBundle() output, making IIFE content script bundling work correctly with Vite 6, 7, and 8-beta.
…kiness" This reverts commit 3814475.
🦋 Changeset detectedLatest commit: 569ab1d The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR 💥 An error occurred when fetching the changed packages and changesets in this PR |
Fix 'Unknown input options: platform' error by only passing valid Rollup input options instead of spreading all rollupOptions from Vite config.
cd06766 to
569ab1d
Compare
FliPPeDround
approved these changes
Feb 5, 2026
Contributor
|
Thanks for contributing to CRXJS! This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within 7 days. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
?iifequery parameterChanges
CI Improvements
IIFE Content Scripts Feature
?iifequery parameter for content scripts that need main-world executionchrome.scripting.registerContentScripts()withworld: "MAIN"Vite 6+ Compatibility Fixes
names,originalFileNames,needsCodeReferenceproperties to emitted assets (fixes manifest plugin crashes)Testing
All tests pass locally on Vite 3, 6, 7, and 8-beta. CI runs the full test suite across all versions.