Skip to content

Commit

Permalink
Clean build configuration (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante authored Jun 1, 2024
1 parent d48ae89 commit 3ddab9d
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 27 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion collector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
export const testableUrls = new Map<string, string[]>();

export function addTests(test: string, urls: string[]): void {
if (import.meta.env.VITE_KEEP_URLS === '1') {
if (import.meta.vitest) {
testableUrls.set(test, urls);
}
}
Expand Down
4 changes: 4 additions & 0 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"',
},
});
8 changes: 1 addition & 7 deletions global.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
/* eslint-disable @typescript-eslint/consistent-type-definitions -- Module augmentation */

/// <reference types="vite/client" />

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
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
9 changes: 2 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
5 changes: 3 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import process from 'node:process';
import {defineConfig} from 'vite';

process.env.VITE_KEEP_URLS ??= '0';

export default defineConfig({
build: {
lib: {
Expand All @@ -14,4 +12,7 @@ export default defineConfig({
outDir: 'distribution',
minify: false,
},
define: {
'import.meta.vitest': 'undefined',
},
});

0 comments on commit 3ddab9d

Please sign in to comment.