Compare commits
3 Commits
173b1e25f5
...
8e96a55661
Author | SHA1 | Date |
---|---|---|
Bauke | 8e96a55661 | |
Bauke | b6fb952580 | |
Bauke | ee1d72362f |
40
package.json
40
package.json
|
@ -3,6 +3,7 @@
|
||||||
"license": "AGPL-3.0-or-later",
|
"license": "AGPL-3.0-or-later",
|
||||||
"repository": "https://git.bauke.xyz/Holllo/re-nav",
|
"repository": "https://git.bauke.xyz/Holllo/re-nav",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "vite build -m development --watch",
|
"start": "vite build -m development --watch",
|
||||||
"start:chromium": "VITE_BROWSER=chromium pnpm start",
|
"start:chromium": "VITE_BROWSER=chromium pnpm start",
|
||||||
|
@ -11,7 +12,8 @@
|
||||||
"build:chromium": "VITE_BROWSER=chromium vite build && web-ext build -n re-nav-chromium-{version}.zip -s build/chromium",
|
"build:chromium": "VITE_BROWSER=chromium vite build && web-ext build -n re-nav-chromium-{version}.zip -s build/chromium",
|
||||||
"build:firefox": "VITE_BROWSER=firefox vite build && web-ext build -n re-nav-firefox-{version}.zip -s build/firefox",
|
"build:firefox": "VITE_BROWSER=firefox vite build && web-ext build -n re-nav-firefox-{version}.zip -s build/firefox",
|
||||||
"zip-source": "git archive --format zip --output web-ext-artifacts/re-nav-source.zip HEAD",
|
"zip-source": "git archive --format zip --output web-ext-artifacts/re-nav-source.zip HEAD",
|
||||||
"test": "xo && stylelint 'source/**/*.scss' && tsc"
|
"test": "xo && stylelint 'source/**/*.scss' && tsc && c8 ava",
|
||||||
|
"test:snapshots": "c8 ava --update-snapshots"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@holllo/migration-helper": "^0.1.3",
|
"@holllo/migration-helper": "^0.1.3",
|
||||||
|
@ -25,18 +27,54 @@
|
||||||
"@preact/preset-vite": "^2.4.0",
|
"@preact/preset-vite": "^2.4.0",
|
||||||
"@types/babel__core": "^7.1.19",
|
"@types/babel__core": "^7.1.19",
|
||||||
"@types/webextension-polyfill": "^0.9.1",
|
"@types/webextension-polyfill": "^0.9.1",
|
||||||
|
"ava": "^4.3.3",
|
||||||
|
"c8": "^7.12.0",
|
||||||
"postcss": "^8.4.16",
|
"postcss": "^8.4.16",
|
||||||
"sass": "^1.55.0",
|
"sass": "^1.55.0",
|
||||||
"stylelint": "^14.13.0",
|
"stylelint": "^14.13.0",
|
||||||
"stylelint-config-standard-scss": "^5.0.0",
|
"stylelint-config-standard-scss": "^5.0.0",
|
||||||
"trash-cli": "^5.0.0",
|
"trash-cli": "^5.0.0",
|
||||||
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.8.4",
|
"typescript": "^4.8.4",
|
||||||
"vite": "^3.1.4",
|
"vite": "^3.1.4",
|
||||||
"vite-plugin-web-extension": "^1.4.4",
|
"vite-plugin-web-extension": "^1.4.4",
|
||||||
"web-ext": "^7.2.0",
|
"web-ext": "^7.2.0",
|
||||||
"xo": "^0.52.3"
|
"xo": "^0.52.3"
|
||||||
},
|
},
|
||||||
|
"ava": {
|
||||||
|
"extensions": {
|
||||||
|
"ts": "module"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"tests/**/*.test.ts"
|
||||||
|
],
|
||||||
|
"nodeArguments": [
|
||||||
|
"--loader=ts-node/esm",
|
||||||
|
"--no-warnings"
|
||||||
|
],
|
||||||
|
"snapshotDir": "tests/snapshots"
|
||||||
|
},
|
||||||
|
"c8": {
|
||||||
|
"include": [
|
||||||
|
"source",
|
||||||
|
"tests"
|
||||||
|
],
|
||||||
|
"reportDir": "coverage",
|
||||||
|
"reporter": [
|
||||||
|
"text",
|
||||||
|
"html"
|
||||||
|
]
|
||||||
|
},
|
||||||
"xo": {
|
"xo": {
|
||||||
|
"overrides": [
|
||||||
|
{
|
||||||
|
"files": "tests/**/*.test.ts",
|
||||||
|
"rules": {
|
||||||
|
"@typescript-eslint/triple-slash-reference": "off",
|
||||||
|
"no-await-in-loop": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
"prettier": true,
|
"prettier": true,
|
||||||
"rules": {
|
"rules": {
|
||||||
"@typescript-eslint/consistent-type-definitions": "off",
|
"@typescript-eslint/consistent-type-definitions": "off",
|
||||||
|
|
565
pnpm-lock.yaml
565
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,9 @@
|
||||||
|
import {HostnameParameters} from './hostname.js';
|
||||||
|
|
||||||
|
export type RedirectParameters = HostnameParameters;
|
||||||
|
|
||||||
|
export abstract class Redirect<P extends RedirectParameters> {
|
||||||
|
constructor(public parameters: P) {}
|
||||||
|
|
||||||
|
public abstract redirect(url: URL | string): URL;
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
import {RedirectParameters} from './base.js';
|
||||||
|
import {HostnameRedirect} from './hostname.js';
|
||||||
|
|
||||||
|
export * from './base.js';
|
||||||
|
export * from './hostname.js';
|
||||||
|
|
||||||
|
export type Redirects = HostnameRedirect;
|
||||||
|
|
||||||
|
export function parseRedirect<P extends RedirectParameters>(
|
||||||
|
parameters: P,
|
||||||
|
): Redirects | undefined {
|
||||||
|
if (parameters.type === 'hostname') {
|
||||||
|
return new HostnameRedirect(parameters);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,14 @@
|
||||||
|
import {Redirect} from './base.js';
|
||||||
|
|
||||||
|
export type HostnameParameters = {
|
||||||
|
hostname: string;
|
||||||
|
type: 'hostname';
|
||||||
|
};
|
||||||
|
|
||||||
|
export class HostnameRedirect extends Redirect<HostnameParameters> {
|
||||||
|
public redirect(url: URL | string): URL {
|
||||||
|
const redirected = new URL(url);
|
||||||
|
redirected.hostname = this.parameters.hostname;
|
||||||
|
return redirected;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
/// <reference path="../source/types.d.ts" />
|
||||||
|
|
||||||
|
import test from 'ava';
|
||||||
|
|
||||||
|
import {
|
||||||
|
parseRedirect,
|
||||||
|
HostnameRedirect,
|
||||||
|
Redirect,
|
||||||
|
RedirectParameters,
|
||||||
|
} from '../source/redirect/exports.js';
|
||||||
|
|
||||||
|
test('parseRedirect', (t) => {
|
||||||
|
const samples: RedirectParameters[] = [
|
||||||
|
{
|
||||||
|
test: 'Invalid parameters',
|
||||||
|
} as unknown as RedirectParameters,
|
||||||
|
{
|
||||||
|
hostname: 'example.org',
|
||||||
|
type: 'hostname',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const sample of samples) {
|
||||||
|
const redirect = parseRedirect(sample);
|
||||||
|
|
||||||
|
if (redirect === undefined) {
|
||||||
|
t.pass('parseRedirect returned undefined');
|
||||||
|
} else {
|
||||||
|
t.snapshot(redirect, `Class ${redirect.constructor.name}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Redirect.redirect', (t) => {
|
||||||
|
const hostnameRedirect = new HostnameRedirect({
|
||||||
|
hostname: 'example.org',
|
||||||
|
type: 'hostname',
|
||||||
|
});
|
||||||
|
|
||||||
|
const samples: Array<[string, Redirect<RedirectParameters>]> = [
|
||||||
|
['https://example.com', hostnameRedirect],
|
||||||
|
['https://example.com/path#hash?query=test', hostnameRedirect],
|
||||||
|
];
|
||||||
|
|
||||||
|
for (const [index, [url, redirect]] of samples.entries()) {
|
||||||
|
t.snapshot(
|
||||||
|
{
|
||||||
|
original: url,
|
||||||
|
redirected: redirect.redirect(url).href,
|
||||||
|
},
|
||||||
|
`${index} ${redirect.constructor.name}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Snapshot report for `tests/redirect.test.ts`
|
||||||
|
|
||||||
|
The actual snapshot is saved in `redirect.test.ts.snap`.
|
||||||
|
|
||||||
|
Generated by [AVA](https://avajs.dev).
|
||||||
|
|
||||||
|
## parseRedirect
|
||||||
|
|
||||||
|
> Class HostnameRedirect
|
||||||
|
|
||||||
|
HostnameRedirect {
|
||||||
|
parameters: {
|
||||||
|
hostname: 'example.org',
|
||||||
|
type: 'hostname',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
## Redirect.redirect
|
||||||
|
|
||||||
|
> 0 HostnameRedirect
|
||||||
|
|
||||||
|
{
|
||||||
|
original: 'https://example.com',
|
||||||
|
redirected: 'https://example.org/',
|
||||||
|
}
|
||||||
|
|
||||||
|
> 1 HostnameRedirect
|
||||||
|
|
||||||
|
{
|
||||||
|
original: 'https://example.com/path#hash?query=test',
|
||||||
|
redirected: 'https://example.org/path#hash?query=test',
|
||||||
|
}
|
Binary file not shown.
|
@ -13,6 +13,7 @@
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"source/**/*.ts",
|
"source/**/*.ts",
|
||||||
|
"tests/**/*.ts",
|
||||||
"vite.config.ts"
|
"vite.config.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue