Home / File/ tsconfig-json.spec.ts — vite Source File

tsconfig-json.spec.ts — vite Source File

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

File typescript 5 imports

Entity Profile

Dependency Diagram

graph LR
  e65c69d0_4903_0ad1_f34d_4364280fc5bf["tsconfig-json.spec.ts"]
  51e96894_3556_ed5c_1ede_97d449867adf["node:path"]
  e65c69d0_4903_0ad1_f34d_4364280fc5bf --> 51e96894_3556_ed5c_1ede_97d449867adf
  e6032fbc_44cf_58d6_868d_dd15106c18c5["node:fs"]
  e65c69d0_4903_0ad1_f34d_4364280fc5bf --> e6032fbc_44cf_58d6_868d_dd15106c18c5
  54c37fea_4fe7_2693_71cb_1276b77f55f9["vite"]
  e65c69d0_4903_0ad1_f34d_4364280fc5bf --> 54c37fea_4fe7_2693_71cb_1276b77f55f9
  a340ba46_b2b7_3048_3bb3_6907a74c8464["vitest"]
  e65c69d0_4903_0ad1_f34d_4364280fc5bf --> a340ba46_b2b7_3048_3bb3_6907a74c8464
  d3fd5575_295b_d6be_24dd_62d277645dc9["~utils"]
  e65c69d0_4903_0ad1_f34d_4364280fc5bf --> d3fd5575_295b_d6be_24dd_62d277645dc9
  style e65c69d0_4903_0ad1_f34d_4364280fc5bf fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import path from 'node:path'
import fs from 'node:fs'
import { transformWithEsbuild } from 'vite'
import { describe, expect, test } from 'vitest'
import { browserLogs, isServe, serverLogs } from '~utils'

test('should respected each `tsconfig.json`s compilerOptions', () => {
  // main side effect should be called (because of `"verbatimModuleSyntax": true`)
  expect(browserLogs).toContain('main side effect')
  // main base setter should not be called (because of `"useDefineForClassFields": true"`)
  expect(browserLogs).not.toContain('data setter in MainBase')

  // nested side effect should not be called (because "verbatimModuleSyntax" is not set, defaults to false)
  expect(browserLogs).not.toContain('nested side effect')
  // nested base setter should be called (because of `"useDefineForClassFields": false"`)
  expect(browserLogs).toContain('data setter in NestedBase')

  // nested-with-extends side effect should be called (because "verbatimModuleSyntax" is extended from the main tsconfig.json, which is true)
  expect(browserLogs).toContain('nested-with-extends side effect')
  // nested-with-extends base setter should be called (because of `"useDefineForClassFields": false"`)
  expect(browserLogs).toContain('data setter in NestedWithExtendsBase')
})

test.runIf(isServe)('scanner should not error with decorators', () => {
  expect(serverLogs).not.toStrictEqual(
    expect.arrayContaining([
      expect.stringContaining(
        'Parameter decorators only work when experimental decorators are enabled',
      ),
    ]),
  )
})

describe('transformWithEsbuild', () => {
  test('merge tsconfigRaw object', async () => {
    const main = path.resolve(import.meta.dirname, '../src/main.ts')
    const mainContent = fs.readFileSync(main, 'utf-8')
    const result = await transformWithEsbuild(mainContent, main, {
      tsconfigRaw: {
        compilerOptions: {
          useDefineForClassFields: false,
        },
      },
    })
    // "verbatimModuleSyntax": true from tsconfig.json should still work
    expect(result.code).toMatch(/import.*".\/not-used-type";/)
  })

  test('overwrite tsconfigRaw string', async () => {
    const main = path.resolve(import.meta.dirname, '../src/main.ts')
    const mainContent = fs.readFileSync(main, 'utf-8')
    const result = await transformWithEsbuild(mainContent, main, {
      tsconfigRaw: `{
        "compilerOptions": {
          "useDefineForClassFields": false
        }
      }`,
    })
    // "verbatimModuleSyntax": true from tsconfig.json should not be read
    // and defaults to false
    expect(result.code).not.toMatch(/import.*".\/not-used-type";/)
  })

  test('verbatimModuleSyntax', async () => {
    const main = path.resolve(import.meta.dirname, '../src/main.ts')
    const mainContent = fs.readFileSync(main, 'utf-8')
    const result = await transformWithEsbuild(mainContent, main, {
      tsconfigRaw: {
        compilerOptions: {
          useDefineForClassFields: false,
          verbatimModuleSyntax: false,
        },
      },
    })
    // "verbatimModuleSyntax": false from tsconfig.json should still work
    expect(result.code).not.toMatch(/import.*".\/not-used-type";/)
  })

  test('experimentalDecorators', async () => {
    const main = path.resolve(import.meta.dirname, '../src/decorator.ts')
    const mainContent = fs.readFileSync(main, 'utf-8')
    // Should not error when transpiling decorators as nearest tsconfig.json
    // has "experimentalDecorators": true
    const result = await transformWithEsbuild(mainContent, main, {
      target: 'es2020',
    })
    expect(result.code).toContain('__decorateClass')
  })
})

Dependencies

  • node:fs
  • node:path
  • vite
  • vitest
  • ~utils

Frequently Asked Questions

What does tsconfig-json.spec.ts do?
tsconfig-json.spec.ts is a source file in the vite codebase, written in typescript.
What does tsconfig-json.spec.ts depend on?
tsconfig-json.spec.ts imports 5 module(s): node:fs, node:path, vite, vitest, ~utils.
Where is tsconfig-json.spec.ts in the architecture?
tsconfig-json.spec.ts is located at playground/tsconfig-json/__tests__/tsconfig-json.spec.ts (directory: playground/tsconfig-json/__tests__).

Analyze Your Own Codebase

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

Try Supermodel Free