diff --git a/bin/pest-tia-vite-deps.mjs b/bin/pest-tia-vite-deps.mjs
index f39af395..7ab3905b 100644
--- a/bin/pest-tia-vite-deps.mjs
+++ b/bin/pest-tia-vite-deps.mjs
@@ -12,6 +12,8 @@ const PAGE_EXTENSIONS = new Set([
'.ts', '.js',
'.mts', '.cts', '.mjs', '.cjs',
])
+const SFC_RE = /\.(vue|svelte)$/i
+const SCRIPT_BLOCK_RE = /\n",
+ ['imports' => ['@/A.vue'], 'moduleType' => 'js'],
+ ],
+ 'plain-script-with-default' => [
+ "",
+ ['imports' => ['@/A.vue'], 'moduleType' => 'js'],
+ ],
+ 'typescript-lang' => [
+ "",
+ ['imports' => ['@/types', '@/B.vue'], 'moduleType' => 'ts'],
+ ],
+ 'lang-tsx' => [
+ "",
+ ['imports' => ['@/C.vue'], 'moduleType' => 'ts'],
+ ],
+ 'lang-unquoted' => [
+ "",
+ ['imports' => ['@/D.vue'], 'moduleType' => 'ts'],
+ ],
+ 'both-script-blocks' => [
+ "\n",
+ ['imports' => ['@/A.vue', '@/B.vue'], 'moduleType' => 'js'],
+ ],
+ 'template-only' => [
+ 'hello
',
+ ['imports' => [], 'moduleType' => 'js'],
+ ],
+ 'style-block-ignored' => [
+ "\n",
+ ['imports' => ['@/A.vue'], 'moduleType' => 'js'],
+ ],
+ 'dynamic-import' => [
+ "",
+ ['imports' => ['@/Lazy.vue'], 'moduleType' => 'js'],
+ ],
+ 'svelte-component' => [
+ "\n
hi
",
+ ['imports' => ['./A.svelte'], 'moduleType' => 'js'],
+ ],
+ 'no-script-at-all' => [
+ 'plain markup
',
+ ['imports' => [], 'moduleType' => 'js'],
+ ],
+ 'default-export-in-line-comment' => [
+ "",
+ ['imports' => ['@/A.vue'], 'moduleType' => 'js'],
+ ],
+ 'default-export-in-block-comment' => [
+ "",
+ ['imports' => ['@/A.vue'], 'moduleType' => 'js'],
+ ],
+ 'default-export-in-string' => [
+ "",
+ ['imports' => ['@/A.vue'], 'moduleType' => 'js'],
+ ],
+ ];
+}
+
+function tiaSfcResults(): array
+{
+ static $cache = null;
+ if ($cache !== null) {
+ return $cache;
+ }
+
+ $payload = [];
+ foreach (tiaSfcFixtures() as $name => [$raw]) {
+ $payload[] = ['name' => $name, 'raw' => $raw];
+ }
+
+ $inputFile = tempnam(sys_get_temp_dir(), 'tia-sfc-');
+ file_put_contents($inputFile, json_encode($payload));
+
+ $helper = str_replace('\\', '/', tiaViteHelperPath());
+ $input = str_replace('\\', '/', $inputFile);
+
+ $script = << m[1])
+ out[c.name] = { code: r.code, moduleType: r.moduleType, imports }
+ }
+ process.stdout.write(JSON.stringify(out))
+ JS;
+
+ $process = new Process(['node', '--input-type=module', '-e', $script]);
+ $process->mustRun();
+
+ @unlink($inputFile);
+
+ return $cache = json_decode($process->getOutput(), true, flags: JSON_THROW_ON_ERROR);
+}
+
+function tiaRolldownPackageDir(): ?string
+{
+ $locate = fn (array $command, ?string $cwd = null): ?string => ($process = new Process($command, $cwd))->run() === 0
+ ? (trim($process->getOutput()) ?: null)
+ : null;
+
+ $paths = [dirname(__DIR__, 4)];
+ if (($global = $locate(['npm', 'root', '-g'])) !== null) {
+ $paths[] = $global;
+ }
+
+ $manifest = $locate(['node', '-p', "require.resolve('rolldown/package.json', { paths: process.argv.slice(1) })", ...$paths]);
+
+ return $manifest === null ? null : dirname($manifest);
+}
+
+function tiaBuildOptionResults(): array
+{
+ static $cache = null;
+ if ($cache !== null) {
+ return $cache;
+ }
+
+ $helper = str_replace('\\', '/', tiaViteHelperPath());
+
+ $script = <<mustRun();
+
+ return $cache = json_decode($process->getOutput(), true, flags: JSON_THROW_ON_ERROR);
+}
+
beforeEach(function (): void {
if ((new ExecutableFinder)->find('node') === null) {
$this->markTestSkipped('node is not available.');
@@ -472,3 +613,101 @@ it('accepts a page directory candidate only when it matches the casing on disk',
expect(tiaViteCasingResults()[$name])->toBe($expected);
})->with(array_keys(tiaViteCasingFixtures()));
+
+it('keeps every import a single file component declares', function (string $name): void {
+ [, $expected] = tiaSfcFixtures()[$name];
+
+ expect(tiaSfcResults()[$name]['imports'])->toEqual($expected['imports']);
+})->with(array_keys(tiaSfcFixtures()));
+
+it('reports the script block language so the parser matches it', function (string $name): void {
+ [, $expected] = tiaSfcFixtures()[$name];
+
+ expect(tiaSfcResults()[$name]['moduleType'])->toBe($expected['moduleType']);
+})->with(array_keys(tiaSfcFixtures()));
+
+it('always leaves a default export for importers to resolve against', function (string $name): void {
+ expect(tiaSfcResults()[$name]['code'])->toMatch('/export\s+default\b/');
+})->with(array_keys(tiaSfcFixtures()));
+
+it('does not add a second default export when the block already has one', function (): void {
+ preg_match_all('/export\s+default\b/', tiaSfcResults()['plain-script-with-default']['code'], $matches);
+
+ expect($matches[0])->toHaveCount(1);
+});
+
+it('drops template and style markup that the parser would reject', function (): void {
+ expect(tiaSfcResults()['style-block-ignored']['code'])->not->toContain('