Skip to content

Commit 3ddab9d

Browse files
authored
Clean build configuration (#195)
1 parent d48ae89 commit 3ddab9d

File tree

7 files changed

+21
-27
lines changed

7 files changed

+21
-27
lines changed

.github/workflows/demo.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ jobs:
1717
steps:
1818
- uses: actions/checkout@v3
1919
- run: npm ci
20-
- run: npm run demo:build
21-
- run: npm run demo:test
20+
- run: npm run build:demo
21+
- run: npm run test:demo
2222
- run: grep -rq "/fregante/" ./demo/dist
2323
# https://github.com/refined-github/github-url-detection/pull/161
2424
name: Ensure that the demo is built correctly

collector.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
export const testableUrls = new Map<string, string[]>();
44

55
export function addTests(test: string, urls: string[]): void {
6-
if (import.meta.env.VITE_KEEP_URLS === '1') {
6+
if (import.meta.vitest) {
77
testableUrls.set(test, urls);
88
}
99
}

demo/vite.config.ts

+4
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ export default defineConfig({
1616
},
1717
},
1818
},
19+
define: {
20+
// eslint-disable-next-line @typescript-eslint/naming-convention -- no.
21+
'import.meta.vitest': '"no vitest here, but I need the URLs"',
22+
},
1923
});

global.d.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
/* eslint-disable @typescript-eslint/consistent-type-definitions -- Module augmentation */
22

3-
/// <reference types="vite/client" />
4-
5-
interface ImportMetaEnv {
6-
readonly VITE_KEEP_URLS: string;
7-
}
8-
93
interface ImportMeta {
10-
readonly env: ImportMetaEnv;
4+
readonly vitest: unknown;
115
}
126

137
// Broaden types because testing against `"undefined"` is fine for our regexes

package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@
2727
"build": "run-p build:*",
2828
"build:vite": "vite build",
2929
"build:typescript": "tsc --declaration --emitDeclarationOnly",
30-
"demo:build": "VITE_KEEP_URLS=1 vite build demo",
31-
"demo:test": "svelte-check",
32-
"demo:watch": "vite preview demo & npm run demo:build -- --watch # vite serve isn't real",
30+
"build:demo": "vite build demo",
3331
"prepack": "npm run build",
34-
"test": "run-p build test:unit xo",
35-
"test:unit": "VITE_KEEP_URLS=1 vitest",
36-
"watch": "run-p watch:typescript demo:watch # vite watch doesn’t generate the lib, so just use the demo",
37-
"watch:typescript": "tsc --watch",
38-
"watch:test:unit": "run-p 'test:unit -- --watch' 'watch:typescript -- --watch'",
32+
"test": "run-p build test:* xo",
33+
"test:unit": "vitest",
34+
"test:demo": "svelte-check",
35+
"watch": "run-p watch:*",
36+
"watch:typescript": "tsc --watch --noEmit",
37+
"watch:test:unit": "npm run test:unit -- --watch",
38+
"watch:demo": "vite preview demo & npm run build:demo -- --watch # vite serve isn't real",
3939
"xo": "xo"
4040
},
4141
"xo": {

tsconfig.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
{
22
"extends": "@sindresorhus/tsconfig",
33
"compilerOptions": {
4-
"outDir": "distribution",
54
"resolveJsonModule": true,
6-
"target": "ES2022",
75
"module": "NodeNext",
8-
"lib": [
9-
"DOM",
10-
"DOM.Iterable",
11-
"ES2022"
12-
],
6+
"moduleResolution": "NodeNext",
7+
"outDir": "distribution"
138
},
149
"include": [
1510
"index.ts",

vite.config.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import process from 'node:process';
22
import {defineConfig} from 'vite';
33

4-
process.env.VITE_KEEP_URLS ??= '0';
5-
64
export default defineConfig({
75
build: {
86
lib: {
@@ -14,4 +12,7 @@ export default defineConfig({
1412
outDir: 'distribution',
1513
minify: false,
1614
},
15+
define: {
16+
'import.meta.vitest': 'undefined',
17+
},
1718
});

0 commit comments

Comments
 (0)