Skip to content

Commit 1d9e93f

Browse files
authored
Replace Rollup build with Vite (#129)
1 parent c8f4447 commit 1d9e93f

File tree

11 files changed

+177
-415
lines changed

11 files changed

+177
-415
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ jobs:
4444
run: npm ci || npm install
4545
- name: build
4646
run: npm run build
47+
- name: Ensure that test URLs aren't included in the built file
48+
run: ! grep http distribution/index.js

collector.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
1-
// This needs to be in a separate file so it can bee tree-shaken before being published, while still being importable by tests
2-
export default new Map<string, string[] | 'combinedTestOnly'>();
1+
/** @file This needs to be in a separate file so it can bee tree-shaken before being published, while still being importable by tests */
2+
3+
const testableUrls = new Map<string, string[]>();
4+
5+
export function addTests(test: string, urls: string[]): void {
6+
// @ts-expect-error KISS for Vite
7+
if (process.env.NODE_ENV !== 'bundling') {
8+
testableUrls.set(test, urls);
9+
}
10+
}
11+
12+
export function getTests(detectName: string): string[] {
13+
if (detectName === 'combinedTestOnly') {
14+
return ['combinedTestOnly'];
15+
}
16+
17+
return testableUrls.get(detectName)?.flatMap(url => url.startsWith('http') ? url : getTests(url) ?? []) ?? [];
18+
}
19+
20+
export function getAllUrls(): Set<string> {
21+
return new Set<string>([...testableUrls.values()].flat().filter(url => url.startsWith('http')));
22+
}

demo/App.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
const defaultUrl = 'https://github.com/refined-github/github-url-detection';
33
export let url = '';
44
import * as urlDetection from '../index';
5-
import collector from '../collector';
5+
import { getAllUrls } from '../collector';
66
7-
const allUrls = new Set([...collector.values()].flat().sort());
8-
allUrls.delete('combinedTestOnly');
7+
const allUrls = [...getAllUrls()].sort();
98
109
let isUrlValid;
1110
$: {

demo/vite.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {defineConfig} from 'vite';
2+
import {svelte} from '@sveltejs/vite-plugin-svelte';
3+
4+
// https://vitejs.dev/config/
5+
export default defineConfig({
6+
base: '',
7+
plugins: [svelte()],
8+
});

index.ts

Lines changed: 94 additions & 94 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)