From 3544ff3622f3a6396cfb5934237479a4aed71fdf Mon Sep 17 00:00:00 2001 From: Phil Bates Date: Thu, 29 Feb 2024 15:38:31 +0000 Subject: [PATCH 1/3] ESLint: Change import/extensions from "always" to "ignorePackages" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It turns out set to "always" is a pain, for example if we write:     import { createRoot } from "react-dom/client" import/extensions doesn't like this. So if you add the explicit file extension:     import { createRoot } from "react-dom/client.js" That makes ESLint happy, but tsc now fails because it can't find the types definition for it, because @types/react-dom only has "exports" defined for "/client" not "/client.js". So it seems its impossible to enforce extensions on package imports while at the same time using tsc. --- .eslintrc.cjs | 2 +- vite.config.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 4a5f255..4230b95 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -22,7 +22,7 @@ module.exports = { plugins: ["import"], rules: { "import/exports-last": "error", - "import/extensions": ["error", "always"], + "import/extensions": ["error", "ignorePackages"], "import/first": "error", "import/newline-after-import": "error", "import/no-default-export": "error", diff --git a/vite.config.ts b/vite.config.ts index 7847686..d1108b1 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,6 +1,6 @@ import laravel from "laravel-vite-plugin"; import { defineConfig } from "vite"; -import { configDefaults } from "vitest/config"; // eslint-disable-line import/extensions +import { configDefaults } from "vitest/config"; // Exclude everything except resources/js/ const projectExcludes = [ From 5c73e4d0c61365da424d47c77f84a4b809763155 Mon Sep 17 00:00:00 2001 From: Phil Bates Date: Wed, 28 Feb 2024 15:44:05 +0000 Subject: [PATCH 2/3] Kernel: Enable AddLinkHeadersForPreloadedAssets middleware This is automatically enabled when using breeze:install to instead React with Intertia, I don't really see any downside in enabling it. See: https://github.com/laravel/framework/pull/44096 --- app/Http/Kernel.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 16552da..52ce328 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -38,6 +38,7 @@ class Kernel extends HttpKernel \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, + \Illuminate\Http\Middleware\AddLinkHeadersForPreloadedAssets::class, ], 'api' => [ From 02e0c51b203339026984a705dfce0181e2132b08 Mon Sep 17 00:00:00 2001 From: Phil Bates Date: Wed, 28 Feb 2024 17:40:50 +0000 Subject: [PATCH 3/3] TS: Move paths from tsconfig.app.json to tsconfig.json So that components.json and eslint-import-resolver-typescript work as they don't appear to support "tsc -b". --- tsconfig.app.json | 6 +----- tsconfig.json | 7 +++++++ 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tsconfig.app.json b/tsconfig.app.json index ce4560d..0710531 100644 --- a/tsconfig.app.json +++ b/tsconfig.app.json @@ -1,4 +1,5 @@ { + "extends": "./tsconfig.json", "include": ["resources/js"], "exclude": ["resources/js/**/__tests__/*"], "compilerOptions": { @@ -19,11 +20,6 @@ "isolatedModules": true, "noEmit": true, - /* Absolute imports */ - "paths": { - "@/*": ["./resources/js/*"] - }, - /* Linting */ "strict": true, "noUnusedLocals": true, diff --git a/tsconfig.json b/tsconfig.json index 4b55668..d5cab78 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,12 @@ { "files": [], + "compilerOptions": { + // Absolute imports. Define here instead of tsconfig.app.json because e.g. eslint-import-resolver-typescript + // and shadcn-ui don't support project references and only read directly from this file + "paths": { + "@/*": ["./resources/js/*"] + } + }, "references": [ { "path": "./tsconfig.app.json"