Home / Function/ getWorkerType() — vite Function Reference

getWorkerType() — vite Function Reference

Architecture documentation for the getWorkerType() function in workerImportMetaUrl.ts from the vite codebase.

Entity Profile

Dependency Diagram

graph TD
  fcb9c288_b3dc_c5f2_7476_d243d97d0e75["getWorkerType()"]
  f241296c_aba8_08ac_c4f9_aed85a9eb247["workerImportMetaUrl.ts"]
  fcb9c288_b3dc_c5f2_7476_d243d97d0e75 -->|defined in| f241296c_aba8_08ac_c4f9_aed85a9eb247
  cc381763_acbd_6aeb_4970_907e43d5b95f["workerImportMetaUrlPlugin()"]
  cc381763_acbd_6aeb_4970_907e43d5b95f -->|calls| fcb9c288_b3dc_c5f2_7476_d243d97d0e75
  27cfa263_1da2_277d_659e_15cddfc4a68f["findClosingParen()"]
  fcb9c288_b3dc_c5f2_7476_d243d97d0e75 -->|calls| 27cfa263_1da2_277d_659e_15cddfc4a68f
  2bc39ad0_e74f_e4f8_2016_48276895bfca["parseWorkerOptions()"]
  fcb9c288_b3dc_c5f2_7476_d243d97d0e75 -->|calls| 2bc39ad0_e74f_e4f8_2016_48276895bfca
  style fcb9c288_b3dc_c5f2_7476_d243d97d0e75 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/vite/src/node/plugins/workerImportMetaUrl.ts lines 134–181

async function getWorkerType(
  raw: string,
  clean: string,
  i: number,
): Promise<WorkerType> {
  const commaIndex = clean.indexOf(',', i)
  if (commaIndex === -1) {
    return 'classic'
  }
  const endIndex = findClosingParen(clean, i)

  // case: ') ... ,' mean no worker options params
  if (commaIndex > endIndex) {
    return 'classic'
  }

  // need to find in comment code
  let workerOptString = raw.substring(commaIndex + 1, endIndex)
  const hasViteIgnore = hasViteIgnoreRE.test(workerOptString)
  if (hasViteIgnore) {
    return 'ignore'
  }

  // need to find in no comment code
  const cleanWorkerOptString = clean.substring(commaIndex + 1, endIndex)
  const trimmedCleanWorkerOptString = cleanWorkerOptString.trim()
  if (!trimmedCleanWorkerOptString.length) {
    return 'classic'
  }

  // strip trailing comma for evalValue
  if (trimmedCleanWorkerOptString.endsWith(',')) {
    workerOptString = workerOptString.slice(
      0,
      cleanWorkerOptString.lastIndexOf(','),
    )
  }

  const workerOpts = await parseWorkerOptions(workerOptString, commaIndex + 1)
  if (
    workerOpts.type &&
    (workerOpts.type === 'module' || workerOpts.type === 'classic')
  ) {
    return workerOpts.type
  }

  return 'classic'
}

Domain

Subdomains

Frequently Asked Questions

What does getWorkerType() do?
getWorkerType() is a function in the vite codebase, defined in packages/vite/src/node/plugins/workerImportMetaUrl.ts.
Where is getWorkerType() defined?
getWorkerType() is defined in packages/vite/src/node/plugins/workerImportMetaUrl.ts at line 134.
What does getWorkerType() call?
getWorkerType() calls 2 function(s): findClosingParen, parseWorkerOptions.
What calls getWorkerType()?
getWorkerType() is called by 1 function(s): workerImportMetaUrlPlugin.

Analyze Your Own Codebase

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

Try Supermodel Free