Skip to content

feat: add cleaning cache for plugin files#2732

Open
kanoru3101 wants to merge 60 commits intomainfrom
chore/add-clean-cache
Open

feat: add cleaning cache for plugin files#2732
kanoru3101 wants to merge 60 commits intomainfrom
chore/add-clean-cache

Conversation

@kanoru3101
Copy link
Copy Markdown
Contributor

@kanoru3101 kanoru3101 commented Apr 9, 2026

What/Why/How?

In VSCE, we have a problem with clean cache for plugin files. This PR adds cleaning the general cache for plugin files, cjs files, and esm files.

  • Moved all logic with plugin caches to separate files and covered by tests
  • Cleaning cache for ESM and СJS files, cover cases with nested imports.
  • Removed __webpack_require__

Reference

Issue Redocly/redocly-vs-code#10
VSCE Part https://github.com/Redocly/redocly/pull/22293

Testing

Tested in VSCE part

Screenshots (optional)

Check yourself

  • This PR follows the contributing guide
  • All new/updated code is covered by tests
  • Core code changed? - Tested with other Redocly products (internal contributions only)
  • New package installed? - Tested in different environments (browser/node)
  • Documentation update has been considered

Security

  • The security impact of the change has been considered
  • Code follows company security practices and guidelines

Note

Medium Risk
Changes plugin loading and caching behavior, including new cache eviction logic and Node loader-hook usage for ESM reloads, which could affect plugin resolution/reload semantics across Node versions.

Overview
Adds a dedicated plugin cache layer with clearPluginsCache() and getPluginCacheVersion() to support reloading plugin code within a running process.

resolvePlugins now delegates all plugin module loading/caching to plugins-cache.ts, removing the legacy __webpack_require__ path and enabling targeted CJS require.cache eviction plus ESM cache-busting via a versioned file: URL (with a Node >=22.15 loader-hook warning when unavailable).

Updates and adds tests/fixtures to validate cache stability, explicit cache clearing for both CJS/ESM, and that eviction does not remove unrelated modules.

Reviewed by Cursor Bugbot for commit cd8b914. Bugbot is set up for automated code reviews on this repo. Configure here.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 9, 2026

🦋 Changeset detected

Latest commit: cd8b914

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@redocly/openapi-core Minor
@redocly/cli Minor
@redocly/respect-core Minor

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

@kanoru3101 kanoru3101 added the snapshot Create experimental release PR label Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1775733825 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1775733825
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1775733825
# or
npm install @redocly/respect-core@0.0.0-snapshot.1775733825

⚠️ Note: This is a development build and may contain unstable features.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 79.99% (🎯 80%) 7233 / 9042
🔵 Statements 79.29% (🎯 79%) 7518 / 9481
🔵 Functions 83.22% (🎯 83%) 1449 / 1741
🔵 Branches 71.72% (🎯 71%) 4884 / 6809
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
packages/core/src/config/config-resolvers.ts 76.54% 61.45% 94.11% 77.35% 73, 101-104, 154, 193, 201, 257, 268, 277, 290, 300, 303-307, 312-321, 344-346, 356, 359, 362, 365, 368, 381-383, 387, 393, 396, 399-402, 405-408, 411-414, 428-430, 437, 440, 443, 446, 449, 452, 477-479, 484-490
packages/core/src/config/plugin-import-tree.ts 11.22% 4% 14.28% 10.58% 36-139, 150-151, 160-175
packages/core/src/config/plugins-cache.ts 74.6% 45% 100% 79.62% 26, 31-38, 47-51, 78, 82-86
Generated in workflow #9772 for commit cd8b914 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

CLI Version Mean Time ± Std Dev (s) Relative Performance (Lower is Faster)
cli-latest 1.939s ± 0.019s ▓ 1.00x (Fastest)
cli-next 1.975s ± 0.032s ▓ 1.02x

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1775739903 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1775739903
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1775739903
# or
npm install @redocly/respect-core@0.0.0-snapshot.1775739903

⚠️ Note: This is a development build and may contain unstable features.

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1775814315 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1775814315
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1775814315
# or
npm install @redocly/respect-core@0.0.0-snapshot.1775814315

⚠️ Note: This is a development build and may contain unstable features.

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 10, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1775819371 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1775819371
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1775819371
# or
npm install @redocly/respect-core@0.0.0-snapshot.1775819371

⚠️ Note: This is a development build and may contain unstable features.

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1776082389 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1776082389
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1776082389
# or
npm install @redocly/respect-core@0.0.0-snapshot.1776082389

⚠️ Note: This is a development build and may contain unstable features.

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1776085657 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1776085657
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1776085657
# or
npm install @redocly/respect-core@0.0.0-snapshot.1776085657

⚠️ Note: This is a development build and may contain unstable features.

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1776087574 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1776087574
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1776087574
# or
npm install @redocly/respect-core@0.0.0-snapshot.1776087574

⚠️ Note: This is a development build and may contain unstable features.

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1777472433 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1777472433
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1777472433
# or
npm install @redocly/respect-core@0.0.0-snapshot.1777472433

⚠️ Note: This is a development build and may contain unstable features.

@kanoru3101 kanoru3101 added snapshot Create experimental release PR and removed snapshot Create experimental release PR labels Apr 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1777474661 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1777474661
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1777474661
# or
npm install @redocly/respect-core@0.0.0-snapshot.1777474661

⚠️ Note: This is a development build and may contain unstable features.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1778237731 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1778237731
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1778237731
# or
npm install @redocly/respect-core@0.0.0-snapshot.1778237731

⚠️ Note: This is a development build and may contain unstable features.

Comment thread packages/core/src/config/plugins-cache.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1778250423 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1778250423
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1778250423
# or
npm install @redocly/respect-core@0.0.0-snapshot.1778250423

⚠️ Note: This is a development build and may contain unstable features.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1778253852 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1778253852
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1778253852
# or
npm install @redocly/respect-core@0.0.0-snapshot.1778253852

⚠️ Note: This is a development build and may contain unstable features.

Comment thread packages/core/src/config/plugins-cache.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1778327478 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1778327478
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1778327478
# or
npm install @redocly/respect-core@0.0.0-snapshot.1778327478

⚠️ Note: This is a development build and may contain unstable features.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

📦 A new experimental 🧪 version v0.0.0-snapshot.1778335458 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1778335458
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1778335458
# or
npm install @redocly/respect-core@0.0.0-snapshot.1778335458

⚠️ Note: This is a development build and may contain unstable features.

@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1778501698 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1778501698
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1778501698
# or
npm install @redocly/respect-core@0.0.0-snapshot.1778501698

⚠️ Note: This is a development build and may contain unstable features.

Comment thread packages/core/src/config/plugin-import-tree.ts Outdated
Comment thread packages/core/src/config/plugin-import-tree.ts
@github-actions
Copy link
Copy Markdown
Contributor

📦 A new experimental 🧪 version v0.0.0-snapshot.1778506313 of Redocly CLI has been published for testing.

Install with NPM:

npm install @redocly/cli@0.0.0-snapshot.1778506313
# or
npm install @redocly/openapi-core@0.0.0-snapshot.1778506313
# or
npm install @redocly/respect-core@0.0.0-snapshot.1778506313

⚠️ Note: This is a development build and may contain unstable features.

Copy link
Copy Markdown

@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 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cd8b914. Configure here.

export async function loadPluginModule(
absolutePluginPath: string
): Promise<Record<string, unknown>> {
ensureEsmCacheBustHook();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Misleading warning emitted on every first plugin load

Medium Severity

loadPluginModule calls ensureEsmCacheBustHook() on every first plugin load. On Node < 22.15, this emits a warning about ESM plugin reload not working — even for CLI users who never call clearPluginsCache, and for CJS-only plugin setups where cache clearing works fine without the hook. The hook is only needed after clearPluginsCache is called, since initial loads (with ?v=0) don't require version propagation to children. Moving the call exclusively to clearPluginsCache would avoid the spurious warning.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cd8b914. Configure here.

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

Labels

snapshot Create experimental release PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants