Skip to content

refactor: extract OG asset plugins into src/plugins/og-assets.ts#706

Merged
james-elicx merged 1 commit intomainfrom
refactor/split-og-assets-plugin
Mar 28, 2026
Merged

refactor: extract OG asset plugins into src/plugins/og-assets.ts#706
james-elicx merged 1 commit intomainfrom
refactor/split-og-assets-plugin

Conversation

@james-elicx
Copy link
Copy Markdown
Collaborator

Summary

  • Extracts vinext:og-inline-fetch-assets and vinext:og-assets out of the monolithic index.ts into packages/vinext/src/plugins/og-assets.ts
  • createOgInlineFetchAssetsPlugin() factory: the per-build Map<string, string> cache and isBuild flag become closure state inside the factory, removing two module-level variables that previously leaked into the outer vinext() closure
  • ogAssetsPlugin constant: the writeBundle-only plugin has no mutable state, so it exports directly as a plain plugin object
  • index.ts imports and delegates to these, removing ~190 lines of inline plugin code

Testing

  • vp check passes on both changed files (no type errors, no lint errors, no format issues)
  • pnpm test tests/features.test.ts — 264/264 pass

Move vinext:og-inline-fetch-assets and vinext:og-assets out of the
monolithic index.ts into a focused file (src/plugins/og-assets.ts).

- createOgInlineFetchAssetsPlugin() factory: owns the per-build cache
  (Map<string, string>) and isBuild flag as closure state, removing
  the two module-level variables that leaked into the outer vinext()
  factory closure.
- ogAssetsPlugin constant: the writeBundle-only plugin has no mutable
  state, so it exports directly as a plain plugin object.

index.ts now imports and delegates to these, removing ~190 lines of
inline plugin code from the main plugin file.
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 28, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@706

commit: a885d1c

@james-elicx
Copy link
Copy Markdown
Collaborator Author

/bigbonk review

@james-elicx james-elicx marked this pull request as ready for review March 28, 2026 20:55
@github-actions
Copy link
Copy Markdown

Example Preview Production Original
app-router-cloudflare preview production
pages-router-cloudflare preview production
app-router-playground preview production original
realworld-api-rest preview production
nextra-docs-template preview production
benchmarks preview production
hackernews preview production original

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

$(cat <<'EOF'
Clean extraction. The code is a 1:1 move — logic, comments, and variable names all match the original. The factory pattern for createOgInlineFetchAssetsPlugin correctly internalizes the cache and isBuild state that was previously leaking into the vinext() closure scope, and the import placement in index.ts is consistent with the other plugins/* imports.

One minor observation (non-blocking): ogAssetsPlugin is exported as a singleton object rather than a factory. Since this plugin is stateless (no mutable fields, only a writeBundle hook that reads from disk), sharing a single object reference across multiple vinext() calls is fine. If mutable state were ever added to it, it would need the same factory treatment — but as-is, it is correct.

LGTM.
EOF
)

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Mar 28, 2026

Approved PR #706. The extraction is clean — it's a faithful 1:1 move of the two OG asset plugins from the monolithic index.ts into packages/vinext/src/plugins/og-assets.ts, consistent with how other plugins (async-hooks-stub, optimize-imports, etc.) are already organized in the plugins/ directory.

Key observations:

  • createOgInlineFetchAssetsPlugin() correctly encapsulates the cache Map and isBuild flag as closure state inside the factory, fixing the prior leak into the outer vinext() scope.
  • ogAssetsPlugin is appropriately exported as a plain object since it has no mutable state — only a writeBundle hook that reads from disk.
  • The import placement and inline comments in index.ts are clean and consistent with the existing plugin import pattern.

github run

@james-elicx james-elicx enabled auto-merge (squash) March 28, 2026 20:56
@james-elicx james-elicx merged commit 0b69dea into main Mar 28, 2026
31 checks passed
@james-elicx james-elicx deleted the refactor/split-og-assets-plugin branch March 28, 2026 20:57
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.

1 participant