Skip to content

feat: ESM/TS single-file plugin support and explicit plugin import API#483

Open
theoephraim wants to merge 3 commits intomainfrom
feature/custom-plugin-tooling
Open

feat: ESM/TS single-file plugin support and explicit plugin import API#483
theoephraim wants to merge 3 commits intomainfrom
feature/custom-plugin-tooling

Conversation

@theoephraim
Copy link
Member

Summary

  • New plugin-context.ts: proxy-based plugin context replaces the globalThis.plugin injection hack, breaking a circular dependency between plugins.ts and plugin-lib.ts
  • ESM/TS single-file plugins: .mjs and .ts files now supported in addition to .js/.cjs; in SEA binary builds, the varlock/plugin-lib import is replaced at load time via source text transform + data: URL execution (no temp files)
  • Explicit plugin import: plugin authors now import plugin from varlock/plugin-lib instead of relying on an injected global; CJS require('varlock/plugin-lib') is intercepted to return live references in all environments including SEA builds
  • Breaking change: the implicit plugin global is no longer injected into CJS plugin modules — updated all @varlock/* plugins and smoke test fixtures accordingly
  • Error classes (ValidationError, CoercionError, etc.) are now directly importable from varlock/plugin-lib

Plugin authoring

// CJS (.js / .cjs)
const { plugin } = require('varlock/plugin-lib');

// ESM (.mjs / .ts)
import { plugin } from 'varlock/plugin-lib';

Test plan

  • Smoke tests pass for existing CJS package plugins
  • Smoke tests pass for new .mjs single-file plugin
  • Smoke tests pass for new .ts single-file plugin (requires Bun binary)
  • Verify plugin.ERRORS and direct error class imports both work

🤖 Generated with Claude Code

Copilot AI and others added 3 commits March 24, 2026 00:31
…t API

- Add plugin-context.ts with proxy-based plugin context (replaces globalThis.plugin)
- Support .mjs and .ts single-file plugins via ESM dynamic import
- In SEA builds, transform varlock/plugin-lib import to globalThis accessor and
  execute via data: URL (no temp files, no Bun.plugin() which doesn't work for
  imports in dynamically loaded modules)
- Wrap CJS require to intercept varlock/plugin-lib, enabling explicit import
- Remove injected `plugin` global from CJS modules (breaking change)
- Update all @varlock/* plugins and smoke test fixtures to use explicit import
- Add @types/bun to support Bun.Transpiler type in non-SEA builds

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link

changeset-bot bot commented Mar 24, 2026

🦋 Changeset detected

Latest commit: a269efd

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

This PR includes changesets to release 12 packages
Name Type
varlock Minor
@varlock/1password-plugin Major
@varlock/aws-secrets-plugin Major
@varlock/azure-key-vault-plugin Major
@varlock/bitwarden-plugin Major
@varlock/google-secret-manager-plugin Major
@varlock/hashicorp-vault-plugin Major
@varlock/infisical-plugin Major
@varlock/pass-plugin Major
@varlock/vite-integration Major
@varlock/astro-integration Major
@varlock/nextjs-integration Major

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 24, 2026

Open in StackBlitz

varlock

npm i https://pkg.pr.new/varlock@483

@varlock/astro-integration

npm i https://pkg.pr.new/@varlock/astro-integration@483

@varlock/nextjs-integration

npm i https://pkg.pr.new/@varlock/nextjs-integration@483

@varlock/vite-integration

npm i https://pkg.pr.new/@varlock/vite-integration@483

@varlock/1password-plugin

npm i https://pkg.pr.new/@varlock/1password-plugin@483

@varlock/aws-secrets-plugin

npm i https://pkg.pr.new/@varlock/aws-secrets-plugin@483

@varlock/azure-key-vault-plugin

npm i https://pkg.pr.new/@varlock/azure-key-vault-plugin@483

@varlock/bitwarden-plugin

npm i https://pkg.pr.new/@varlock/bitwarden-plugin@483

@varlock/google-secret-manager-plugin

npm i https://pkg.pr.new/@varlock/google-secret-manager-plugin@483

@varlock/hashicorp-vault-plugin

npm i https://pkg.pr.new/@varlock/hashicorp-vault-plugin@483

@varlock/infisical-plugin

npm i https://pkg.pr.new/@varlock/infisical-plugin@483

@varlock/pass-plugin

npm i https://pkg.pr.new/@varlock/pass-plugin@483

commit: a269efd

@theoephraim theoephraim requested a review from philmillman March 25, 2026 03:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants