From 065f83eaedd1d6a8ef302f4db51e6c099da93dad Mon Sep 17 00:00:00 2001 From: valon Date: Tue, 12 Nov 2024 18:19:05 -0500 Subject: [PATCH] Update backend configuration and improve ESLint setup; add .js extensions, refine tsconfig, and enhance tsup settings --- apps/backend/src/index.ts | 13 ++---- apps/backend/src/server.ts | 2 - eslint.config.js | 90 +++++++++++++++++++++++++------------- tsup.config.ts | 11 +++-- 4 files changed, 69 insertions(+), 47 deletions(-) diff --git a/apps/backend/src/index.ts b/apps/backend/src/index.ts index 39344c7..30adf81 100644 --- a/apps/backend/src/index.ts +++ b/apps/backend/src/index.ts @@ -1,14 +1,7 @@ -import { fileURLToPath } from "url"; -import { dirname } from "path"; -import app from "./app"; -import { createServer } from "./server"; - -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); +// apps/backend/src/index.ts +import { createServer } from "./server.js"; // Add .js extension +import app from "./app.js"; // Add .js extension const server = createServer(app); -server.listen(process.env.PORT || 3000, () => { - console.log(`Server running on port ${process.env.PORT || 3000}`); -}); export { server }; diff --git a/apps/backend/src/server.ts b/apps/backend/src/server.ts index c934c03..9ce2116 100644 --- a/apps/backend/src/server.ts +++ b/apps/backend/src/server.ts @@ -1,6 +1,4 @@ -// apps/backend/src/server.ts import { Server } from "http"; -import express from "express"; import type { Express } from "express"; export function createServer(app: Express): Server { diff --git a/eslint.config.js b/eslint.config.js index 94d46dd..046d9a2 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -12,38 +12,66 @@ const compat = new FlatCompat({ baseDirectory: __dirname, }); -export default tseslint.config( - js.configs.recommended, - ...tseslint.configs.recommended, +export default [ { - plugins: { - n: eslintPluginN, - import: eslintPluginImport, - }, - rules: { - "n/no-missing-import": "error", - "import/no-unresolved": "error", - }, - }, - prettier, - ...compat.config({ - extends: ["plugin:import/typescript"], - settings: { - "import/resolver": { - typescript: { - project: ["./apps/*/tsconfig.json"], + // Config files + files: ["*.config.{js,ts}", ".eslintrc.{js,cjs,mjs}"], + ...tseslint.config( + js.configs.recommended, + ...tseslint.configs.recommended, + { + languageOptions: { + parserOptions: { + project: null, // Disable project for config files + }, }, - node: true, - }, - }, - }), + } + ), + }, { - ignores: ["**/dist/**", "**/node_modules/**", "**/.next/**"], - languageOptions: { - parserOptions: { - project: ["./tsconfig.json", "./apps/*/tsconfig.json"], - tsconfigRootDir: __dirname, + // Source files + files: ["apps/**/*.{ts,tsx}"], + ...tseslint.config( + js.configs.recommended, + ...tseslint.configs.recommended, + { + plugins: { + n: eslintPluginN, + import: eslintPluginImport, + }, + rules: { + "n/no-missing-import": "error", + "import/no-unresolved": "error", + "@typescript-eslint/no-unused-vars": [ + "error", + { + argsIgnorePattern: "^_", + varsIgnorePattern: "^_", + }, + ], + }, }, - }, - } -); + prettier, + ...compat.config({ + extends: ["plugin:import/typescript"], + settings: { + "import/resolver": { + typescript: { + project: ["./apps/*/tsconfig.json"], + }, + node: true, + }, + }, + }), + { + ignores: ["**/dist/**", "**/node_modules/**", "**/.next/**"], + languageOptions: { + parserOptions: { + project: ["./apps/*/tsconfig.json"], + tsconfigRootDir: __dirname, + }, + }, + } + ), + }, +]; diff --git a/tsup.config.ts b/tsup.config.ts index 81b0cc0..ed27a5a 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -6,10 +6,13 @@ export default defineConfig([ { entry: ["apps/backend/src/index.ts"], outDir: "apps/backend/dist", - format: ["esm"], // Ensure this is set to "esm" - dts: true, - clean: true, - tsconfig: "./apps/backend/tsconfig.json", + format: ["esm"], + target: "node20", + platform: "node", + sourcemap: true, + bundle: true, + splitting: false, + noExternal: ["express"], }, // Frontend config {