Skip to content

Commit

Permalink
feat: Export and bootstrap the /client package
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Jun 25, 2023
1 parent e6c0d84 commit 5b07c95
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 52 deletions.
6 changes: 6 additions & 0 deletions demo/entrypoints/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineBackgroundScript } from 'exvite/client';
import browser from 'webextension-polyfill';

export default defineBackgroundScript(() => {
console.log(browser.runtime.id);
});
13 changes: 13 additions & 0 deletions demo/entrypoints/options/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Extension Settings</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<p>Hello options page!</p>
<script type="module" src="./main.ts"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions demo/entrypoints/options/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import browser from 'webextension-polyfill';

console.log(browser.runtime.id);
4 changes: 4 additions & 0 deletions demo/entrypoints/options/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
html {
background: black;
color: white;
}
11 changes: 11 additions & 0 deletions demo/entrypoints/overlay.content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { defineContentScript, mountContentScriptUi } from 'exvite/client';
import browser from 'webextension-polyfill';

export default defineContentScript({
matches: ['*://*/*'],
async main() {
console.log(browser.runtime.id);

mountContentScriptUi();
},
});
11 changes: 11 additions & 0 deletions demo/entrypoints/popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Popup</title>
</head>
<body>
<p>Hello popup!</p>
</body>
</html>
7 changes: 4 additions & 3 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
"build": "pnpm -w build && exvite build",
"prepare": "pnpm -w build && exvite prepare"
},
"dependencies": {
"webextension-polyfill": "^0.10.0"
},
"devDependencies": {
"@types/webextension-polyfill": "^0.10.0",
"exvite": "workspace:*"
},
"dependencies": {
"unimport": "^3.0.8"
}
}
4 changes: 4 additions & 0 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../tsconfig.base.json",
"exclude": [".output"]
}
1 change: 1 addition & 0 deletions demo/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default console;
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"files": [
"dist"
],
"bin": "dist/cli.cjs",
"bin": "dist/cli/index.cjs",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -25,13 +25,19 @@
"require": "./dist/index.cjs",
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./client": {
"require": "./dist/client/index.cjs",
"import": "./dist/client/index.js",
"types": "./dist/client/index.d.ts"
}
},
"scripts": {
"dev": "tsx src/cli.ts",
"build": "run-s build:*",
"build:js": "tsup src/index.ts --clean --sourcemap --dts --format esm,cjs",
"build:cli": "tsup src/cli.ts",
"build:cli": "tsup src/cli/index.ts -d dist/cli --sourcemap",
"build:client": "tsup src/client/index.ts -d dist/client --sourcemap --dts --format esm,cjs",
"format": "prettier --write .",
"format:check": "prettier --write .",
"prepare": "simple-git-hooks"
Expand Down
47 changes: 0 additions & 47 deletions src/cli.ts

This file was deleted.

14 changes: 14 additions & 0 deletions src/client/defineBackgroundScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { BackgroundScriptDefintition } from '..';

export function defineBackgroundScript(
main: () => void,
): BackgroundScriptDefintition;
export function defineBackgroundScript(
definition: BackgroundScriptDefintition,
): BackgroundScriptDefintition;
export function defineBackgroundScript(
arg: (() => void) | BackgroundScriptDefintition,
): BackgroundScriptDefintition {
if (typeof arg === 'function') return { main: arg };
return arg;
}
7 changes: 7 additions & 0 deletions src/client/defineContentScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ContentScriptDefinition } from '../types';

export function defineContentScript(
definition: ContentScriptDefinition,
): ContentScriptDefinition {
return definition;
}
3 changes: 3 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './defineContentScript';
export * from './defineBackgroundScript';
export * from './mountContentScriptUi';
3 changes: 3 additions & 0 deletions src/client/mountContentScriptUi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function mountContentScriptUi() {
throw Error('Not implemented: mountContentScriptUi');
}

0 comments on commit 5b07c95

Please sign in to comment.