From 029f63ddd0a9f1cea395d80feec77df54dae87e8 Mon Sep 17 00:00:00 2001 From: moontai0724 Date: Wed, 9 Oct 2024 09:59:07 +0800 Subject: [PATCH] build: correct tsconfig for test files in src --- eslint.config.js | 2 +- src/tsconfig.build.json | 2 ++ src/tsconfig.json | 19 ++++++++++++++----- tests/tsconfig.json | 17 +++++++++++------ tsconfig.json | 7 ++++--- vitest.config.ts | 7 +++++++ 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 44e3ab6..63ba56a 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -7,7 +7,7 @@ import globals from "globals"; import { config as typedConfig, configs as tsConfigs } from "typescript-eslint"; export default typedConfig( - { ignores: ["node_modules", "dist", "build", "coverage"] }, + { ignores: ["node_modules", "dist", "build", "docs", "coverage"] }, { files: ["src/**/*.ts"], languageOptions: { diff --git a/src/tsconfig.build.json b/src/tsconfig.build.json index cd01874..6ba8e91 100644 --- a/src/tsconfig.build.json +++ b/src/tsconfig.build.json @@ -1,7 +1,9 @@ { "extends": "./tsconfig.json", "compilerOptions": { + "composite": false, "noEmit": false, + "emitDeclarationOnly": false, "declaration": true, "noEmitOnError": true }, diff --git a/src/tsconfig.json b/src/tsconfig.json index f95f3be..7a71416 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,14 +1,23 @@ { "extends": "../tsconfig.json", "compilerOptions": { + "composite": true, + "noEmit": false, + "emitDeclarationOnly": true, "target": "ES6", - "module": "ESNext", - // Bundler mode - "moduleResolution": "bundler", "lib": ["ES6", "DOM", "DOM.Iterable"], - "rootDir": "." + "rootDir": ".", + "paths": { + "@/*": ["../src/*"] + } }, - "include": ["."] + "include": ["./**/*.ts"], + "exclude": ["./**/*.spec.ts"], + "references": [ + { + "path": "../tests" + } + ] } diff --git a/tests/tsconfig.json b/tests/tsconfig.json index 162afb9..9288f38 100644 --- a/tests/tsconfig.json +++ b/tests/tsconfig.json @@ -1,11 +1,16 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "baseUrl": "../src", - "paths": { - "@/*": ["../src/*"], - "~/*": ["../tests/*"] - } + "composite": true, + "noEmit": false, + "emitDeclarationOnly": true, + "target": "ESNext", + "baseUrl": "../src" }, - "include": [".", "../src"] + "include": ["./**/*.ts", "../src/**/*.spec.ts"], + "references": [ + { + "path": "../src" + } + ] } diff --git a/tsconfig.json b/tsconfig.json index 1680ac9..feb51d5 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,14 +5,15 @@ // Specify what module code is generated "module": "ESNext", // Specify how TypeScript looks up a file from a given module specifier - "moduleResolution": "Node", + "moduleResolution": "Bundler", // Specify the root folder contains all ts files "rootDir": ".", // Specify the base directory to resolve non-relative module names "baseUrl": "./src", "paths": { - "@/*": ["./*"] // => `./src/*` + "@/*": ["../src/*"], + "~/*": ["../tests/*"] }, "outDir": "./build", @@ -40,7 +41,7 @@ "skipLibCheck": true, "useDefineForClassFields": true }, - "exclude": ["node_modules", "dist"], + "exclude": ["node_modules", "dist", "build", "docs", "coverage"], "tsc-alias": { "resolveFullPaths": true, "verbose": true diff --git a/vitest.config.ts b/vitest.config.ts index 112071b..8219ca8 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,3 +1,5 @@ +import { resolve } from "node:path"; + import { defineConfig, mergeConfig } from "vitest/config"; import viteConfig from "./vite.config"; @@ -5,6 +7,11 @@ import viteConfig from "./vite.config"; export default mergeConfig( viteConfig, defineConfig({ + resolve: { + alias: { + "~": resolve(import.meta.dirname, "tests"), + }, + }, test: { coverage: { enabled: true,