From 3ddab9dc8f09ca390aa20d8d9217dcc783281c3e Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sat, 1 Jun 2024 13:21:53 +0800 Subject: [PATCH] Clean build configuration (#195) --- .github/workflows/demo.yml | 4 ++-- collector.ts | 2 +- demo/vite.config.ts | 4 ++++ global.d.ts | 8 +------- package.json | 16 ++++++++-------- tsconfig.json | 9 ++------- vite.config.ts | 5 +++-- 7 files changed, 21 insertions(+), 27 deletions(-) diff --git a/.github/workflows/demo.yml b/.github/workflows/demo.yml index d2aebf6..0c72c66 100644 --- a/.github/workflows/demo.yml +++ b/.github/workflows/demo.yml @@ -17,8 +17,8 @@ jobs: steps: - uses: actions/checkout@v3 - run: npm ci - - run: npm run demo:build - - run: npm run demo:test + - run: npm run build:demo + - run: npm run test:demo - run: grep -rq "/fregante/" ./demo/dist # https://github.com/refined-github/github-url-detection/pull/161 name: Ensure that the demo is built correctly diff --git a/collector.ts b/collector.ts index 4721180..c66cd7f 100644 --- a/collector.ts +++ b/collector.ts @@ -3,7 +3,7 @@ export const testableUrls = new Map(); export function addTests(test: string, urls: string[]): void { - if (import.meta.env.VITE_KEEP_URLS === '1') { + if (import.meta.vitest) { testableUrls.set(test, urls); } } diff --git a/demo/vite.config.ts b/demo/vite.config.ts index f5192f4..a771c26 100644 --- a/demo/vite.config.ts +++ b/demo/vite.config.ts @@ -16,4 +16,8 @@ export default defineConfig({ }, }, }, + define: { + // eslint-disable-next-line @typescript-eslint/naming-convention -- no. + 'import.meta.vitest': '"no vitest here, but I need the URLs"', + }, }); diff --git a/global.d.ts b/global.d.ts index 64b043c..fafe0d5 100644 --- a/global.d.ts +++ b/global.d.ts @@ -1,13 +1,7 @@ /* eslint-disable @typescript-eslint/consistent-type-definitions -- Module augmentation */ -/// - -interface ImportMetaEnv { - readonly VITE_KEEP_URLS: string; -} - interface ImportMeta { - readonly env: ImportMetaEnv; + readonly vitest: unknown; } // Broaden types because testing against `"undefined"` is fine for our regexes diff --git a/package.json b/package.json index d260fe6..b8ec8ae 100644 --- a/package.json +++ b/package.json @@ -27,15 +27,15 @@ "build": "run-p build:*", "build:vite": "vite build", "build:typescript": "tsc --declaration --emitDeclarationOnly", - "demo:build": "VITE_KEEP_URLS=1 vite build demo", - "demo:test": "svelte-check", - "demo:watch": "vite preview demo & npm run demo:build -- --watch # vite serve isn't real", + "build:demo": "vite build demo", "prepack": "npm run build", - "test": "run-p build test:unit xo", - "test:unit": "VITE_KEEP_URLS=1 vitest", - "watch": "run-p watch:typescript demo:watch # vite watch doesn’t generate the lib, so just use the demo", - "watch:typescript": "tsc --watch", - "watch:test:unit": "run-p 'test:unit -- --watch' 'watch:typescript -- --watch'", + "test": "run-p build test:* xo", + "test:unit": "vitest", + "test:demo": "svelte-check", + "watch": "run-p watch:*", + "watch:typescript": "tsc --watch --noEmit", + "watch:test:unit": "npm run test:unit -- --watch", + "watch:demo": "vite preview demo & npm run build:demo -- --watch # vite serve isn't real", "xo": "xo" }, "xo": { diff --git a/tsconfig.json b/tsconfig.json index 4c475a7..e78f13f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,15 +1,10 @@ { "extends": "@sindresorhus/tsconfig", "compilerOptions": { - "outDir": "distribution", "resolveJsonModule": true, - "target": "ES2022", "module": "NodeNext", - "lib": [ - "DOM", - "DOM.Iterable", - "ES2022" - ], + "moduleResolution": "NodeNext", + "outDir": "distribution" }, "include": [ "index.ts", diff --git a/vite.config.ts b/vite.config.ts index a4e08d7..8898504 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,8 +1,6 @@ import process from 'node:process'; import {defineConfig} from 'vite'; -process.env.VITE_KEEP_URLS ??= '0'; - export default defineConfig({ build: { lib: { @@ -14,4 +12,7 @@ export default defineConfig({ outDir: 'distribution', minify: false, }, + define: { + 'import.meta.vitest': 'undefined', + }, });