Skip to content

feat: add core/plugin entrypoints#178

Open
tmm wants to merge 1 commit into
vercel-labs:mainfrom
tmm:composition-exports
Open

feat: add core/plugin entrypoints#178
tmm wants to merge 1 commit into
vercel-labs:mainfrom
tmm:composition-exports

Conversation

@tmm

@tmm tmm commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Adds emulate/core and emulate/plugins entrypoint re-exports so downstream projects can compose custom emulators or extend built-in ones without needing to install and manage @emulators/* packages directly.

Extend a built-in emulator with a missing GitHub Contents API endpoint:

import { createPlugin, createServer, serve } from 'emulate/core'
import { githubPlugin } from 'emulate/plugins'

const plugin = createPlugin({ // `createPlugin` API added for simpler typing
  name: 'github',
  register(app, store, webhooks, baseUrl, tokenMap) {
    // Register the built-in GitHub emulator first.
    githubPlugin.register(app, store, webhooks, baseUrl, tokenMap)

    // Add a downstream-only endpoint that your app or SDK needs.
    app.get('/repos/:owner/:repo/contents/:path{.+}', (c) => {
      const owner = c.req.param('owner')
      const repo = c.req.param('repo')
      const path = c.req.param('path')
      const content = `# ${repo}\n\nLocal fixture for ${owner}/${repo}.\n`

      return c.json({
        type: 'file',
        name: path.split('/').at(-1),
        path,
        sha: 'local-fixture',
        encoding: 'base64',
        content: Buffer.from(content).toString('base64'),
        download_url: `${baseUrl}/repos/${owner}/${repo}/raw/${path}`,
      })
    })
  },
  seed: githubPlugin.seed,
})

const { app } = createServer(plugin, { baseUrl: 'http://localhost:4000' })
const server = serve({ fetch: app.fetch, port: 4000 })

Create a fully custom emulator:

import { createPlugin, createServer, serve } from 'emulate/core'

const plugin = createPlugin({
  name: 'custom',
  register(app) {
    // Define whatever API surface your app needs for tests.
    app.get('/ping', (c) => c.json({ ok: true }))
  },
})

const { app } = createServer(plugin, { baseUrl: 'http://localhost:4100' })
const server = serve({ fetch: app.fetch, port: 4100 })

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

@tmm is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@tmm tmm changed the title Add emulator composition exports feat: add core/plugin entrypoints Jun 12, 2026
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