Skip to content

Commit 715964a

Browse files
authored
Detect TypeScript extension (#749)
1 parent d8fc2c3 commit 715964a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/Generators/Statements/InertiaPageGenerator.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,25 @@ public function output(Tree $tree): array
5858
protected function getAdapter(): ?array
5959
{
6060
$packagePath = base_path('package.json');
61-
6261
if (!$this->filesystem->exists($packagePath)) {
6362
return null;
6463
}
6564

6665
$contents = $this->filesystem->get($packagePath);
66+
if (!preg_match('/@inertiajs\/(vue3|react|svelte)/i', $contents, $matches)) {
67+
return null;
68+
}
6769

68-
if (preg_match('/@inertiajs\/(vue3|react|svelte)/i', $contents, $matches)) {
69-
$adapterKey = strtolower($matches[1]);
70+
$adapterKey = strtolower($matches[1]);
71+
if (!isset($this->adapters[$adapterKey])) {
72+
return null;
73+
}
7074

71-
return $this->adapters[$adapterKey] ?? null;
75+
if ($adapterKey === 'react' && ($this->filesystem->exists(base_path('tsconfig.json')) || preg_match('/"typescript"/i', $contents))) {
76+
return array_replace($this->adapters[$adapterKey], ['extension' => '.tsx']);
7277
}
7378

74-
return null;
79+
return $this->adapters[$adapterKey];
7580
}
7681

7782
protected function getStatementPath(string $view): string

tests/Feature/Generators/Statements/InertiaPageGeneratorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public static function inertiaAdaptersDataProvider(): array
147147
return [
148148
['vue', '"@inertiajs/vue3": "^2.0.0"', 'resources/js/Pages/Customer/Show.vue', '.vue'],
149149
['react', '"@inertiajs/react": "^2.0.0"', 'resources/js/Pages/Customer/Show.jsx', '.jsx'],
150+
['react', '"@inertiajs/react": "^2.0.0", "typescript": "^5.0.0"', 'resources/js/Pages/Customer/Show.tsx', '.tsx'],
150151
['svelte', '"@inertiajs/svelte": "^2.0.0"', 'resources/js/Pages/Customer/Show.svelte', '.svelte'],
151152
];
152153
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { Head } from '@inertiajs/react'
2+
3+
export default function Show({ customer, customers }) {
4+
return (
5+
<div>
6+
<Head title="Customer Show" />
7+
<h1>Customer Show</h1>
8+
</div>
9+
)
10+
}

0 commit comments

Comments
 (0)