From c1e51aa5329d9297e70bbc05d44ab96b974bbdd6 Mon Sep 17 00:00:00 2001 From: Kevin Brey Date: Mon, 22 Jul 2024 14:03:42 -0500 Subject: [PATCH] fix(build): use vite to emit cjs and esm formats --- package-lock.json | 11 ++++++++++- package.json | 23 ++++++++++++++++++----- tsconfig.json | 5 +++-- tsconfig.types.json | 10 ++++++++++ vitest.config.mts => vite.config.ts | 18 +++++++++++++++++- 5 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 tsconfig.types.json rename vitest.config.mts => vite.config.ts (54%) diff --git a/package-lock.json b/package-lock.json index d7a6935..69b1358 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,12 +19,14 @@ "@commitlint/config-angular": "^19.3.0", "@tsconfig/recommended": "^1.0.3", "@tsconfig/strictest": "^2.0.2", + "@tsconfig/vite-react": "^3.0.2", "@types/node": "^20.12.12", "@vitest/coverage-v8": "^2.0.3", "@vitest/ui": "^2.0.3", "happy-dom": "^14.12.3", "semantic-release": "^22.0.0", - "typescript": "^5.2.2" + "typescript": "^5.2.2", + "vite": "^5.3.4" } }, "node_modules/@ampproject/remapping": { @@ -1805,6 +1807,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@tsconfig/vite-react": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@tsconfig/vite-react/-/vite-react-3.0.2.tgz", + "integrity": "sha512-AFynAtE1Un3Rko20Ghe2mVC/QWD4rStJ2PnyIZU2kzC4UyWpf1YhAEY87GojH/XPZCY8Mdt27gsYyy+6l6HV+w==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/conventional-commits-parser": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/@types/conventional-commits-parser/-/conventional-commits-parser-5.0.0.tgz", diff --git a/package.json b/package.json index 10dad01..c0be7fa 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,13 @@ "name": "vitest-tiny-reporter", "version": "0.0.0-development", "description": "Tiny reporter for vitest", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "files": ["/dist"], + "types": "dist/types/index.d.ts", + "files": ["dist"], "keywords": ["vitest", "reporter", "lefthook"], "scripts": { - "build": "tsc", + "build": "npx concurrently npm:build:*", + "build:vite": "vite build", + "build:tsc": "tsc -b tsconfig.types.json", "test": "vitest run", "coverage": "vitest run --coverage", "test:watch": "vitest --watch --coverage --ui", @@ -32,12 +33,14 @@ "@commitlint/config-angular": "^19.3.0", "@tsconfig/recommended": "^1.0.3", "@tsconfig/strictest": "^2.0.2", + "@tsconfig/vite-react": "^3.0.2", "@types/node": "^20.12.12", "@vitest/coverage-v8": "^2.0.3", "@vitest/ui": "^2.0.3", "happy-dom": "^14.12.3", "semantic-release": "^22.0.0", - "typescript": "^5.2.2" + "typescript": "^5.2.2", + "vite": "^5.3.4" }, "dependencies": { "@vitest/runner": "^2.0.3", @@ -46,5 +49,15 @@ }, "release": { "branches": ["main"] + }, + "type": "module", + "main": "./dist/vitest-tiny-reporter.umd.cjs", + "module": "./dist/vitest-tiny-reporter.js", + "exports": { + ".": { + "import": "./dist/vitest-tiny-reporter.js", + "require": "./dist/vitest-tiny-reporter.umd.cjs", + "types": "./dist/types/index.d.ts" + } } } diff --git a/tsconfig.json b/tsconfig.json index 160dc1b..454e1a4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,10 @@ { "$schema": "https://json.schemastore.org/tsconfig", - "extends": ["@tsconfig/strictest/tsconfig", "@tsconfig/recommended/tsconfig"], + "extends": ["@tsconfig/strictest/tsconfig", "@tsconfig/vite-react/tsconfig"], "compilerOptions": { "declaration": true, "outDir": "./dist" }, - "files": ["src/index.ts"] + "files": ["src/index.ts"], + "exclude": ["src/**/*.test*"] } diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 0000000..5e71ccb --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,10 @@ +{ + "$schema": "https://json.schemastore.org/tsconfig", + "extends": "./tsconfig.json", + "compilerOptions": { + "declaration": true, + "declarationDir": "dist/types", + "emitDeclarationOnly": true, + "noEmit": false + } +} diff --git a/vitest.config.mts b/vite.config.ts similarity index 54% rename from vitest.config.mts rename to vite.config.ts index 3e4c73f..732a604 100644 --- a/vitest.config.mts +++ b/vite.config.ts @@ -1,13 +1,29 @@ import type { UserConfig } from 'vitest/config'; export default { + build: { + emptyOutDir: false, + lib: { + entry: 'src/index.ts', + name: 'vitest-tiny-reporter', + }, + rollupOptions: { + external: ['tinyrainbow'], + output: { + globals: { + tinyrainbow: 'tinyrainbow', + }, + }, + }, + sourcemap: true, + }, test: { environment: 'happy-dom', coverage: { reporter: ['cobertura', 'text', 'html', 'lcov'], thresholds: { statements: 93.75, - branches: 82.14, + branches: 82.75, functions: 100, lines: 93.75, autoUpdate: true,