Home / File/ rolldownDepPlugin.spec.ts — vite Source File

rolldownDepPlugin.spec.ts — vite Source File

Architecture documentation for rolldownDepPlugin.spec.ts, a typescript file in the vite codebase. 5 imports, 0 dependents.

File typescript ViteCore ConfigEngine 5 imports 1 functions

Entity Profile

Dependency Diagram

graph LR
  5f77933b_9c4a_6082_7bba_80a4920b25ef["rolldownDepPlugin.spec.ts"]
  88c474dd_3ef0_0479_2549_43cd02a6f84b["rolldownDepPlugin.ts"]
  5f77933b_9c4a_6082_7bba_80a4920b25ef --> 88c474dd_3ef0_0479_2549_43cd02a6f84b
  9d9d1d96_da01_acb8_5086_7a043722cf91["rolldownDepPlugin"]
  5f77933b_9c4a_6082_7bba_80a4920b25ef --> 9d9d1d96_da01_acb8_5086_7a043722cf91
  031bc221_67a8_c579_f2bf_bb30a08beeb2["utils.ts"]
  5f77933b_9c4a_6082_7bba_80a4920b25ef --> 031bc221_67a8_c579_f2bf_bb30a08beeb2
  a4adb1a7_cf54_091f_eb63_8217e684a8e1["normalizePath"]
  5f77933b_9c4a_6082_7bba_80a4920b25ef --> a4adb1a7_cf54_091f_eb63_8217e684a8e1
  a340ba46_b2b7_3048_3bb3_6907a74c8464["vitest"]
  5f77933b_9c4a_6082_7bba_80a4920b25ef --> a340ba46_b2b7_3048_3bb3_6907a74c8464
  style 5f77933b_9c4a_6082_7bba_80a4920b25ef fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { describe, expect, test } from 'vitest'
import { rolldownDepPlugin } from '../../optimizer/rolldownDepPlugin'
import { normalizePath } from '../../utils'

async function createRolldownDepPluginTransform(cacheDir: string) {
  const baseConfig = {
    cacheDir: normalizePath(cacheDir),
    optimizeDeps: { extensions: [] },
    server: { fs: { allow: [] } },
    resolve: { builtins: [] },
    createResolver: () => ({}),
  }

  const mockEnvironment = {
    config: baseConfig,
    getTopLevelConfig: () => baseConfig,
  } as any

  const plugins = rolldownDepPlugin(mockEnvironment, {}, [])
  const plugin = plugins.find(
    (p: any) => p.name === 'vite:dep-pre-bundle',
  ) as any

  if (!plugin || !plugin.transform) {
    throw new Error('Could not find vite:dep-pre-bundle plugin')
  }

  const handler = plugin.transform.handler

  return async (code: string, id: string) => {
    const result = await handler.call({}, code, normalizePath(id))
    return result?.code || result
  }
}

describe('rolldownDepPlugin transform', async () => {
  const transform = await createRolldownDepPluginTransform('/root/.vite')

  test('rewrite various relative asset formats', async () => {
    const code = `
      const img = new URL('./logo.png', import.meta.url).href
      const icon = new URL('./icons/search.svg', import.meta.url)
      const worker = new URL('./worker.js', import.meta.url)
      const wasm = new URL('./module.wasm', import.meta.url)
    `
    expect(await transform(code, '/root/node_modules/my-lib/dist/index.js'))
      .toMatchInlineSnapshot(`
      "
            const img = new URL('' + "../../node_modules/my-lib/dist/logo.png", import.meta.url).href
            const icon = new URL('' + "../../node_modules/my-lib/dist/icons/search.svg", import.meta.url)
            const worker = new URL('' + "../../node_modules/my-lib/dist/worker.js", import.meta.url)
            const wasm = new URL('' + "../../node_modules/my-lib/dist/module.wasm", import.meta.url)
          "
    `)
  })

  test('respects /* @vite-ignore */', async () => {
    expect(
      await transform(
        "new URL(/* @vite-ignore */ './worker.js', import.meta.url)",
// ... (73 more lines)

Domain

Subdomains

Frequently Asked Questions

What does rolldownDepPlugin.spec.ts do?
rolldownDepPlugin.spec.ts is a source file in the vite codebase, written in typescript. It belongs to the ViteCore domain, ConfigEngine subdomain.
What functions are defined in rolldownDepPlugin.spec.ts?
rolldownDepPlugin.spec.ts defines 1 function(s): createRolldownDepPluginTransform.
What does rolldownDepPlugin.spec.ts depend on?
rolldownDepPlugin.spec.ts imports 5 module(s): normalizePath, rolldownDepPlugin, rolldownDepPlugin.ts, utils.ts, vitest.
Where is rolldownDepPlugin.spec.ts in the architecture?
rolldownDepPlugin.spec.ts is located at packages/vite/src/node/__tests__/optimizer/rolldownDepPlugin.spec.ts (domain: ViteCore, subdomain: ConfigEngine, directory: packages/vite/src/node/__tests__/optimizer).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free