feat(vite): add compiler option to vite plugin for tsgo support#35429
Conversation
Mirrors the existing compiler option in @nx/js plugin (added in nrwl#33821). Allows users to specify an alternative TypeScript compiler (e.g. tsgo from @typescript/native-preview) for the inferred typecheck target. Usage in nx.json: { "plugin": "@nx/vite/plugin", "options": { "compiler": "tsgo" } } Fixes: the @nx/vite plugin hardcodes 'tsc' while @nx/js already supports a configurable compiler. This brings parity between the two plugins.
👷 Deploy request for nx-docs pending review.Visit the deploys page to approve it
|
👷 Deploy request for nx-dev pending review.Visit the deploys page to approve it
|
|
View your CI Pipeline Execution ↗ for commit e0b25cf
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:
We ran nx format to fix the format:check failure caused by the newly added ternary expression in plugin.ts exceeding prettier's line-length limit. The single-line ternary hasVuePlugin ? 'vue-tsc' : (options.compiler ?? 'tsc') was reformatted into a multi-line form that satisfies prettier's rules.
Tip
✅ We verified this fix by re-running nx-cloud record -- nx format:check.
diff --git a/packages/vite/src/plugins/plugin.ts b/packages/vite/src/plugins/plugin.ts
index 3e1fa1da..f63ce5e9 100644
--- a/packages/vite/src/plugins/plugin.ts
+++ b/packages/vite/src/plugins/plugin.ts
@@ -423,7 +423,9 @@ async function buildViteTargets(
const hasVuePlugin = viteBuildConfig.plugins?.some(
(p) => p.name === 'vite:vue'
);
- const typeCheckCommand = hasVuePlugin ? 'vue-tsc' : (options.compiler ?? 'tsc');
+ const typeCheckCommand = hasVuePlugin
+ ? 'vue-tsc'
+ : (options.compiler ?? 'tsc');
targets[options.typecheckTargetName] = {
cache: true,
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.
Apply changes locally with:
npx nx-cloud apply-locally vEMJ-vl7r
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
| const typeCheckCommand = hasVuePlugin | ||
| ? 'vue-tsc' | ||
| : (options.compiler ?? 'tsc'); |
There was a problem hiding this comment.
Imo, the explicit compiler should take precedent over hasVuePlugin (e.g. what if we have vue-tsgo). So:
const typeCheckCommand = options.compiler ?? hasVuePlugin
? 'vue-tsc'
: 'tsc';
But the NX folks can probably be the arbiters
There was a problem hiding this comment.
Yeah it's a good consideration.
Ultimately.. I'm not sure we can anticipate that in this version. The gap is that we also need the right external dependencies.. which sometimes aren't exactly the same as the compiler... so we're going to explicitly handle these 3 valid compiler settings.
When there is a vue-tsgo alternative we can look separately into providing support.
…h resolved compiler - Narrow `compiler` to `'tsc' | 'tsgo' | 'vue-tsc'` (matches @nx/js and gives users an explicit escape hatch when `hasVuePlugin` inference misses their setup). - Explicit `compiler` option now takes precedence over Vue inference. - Map `tsgo` to `@typescript/native-preview` and `vue-tsc` to `['vue-tsc', 'typescript']` in `externalDependencies` so the cache invalidates against the actual compiler package. - Drop redundant `options.compiler ??= 'tsc'` from `normalizeOptions`.
|
Thank you for the contribution! |
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Description
Adds a
compileroption to the@nx/viteplugin, mirroring the same option already in@nx/js(added in #33821).This lets users specify an alternative TypeScript compiler for the inferred
typechecktarget — specificallytsgofrom@typescript/native-preview(TypeScript 7 Go compiler).Problem
@nx/vitehardcodes'tsc'for typecheck while@nx/jsalready supports a configurablecompileroption. Users who wanttsgohave to patch@nx/vitemanually.Solution
3 lines in
packages/vite/src/plugins/plugin.ts:compiler?: stringtoVitePluginOptions(with JSDoc)options.compiler ?? 'tsc'instead of hardcoded'tsc'(Vue projects still usevue-tsc)options.compiler ??= 'tsc'innormalizeOptionsUsage
Benchmarks (large monorepo, ~400 projects)
tsctsgodashboard-webmarket-reactOn CI: total typecheck CPU dropped 2.7×, allowing us to eliminate worker sharding entirely.
Currently working around this with a pnpm patch on
@nx/vite— happy to remove it once this lands.Prior art
compileroption added to@nx/js