Fix TIA JS module graph for Vue and Svelte projects - #1893
Open
m0shiurX wants to merge 1 commit into
Open
Conversation
The vite deps helper ran rolldown over the page files with no plugin that could read a single file component, so every .vue and .svelte file failed to parse and the whole build exited non zero. TIA then got an empty JS to component map on every run and quietly fell back to coarse selection. The helper now hands rolldown the script blocks of a component instead of the raw file. That is all the graph needs, since every import edge lives in a script block, so there is no framework plugin and no compile step. Two things surfaced once the components parsed. TypeScript drops an import whose bindings the emitted code never uses, and a component used only in a template is exactly that, so the typed pages lost their edges until the transform kept value imports. Rolldown also refuses to bundle CSS now, so the asset stub has to claim the js module type for the file it replaces. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
Description:
bin/pest-tia-vite-deps.mjsruns rolldown over the page files, but none of its three plugins can read a.vueor.sveltefile. Every single file component fails to parse, so the build exits non zero:JsModuleGraph::resolve()swallows that, sobuild()handsTia.phpan empty map on every run andbuildStrict()shows theVite resolver unavailablewarning. TIA keeps working, it just loses all frontend precision for the whole Inertia layer, silently, on every Laravel + Inertia + Vue project.The fix is a
loadhook that returns the component's<script>blocks in place of the raw file. Every import edge lives in a script block, so the graph is the same one the real compiler would produce, with no framework plugin, no new dependency and no compile step. That matches howassetStubalready stubs CSS and images rather than processing them.Two more things showed up once the components parsed, and both are in the same helper:
<template>is exactly that, so everylang="ts"page came back with zero edges.transform.typescript.onlyRemoveTypeImportskeeps the value imports.assetStubhas to returnmoduleType: 'js'for the file it replaces. Without it any page that imports a stylesheet fails the build, single file component or not.Verified against a real Inertia + Vue app: the helper went from exit 1 with 367 parse errors to exit 0 with a full page map. Tests cover the extraction as a pure function (
extractSfcScript) plus an end to end rolldown build over a fixture component tree, skipped when rolldown is not installed.Two alternatives I did not take. Loading
@vitejs/plugin-vueor@sveltejs/vite-plugin-sveltefrom the project'snode_modulesmeans resolving and version matching arbitrary plugins and pulling a full component compile into a pre pass that is meant to be fast, for output the graph never reads. Importing the project'svite.config.*and reusing its plugins is something the file already rejects on purpose, see the comment aboveloadAliasFromViteConfig().