From d5a10c0bd161677a9c611c63b1263fc6fe07f1b5 Mon Sep 17 00:00:00 2001 From: Kavian77 Date: Thu, 26 Dec 2024 19:05:19 +0100 Subject: [PATCH 1/3] Setup Prettier and run it once on the project --- .github/workflows/ci.yml | 12 +- .prettierignore | 3 + .prettierrc | 1 + eslint.config.js | 9 +- examples/react/src/main.tsx | 2 +- examples/react/tailwind.config.js | 2 +- examples/react/tsconfig.json | 4 +- examples/react/vite.config.ts | 8 +- package-lock.json | 120 +++++++++++++++++++ package.json | 7 +- packages/core/src/__tests__/core.test.ts | 47 +++++--- packages/core/src/__tests__/storage.test.ts | 12 +- packages/core/src/index.ts | 16 +-- packages/core/src/logger.ts | 12 +- packages/core/src/storage.ts | 4 +- packages/core/src/types.ts | 4 +- packages/core/tsconfig.json | 2 +- packages/core/vitest.config.ts | 21 ++-- packages/trackers/click-tracker/src/index.ts | 2 +- tsconfig.base.json | 2 +- tsconfig.json | 2 +- turbo.json | 9 +- vitest.config.ts | 27 +++-- vitest.setup.ts | 16 +-- vitest.workspace.ts | 6 +- 25 files changed, 259 insertions(+), 91 deletions(-) create mode 100644 .prettierignore create mode 100644 .prettierrc diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d61ba8..f45d27e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,11 +1,11 @@ name: CI - + on: push: branches: ["main"] pull_request: types: [opened, synchronize] - + jobs: build: runs-on: ubuntu-latest @@ -15,7 +15,7 @@ jobs: - name: Cache turbo build setup uses: actions/cache@v4 - with: + with: path: .turbo key: ${{ runner.os }}-turbo-${{ github.sha }} restore-keys: | @@ -25,17 +25,19 @@ jobs: uses: actions/setup-node@v4 with: node-version: 22 - cache: 'npm' + cache: "npm" - name: Install dependencies run: npm ci - name: Build run: npm run build - + - name: Run tests run: npm run test - name: Lint run: npm run lint + - name: Check formatting + run: npm run check-formatting diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..ca8cdd0 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,3 @@ +# Ignore artifacts: +dist +node_modules \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/eslint.config.js b/eslint.config.js index 2fa30ce..94f3ad7 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -2,11 +2,16 @@ import js from "@eslint/js"; import globals from "globals"; import tseslint from "typescript-eslint"; import noOnlyTestsPlugin from "eslint-plugin-no-only-tests"; +import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"; export default tseslint.config( { ignores: ["dist"] }, { - extends: [js.configs.recommended, ...tseslint.configs.recommended], + extends: [ + js.configs.recommended, + ...tseslint.configs.recommended, + eslintPluginPrettierRecommended, + ], files: ["**/*.{ts,tsx}"], languageOptions: { ecmaVersion: 2020, @@ -18,5 +23,5 @@ export default tseslint.config( rules: { "no-only-tests/no-only-tests": "error", }, - } + }, ); diff --git a/examples/react/src/main.tsx b/examples/react/src/main.tsx index 19ab588..886a31d 100644 --- a/examples/react/src/main.tsx +++ b/examples/react/src/main.tsx @@ -22,5 +22,5 @@ window.fetch = async (input: RequestInfo | URL, init?: RequestInit) => { createRoot(document.getElementById("root")!).render( - + , ); diff --git a/examples/react/tailwind.config.js b/examples/react/tailwind.config.js index d21f1cd..614c86b 100644 --- a/examples/react/tailwind.config.js +++ b/examples/react/tailwind.config.js @@ -1,6 +1,6 @@ /** @type {import('tailwindcss').Config} */ export default { - content: ['./index.html', './src/**/*.{js,ts,jsx,tsx}'], + content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], theme: { extend: {}, }, diff --git a/examples/react/tsconfig.json b/examples/react/tsconfig.json index 6758255..d55d165 100644 --- a/examples/react/tsconfig.json +++ b/examples/react/tsconfig.json @@ -20,8 +20,8 @@ "paths": { /* TODO: Remove these when the packages are published */ "@cluesive/core": ["../../packages/core/src"], - "@cluesive/click-tracker": ["../../packages/trackers/click-tracker/src"], + "@cluesive/click-tracker": ["../../packages/trackers/click-tracker/src"] } }, "include": ["src", "../../packages/*/src"] -} \ No newline at end of file +} diff --git a/examples/react/vite.config.ts b/examples/react/vite.config.ts index ac340be..9b2452a 100644 --- a/examples/react/vite.config.ts +++ b/examples/react/vite.config.ts @@ -1,5 +1,5 @@ -import { defineConfig } from 'vite'; -import react from '@vitejs/plugin-react'; +import { defineConfig } from "vite"; +import react from "@vitejs/plugin-react"; // https://vitejs.dev/config/ export default defineConfig({ @@ -7,8 +7,8 @@ export default defineConfig({ resolve: { alias: { // TODO: Remove these once the packages are published - '@cluesive/core': '../../../packages/core/src', - '@cluesive/click-tracker': '../../../packages/trackers/click-tracker/src', + "@cluesive/core": "../../../packages/core/src", + "@cluesive/click-tracker": "../../../packages/trackers/click-tracker/src", }, }, }); diff --git a/package-lock.json b/package-lock.json index dc67183..8e7258c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,9 +16,12 @@ "@vitest/coverage-v8": "^1.3.1", "autoprefixer": "^10.4.18", "eslint": "^9.9.1", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-no-only-tests": "^3.3.0", + "eslint-plugin-prettier": "^5.2.1", "globals": "^15.9.0", "happy-dom": "^15.11.7", + "prettier": "3.4.2", "tsup": "^8.3.5", "turbo": "^1.12.5", "typescript": "^5.5.3", @@ -394,6 +397,19 @@ "node": ">=14" } }, + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@rollup/rollup-android-arm-eabi": { "version": "4.24.3", "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.24.3.tgz", @@ -1512,6 +1528,19 @@ } } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, "node_modules/eslint-plugin-no-only-tests": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/eslint-plugin-no-only-tests/-/eslint-plugin-no-only-tests-3.3.0.tgz", @@ -1522,6 +1551,37 @@ "node": ">=5.0.0" } }, + "node_modules/eslint-plugin-prettier": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", + "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", + "dev": true, + "license": "MIT", + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.9.1" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": "*", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-scope": { "version": "8.2.0", "dev": true, @@ -1637,6 +1697,13 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/fast-glob": { "version": "3.3.2", "dev": true, @@ -2634,6 +2701,35 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.4.2", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.4.2.tgz", + "integrity": "sha512-e9MewbtFo+Fevyuxn/4rrcDAaq0IYxPGLvObpQjiZBMAzB9IGmzlnG9RZy3FFas+eBMu2vA0CszMeduow5dIuQ==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "dev": true, @@ -3024,6 +3120,23 @@ "node": ">=8" } }, + "node_modules/synckit": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", + "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/test-exclude": { "version": "6.0.0", "dev": true, @@ -3185,6 +3298,13 @@ "dev": true, "license": "Apache-2.0" }, + "node_modules/tslib": { + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", + "dev": true, + "license": "0BSD" + }, "node_modules/tsup": { "version": "8.3.5", "dev": true, diff --git a/package.json b/package.json index 84248ae..c3e9e7b 100644 --- a/package.json +++ b/package.json @@ -10,16 +10,21 @@ "scripts": { "build": "turbo run build", "lint": "turbo run lint", - "test": "turbo run test" + "test": "turbo run test", + "check-formatting": "prettier . --check", + "format": "prettier . --write" }, "devDependencies": { "@eslint/js": "^9.9.1", "@vitest/coverage-v8": "^1.3.1", "autoprefixer": "^10.4.18", "eslint": "^9.9.1", + "eslint-config-prettier": "^9.1.0", "eslint-plugin-no-only-tests": "^3.3.0", + "eslint-plugin-prettier": "^5.2.1", "globals": "^15.9.0", "happy-dom": "^15.11.7", + "prettier": "3.4.2", "tsup": "^8.3.5", "turbo": "^1.12.5", "typescript": "^5.5.3", diff --git a/packages/core/src/__tests__/core.test.ts b/packages/core/src/__tests__/core.test.ts index ae97f1d..6607c36 100644 --- a/packages/core/src/__tests__/core.test.ts +++ b/packages/core/src/__tests__/core.test.ts @@ -66,29 +66,29 @@ describe("cluesive", () => { await cluesive.start(); expect(windowAddListenerSpy).toHaveBeenCalledWith( "online", - expect.any(Function) + expect.any(Function), ); expect(windowAddListenerSpy).toHaveBeenCalledWith( "offline", - expect.any(Function) + expect.any(Function), ); expect(documentAddListenerSpy).toHaveBeenCalledWith( "visibilitychange", - expect.any(Function) + expect.any(Function), ); await cluesive.stop(); expect(WindowRemoveListenerSpy).toHaveBeenCalledWith( "online", - expect.any(Function) + expect.any(Function), ); expect(WindowRemoveListenerSpy).toHaveBeenCalledWith( "offline", - expect.any(Function) + expect.any(Function), ); expect(documentRemoveListenerSpy).toHaveBeenCalledWith( "visibilitychange", - expect.any(Function) + expect.any(Function), ); windowAddListenerSpy.mockRestore(); @@ -149,11 +149,16 @@ describe("cluesive", () => { new Response(JSON.stringify({ success: true }), { status: 200, headers: { "Content-Type": "application/json" }, - }) + }), ); const onSuccess = vi.fn(); - - const event: TrackingEvent = { id: "testEvent", context: {}, type: "type", timestamp: 0 }; + + const event: TrackingEvent = { + id: "testEvent", + context: {}, + type: "type", + timestamp: 0, + }; cluesive["options"].onSuccess = onSuccess; const wasSendEventSuccessful = await cluesive["sendEvents"]([event]); @@ -162,7 +167,7 @@ describe("cluesive", () => { trackerOptions.endpoint, expect.objectContaining({ body: JSON.stringify({ events: [event] }), - }) + }), ); expect(onSuccess).toHaveBeenCalledWith([event]); fetchSpy.mockRestore(); @@ -172,7 +177,12 @@ describe("cluesive", () => { const fetchSpy = vi .spyOn(window, "fetch") .mockImplementation(() => Promise.reject("Network error")); - const event: TrackingEvent= { id: "testEvent", context: {}, type: "type", timestamp: 0 }; + const event: TrackingEvent = { + id: "testEvent", + context: {}, + type: "type", + timestamp: 0, + }; cluesive["options"].retryAttempts = 2; @@ -206,8 +216,10 @@ describe("cluesive", () => { timestamp: 0, }; - // @ts-expect-error - sendEvents is private - const sendEventsSpy = vi.spyOn(cluesive, "sendEvents").mockResolvedValue(true); + const sendEventsSpy = vi + // @ts-expect-error - sendEvents is private + .spyOn(cluesive, "sendEvents") + .mockResolvedValue(true); storageManagerMock.getPendingEvents.mockResolvedValueOnce([event]); storageManagerMock.clearPendingEvents.mockResolvedValueOnce(void 0); @@ -219,10 +231,15 @@ describe("cluesive", () => { it("should apply middlewares before sending events", async () => { const middleware = vi.fn(async (events: TrackingEvent[]) => - events.map((e) => ({ ...e, modified: true })) + events.map((e) => ({ ...e, modified: true })), ); cluesive["options"].middlewares = [middleware]; - const event: TrackingEvent = { id: "event1", context: {}, type: "type", timestamp: 0 }; + const event: TrackingEvent = { + id: "event1", + context: {}, + type: "type", + timestamp: 0, + }; await cluesive["track"](event); const processedEvents = await cluesive["applyMiddlewares"]([event]); diff --git a/packages/core/src/__tests__/storage.test.ts b/packages/core/src/__tests__/storage.test.ts index 42aef47..73ddb5f 100644 --- a/packages/core/src/__tests__/storage.test.ts +++ b/packages/core/src/__tests__/storage.test.ts @@ -60,7 +60,7 @@ describe("StorageManager", () => { expect(openDB).toHaveBeenCalledWith( "cluesive_tracking", 1, - expect.any(Object) + expect.any(Object), ); }); @@ -84,7 +84,7 @@ describe("StorageManager", () => { it("should store events successfully", async () => { mockObjectStore.add.mockResolvedValue(undefined); await expect( - storageManager.storePendingEvents([mockEvent]) + storageManager.storePendingEvents([mockEvent]), ).resolves.toBeUndefined(); expect(mockObjectStore.add).toHaveBeenCalledWith(mockEvent); }); @@ -104,7 +104,7 @@ describe("StorageManager", () => { } await expect(rejectSpy).toHaveBeenCalledWith( - new Error("Transaction failed") + new Error("Transaction failed"), ); }); }); @@ -125,7 +125,7 @@ describe("StorageManager", () => { it("should handle errors when retrieving events", async () => { mockObjectStore.getAll.mockRejectedValue(new Error("Read error")); await expect(storageManager.getPendingEvents()).rejects.toThrow( - "Read error" + "Read error", ); }); }); @@ -138,7 +138,7 @@ describe("StorageManager", () => { it("should clear specified events", async () => { mockObjectStore.delete.mockResolvedValue(undefined); await expect( - storageManager.clearPendingEvents([mockEvent]) + storageManager.clearPendingEvents([mockEvent]), ).resolves.toBeUndefined(); expect(mockObjectStore.delete).toHaveBeenCalledWith([ mockEvent.id, @@ -161,7 +161,7 @@ describe("StorageManager", () => { } await expect(rejectSpy).toHaveBeenCalledWith( - new Error("Transaction failed") + new Error("Transaction failed"), ); }); }); diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 8656f9f..780f64e 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -50,7 +50,7 @@ export class Cluesive { window.removeEventListener("offline", this.handleOffline); document.removeEventListener( "visibilitychange", - this.handleVisibilityChange + this.handleVisibilityChange, ); } @@ -107,7 +107,7 @@ export class Cluesive { dispatcher: EventDispatcher; name?: string; }) => Tracker, - options: { name?: string } = {} + options: { name?: string } = {}, ): this { const tracker = new TrackerConstructor({ ...options, @@ -130,7 +130,7 @@ export class Cluesive { } private async applyMiddlewares( - events: TrackingEvent[] + events: TrackingEvent[], ): Promise { let processedEvents = [...events]; @@ -157,11 +157,11 @@ export class Cluesive { if (processedEvents.length === 0) { return true; } - + const retryAttempts = this.options.retryAttempts ?? 3; const retryDelay = this.options.retryDelay ?? 1000; let attempt = 0; - + while (attempt < retryAttempts) { try { const response = await fetch(this.options.endpoint, { @@ -173,7 +173,7 @@ export class Cluesive { body: JSON.stringify({ events: processedEvents }), keepalive: document.visibilityState === "hidden", }); - + if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } @@ -214,7 +214,7 @@ export class Cluesive { this.logger.warn( `Event size (${firstEventSize.toFixed(2)}KB) exceeds batch limit (${ this.maxBatchSizeInKB - }KB). Processing anyway.` + }KB). Processing anyway.`, ); return [events[0]]; } @@ -249,7 +249,7 @@ export class Cluesive { this.events.push(enrichedEvent); this.logger.info( "Event added to memory queue. Queue size:", - this.events.length + this.events.length, ); this.logger.groupEnd(); } diff --git a/packages/core/src/logger.ts b/packages/core/src/logger.ts index 86cb2be..a9122e7 100644 --- a/packages/core/src/logger.ts +++ b/packages/core/src/logger.ts @@ -2,32 +2,32 @@ export class Logger { private isDebug: boolean; private prefix: string; - constructor(isDebug: boolean = false, prefix: string = '[cluesive]') { + constructor(isDebug: boolean = false, prefix: string = "[cluesive]") { this.isDebug = isDebug; this.prefix = prefix; } debug(...args: unknown[]): void { if (this.isDebug) { - console.debug(this.prefix, '🔍', ...args); + console.debug(this.prefix, "🔍", ...args); } } info(...args: unknown[]): void { if (this.isDebug) { - console.info(this.prefix, 'ℹī¸', ...args); + console.info(this.prefix, "ℹī¸", ...args); } } warn(...args: unknown[]): void { if (this.isDebug) { - console.warn(this.prefix, '⚠ī¸', ...args); + console.warn(this.prefix, "⚠ī¸", ...args); } } error(...args: unknown[]): void { // Always log errors, even in non-debug mode - console.error(this.prefix, '❌', ...args); + console.error(this.prefix, "❌", ...args); } group(label: string): void { @@ -41,4 +41,4 @@ export class Logger { console.groupEnd(); } } -} \ No newline at end of file +} diff --git a/packages/core/src/storage.ts b/packages/core/src/storage.ts index dd81d7d..94d37bd 100644 --- a/packages/core/src/storage.ts +++ b/packages/core/src/storage.ts @@ -63,7 +63,7 @@ export class StorageManager { if (attempt < 3) { setTimeout( () => retryOperation(attempt + 1), - Math.pow(2, attempt) * 1000 + Math.pow(2, attempt) * 1000, ); } else { reject(error); @@ -117,7 +117,7 @@ export class StorageManager { if (attempt < 3) { setTimeout( () => retryOperation(attempt + 1), - Math.pow(2, attempt) * 1000 + Math.pow(2, attempt) * 1000, ); } else { reject(error); diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 22e177d..40e1b27 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -11,12 +11,12 @@ export type TrackingEvent = z.infer; export type BatchSize = number | "disabled"; export type EventMiddleware = ( - events: TrackingEvent[] + events: TrackingEvent[], ) => TrackingEvent[] | Promise; export type SuccessHandler = (events: TrackingEvent[]) => void | Promise; export type ErrorHandler = ( error: Error, - events: TrackingEvent[] + events: TrackingEvent[], ) => void | Promise; export interface TrackerOptions { diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 96a27d9..9536a0f 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -1,3 +1,3 @@ { - "extends": "../../tsconfig.base.json", + "extends": "../../tsconfig.base.json" } diff --git a/packages/core/vitest.config.ts b/packages/core/vitest.config.ts index 9de6171..15c277b 100644 --- a/packages/core/vitest.config.ts +++ b/packages/core/vitest.config.ts @@ -1,15 +1,20 @@ -import { defineConfig } from 'vitest/config'; +import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - environment: 'happy-dom', + environment: "happy-dom", coverage: { - provider: 'v8', - reporter: ['text', 'json', 'html'], - exclude: ['**/node_modules/**', '**/dist/**', '**/coverage/**', '**/*.config.*'] + provider: "v8", + reporter: ["text", "json", "html"], + exclude: [ + "**/node_modules/**", + "**/dist/**", + "**/coverage/**", + "**/*.config.*", + ], }, globals: true, passWithNoTests: true, - setupFiles: ['../../vitest.setup.ts'] - } -}); \ No newline at end of file + setupFiles: ["../../vitest.setup.ts"], + }, +}); diff --git a/packages/trackers/click-tracker/src/index.ts b/packages/trackers/click-tracker/src/index.ts index 486725e..f87057f 100644 --- a/packages/trackers/click-tracker/src/index.ts +++ b/packages/trackers/click-tracker/src/index.ts @@ -43,7 +43,7 @@ export class ClickTracker implements Tracker { const trackId = element.getAttribute("data-cv-id"); const universalContextAttribute = element.getAttribute("data-cv-context"); const localContextAttr = element.getAttribute( - `data-cv-${this.name}-context` + `data-cv-${this.name}-context`, ); let context: Record = {}; diff --git a/tsconfig.base.json b/tsconfig.base.json index 5a6dc1d..d2f8895 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -16,6 +16,6 @@ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, - "noFallthroughCasesInSwitch": true, + "noFallthroughCasesInSwitch": true } } diff --git a/tsconfig.json b/tsconfig.json index bc98565..a7e8f5a 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,6 @@ "files": [], "references": [ { "path": "packages/core" }, - { "path": "packages/trackers/click-tracker" }, + { "path": "packages/trackers/click-tracker" } ] } diff --git a/turbo.json b/turbo.json index 675c0e0..22daf97 100644 --- a/turbo.json +++ b/turbo.json @@ -11,8 +11,13 @@ "outputs": [] }, "lint": { - "inputs": ["packages/**", "eslint.config.js", "tsconfig.base.json", "tsconfig.json"], + "inputs": [ + "packages/**", + "eslint.config.js", + "tsconfig.base.json", + "tsconfig.json" + ], "outputs": [] } } -} \ No newline at end of file +} diff --git a/vitest.config.ts b/vitest.config.ts index c3d23fd..7acf1dc 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,22 +1,27 @@ -import { defineConfig } from 'vitest/config'; +import { defineConfig } from "vitest/config"; export default defineConfig({ test: { - environment: 'happy-dom', + environment: "happy-dom", coverage: { - provider: 'v8', - reporter: ['text', 'json', 'html'], - exclude: ['**/node_modules/**', '**/dist/**', '**/coverage/**', '**/*.config.*'] + provider: "v8", + reporter: ["text", "json", "html"], + exclude: [ + "**/node_modules/**", + "**/dist/**", + "**/coverage/**", + "**/*.config.*", + ], }, globals: true, - setupFiles: ['./vitest.setup.ts'], + setupFiles: ["./vitest.setup.ts"], passWithNoTests: true, }, resolve: { alias: { - '@cluesive/core': '/packages/core/src', - '@cluesive/click-tracker': '/packages/trackers/click-tracker/src', - '@cluesive/utils': '/packages/utils/src' - } + "@cluesive/core": "/packages/core/src", + "@cluesive/click-tracker": "/packages/trackers/click-tracker/src", + "@cluesive/utils": "/packages/utils/src", + }, }, -}); \ No newline at end of file +}); diff --git a/vitest.setup.ts b/vitest.setup.ts index 2ba7421..3461493 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -1,15 +1,15 @@ -import { vi } from 'vitest'; +import { vi } from "vitest"; // Mock window methods that aren't in happy-dom -Object.defineProperty(window, 'clearTimeout', { - value: vi.fn() +Object.defineProperty(window, "clearTimeout", { + value: vi.fn(), }); -Object.defineProperty(window, 'setTimeout', { - value: vi.fn() +Object.defineProperty(window, "setTimeout", { + value: vi.fn(), }); // Mock crypto.randomUUID -Object.defineProperty(window.crypto, 'randomUUID', { - value: () => '12345678-1234-1234-1234-123456789012' -}); \ No newline at end of file +Object.defineProperty(window.crypto, "randomUUID", { + value: () => "12345678-1234-1234-1234-123456789012", +}); diff --git a/vitest.workspace.ts b/vitest.workspace.ts index f2c1bfe..6de0c20 100644 --- a/vitest.workspace.ts +++ b/vitest.workspace.ts @@ -1,8 +1,8 @@ -import { defineWorkspace } from 'vitest/config' +import { defineWorkspace } from "vitest/config"; export default defineWorkspace([ "./vitest.config.ts", "./examples/react/vite.config.ts", "./packages/trackers/click-tracker/vitest.config.ts", - "./packages/core/vitest.config.ts" -]) + "./packages/core/vitest.config.ts", +]); From f80d5d55c14349e3cc81b640a5347e2bcb35a135 Mon Sep 17 00:00:00 2001 From: Kavian77 Date: Thu, 26 Dec 2024 19:24:56 +0100 Subject: [PATCH 2/3] Setup husky to run tsc, eslint, and prettier on staged files before commit --- .github/workflows/ci.yml | 3 + .husky/pre-commit | 2 + package-lock.json | 502 ++++++++++++++++++- package.json | 11 +- packages/core/package.json | 3 +- packages/trackers/click-tracker/package.json | 3 +- turbo.json | 11 +- 7 files changed, 525 insertions(+), 10 deletions(-) create mode 100644 .husky/pre-commit diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f45d27e..133b34a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -39,5 +39,8 @@ jobs: - name: Lint run: npm run lint + - name: Check types + run: npm run check-types + - name: Check formatting run: npm run check-formatting diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100644 index 0000000..03a05dc --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,2 @@ +npm run check-types +lint-staged \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 8e7258c..4bd6e3a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,8 @@ "eslint-plugin-prettier": "^5.2.1", "globals": "^15.9.0", "happy-dom": "^15.11.7", + "husky": "^9.1.7", + "lint-staged": "^15.2.11", "prettier": "3.4.2", "tsup": "^8.3.5", "turbo": "^1.12.5", @@ -1051,6 +1053,22 @@ "url": "https://github.com/sponsors/epoberezkin" } }, + "node_modules/ansi-escapes": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-7.0.0.tgz", + "integrity": "sha512-GdYO7a61mR0fOlAsvC9/rIHf7L96sBc6dEWzeOu+KAea5bZyQRPIpojrVoI4AXGJS/ycu/fBTdLrUkA4ODrvjw==", + "dev": true, + "license": "MIT", + "dependencies": { + "environment": "^1.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/ansi-regex": { "version": "6.1.0", "dev": true, @@ -1292,6 +1310,64 @@ "url": "https://paulmillr.com/funding/" } }, + "node_modules/cli-cursor": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-5.0.0.tgz", + "integrity": "sha512-aCj4O5wKyszjMmDT4tZj93kxyydN/K5zPWSCe6/0AV/AA1pqe5ZBIw0a2ZfPQV7lL5/yb5HsUreJ6UFAF1tEQw==", + "dev": true, + "license": "MIT", + "dependencies": { + "restore-cursor": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-truncate": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cli-truncate/-/cli-truncate-4.0.0.tgz", + "integrity": "sha512-nPdaFdQ0h/GEigbPClz11D0v/ZJEwxmeVZGeMo3Z5StPtUTkA9o1lD6QwoirYiSDzbcwn2XcjwmCp68W1IS4TA==", + "dev": true, + "license": "MIT", + "dependencies": { + "slice-ansi": "^5.0.0", + "string-width": "^7.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-truncate/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", + "dev": true, + "license": "MIT" + }, + "node_modules/cli-truncate/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/color-convert": { "version": "2.0.1", "dev": true, @@ -1308,6 +1384,13 @@ "dev": true, "license": "MIT" }, + "node_modules/colorette": { + "version": "2.0.20", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-2.0.20.tgz", + "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", + "dev": true, + "license": "MIT" + }, "node_modules/commander": { "version": "4.1.1", "dev": true, @@ -1348,7 +1431,9 @@ } }, "node_modules/debug": { - "version": "4.3.7", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "dev": true, "license": "MIT", "dependencies": { @@ -1413,6 +1498,19 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, + "node_modules/environment": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/environment/-/environment-1.1.0.tgz", + "integrity": "sha512-xUtoPkMggbz0MPyPiIWr1Kp4aeWJjDZ6SMvURhimjdZgsRuDplF5/s9hcgGhyXMhs+6vpnuoiZ2kFiu3FMnS8Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/esbuild": { "version": "0.21.5", "dev": true, @@ -1670,6 +1768,13 @@ "node": ">=0.10.0" } }, + "node_modules/eventemitter3": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.1.tgz", + "integrity": "sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==", + "dev": true, + "license": "MIT" + }, "node_modules/execa": { "version": "8.0.1", "dev": true, @@ -1846,6 +1951,19 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/get-east-asian-width": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-east-asian-width/-/get-east-asian-width-1.3.0.tgz", + "integrity": "sha512-vpeMIQKxczTD/0s2CdEWHcb0eeJe6TFjxb+J5xgX7hScxqrGuyjmv4c1D4A/gelKfyox0gJJwIHF+fLjeaM8kQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/get-func-name": { "version": "2.0.2", "dev": true, @@ -1969,6 +2087,22 @@ "node": ">=16.17.0" } }, + "node_modules/husky": { + "version": "9.1.7", + "resolved": "https://registry.npmjs.org/husky/-/husky-9.1.7.tgz", + "integrity": "sha512-5gs5ytaNjBrh5Ow3zrvdUUY+0VxIuWVL4i9irt6friV+BqdCfmV11CQTWMiBYWHbXhco+J1kHfTOUkePhCDvMA==", + "dev": true, + "license": "MIT", + "bin": { + "husky": "bin.js" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/typicode" + } + }, "node_modules/idb": { "version": "8.0.0", "license": "ISC" @@ -2209,6 +2343,131 @@ "dev": true, "license": "MIT" }, + "node_modules/lint-staged": { + "version": "15.2.11", + "resolved": "https://registry.npmjs.org/lint-staged/-/lint-staged-15.2.11.tgz", + "integrity": "sha512-Ev6ivCTYRTGs9ychvpVw35m/bcNDuBN+mnTeObCL5h+boS5WzBEC6LHI4I9F/++sZm1m+J2LEiy0gxL/R9TBqQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "chalk": "~5.3.0", + "commander": "~12.1.0", + "debug": "~4.4.0", + "execa": "~8.0.1", + "lilconfig": "~3.1.3", + "listr2": "~8.2.5", + "micromatch": "~4.0.8", + "pidtree": "~0.6.0", + "string-argv": "~0.3.2", + "yaml": "~2.6.1" + }, + "bin": { + "lint-staged": "bin/lint-staged.js" + }, + "engines": { + "node": ">=18.12.0" + }, + "funding": { + "url": "https://opencollective.com/lint-staged" + } + }, + "node_modules/lint-staged/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/lint-staged/node_modules/commander": { + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, + "node_modules/listr2": { + "version": "8.2.5", + "resolved": "https://registry.npmjs.org/listr2/-/listr2-8.2.5.tgz", + "integrity": "sha512-iyAZCeyD+c1gPyE9qpFu8af0Y+MRtmKOncdGoA2S5EY8iFq99dmmvkNnHiWo+pj0s7yH7l3KPIgee77tKpXPWQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "cli-truncate": "^4.0.0", + "colorette": "^2.0.20", + "eventemitter3": "^5.0.1", + "log-update": "^6.1.0", + "rfdc": "^1.4.1", + "wrap-ansi": "^9.0.0" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/listr2/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/listr2/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", + "dev": true, + "license": "MIT" + }, + "node_modules/listr2/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/listr2/node_modules/wrap-ansi": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz", + "integrity": "sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.2.1", + "string-width": "^7.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/load-tsconfig": { "version": "0.2.5", "dev": true, @@ -2256,6 +2515,115 @@ "dev": true, "license": "MIT" }, + "node_modules/log-update": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/log-update/-/log-update-6.1.0.tgz", + "integrity": "sha512-9ie8ItPR6tjY5uYJh8K/Zrv/RMZ5VOlOWvtZdEHYSTFKZfIBPQa9tOAEeAWhd+AnIneLJ22w5fjOYtoutpWq5w==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-escapes": "^7.0.0", + "cli-cursor": "^5.0.0", + "slice-ansi": "^7.1.0", + "strip-ansi": "^7.1.0", + "wrap-ansi": "^9.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-update/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/log-update/node_modules/emoji-regex": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.4.0.tgz", + "integrity": "sha512-EC+0oUMY1Rqm4O6LLrgjtYDvcVYTy7chDnM4Q7030tP4Kwj3u/pR6gP9ygnp2CJMK5Gq+9Q2oqmrFJAz01DXjw==", + "dev": true, + "license": "MIT" + }, + "node_modules/log-update/node_modules/is-fullwidth-code-point": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-5.0.0.tgz", + "integrity": "sha512-OVa3u9kkBbw7b8Xw5F9P+D/T9X+Z4+JruYVNapTjPYZYUznQ5YfWeFkOj606XYYW8yugTfC8Pj0hYqvi4ryAhA==", + "dev": true, + "license": "MIT", + "dependencies": { + "get-east-asian-width": "^1.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-update/node_modules/slice-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-7.1.0.tgz", + "integrity": "sha512-bSiSngZ/jWeX93BqeIAbImyTbEihizcwNjFoRUIY/T1wWQsfsm2Vw1agPKylXvQTU7iASGdHhyqRlqQzfz+Htg==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.2.1", + "is-fullwidth-code-point": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/chalk/slice-ansi?sponsor=1" + } + }, + "node_modules/log-update/node_modules/string-width": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-7.2.0.tgz", + "integrity": "sha512-tsaTIkKW9b4N+AEj+SVA+WhJzV7/zMhcSu78mLKWSk7cXMOSHsBKFWUs0fWwq8QyK3MgJBQRX6Gbi4kYbdvGkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "emoji-regex": "^10.3.0", + "get-east-asian-width": "^1.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/log-update/node_modules/wrap-ansi": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-9.0.0.tgz", + "integrity": "sha512-G8ura3S+3Z2G+mkgNRq8dqaFZAuxfsxpBB8OCTGRTCtp+l/v9nbFNmCUP1BZMts3G1142MsZfn6eeUKrr4PD1Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.2.1", + "string-width": "^7.0.0", + "strip-ansi": "^7.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/loupe": { "version": "2.3.7", "dev": true, @@ -2337,6 +2705,19 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/mimic-function": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/mimic-function/-/mimic-function-5.0.1.tgz", + "integrity": "sha512-VP79XUPxV2CigYP3jWwAUFSku2aKqBH7uTAapFWCBqutsbmDo96KY5o8uh6U+/YSIn5OxJnXp73beVkpqMIGhA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/minimatch": { "version": "3.1.2", "dev": true, @@ -2602,6 +2983,19 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pidtree": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/pidtree/-/pidtree-0.6.0.tgz", + "integrity": "sha512-eG2dWTVw5bzqGRztnHExczNxt5VGsE6OwTeCG3fdUf9KBsZzO3R5OIIIzWR+iZA0NtZ+RDVdaoE2dK1cn6jH4g==", + "dev": true, + "license": "MIT", + "bin": { + "pidtree": "bin/pidtree.js" + }, + "engines": { + "node": ">=0.10" + } + }, "node_modules/pirates": { "version": "4.0.6", "dev": true, @@ -2806,6 +3200,39 @@ "node": ">=4" } }, + "node_modules/restore-cursor": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-5.1.0.tgz", + "integrity": "sha512-oMA2dcrw6u0YfxJQXm342bFKX/E4sG9rbTzO9ptUcR/e8A33cHuvStiYOwH7fszkZlZ1z/ta9AAoPk2F4qIOHA==", + "dev": true, + "license": "MIT", + "dependencies": { + "onetime": "^7.0.0", + "signal-exit": "^4.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/restore-cursor/node_modules/onetime": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-7.0.0.tgz", + "integrity": "sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "mimic-function": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/reusify": { "version": "1.0.4", "dev": true, @@ -2815,6 +3242,13 @@ "node": ">=0.10.0" } }, + "node_modules/rfdc": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "dev": true, + "license": "MIT" + }, "node_modules/rollup": { "version": "4.24.3", "dev": true, @@ -2933,6 +3367,49 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/slice-ansi": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-5.0.0.tgz", + "integrity": "sha512-FC+lgizVPfie0kkhqUScwRu1O/lF6NOgJmlCgK+/LYxDCTk8sGelYaHDhFcDN+Sn3Cv+3VSa4Byeo+IMCzpMgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^6.0.0", + "is-fullwidth-code-point": "^4.0.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/slice-ansi?sponsor=1" + } + }, + "node_modules/slice-ansi/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/slice-ansi/node_modules/is-fullwidth-code-point": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-4.0.0.tgz", + "integrity": "sha512-O4L094N2/dZ7xqVdrXhh9r1KODPJpFms8B5sGdJLPy664AgvXsreZUyCQQNItZRDlYug4xStLjNp/sz3HvBowQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/source-map": { "version": "0.8.0-beta.0", "dev": true, @@ -2962,6 +3439,16 @@ "dev": true, "license": "MIT" }, + "node_modules/string-argv": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.2.tgz", + "integrity": "sha512-aqD2Q0144Z+/RqG52NeHEkZauTAUWJO8c6yTftGJKO3Tja5tUgIfmIl6kExvhtxSDP7fXB6DvzkfMpCd/F3G+Q==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.6.19" + } + }, "node_modules/string-width": { "version": "5.1.2", "dev": true, @@ -3918,6 +4405,19 @@ "dev": true, "license": "ISC" }, + "node_modules/yaml": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.6.1.tgz", + "integrity": "sha512-7r0XPzioN/Q9kXBro/XPnA6kznR73DHq+GXh5ON7ZozRO6aMjbmiBuKste2wslTFkC5d1dw0GooOCepZXJ2SAg==", + "dev": true, + "license": "ISC", + "bin": { + "yaml": "bin.mjs" + }, + "engines": { + "node": ">= 14" + } + }, "node_modules/yocto-queue": { "version": "0.1.0", "dev": true, diff --git a/package.json b/package.json index c3e9e7b..f83163f 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,9 @@ "build": "turbo run build", "lint": "turbo run lint", "test": "turbo run test", + "check-types": "turbo run check-types", "check-formatting": "prettier . --check", - "format": "prettier . --write" + "prepare": "husky" }, "devDependencies": { "@eslint/js": "^9.9.1", @@ -24,6 +25,8 @@ "eslint-plugin-prettier": "^5.2.1", "globals": "^15.9.0", "happy-dom": "^15.11.7", + "husky": "^9.1.7", + "lint-staged": "^15.2.11", "prettier": "3.4.2", "tsup": "^8.3.5", "turbo": "^1.12.5", @@ -34,5 +37,11 @@ }, "optionalDependencies": { "@rollup/rollup-linux-x64-gnu": "^4.29.1" + }, + "lint-staged": { + "*.{js,ts,tsx}": [ + "eslint --fix", + "prettier --write" + ] } } diff --git a/packages/core/package.json b/packages/core/package.json index 778bfe1..b3cb031 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -6,7 +6,8 @@ "types": "./dist/index.d.ts", "scripts": { "build": "tsup src/index.ts --format cjs,esm --dts --out-dir dist", - "lint": "tsc && eslint .", + "lint": "eslint .", + "check-types": "tsc --project tsconfig.json", "test": "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage" diff --git a/packages/trackers/click-tracker/package.json b/packages/trackers/click-tracker/package.json index 80e9390..9f9b23c 100644 --- a/packages/trackers/click-tracker/package.json +++ b/packages/trackers/click-tracker/package.json @@ -6,7 +6,8 @@ "types": "./dist/index.d.ts", "scripts": { "build": "tsup src/index.ts --format cjs,esm --dts --out-dir dist", - "lint": "tsc && eslint .", + "lint": "eslint .", + "check-types": "tsc --project tsconfig.json", "test": "vitest run", "test:watch": "vitest", "test:coverage": "vitest run --coverage" diff --git a/turbo.json b/turbo.json index 22daf97..44bcf16 100644 --- a/turbo.json +++ b/turbo.json @@ -10,13 +10,12 @@ "dependsOn": ["^build"], "outputs": [] }, + "check-types": { + "inputs": ["packages/**", "tsconfig.base.json", "tsconfig.json"], + "outputs": [] + }, "lint": { - "inputs": [ - "packages/**", - "eslint.config.js", - "tsconfig.base.json", - "tsconfig.json" - ], + "inputs": ["packages/**", "eslint.config.js"], "outputs": [] } } From 63a919f0032c9484265180f2190106ae4cdb9c2b Mon Sep 17 00:00:00 2001 From: Kavian77 Date: Thu, 26 Dec 2024 20:34:03 +0100 Subject: [PATCH 3/3] Instruct ESLint to ignore all dist folders, even those that are nested --- eslint.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eslint.config.js b/eslint.config.js index 94f3ad7..7925591 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -5,7 +5,7 @@ import noOnlyTestsPlugin from "eslint-plugin-no-only-tests"; import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"; export default tseslint.config( - { ignores: ["dist"] }, + { ignores: ["**/dist"] }, { extends: [ js.configs.recommended,