Skip to content

feat: support .vue files in build-time transform #14

Description

@anton-gor-dev

Problem

The unplugin transform currently only processes .ts and .js files. Composables defined inside <script setup> blocks of .vue files are not instrumented.

// unplugin.ts — current filter
if (!id.endsWith('.ts') && !id.endsWith('.js')) return

This means many real-world projects where composables live in .vue files (e.g. useLocalState defined inline) are partially tracked.

Solution

Use @vue/compiler-sfc to parse the <script> / <script setup> block, extract the JS/TS source, run transformComposable on it, then stitch the result back.

Implementation sketch

import { parse } from '@vue/compiler-sfc'

if (id.endsWith('.vue')) {
  const { descriptor } = parse(code)
  const script = descriptor.scriptSetup ?? descriptor.script
  if (!script) return null
  const result = transformComposable(script.content, id)
  if (!result) return null
  // replace script block content with result.code + inject map
}

Acceptance criteria

  • Composables exported from <script setup> are tracked
  • Sourcemaps remain correct
  • Existing .ts/.js tests still pass
  • New tests covering .vue transform

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions