From 9948a6355bfa0e3f6e5fd31395b197ba89ec11f1 Mon Sep 17 00:00:00 2001
From: Thiago Felix <thiagofelix@Thiagos-MacBook-Air.local>
Date: Tue, 24 Sep 2024 07:58:21 -0300
Subject: [PATCH] fix wront import path and add special tsinfo for eslint on
 core to include tests

---
 apps/nextjs/src/app/(auth)/actions.ts               |  3 +--
 apps/nextjs/src/app/actions.ts                      |  3 +--
 apps/nextjs/src/app/page.tsx                        |  2 +-
 apps/nextjs/src/env.ts                              |  5 ++---
 packages/core/eslint.config.js                      |  8 ++++++++
 packages/core/src/env.ts                            |  5 ++++-
 .../controllers/auth/sign-in.controller.test.ts     |  2 +-
 .../controllers/auth/sign-out.controller.test.ts    |  2 +-
 .../controllers/auth/sign-up.controller.test.ts     |  2 +-
 .../unit/use-cases/auth/sign-out.use-case.test.ts   |  2 +-
 packages/core/tsconfig.eslint.json                  |  9 +++++++++
 turbo.json                                          | 13 +++++++------
 12 files changed, 37 insertions(+), 19 deletions(-)
 create mode 100644 packages/core/tsconfig.eslint.json

diff --git a/apps/nextjs/src/app/(auth)/actions.ts b/apps/nextjs/src/app/(auth)/actions.ts
index 7d251c9..cfac0e3 100644
--- a/apps/nextjs/src/app/(auth)/actions.ts
+++ b/apps/nextjs/src/app/(auth)/actions.ts
@@ -6,6 +6,7 @@ import {
   captureException,
   withServerActionInstrumentation,
 } from "@sentry/nextjs";
+import { env } from "#env";
 
 import type { Cookie } from "@acme/core/entities/models/cookie";
 import { signInController } from "@acme/core/controllers/auth/sign-in.controller";
@@ -17,8 +18,6 @@ import {
 } from "@acme/core/entities/errors/auth";
 import { InputParseError } from "@acme/core/entities/errors/common";
 
-import { env } from "../../../../../packages/core/dist/src/env";
-
 export async function signUp(formData: FormData) {
   return await withServerActionInstrumentation(
     "signUp",
diff --git a/apps/nextjs/src/app/actions.ts b/apps/nextjs/src/app/actions.ts
index 0df9fd3..7ed3e55 100644
--- a/apps/nextjs/src/app/actions.ts
+++ b/apps/nextjs/src/app/actions.ts
@@ -6,6 +6,7 @@ import {
   captureException,
   withServerActionInstrumentation,
 } from "@sentry/nextjs";
+import { env } from "#env";
 
 import { createTodoController } from "@acme/core/controllers/todos/create-todo.controller";
 import { toggleTodoController } from "@acme/core/controllers/todos/toggle-todo.controller";
@@ -15,8 +16,6 @@ import {
   NotFoundError,
 } from "@acme/core/entities/errors/common";
 
-import { env } from "../../../../packages/core/dist/src/env";
-
 export async function createTodo(formData: FormData) {
   return await withServerActionInstrumentation(
     "createTodo",
diff --git a/apps/nextjs/src/app/page.tsx b/apps/nextjs/src/app/page.tsx
index 4c937a1..2d473a1 100644
--- a/apps/nextjs/src/app/page.tsx
+++ b/apps/nextjs/src/app/page.tsx
@@ -1,6 +1,7 @@
 import { cookies } from "next/headers";
 import { redirect } from "next/navigation";
 import { captureException, startSpan } from "@sentry/nextjs";
+import { env } from "#env";
 
 import { getTodosForUserController } from "@acme/core/controllers/todos/get-todos-for-user.controller";
 import {
@@ -10,7 +11,6 @@ import {
 import { Card, CardContent, CardHeader, CardTitle } from "@acme/ui/card";
 import { Separator } from "@acme/ui/separator";
 
-import { env } from "../../../../packages/core/dist/src/env";
 import { UserMenu } from "./_components/user-menu";
 import { CreateTodo } from "./add-todo";
 import { Todos } from "./todos";
diff --git a/apps/nextjs/src/env.ts b/apps/nextjs/src/env.ts
index 8dcc769..0e857d7 100644
--- a/apps/nextjs/src/env.ts
+++ b/apps/nextjs/src/env.ts
@@ -1,7 +1,7 @@
 import { createEnv } from "@t3-oss/env-nextjs";
 import { z } from "zod";
 
-import { env as coreEnv } from "../../../packages/core/dist/src/env";
+import { env as coreEnv } from "@acme/core/env";
 
 export const env = createEnv({
   extends: [coreEnv],
@@ -15,8 +15,7 @@ export const env = createEnv({
    * This way you can ensure the app isn't built with invalid env vars.
    */
   server: {
-    DATABASE_URL: z.string().url(),
-    NEXT_RUNTIME: z.string().optional(),
+    NEXT_RUNTIME: z.enum(["nodejs", "edge"]).optional(),
   },
 
   /**
diff --git a/packages/core/eslint.config.js b/packages/core/eslint.config.js
index 98d3bf2..e457604 100644
--- a/packages/core/eslint.config.js
+++ b/packages/core/eslint.config.js
@@ -10,4 +10,12 @@ export default [
       "@typescript-eslint/no-floating-promises": "off",
     },
   },
+  {
+    languageOptions: {
+      parserOptions: {
+        project: "./tsconfig.eslint.json",
+        projectService: false,
+      },
+    },
+  },
 ];
diff --git a/packages/core/src/env.ts b/packages/core/src/env.ts
index 47caa68..4e27ec7 100644
--- a/packages/core/src/env.ts
+++ b/packages/core/src/env.ts
@@ -11,5 +11,8 @@ export const env = createEnv({
       .enum(["development", "production", "test"])
       .default("development"),
   },
-  runtimeEnv: process.env,
+  runtimeEnvStrict: {
+    SESSION_COOKIE: process.env.SESSION_COOKIE,
+    NODE_ENV: process.env.NODE_ENV,
+  },
 });
diff --git a/packages/core/tests/unit/controllers/auth/sign-in.controller.test.ts b/packages/core/tests/unit/controllers/auth/sign-in.controller.test.ts
index e760a4f..b0ae880 100644
--- a/packages/core/tests/unit/controllers/auth/sign-in.controller.test.ts
+++ b/packages/core/tests/unit/controllers/auth/sign-in.controller.test.ts
@@ -1,10 +1,10 @@
 import "reflect-metadata";
 
-import { env } from "#config";
 import { signInController } from "#controllers/auth/sign-in.controller";
 import { destroyContainer, initializeContainer } from "#di/container";
 import { AuthenticationError } from "#entities/errors/auth";
 import { InputParseError } from "#entities/errors/common";
+import { env } from "#env";
 import { afterEach, beforeEach, expect, it } from "vitest";
 
 beforeEach(() => {
diff --git a/packages/core/tests/unit/controllers/auth/sign-out.controller.test.ts b/packages/core/tests/unit/controllers/auth/sign-out.controller.test.ts
index 67b9252..a928f1d 100644
--- a/packages/core/tests/unit/controllers/auth/sign-out.controller.test.ts
+++ b/packages/core/tests/unit/controllers/auth/sign-out.controller.test.ts
@@ -1,6 +1,6 @@
 import "reflect-metadata";
 
-import { env } from "#config";
+import { env } from "#env";
 import { signOutController } from "#controllers/auth/sign-out.controller";
 import { destroyContainer, initializeContainer } from "#di/container";
 import { InputParseError } from "#entities/errors/common";
diff --git a/packages/core/tests/unit/controllers/auth/sign-up.controller.test.ts b/packages/core/tests/unit/controllers/auth/sign-up.controller.test.ts
index eec059a..333b4cf 100644
--- a/packages/core/tests/unit/controllers/auth/sign-up.controller.test.ts
+++ b/packages/core/tests/unit/controllers/auth/sign-up.controller.test.ts
@@ -1,6 +1,6 @@
 import "reflect-metadata";
 
-import { env } from "#config";
+import { env } from "#env";
 import { signUpController } from "#controllers/auth/sign-up.controller";
 import { destroyContainer, initializeContainer } from "#di/container";
 import { AuthenticationError } from "#entities/errors/auth";
diff --git a/packages/core/tests/unit/use-cases/auth/sign-out.use-case.test.ts b/packages/core/tests/unit/use-cases/auth/sign-out.use-case.test.ts
index 295bfc9..55b31fb 100644
--- a/packages/core/tests/unit/use-cases/auth/sign-out.use-case.test.ts
+++ b/packages/core/tests/unit/use-cases/auth/sign-out.use-case.test.ts
@@ -1,6 +1,6 @@
 import "reflect-metadata";
 
-import { env } from "#config";
+import { env } from "#env";
 import { destroyContainer, initializeContainer } from "#di/container";
 import { signInUseCase } from "#use-cases/auth/sign-in.use-case";
 import { signOutUseCase } from "#use-cases/auth/sign-out.use-case";
diff --git a/packages/core/tsconfig.eslint.json b/packages/core/tsconfig.eslint.json
new file mode 100644
index 0000000..efa4865
--- /dev/null
+++ b/packages/core/tsconfig.eslint.json
@@ -0,0 +1,9 @@
+{
+  "extends": "@acme/tsconfig/internal-package.json",
+  "compilerOptions": {
+    "rootDir": ".",
+    "types": ["reflect-metadata"]
+  },
+  "include": ["src", "tests"],
+  "exclude": ["node_modules"]
+}
diff --git a/turbo.json b/turbo.json
index c148039..2243313 100644
--- a/turbo.json
+++ b/turbo.json
@@ -31,11 +31,12 @@
       "cache": false
     }
   },
-  "globalEnv": ["PORT", "DATABASE_URL", "DATABASE_AUTH_TOKEN"],
-  "globalPassThroughEnv": [
+  "globalEnv": [
     "NODE_ENV",
-    "NEXT_RUNTIME",
-    "CI",
-    "npm_lifecycle_event"
-  ]
+    "SESSION_COOKIE",
+    "PORT",
+    "DATABASE_URL",
+    "DATABASE_AUTH_TOKEN"
+  ],
+  "globalPassThroughEnv": []
 }