Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion collector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/** @file This needs to be in a separate file so it can bee tree-shaken before being published, while still being importable by tests */

const testableUrls = new Map<string, string[]>();
export const testableUrls = new Map<string, string[]>();

export function addTests(test: string, urls: string[]): void {
// @ts-expect-error KISS for Vite
Expand Down
30 changes: 30 additions & 0 deletions demo/Detections.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<script>
import * as urlDetection from '../index';
import { getTests } from '../collector';
</script>

<style>
pre, code {
white-space: nowrap;
}
pre a {
color: inherit;
}
</style>
{#each Object.keys(urlDetection) as name}
{#if !name.startsWith('_') && name !== 'utils'}
<h2 id={name}><a href="#{name}">{name}</a></h2>
{@const urls = getTests(name)}
{#if urls[0] === 'combinedTestOnly'}
<p><em>Demo URLs missing</em></p>
{:else if urls.length === 0}
<p><em>Undeterminable via URL</em></p>
{:else}
<pre><code>
{#each urls as url}
<a href="/?url={encodeURIComponent(url)}">{url}</a><br>
{/each}
</code></pre>
{/if}
{/if}
{/each}
9 changes: 6 additions & 3 deletions demo/App.svelte → demo/Index.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<script>

import parseUrl from './parse-url.js';
import * as urlDetection from '../index';
import { getAllUrls } from '../collector';
import { getAllUrls, testableUrls } from '../collector';

const defaultUrl = 'https://github.com/refined-github/github-url-detection';
const urlParameter = new URLSearchParams(location.search);
Expand Down Expand Up @@ -75,6 +74,10 @@
.undefined {
color: gray;
}

pre a {
color: inherit;
}
</style>

<label>
Expand All @@ -99,7 +102,7 @@
{#each detections as {name, detect, result} (name)}
{#if detect}
<div class={String(result)}>
{name}(url) // <span>{String(result)}</span></div>
<a href="/detections.html#{name}">{name}</a>(url) // <span>{String(result)}</span></div>
{:else}
<div class="undefined">
{name}() // undeterminable via URL</div>
Expand Down
26 changes: 26 additions & 0 deletions demo/detections.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link
rel="stylesheet"
href="https://unpkg.com/chota@0.7.2/dist/chota.min.css"
/>
<meta name="viewport" content="width=device-width,initial-scale=1" />

<title>`github-url-detection` detections</title>

<link rel="stylesheet" href="global.css" />
<script defer type="module" src="detections.js"></script>
</head>

<body>
<h1>
<a href="https://github.com/refined-github/github-url-detection">
refined-github/github-url-detection
</a>
</h1>
<main class="container">
</main>
</body>
</html>
7 changes: 7 additions & 0 deletions demo/detections.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Detections from './Detections.svelte';

const app = new Detections({
target: document.querySelector('main'),
});

export default app;
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<title>`github-url-detection` npm module testing ground</title>

<link rel="stylesheet" href="global.css" />
<script defer type="module" src="main.js"></script>
<script defer type="module" src="index.js"></script>
</head>

<body>
Expand Down
4 changes: 2 additions & 2 deletions demo/main.js → demo/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import App from './App.svelte';
import Index from './Index.svelte';

const app = new App({
const app = new Index({
target: document.querySelector('main'),
});

Expand Down
12 changes: 12 additions & 0 deletions demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import {resolve} from 'node:path';
import * as url from 'node:url';
import {defineConfig} from 'vite';
import {svelte} from '@sveltejs/vite-plugin-svelte';

const __dirname = url.fileURLToPath(new URL('.', import.meta.url));

export default defineConfig({
base: '',
plugins: [svelte()],
build: {
rollupOptions: {
input: {
main: resolve(__dirname, 'index.html'),
nested: resolve(__dirname, 'detections.html'),
},
},
},
});