•  


Volatile paths in generated `tsconfig.json` in monorepo · Issue #12140 · sveltejs/kit · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Volatile paths in generated tsconfig.json in monorepo #12140

Open
echocrow opened this issue Apr 19, 2024 · 0 comments
Open

Volatile paths in generated tsconfig.json in monorepo #12140

echocrow opened this issue Apr 19, 2024 · 0 comments

Comments

@echocrow
Copy link

echocrow commented Apr 19, 2024

Describe the bug

Running Vite-related tools (e.g. Vitest) in a monorepo may mess up SvelteKit's generated .svelte-kit/tsconfig.json .

Looks like the Vite plugin currently uses process.cwd() in async functions. However, due to a race condition, it's not guaranteed that process.cwd() still points to SvelteKit's package dir by the time the configureServer Vite plugin hook is invoked.

More context from a previous discovery is available in this issue .

Reproduction

https://stackblitz.com/edit/sveltekit-vitest-tsconfig-hijack?file=README.md

Running e.g. vitest or vite build from within packages/my-app will generate .svelte-kit/tsconfig.json as expected.

However, running vitest from the root monorepo dir can cause .svelte-kit/tsconfig.json to be generated with unexpected relative paths pointing to other packages. If SvelteKit dev is running at the same time, that'll also bust the dev preview.

Notable repro logs:

When running e.g. vitest , you'll see the Vite plugin log different values for process.cmd() vs config.root :

[cwd-vs-config-root] process.cwd: /home/projects/sveltekit-vitest-tsconfig-hijack/packages/z-another-app
[cwd-vs-config-root] config.root: /home/projects/sveltekit-vitest-tsconfig-hijack/packages/my-app

Afterwards, .sveltekit/tsconfig.json is still expected to contain:

{

  "compilerOptions"
: 
{

    "paths"
: 
{

      "$myAlias"
: 
[
"../src/myAlias"
]
,

      "$myAlias/*"
: 
[
"../src/myAlias/*"
]
,

      // ...

    }
,

    "rootDirs"
: 
[
".."
,
 "./types"
]
,

    // ...

  }

}

However, the actual contents are:

{

  "compilerOptions"
: 
{

    "paths"
: 
{

      "$myAlias"
: 
[
"../../z-another-app/src/myAlias"
]
,

      "$myAlias/*"
: 
[
"../../z-another-app/src/myAlias/*"
]
,

      // ...

    }
,

    "rootDirs"
: 
[
"../../z-another-app"
,
 "./types"
]
,

    // ...

  }

}

(This is just a stub; other paths in "include" and "exclude" are also affected.)

System Info

(should be irrelevant - below from the Stackblitz repro)

  System:
    OS: Linux 5.0 undefined
    CPU: (6) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.18.0 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.3 - /usr/local/bin/pnpm

Severity

serious, but I can work around it

Current workarounds:

  • Never run Vitest at the same time as SvelteKit's dev (also disable the Vitest VSCode extension!)
    or
  • Omit the global vitest.workspace.js file for now

Additional Information

A Vitest contributor suggested to use vite_config.root instead of process.cmd()

The Vite config root is available e.g. via server.config.root in the configureServer Vite plugin hook, which could then be passed down as an argument (or some kind of context object).

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

No branches or pull requests

1 participant
- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본