Compare commits

...

7 Commits

12 changed files with 150 additions and 20 deletions
+1
View File
@@ -21,3 +21,4 @@ docs/api/reference
stats.html
.tool-versions
.cache
*-stats.txt
+15
View File
@@ -57,6 +57,21 @@ pnpm test
pnpm docs:dev
```
## Profiling
```sh
# Build the latest version
pnpm --filter wxt build
# CD to the demo directory
cd packages/wxt-demo
# 1. Generate a flamechart with 0x
pnpm dlx 0x node_modules/wxt/bin/wxt.mjs build
# 2. Inspect the process with chrome @ chrome://inspect
pnpm node --inspect node_modules/wxt/bin/wxt.mjs build
```
## Updating Docs
Documentation is written with VitePress, and is located in the `docs/` directory.
+3 -1
View File
@@ -35,4 +35,6 @@ Only MV3 support ESM background scripts/service workers. When targeting MV2, the
## Content Scripts
Coming soon. Follow [Content Script ESM Support #357](https://github.com/wxt-dev/wxt/issues/357) for updates.
WXT does not include built-in support for ESM content scripts. There are several technical issues that make implementing a generic solution impossible. See [Content Script ESM Support #357](https://github.com/wxt-dev/wxt/issues/357) for details.
Instead, depending on your requirements, you can implement ESM support manually. See the [ESM Content Script UI](https://github.com/wxt-dev/examples/tree/main/examples/esm-content-script-ui) example to get started.
+17
View File
@@ -1,5 +1,22 @@
# Changelog
## v0.19.6
[compare changes](https://github.com/wxt-dev/wxt/compare/wxt-v0.19.5...wxt-v0.19.6)
### 🔥 Performance
- Ignore non-source code from the file watcher ([#919](https://github.com/wxt-dev/wxt/pull/919))
### 🩹 Fixes
- Typo in sidepanel options (`browse_style``browser_style`) ([#914](https://github.com/wxt-dev/wxt/pull/914))
- **types:** Don't report type errors when using string templates with `browser.i18n.getMessage` ([#916](https://github.com/wxt-dev/wxt/pull/916))
### ❤️ Contributors
- 1natsu
## v0.19.5
[compare changes](https://github.com/wxt-dev/wxt/compare/wxt-v0.19.4...wxt-v0.19.5)
@@ -126,7 +126,7 @@ describe('TypeScript Project', () => {
export interface WxtI18n extends I18n.Static {
/**
* The extension or app ID; you might use this string to construct URLs for resources inside the extension. Even unlocalized extensions can use this message.
Note: You can't use this message in a manifest file.
* Note: You can't use this message in a manifest file.
*
* "<browser.runtime.id>"
*/
@@ -136,8 +136,6 @@ describe('TypeScript Project', () => {
options?: GetMessageOptions,
): string;
/**
* No message description.
*
* "<browser.i18n.getUiLocale()>"
*/
getMessage(
@@ -215,6 +213,11 @@ describe('TypeScript Project', () => {
substitutions?: string | string[],
options?: GetMessageOptions,
): string;
getMessage(
messageName: "@@extension_id" | "@@ui_locale" | "@@bidi_dir" | "@@bidi_reversed_dir" | "@@bidi_start_edge" | "@@bidi_end_edge" | "prompt_for_name" | "hello" | "bye",
substitutions?: string | string[],
options?: GetMessageOptions,
): string;
}
}
"
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "wxt",
"type": "module",
"version": "0.19.5",
"version": "0.19.6",
"description": "Next gen framework for developing web extensions",
"repository": {
"type": "git",
@@ -287,6 +287,9 @@ export async function createViteBuilder(
strictPort: true,
host: info.hostname,
origin: info.origin,
watch: {
ignored: [`${wxtConfig.outBaseDir}/**`, `${wxtConfig.wxtDir}/**`],
},
},
};
const baseConfig = await getBaseConfig();
+2 -5
View File
@@ -145,11 +145,6 @@ function createFileReloader(server: WxtDevServer) {
const changeQueue: Array<[string, string]> = [];
return async (event: string, path: string) => {
await wxt.reloadConfig();
// Here, "path" is a non-normalized path (ie: C:\\users\\... instead of C:/users/...)
if (path.startsWith(wxt.config.outBaseDir)) return;
if (path.startsWith(wxt.config.wxtDir)) return;
changeQueue.push([event, path]);
await fileChangedMutex.runExclusive(async () => {
@@ -160,6 +155,8 @@ function createFileReloader(server: WxtDevServer) {
.map(([_, file]) => file);
if (fileChanges.length === 0) return;
await wxt.reloadConfig();
const changes = detectDevChanges(fileChanges, server.currentOutput);
if (changes.type === 'no-change') return;
@@ -387,7 +387,7 @@ async function getSidepanelEntrypoint(
const options = await getHtmlEntrypointOptions<SidepanelEntrypointOptions>(
info,
{
browserStyle: 'browse_style',
browserStyle: 'browser_style',
exclude: 'exclude',
include: 'include',
defaultIcon: 'default_icon',
@@ -150,18 +150,43 @@ declare module "wxt/browser" {
messages = parseI18nMessages({});
}
const overrides = messages.map((message) => {
return ` /**
* ${message.description || 'No message description.'}
*
* "${message.message}"
*/
getMessage(
messageName: "${message.name}",
const renderGetMessageOverload = (
keyType: string,
description?: string,
translation?: string,
) => {
const commentLines: string[] = [];
if (description) commentLines.push(...description.split('\n'));
if (translation) {
if (commentLines.length > 0) commentLines.push('');
commentLines.push(`"${translation}"`);
}
const comment =
commentLines.length > 0
? `/**\n${commentLines.map((line) => ` * ${line}`.trimEnd()).join('\n')}\n */\n `
: '';
return ` ${comment}getMessage(
messageName: ${keyType},
substitutions?: string | string[],
options?: GetMessageOptions,
): string;`;
});
};
const overrides = [
// Generate individual overloads for each message so JSDoc contains description and base translation.
...messages.map((message) =>
renderGetMessageOverload(
`"${message.name}"`,
message.description,
message.message,
),
),
// Include a final union-based override so TS accepts valid string templates or concatinations
// ie: browser.i18n.getMessage(`some_enum_${enumValue}`)
renderGetMessageOverload(
messages.map((message) => `"${message.name}"`).join(' | '),
),
];
return {
path: 'types/i18n.d.ts',
+26
View File
@@ -0,0 +1,26 @@
diff --git a/packages/wxt/src/core/runners/web-ext.ts b/packages/wxt/src/core/runners/web-ext.ts
index 09819c3..a0f0df2 100644
--- a/packages/wxt/src/core/runners/web-ext.ts
+++ b/packages/wxt/src/core/runners/web-ext.ts
@@ -3,6 +3,8 @@ import { ExtensionRunner } from '../../types';
import { formatDuration } from '../utils/time';
import defu from 'defu';
import { wxt } from '../wxt';
+import fs from 'node:fs';
+import stream from 'node:stream/promises';
/**
* Create an `ExtensionRunner` backed by `web-ext`.
@@ -78,6 +80,12 @@ export function createWebExtRunner(): ExtensionRunner {
const duration = Date.now() - startTime;
wxt.logger.success(`Opened browser in ${formatDuration(duration)}`);
+ await runner.exit();
+ const s = fs.createWriteStream('stats.txt', { flags: 'a' });
+ s.write(duration + ' ');
+ s.end();
+ await stream.finished(s);
+ process.exit(0);
},
async closeBrowser() {
+41
View File
@@ -0,0 +1,41 @@
#!/bin/bash
set -e
#
# Benchmark how long it takes for the browser to open in dev mode.
#
# To run:
# cd <root>
# ./scripts/benchmarks/browser-startup.sh
#
# You can set N below to change the number of samples per git ref.
#
N=20
function benchmark_ref() {
# Prep
git checkout $1
pnpm buildc clean
git apply scripts/benchmarks/browser-startup.patch
pnpm i --ignore-scripts
pnpm -r --filter wxt build
echo -n "$1 " >> stats.txt
# Run benchmark
for i in $(seq $N); do
pnpm wxt packages/wxt-demo
done
git checkout HEAD -- packages/wxt/src/core/runners/web-ext.ts pnpm-lock.yaml
echo "" >> stats.txt
}
rm -f stats.txt
benchmark_ref "HEAD"
# Benchmark a commit:
# benchmark_ref "3109bba"
#
# Benchmark a version:
# benchmark_ref "v0.19.0"